Clean up a few functions and get ready for new features.

This commit is contained in:
Anna Rose Wiggins 2019-12-09 16:12:48 -05:00
parent 15c76c3884
commit 753700c144
4 changed files with 52 additions and 30 deletions

View file

@ -7,20 +7,7 @@ function init_mapgen()
-- Metadata for different biomes
-- frequencies don't have to add up to 100, but they should by convention
--
-- Sprites are:
-- * 2 - grass
-- * 3 - bush
-- * 4 - tree
-- * 5 - red flowers
-- * 6 - pink flowers
-- * 7 - mushrooms
-- * 8 - big mushroom
-- * 9 - sand
-- * 10 - cactus with flower
-- * 11 - pebbles
-- * 12 - rock
-- * 13 - cactus
-- tile_frequencies tuples are {frequency, sprite_index}, see index_map.md
biome_data = {
grassland = {
biome_frequency = 75,
@ -92,17 +79,17 @@ end
-- determines which biome a given world map position should be,
-- returns the object out of the biome_data table
function get_biome(pos)
function get_biome_name(pos)
local biome_pos = calculate_biome_pos(pos)
local uid = generate_uid(biome_pos)
local biome_name = biome_metadata[(uid % #biome_metadata) + 1]
return biome_data[biome_name]
return biome_metadata[(uid % #biome_metadata) + 1]
end
-- determine what sprite to render for a given position.
-- todo: this needs the ability to have a list of 'changed' tiles to check against.
function get_tile(pos)
local biome = get_biome(pos)
local biome_name = get_biome_name(pos)
local biome = biome_data[biome_name]
local uid = generate_uid(pos)
return biome["tile_lookup"][(uid % #biome["tile_lookup"]) + 1]