Skip to content

Instantly share code, notes, and snippets.

@dermotbalson
Created May 9, 2013 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dermotbalson/5545776 to your computer and use it in GitHub Desktop.
Save dermotbalson/5545776 to your computer and use it in GitHub Desktop.
nav1
--# Main
-- Navigator
function setup()
x,y=200,200 --starting position
dx,dy=0,0 --velocities
s=10 --speed change/second per tap
end
function draw()
background(220)
pushStyle()
fill(255,255,0,100)
x,y=x+dx/60,y+dy/60
ellipse(x,y,50)
popStyle()
end
function touched(touch)
local t=false --to tell us if touch has been located yet
--change y speed if in outer 1/4 of screen
if touch.y<HEIGHT/4 then dy=dy-s t=true
elseif touch.y>HEIGHT*.75 then dy=dy+s t=true
end
--change x speed if in top/bottom 1/4 of screen
if touch.x<WIDTH/4 then dx=dx-s t=true
elseif touch.x>WIDTH*.75 then dx=dx+s t=true
end
--stop moving otherwise
if t==false then dx,dy=0,0 end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment