Created
May 9, 2013 05:41
-
-
Save dermotbalson/5545776 to your computer and use it in GitHub Desktop.
nav1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--# 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