Skip to content

Instantly share code, notes, and snippets.

Created August 11, 2014 06:00
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 anonymous/d312a327e7c72af8eaff to your computer and use it in GitHub Desktop.
Save anonymous/d312a327e7c72af8eaff to your computer and use it in GitHub Desktop.
Gists Codea Upload
--# Main
--[[TITLE: flies]]
--[[AUTHOR: dave1707]]
--[[DESCRIPTION: Smash the files to get highest score.
]]
displayMode(FULLSCREEN)
function setup()
fx=WIDTH/2
fy=HEIGHT/2
dx,dy=0,0
x1,y1=0,0
hit=0
miss=0
score=0
end
function draw()
background(40, 40, 50)
if math.random(2)==1 then
sprite("Platformer Art:Battor Flap 1",fx,fy)
else
sprite("Platformer Art:Battor Flap 2",fx,fy)
end
x1=x1-1
if x1<0 then
dx=math.random(-1,1)*score -- change fly x direction
x1=20
end
y1=y1-1
if y1<0 then
dy=math.random(-1,1)*score -- change fly y direction
y1=20
end
fx=fx+dx -- update fly position
fy=fy+dy
if fx>WIDTH then -- check if fly is off screen
fx=0
end
if fx<0 then
fx=WIDTH
end
if fy>HEIGHT then -- check if fly is off screen
fy=0
end
if fy<0 then
fy=HEIGHT
end
fontSize(20)
fill(255)
text("Hits "..hit,WIDTH/2,HEIGHT-50)
text("Miss "..miss,WIDTH/2,HEIGHT-100)
fontSize(40)
score=hit-miss
if score<0 then
score=0
end
text("Score "..score,WIDTH/2,HEIGHT-150)
end
function touched(t)
if t.state==BEGAN then
v1=vec2(fx,fy) -- center of fly
d=v1:dist(vec2(t.x,t.y)) -- check touch distance to center of the fly
if d<40 then
hit=hit+1 -- fly was hit
fx=math.random(50,WIDTH-50)
fy=math.random(50,HEIGHT-50)
else
miss=miss+1 -- fly was missed
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment