Compress location data into a single byte.

This commit is contained in:
Anna Rose Wiggins 2019-12-11 19:23:28 -05:00
parent ea8b0360bc
commit c86589ec6a
3 changed files with 42 additions and 35 deletions

View file

@ -5,16 +5,21 @@ function init_savegame()
end
function load_game()
player_x = dget(0)
player_y = dget(1)
local pos = dget"0"
player_x = flr(pos)
player_y = shl(pos, 16)
end
function save_game()
dset(0, player_x)
dset(1, player_y)
-- store location in 1 byte by packing Y position into the nominal
-- fraction section.
local pos = bor(player_x, lshr(player_y, 16))
dset(0, pos)
end
-- delete the save data
function clear_save()
memset(0x5e00, 0, 256)
init_world""
init_player""
end