diff --git a/constants.lua b/constants.lua new file mode 100644 index 0000000..5e399c3 --- /dev/null +++ b/constants.lua @@ -0,0 +1,45 @@ +-- unavoidable table lookups used by multiple files are stored here. +-- nothing in here should +-- be changed at runtime. +-- +-- also has commented "fake constants" that are replaced by actual values, for +-- reference. +-- +-- see index_map.md for more "constant" values + +function init_constants() + -- block_size = 64 + -- biome_size = 128 + + -- the indices here are sprite numbers. + object_interaction_map = { + -- 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 + } + } + +end diff --git a/index_map.md b/index_map.md index da118b2..22a8fda 100644 --- a/index_map.md +++ b/index_map.md @@ -22,6 +22,7 @@ 65 - wood 66 - mushroom 67 - cactus meat +68 - cactus flower ### sfx --- diff --git a/infimap.p8 b/infimap.p8 index 640ff75..7a2fcc0 100644 --- a/infimap.p8 +++ b/infimap.p8 @@ -1,6 +1,7 @@ pico-8 cartridge // http://www.pico-8.com version 18 __lua__ +#include constants.lua #include sound.lua #include mapgen.lua #include player.lua diff --git a/main.lua b/main.lua index c746a82..bf80e43 100644 --- a/main.lua +++ b/main.lua @@ -1,4 +1,5 @@ function _init() + init_constants() init_sound() init_mapgen() init_player(32, 32) diff --git a/mapgen.lua b/mapgen.lua index 40c6fa8..f04f8fb 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -2,8 +2,6 @@ function init_mapgen() uid_seed = 2229 -- arbitrarily chosen number - -- block_size = 64 - -- biome_size = 128 -- Metadata for different biomes -- frequencies don't have to add up to 100, but they should by convention @@ -36,7 +34,7 @@ function init_mapgen() local biome = biome_list[i] -- add the biome's name N times to the biome metadata 'hat' - for i=1,biome_data[biome]["biome_frequency"] do + for i=1,biome_data[biome].biome_frequency do add(biome_metadata, biome) end @@ -47,7 +45,7 @@ end -- build the lookup table for a given biome, based on the biome_meta data for -- that string. function build_biome(biome_name, data) - local meta_frequencies = data["tile_frequencies"] + local meta_frequencies = data.tile_frequencies local tile_lookup = {} for i=1,#meta_frequencies do @@ -57,7 +55,7 @@ function build_biome(biome_name, data) end end - data["tile_lookup"] = tile_lookup + data.tile_lookup = tile_lookup end -- generates a unique identifier for a position @@ -90,7 +88,7 @@ function get_tile(pos_x, pos_y) local biome = biome_data[biome_name] local uid = generate_uid(pos_x, pos_y) - return biome["tile_lookup"][(uid % #biome["tile_lookup"]) + 1] + return biome.tile_lookup[(uid % #biome.tile_lookup) + 1] end -- generate the map and writes to the map area from 0 - block_size,