-- 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 = 68 }, -- tree [4] = { replacement = 14, sfx = 11, drop = 64 }, -- big mushroom [8] = { replacement = 16, sfx = 12, drop = 65 }, -- cactus w/ flower [10] = { replacement = 15, sfx = 12, drop = 67 }, -- cactus [13] = { replacement = 15, sfx = 12, drop = 66 } } -- 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 get_mod_key(x, y) return tostr(x) .. ":" .. tostr(y) end -- x and y are map-local 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 cull_mod_buffer() end mod_buffer[get_mod_key(global_x, global_y)] = new_sprite end function cull_mod_buffer() -- we cull 10% of the mod buffer at a time -- todo: implement this 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