Last active
April 7, 2017 05:36
-
-
Save byronhulcher/73f7765cfdab5b6d4ae1f72b72714ef3 to your computer and use it in GitHub Desktop.
PICO-8 Starter LUA code (save this as starter.p8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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