Skip to content

Instantly share code, notes, and snippets.

@abehmiel
Forked from byronhulcher/starter.lua
Created April 7, 2017 05:36
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 abehmiel/161575bb3d4ce1f9baea4245e87ad32f to your computer and use it in GitHub Desktop.
Save abehmiel/161575bb3d4ce1f9baea4245e87ad32f to your computer and use it in GitHub Desktop.
PICO-8 Starter LUA code (save this as starter.p8)
-- pico-8 starter code
-- by @hypirlink
-- _init() is called when
-- you 'run' the program
function _init()
-- states: menu, game, end
state = "menu"
end
-- checks if player 0
-- is pressing a or b
function pressing_button()
return btnp(4) or btnp(5)
end
function start_game()
state = "game"
timer = 300
end
function end_game()
state = "end"
timer = 0
end
function update_game()
timer -= 1
if (timer <= 0) then
end_game()
end
end
-- _update() is called once per
-- frame, before _draw()
function _update()
if (state == "menu" and pressing_button()) then
start_game()
elseif (state == "end" and pressing_button()) then
_init()
elseif (state == "game") then
update_game()
end
end
function draw_bg()
rectfill(0,0,128,128,0)
end
function draw_console()
print(state,0,0,11)
end
function draw_game()
print(timer,0,12,11)
end
-- _draw() is called once per
-- frame, after _update()
function _draw()
draw_bg()
if (state == "game") then
draw_game()
end
draw_console()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment