Skip to content

Instantly share code, notes, and snippets.

@qolop
Created February 19, 2016 22:58
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 qolop/48448f98b30c6636b059 to your computer and use it in GitHub Desktop.
Save qolop/48448f98b30c6636b059 to your computer and use it in GitHub Desktop.
Wallvoid, a simple game made in Codea where the user must tap before the UFO exits the screen, the UFO then heading in a semi-opposite direction. http://twolivesleft.com/Codea/
--This game only works in the Codea app for iPad (which uses Lua); http://twolivesleft.com/Codea/
--This code was originally made in April 2014.
function setup()
score = 0
hit = 0
x=380 --starting x
y=400 --starting y
d=100 --diameter of ball
dx = 0
dy = 0
k = 0
alrighty = 0
end
function draw()
background(0, 0, 0, 255)
pushStyle()
sprite("Space Art:UFO",x,y,d)
font("HelveticaNeue-Bold")
textAlign(CENTER)
fill(255, 255, 255, 255)
--lel = string.format("%.f",(ElapsedTime - alrighty))
if score == 0 then
alrighty = ElapsedTime
elseif score == 1 then
alrighty = ElapsedTime
end
text("Score: " .. score .. "\n\nTap screen when UFO is about to hit wall.\n\nYou have survived for " .. string.format("%.f",(ElapsedTime - alrighty)) .. " seconds.", 380, 555)
fontSize(50)
popStyle()
--[[ change direction if we hit a wall
if x>WIDTH-d/2 or x<d/2 then dx=-dx score = score + 1 print("You hit a wall! Try again") end
if y>HEIGHT-d/2 or y<d/2 then dy=-dy end
]]
if x>WIDTH-d/2 or x<d/2 or y>HEIGHT-d/2 or y<d/2 then y = 400 x = 380 oldscore = score print("You just got a score of " .. oldscore .. "!") score = 0 dx = 0 dy = 0 k = 0 else x=x+dx
y=y+dy end
end
function touched(touch)
if touch.state == BEGAN then
k = k + 1
if k == 1 then
dx=2 --the amount x changes
dy=2 --the amount y changes
score = score + 2
end
if touch.state == MOVING or touch.state == BEGAN and k > 1 then
if dx > 0 then
dx= math.random(-6, -2) --the amount x changes
dy= math.random(-6, -2) --the amount y changes
score = score + 1
elseif dx < 0 then
dx=math.random(2,6)
dy=math.random(2,6)
end
if y > 619 or y < 101 then
score = score + math.random(8,11)
elseif x > 619 or x < 101 then
score = score + math.random(8,11)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment