64 lines
1.5 KiB
Lua
64 lines
1.5 KiB
Lua
function _init()
|
|
init_data()
|
|
init_sound()
|
|
init_mapgen()
|
|
init_player(32, 32)
|
|
generate_map(0, 0)
|
|
debug = false
|
|
end
|
|
|
|
|
|
function _update()
|
|
handle_input()
|
|
handle_map_update()
|
|
end
|
|
|
|
function _draw()
|
|
rectfill(0, 0, 127, 127, 0)
|
|
-- the screen is 128x128 pixels, so it fits 16x16 sprites
|
|
map(camera_pos_x, camera_pos_y, 0, 0, 16, 16)
|
|
draw_player()
|
|
if debug then
|
|
render_debug_info()
|
|
end
|
|
end
|
|
|
|
-- decide whether we need to regenerate the map.
|
|
-- if so, call generate_map appropriately and reset coordinates.
|
|
function handle_map_update()
|
|
if out_of_bounds(camera_pos_x, camera_pos_y) then
|
|
-- out_of_bounds() checks all screen bounds
|
|
-- we need to regenerate the map, so we generate a map chunk that
|
|
-- places the player in the middle of it.
|
|
generate_map(player_pos_x-32, player_pos_y-32)
|
|
camera_pos_x, camera_pos_y = 24, 24
|
|
end
|
|
end
|
|
|
|
function out_of_bounds(pos_x, pos_y)
|
|
return pos_x < 0 or pos_x > 48 or
|
|
pos_y < 0 or pos_y > 48
|
|
end
|
|
|
|
function debug_res()
|
|
print("mem: " + stat(0))
|
|
print("cpu: " + stat(1))
|
|
print("fps: " .. stat(9) .. " / " .. stat(8))
|
|
end
|
|
|
|
function debug_sfx()
|
|
print("Music pattern: " .. stat(24))
|
|
end
|
|
|
|
function debug_map()
|
|
print("Local: " .. camera_pos_x .. " " .. camera_pos_y)
|
|
print("Global: " .. player_pos_x .. " " .. player_pos_y)
|
|
print(get_biome_name(player_pos_x, player_pos_y))
|
|
end
|
|
|
|
function debug_mod_buffer()
|
|
for k,v in pairs(mod_buffer) do
|
|
print(k .. ": " .. tostr(v))
|
|
end
|
|
end
|