More optimization, add constants file for eventual descructible scenery.
This commit is contained in:
parent
130c393c51
commit
3a9fac53f0
45
constants.lua
Normal file
45
constants.lua
Normal 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
|
|
@ -22,6 +22,7 @@
|
||||||
65 - wood
|
65 - wood
|
||||||
66 - mushroom
|
66 - mushroom
|
||||||
67 - cactus meat
|
67 - cactus meat
|
||||||
|
68 - cactus flower
|
||||||
|
|
||||||
### sfx
|
### sfx
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
pico-8 cartridge // http://www.pico-8.com
|
pico-8 cartridge // http://www.pico-8.com
|
||||||
version 18
|
version 18
|
||||||
__lua__
|
__lua__
|
||||||
|
#include constants.lua
|
||||||
#include sound.lua
|
#include sound.lua
|
||||||
#include mapgen.lua
|
#include mapgen.lua
|
||||||
#include player.lua
|
#include player.lua
|
||||||
|
|
1
main.lua
1
main.lua
|
@ -1,4 +1,5 @@
|
||||||
function _init()
|
function _init()
|
||||||
|
init_constants()
|
||||||
init_sound()
|
init_sound()
|
||||||
init_mapgen()
|
init_mapgen()
|
||||||
init_player(32, 32)
|
init_player(32, 32)
|
||||||
|
|
10
mapgen.lua
10
mapgen.lua
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
function init_mapgen()
|
function init_mapgen()
|
||||||
uid_seed = 2229 -- arbitrarily chosen number
|
uid_seed = 2229 -- arbitrarily chosen number
|
||||||
-- block_size = 64
|
|
||||||
-- biome_size = 128
|
|
||||||
|
|
||||||
-- Metadata for different biomes
|
-- Metadata for different biomes
|
||||||
-- frequencies don't have to add up to 100, but they should by convention
|
-- 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]
|
local biome = biome_list[i]
|
||||||
|
|
||||||
-- add the biome's name N times to the biome metadata 'hat'
|
-- 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)
|
add(biome_metadata, biome)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,7 +45,7 @@ end
|
||||||
-- build the lookup table for a given biome, based on the biome_meta data for
|
-- build the lookup table for a given biome, based on the biome_meta data for
|
||||||
-- that string.
|
-- that string.
|
||||||
function build_biome(biome_name, data)
|
function build_biome(biome_name, data)
|
||||||
local meta_frequencies = data["tile_frequencies"]
|
local meta_frequencies = data.tile_frequencies
|
||||||
local tile_lookup = {}
|
local tile_lookup = {}
|
||||||
|
|
||||||
for i=1,#meta_frequencies do
|
for i=1,#meta_frequencies do
|
||||||
|
@ -57,7 +55,7 @@ function build_biome(biome_name, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
data["tile_lookup"] = tile_lookup
|
data.tile_lookup = tile_lookup
|
||||||
end
|
end
|
||||||
|
|
||||||
-- generates a unique identifier for a position
|
-- 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 biome = biome_data[biome_name]
|
||||||
local uid = generate_uid(pos_x, pos_y)
|
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
|
end
|
||||||
|
|
||||||
-- generate the map and writes to the map area from 0 - block_size,
|
-- generate the map and writes to the map area from 0 - block_size,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user