39 lines
972 B
Lua
39 lines
972 B
Lua
function _init()
|
|
init_sound""
|
|
init_world""
|
|
init_player(32, 32)
|
|
init_debug""
|
|
end
|
|
|
|
|
|
function _update()
|
|
handle_input""
|
|
-- handle_map_update""
|
|
end
|
|
|
|
function _draw()
|
|
cls""
|
|
-- the screen is 128x128 pixels, so it fits 16x16 sprites
|
|
-- map(camera_pos_x, camera_pos_y, 0, 0, 16, 16)
|
|
draw_world_segment(player_pos_x, player_pos_y)
|
|
draw_player""
|
|
debug_print""
|
|
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
|