2019-12-04 23:48:04 +00:00
|
|
|
function _init()
|
2019-12-10 02:50:06 +00:00
|
|
|
init_data()
|
2019-12-09 01:43:32 +00:00
|
|
|
init_sound()
|
2019-12-04 23:48:04 +00:00
|
|
|
init_mapgen()
|
2019-12-09 21:35:45 +00:00
|
|
|
init_player(32, 32)
|
|
|
|
generate_map(0, 0)
|
2019-12-11 05:29:02 +00:00
|
|
|
init_debug()
|
2019-12-04 23:48:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function _update()
|
|
|
|
handle_input()
|
2019-12-07 20:36:32 +00:00
|
|
|
handle_map_update()
|
2019-12-04 23:48:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _draw()
|
|
|
|
rectfill(0, 0, 127, 127, 0)
|
2019-12-06 04:09:01 +00:00
|
|
|
-- the screen is 128x128 pixels, so it fits 16x16 sprites
|
2019-12-09 21:35:45 +00:00
|
|
|
map(camera_pos_x, camera_pos_y, 0, 0, 16, 16)
|
2019-12-04 23:48:04 +00:00
|
|
|
draw_player()
|
2019-12-11 05:29:02 +00:00
|
|
|
debug_print()
|
2019-12-04 23:48:04 +00:00
|
|
|
end
|
2019-12-06 03:03:05 +00:00
|
|
|
|
2019-12-07 20:36:32 +00:00
|
|
|
-- decide whether we need to regenerate the map.
|
|
|
|
-- if so, call generate_map appropriately and reset coordinates.
|
|
|
|
function handle_map_update()
|
2019-12-09 21:35:45 +00:00
|
|
|
if out_of_bounds(camera_pos_x, camera_pos_y) then
|
|
|
|
-- out_of_bounds() checks all screen bounds
|
2019-12-07 20:36:32 +00:00
|
|
|
-- we need to regenerate the map, so we generate a map chunk that
|
|
|
|
-- places the player in the middle of it.
|
2019-12-09 21:35:45 +00:00
|
|
|
generate_map(player_pos_x-32, player_pos_y-32)
|
2019-12-09 23:50:20 +00:00
|
|
|
camera_pos_x, camera_pos_y = 24, 24
|
2019-12-07 20:36:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-09 21:35:45 +00:00
|
|
|
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
|
|
|
|
|
2019-12-11 05:29:02 +00:00
|
|
|
-- debug functions toggle debug status displays along the
|
|
|
|
-- top of the screen
|
|
|
|
function init_debug()
|
|
|
|
debug_res = false
|
|
|
|
debug_map = false
|
|
|
|
debug_sfx = false
|
|
|
|
debug_mod_buffer = false
|
|
|
|
end
|
|
|
|
|
|
|
|
function debug_t(mode)
|
|
|
|
if mode == "res" then
|
|
|
|
debug_res = not debug_res
|
|
|
|
elseif mode == "map" then
|
|
|
|
debug_map = not debug_map
|
|
|
|
elseif mode == "sfx" then
|
|
|
|
debug_sfx = not debug_sfx
|
|
|
|
elseif mode == "" then
|
|
|
|
debug_mod_buffer = not debug_mod_buffer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function debug_print()
|
|
|
|
if debug_res then
|
|
|
|
debug_print_res()
|
|
|
|
end
|
|
|
|
|
|
|
|
if debug_map then
|
|
|
|
debug_print_map()
|
|
|
|
end
|
|
|
|
|
|
|
|
if debug_sfx then
|
|
|
|
debug_print_sfx()
|
|
|
|
end
|
|
|
|
|
|
|
|
if debug_mod_buffer then
|
|
|
|
debug_print_mod_buffer()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function debug_print_res()
|
|
|
|
clip(70, 0, 16, 24)
|
|
|
|
print(stat(0), 70, 0, 15)
|
|
|
|
print(stat(1), 70, 8, 15)
|
|
|
|
print(stat(9) .. " / " .. stat(8), 70, 16, 15)
|
|
|
|
clip()
|
2019-12-07 20:36:32 +00:00
|
|
|
end
|
|
|
|
|
2019-12-11 05:29:02 +00:00
|
|
|
function debug_print_sfx()
|
|
|
|
clip(64, 0, 8, 8)
|
|
|
|
print(stat(24), 64, 0, 15)
|
|
|
|
clip()
|
2019-12-10 02:50:06 +00:00
|
|
|
end
|
2019-12-09 21:35:45 +00:00
|
|
|
|
2019-12-11 05:29:02 +00:00
|
|
|
function debug_print_map()
|
|
|
|
clip(24, 0, 32, 24)
|
|
|
|
print(camera_pos_x .. " " .. camera_pos_y, 24, 0, 15)
|
|
|
|
print(player_pos_x .. " " .. player_pos_y, 24, 8, 15)
|
|
|
|
print(get_biome_name(player_pos_x, player_pos_y), 24, 16, 15)
|
|
|
|
clip()
|
2019-12-10 02:50:06 +00:00
|
|
|
end
|
2019-12-09 21:35:45 +00:00
|
|
|
|
2019-12-11 05:29:02 +00:00
|
|
|
function debug_print_mod_buffer()
|
|
|
|
clip(0, 0, 16, 128)
|
2019-12-10 02:50:06 +00:00
|
|
|
for k,v in pairs(mod_buffer) do
|
|
|
|
print(k .. ": " .. tostr(v))
|
2019-12-09 21:35:45 +00:00
|
|
|
end
|
2019-12-11 05:29:02 +00:00
|
|
|
clip()
|
2019-12-06 03:03:05 +00:00
|
|
|
end
|