Thanks to HTML export, it's now possible to run picotron cartridges on a mobile phone.
However, at present the DPAD isn't displayed, and touch operations are replaced by mouse movements, making operation very uncomfortable.
So I wrote the following code to simulate touch operations.
This also led me to notice some strange behavior, but that's another story.
I'd be happy if the picotron itself could support touch operations in the future.
function _init()
window{cursor=0} -- Hide the mouse cursor
tch = touch.new() -- Initializing the touch structure
end
function _draw()
-- Touch Structure Update. This is necessary to determine touch.
tch:check()
--[[
*** Wait until it truly becomes the initial state ***
Since _init cannot fully initialize, it waits for time to pass in the main program.
It seems that the time t() stops in _init, and the mouse position does not change.
It seems that time progresses entirely within _draw(_update).
This is to prevent unnecessary tap events from occurring because a touch is
determined by moving the position of the mouse cursor, and the initial position of
the mouse cannot be obtained correctly.
There may be a way to avoid this using memory manipulation, etc.
This decision statement is clearly a waste of processing.
--]]
if t() < 0.2 then return end
-- Processes when it is determined that a touch has occurred.
if tch.tap then
splatter(tch.x, tch.y)
end
end
--[[
It's not used within the program, but is useful
for making the mouse cursor visible again.
--]]
function rst()
cls()
window { cursor=1 }
end
--[[
Creates an ink splatter effect.
This is just to make the examples a bit more interesting. Have fun!
--]]
function splatter(x, y)
local col = flr(rnd(31)+1)
local mdist = rnd(20)+10
for i=0,mdist do
local ang = rnd(1)
local dist = rnd(mdist)
local rad = rnd(mdist-dist)
local xx = dist * cos(ang) + x
local yy = dist * sin(ang) + y
circfill(xx, yy, rad, col)
end
end
--[[
Touch Structure
This determines if a tap has been performed by touch
operation when the mouse cursor is moved.
--]]
touch = {}
touch.new = function()
local x, y, _ = mouse()
local obj = {}
obj.x = 0
obj.y = 0
obj.tap = false
obj.check = function(self)
local x, y, _ = mouse()
if self.tap == false and (x != self.x or y != self.y) then
self.x = x
self.y = y
self.tap = true
else
self.tap = false
end
end
return obj
end
|
[Please log in to post a comment]




