a_pleasant_stroll/main.lua

40 lines
953 B
Lua
Raw Normal View History

2019-12-04 23:48:04 +00:00
function _init()
init_data()
2019-12-09 01:43:32 +00:00
init_sound()
2019-12-04 23:48:04 +00:00
init_mapgen()
init_player(32, 32)
generate_map(0, 0)
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()
cls()
-- the screen is 128x128 pixels, so it fits 16x16 sprites
map(camera_pos_x, camera_pos_y, 0, 0, 16, 16)
2019-12-04 23:48:04 +00:00
draw_player()
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()
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.
generate_map(player_pos_x-32, player_pos_y-32)
camera_pos_x, camera_pos_y = 24, 24
2019-12-07 20:36:32 +00:00
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