Skip to content

Instantly share code, notes, and snippets.

@dermotbalson
Created April 9, 2013 14:45
Show Gist options
  • Select an option

  • Save dermotbalson/5346269 to your computer and use it in GitHub Desktop.

Select an option

Save dermotbalson/5346269 to your computer and use it in GitHub Desktop.
21. Multi
--# Main
-- Main
function setup()
parameter.integer("Game",1,2,1)
games={Game1,Game2}
end
function SetupGame()
if g then g:cleanup() end
g=games[Game]
currGame=Game
g:init()
end
function draw()
background(40, 40, 50)
if Game~=currGame then SetupGame() end
g:draw()
end
function touched(touch)
g:touched(touch)
end
--# Game1
Game1 = class()
function Game1:init()
print("Game1 initialised")
end
function Game1:cleanup()
print("Game1 is cleaned up")
end
function Game1:draw()
fill(255,0,0)
rect(200,200,300,300)
end
function Game1:touched(touch)
if touch.state==ENDED then print("You touched Game1") end
end
--# Game2
Game2 = class()
function Game2:init()
print("Game2 initialised")
end
function Game2:cleanup()
print("Game2 is cleaned up")
end
function Game2:draw()
fill(0,255,0)
ellipse(200,200,300,300)
end
function Game2:touched(touch)
if touch.state==ENDED then print("You touched Game2") end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment