More optimization, add constants file for eventual descructible scenery.

This commit is contained in:
Anna Rose 2019-12-09 16:51:15 -05:00
parent 130c393c51
commit 3a9fac53f0
5 changed files with 52 additions and 6 deletions

45
constants.lua Normal file
View File

@ -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

View File

@ -22,6 +22,7 @@
65 - wood
66 - mushroom
67 - cactus meat
68 - cactus flower
### sfx
---

View File

@ -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

View File

@ -1,4 +1,5 @@
function _init()
init_constants()
init_sound()
init_mapgen()
init_player(32, 32)

View File

@ -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,