Skip to content

Commit

Permalink
State system for switching screens
Browse files Browse the repository at this point in the history
  • Loading branch information
irismessage committed Apr 27, 2022
1 parent 1da7244 commit 358a16c
Showing 1 changed file with 64 additions and 10 deletions.
74 changes: 64 additions & 10 deletions cart/bros.p8
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,49 @@ e = {
curs=1,
}

-- state
s = {
main=true,
hi=false,
entry=false,
play=false,
}

scoresn={}
scoresc={}

function _init()
loadfont()
loadscores()
-- mainscreen()
-- scorescreen()
askname()
mainscreen()
end

function _update()
-- g.timer -= 1
updatenameentry()
updatestate()

if s.main then
-- main screen
elseif s.hi then
-- high scores display
elseif s.entry then
updatenameentry()
elseif s.play then
-- levels
g.timer -= 1
end
end

function _draw()
scorebarl()
drawnameentry()
if s.main then
-- main screen
elseif s.hi then
-- high scores display
elseif s.entry then
drawnameentry()
elseif s.play then
-- levels
end
end

function mainscreen()
Expand All @@ -79,6 +103,32 @@ function scorescreen()
scorescol(64,6)
end

function updatestate()
if s.main then
if btnp(❎) then
-- s.main = false
-- s.play = true
elseif btnp(🅾️) then
s.main = false
s.hi = true
scorescreen()
end
elseif s.hi then
if btnp(❎) or btnp(🅾️) then
s.hi = false
s.main = true
mainscreen()
end
elseif s.entry then
if btnp(❎) then
savescore()
s.entry = false
s.hi = true
scorescreen()
end
end
end

-->8
--highscore system

Expand Down Expand Up @@ -157,7 +207,6 @@ function askname()
scorebars()
print("great score",42,40)
print("enter your name",34,56)
return "abc"
end

function drawnameentry()
Expand Down Expand Up @@ -187,11 +236,16 @@ function updatenameentry()
end
end

function savescore(num)
function checkscore(num)
rank = rankscore(num)
if (rank == 10) return
name = askname()
if (rank == 10) return false
shiftscores(rank)
return true
end

function savescore()
cs = e.text
name = cs[1]..cs[2]..cs[3]
dset(rank, num)
dset(rank+10, packname(name))
end
Expand Down

0 comments on commit 358a16c

Please sign in to comment.