Skip to content

Instantly share code, notes, and snippets.

@murilopolese
Last active July 10, 2016 09: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 murilopolese/bfeef4405fcf4d5faa14d7ce8f9e69c3 to your computer and use it in GitHub Desktop.
Save murilopolese/bfeef4405fcf4d5faa14d7ce8f9e69c3 to your computer and use it in GitHub Desktop.
PICO-8 Boilerplate
pico-8 cartridge // http://www.pico-8.com
version 8
__lua__
-- game boilerplate
-- by murilo
-- Game states
game_mode = "splash"
-- Event manager
function event( e, v )
if e == "hello" then
print "hello world!"
elseif e == "game:start" then
game_mode = "game"
elseif e == "game:over" then
game_mode = "gameover"
elseif e == "game:reset" then
game_mode = "splash"
else
print( e )
end
end
-- Keyboard listener
function controls_splash()
if btnp( 0 )
or btnp( 1 )
or btnp( 2 )
or btnp( 3 )
or btnp( 4 )
or btnp( 5 )
then
print "start game"
event( "game:start" )
end
end
function controls_gameover()
if btnp( 0 )
or btnp( 1 )
or btnp( 2 )
or btnp( 3 )
or btnp( 4 )
or btnp( 5 )
then
print "reset game"
event( "game:reset" )
end
end
function controls_game()
if btnp( 0 ) then
event( "p1:left" )
end
if btnp( 1 ) then
event( "p1:right" )
end
if btnp( 2 ) then
event( "p1:up" )
end
if btnp( 3 ) then
event( "p1:down" )
end
if btnp( 4 ) then
event( "p1:o" )
event( "hello" )
end
if btnp( 5 ) then
event( "p1:x" )
event( "game:over" )
end
end
-- Draw game modes
function draw_splash()
print "splash - press any key to start"
end
function draw_gameover()
print "game over - press any key to reset"
end
function draw_game()
end
------------------------
-- Update game modes
function update_splash()
end
function update_gameover()
end
function update_game()
end
------------------------
-- Runtime methods
function _init()
end
function _update()
if game_mode == "splash" then
controls_splash()
update_splash()
elseif game_mode == "gameover" then
controls_gameover()
update_gameover()
elseif game_mode == "game" then
controls_game()
update_game()
end
end
function _draw()
if game_mode == "splash" then
draw_splash()
elseif game_mode == "gameover" then
draw_gameover()
elseif game_mode == "game" then
draw_game()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment