Add interactability with some map objects, and store changed map tiles in a buffer for persistence.
This commit is contained in:
parent
89a63f59b8
commit
c6dd13d332
6 changed files with 120 additions and 92 deletions
74
data.lua
Normal file
74
data.lua
Normal file
|
@ -0,0 +1,74 @@
|
|||
-- data shared between modules goes here, both constants and mutable data.
|
||||
-- also contains some functions that act solely on the data
|
||||
--
|
||||
-- also has commented "fake constants" that are replaced by actual values, for
|
||||
-- reference.
|
||||
--
|
||||
-- also see index_map.md for more "constant" values
|
||||
|
||||
function init_data()
|
||||
-- block_size = 64
|
||||
-- biome_size = 128
|
||||
|
||||
-- the indices here are sprite numbers.
|
||||
object_interaction_map = {
|
||||
-- bush
|
||||
[3] = {
|
||||
replacement = 17,
|
||||
sfx = 13,
|
||||
drop = 69
|
||||
},
|
||||
|
||||
-- tree
|
||||
[4] = {
|
||||
replacement = 14,
|
||||
sfx = 11,
|
||||
drop = 65
|
||||
},
|
||||
|
||||
-- big mushroom
|
||||
[8] = {
|
||||
replacement = 16,
|
||||
sfx = 12,
|
||||
drop = 66
|
||||
},
|
||||
|
||||
-- cactus w/ flower
|
||||
[10] = {
|
||||
replacement = 15,
|
||||
sfx = 12,
|
||||
drop = 68
|
||||
},
|
||||
|
||||
-- cactus
|
||||
[13] = {
|
||||
replacement = 15,
|
||||
sfx = 12,
|
||||
drop = 67
|
||||
}
|
||||
}
|
||||
|
||||
-- initialize a ring buffer of changed positions. In use, this will be keyed
|
||||
-- using strings of the form mod_buffer["x+y"], using absolute world
|
||||
-- coordinates. this is to flatten the buffer so that #mod_cache is useful
|
||||
-- for checking against max_mod_entries.
|
||||
max_mod_entries = 4096
|
||||
mod_buffer = {}
|
||||
end
|
||||
|
||||
-- x and y are global coords
|
||||
function write_map_change(new_sprite, x, y)
|
||||
local global_x, global_y = calculate_world_pos(x, y)
|
||||
if #mod_buffer >= max_mod_entries then
|
||||
-- todo: make the buffer ring
|
||||
end
|
||||
|
||||
mod_buffer[tostr(global_x) .. "+" .. tostr(global_y)] = new_sprite
|
||||
end
|
||||
|
||||
function calculate_world_pos(x, y)
|
||||
-- player_pos_[xy] is world absolute, so we can get the world pos of map 0,0,
|
||||
-- then add x and y back in.
|
||||
return player_pos_x - camera_pos_x - 8 + x,
|
||||
player_pos_y - camera_pos_y - 8 + y
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue