Save/load system. Not golfed.

Saves the music flag, the last level the player played, and the furthest level reached. Loads music flag on launch. Title screen starts on most recent level played; when in "release configuration" the title screen will only let the player pick levels up to the maximum reached through gameplay, but right now this is replaced with the 31.

Save file can be wiped by holding the down arrow at the title screen.
This commit is contained in:
Kistaro Windrider 2023-01-02 12:55:45 -08:00
parent 7c209f1125
commit 7b931d1fba
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -8,8 +8,9 @@ real_modules={}
frame=0
function _init()
-- printh("restarting")
music_on()
_doall("init") end
_doall("init")
end
function _update()
frame+=1
if (frame%1==0) _doall("update") end
@ -17,12 +18,16 @@ function _draw()
_doall("draw") end
function music_on()
music(0)
if (stat(54) ~= 0) music(0)
persist.music=true
persist:write()
menuitem(3, "music: on", music_off)
end
function music_off()
music(-1)
persist.music=false
persist:write()
menuitem(3, "music: off", music_on)
end
@ -261,7 +266,7 @@ end
title={}
add(modules,title)
blinkcol=10
lvlshimmer = {4,9,10,10,9}
function title:draw()
cls(0)
-- this is right for 72x32
@ -270,22 +275,33 @@ function title:draw()
print("[nyeogmi]",62,73,7)
print("kistaro",32,79,7)
local lvlstr = "⬅️ "..start_level.." ➡️"
print(lvlstr,50,91,1)
print(lvlstr,51,90,blinkcol)
local lx, ly = 51+wrongbleep:vibrate(), 90+wrongbleep:vibrate()
print(lvlstr,lx-1,ly+1,1)
print(lvlstr,lx,ly,cycle(lvlshimmer))
end
start_level=0
max_level=31
function title:init()
start_level=persist.recent_level
-- max_level=persist.max_level
max_level = 31 --debugging/coding
wiped = false
end
function title:update()
blinkcol=9
if (time()*4\1%2==0) blinkcol=10
if (btnp"0") start_level-=1
if (btnp"1") start_level+=1
start_level%=max_level
if (btnp"4" or btnp"5") modules=real_modules _init() music(0)
start_level%=(max_level+1)
if btn"3" and not wiped then
wrongbleep:bleep()
if (wrongbleep:adequately_warned()) then
persist:wipe()
max_level = 0
start_level = 0
wiped=true
-- todo: sfx(kaboom!)
end
end
if (btnp"4" or btnp"5") modules=real_modules _init()
end
-->8
@ -308,6 +324,8 @@ function level:reinit(n)
self:load_dynobjs()
self:recollide_reanchor()
self:spawn_exit()
persist:lvlstart()
end
function level:restart()
@ -1715,6 +1733,7 @@ end
-->8
--wrongbleeps
wrongbleep={}
add(modules,wrongbleep)
add(real_modules,wrongbleep)
function wrongbleep:init()
self.duration=0
@ -1722,8 +1741,12 @@ function wrongbleep:init()
end
function wrongbleep:update()
if (self.duration>5) self.duration=5
if self.duration>0 then sfx(63,3) self.continuous+=1
else self.continuous=0 end
if self.duration>0 then
sfx(63,3)
self.continuous+=1
else
self.continuous=0
end
self.duration=max(self.duration-1,-4)
end
function wrongbleep:bleep(duration)
@ -1881,6 +1904,49 @@ function debugmouse:draw3()
pal()
end
-->8
-- save/load
persist={}
add(modules, persist)
add(real_modules, persist)
function persist:init0()
cartdata("ulimate_lizard_total_destruction_0_1")
self.init0 = self.read
self:read()
self.ready=true
end
function persist:read()
local m = dget(0) == 0
self.music = m
if m then music_on() else music_off() end
self.max_level = dget(1)
self.recent_level = dget(2)
end
function persist:wipe()
self.ready=false
for i=0,64 do
dset(i,0)
end
self:read()
self.ready=true
end
function persist:lvlstart()
self.recent_level = level.ix
self.max_level = max(self.max_level, level.ix)
self:write()
end
function persist:write()
if (not self.ready) return
dset(0, self.music and 0 or -1)
dset(1, self.max_level)
dset(2, self.recent_level)
end
__gfx__
000030000000002200003000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeff1ff1ff1fffffff1ffffff1fffffff1dddddddd111111110000000033300333
003333300000332200333330eeffffffffffffffffffffeee5e555e55e555e5eff1ff1ffffffffffffffffffffffffffdddddddd111111110cc00cc033300333