Rework the game to use double-sized sprites. This gives us more room for detail.
This commit is contained in:
parent
873cbbbad4
commit
aa22c8a054
3 changed files with 137 additions and 81 deletions
103
world.lua
103
world.lua
|
@ -2,6 +2,24 @@
|
|||
--- environment
|
||||
|
||||
function init_world()
|
||||
-- constants for map tiles' sprite locations, as long as we have the
|
||||
-- tokens
|
||||
tile_tree = 1
|
||||
tile_tree_stump = 3
|
||||
tile_bush = 5
|
||||
tile_empty_bush = 7
|
||||
tile_cactus = 9
|
||||
tile_flowering_cactus = 11
|
||||
tile_cactus_stump = 13
|
||||
tile_big_mushroom = 32
|
||||
tile_mushroom_stump = 34
|
||||
tile_pebbles = 36
|
||||
tile_long_grass = 38
|
||||
tile_red_flowers = 40
|
||||
tile_pink_flowers = 42
|
||||
tile_fairy_ring = 44
|
||||
tile_rock = 46
|
||||
|
||||
-- Metadata for different biomes
|
||||
-- tile_frequencies tuples are {frequency, sprite_index}, see index_map.md
|
||||
-- frequencies by convention add up to 1000, but this is arbitrary, the
|
||||
|
@ -9,19 +27,51 @@ function init_world()
|
|||
biome_data = {
|
||||
meadow = {
|
||||
biome_frequency = 20,
|
||||
tile_frequencies = { {525, 2}, {200, 5}, {200, 6}, {55, 18}, {19, 3}, {1, 4} }
|
||||
base_color = 3,
|
||||
tile_frequencies = {
|
||||
{525, 0},
|
||||
{200, tile_red_flowers},
|
||||
{200, tile_pink_flowers},
|
||||
{55, tile_long_grass},
|
||||
{19, tile_bush},
|
||||
{1, tile_tree}
|
||||
}
|
||||
},
|
||||
grassland = {
|
||||
biome_frequency = 55,
|
||||
tile_frequencies = { {500, 2}, {345, 18}, {4, 3}, {1, 4}, {100, 5}, {50, 6} }
|
||||
base_color = 3,
|
||||
tile_frequencies = {
|
||||
{500, 0},
|
||||
{345, tile_long_grass},
|
||||
{4, tile_bush},
|
||||
{1, tile_tree},
|
||||
{100, tile_red_flowers},
|
||||
{50, tile_pink_flowers}
|
||||
}
|
||||
},
|
||||
forest = {
|
||||
biome_frequency = 20,
|
||||
tile_frequencies = { {600, 2}, {200, 4}, {50, 3}, {50, 5}, {40, 7}, {59, 6}, {1, 8} }
|
||||
base_color = 3,
|
||||
tile_frequencies = {
|
||||
{600, 0},
|
||||
{200, tile_tree},
|
||||
{50, tile_bush},
|
||||
{50, tile_red_flowers},
|
||||
{40, tile_mushrooms},
|
||||
{59, tile_pink_flowers},
|
||||
{1, tile_big_mushroom}
|
||||
}
|
||||
},
|
||||
desert = {
|
||||
biome_frequency = 5,
|
||||
tile_frequencies = { {800, 9}, {109, 11}, {60, 13}, {30, 12}, {1, 10} },
|
||||
base_color = 9,
|
||||
tile_frequencies = {
|
||||
{800, 0},
|
||||
{109, tile_pebbles},
|
||||
{60, tile_cactus},
|
||||
{30, tile_rock},
|
||||
{1, tile_flowering_cactus}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,39 +95,35 @@ function init_world()
|
|||
build_biome(biome, biome_data[biome])
|
||||
end
|
||||
|
||||
-- the indices here are sprite numbers.
|
||||
object_interaction_map = {
|
||||
-- bush
|
||||
[3] = {
|
||||
replacement = 17,
|
||||
[tile_bush] = {
|
||||
replacement = tile_empty_bush,
|
||||
sfx = 13,
|
||||
drop = 68
|
||||
},
|
||||
|
||||
-- tree
|
||||
[4] = {
|
||||
replacement = 14,
|
||||
[tile_tree] = {
|
||||
replacement = tile_tree_stump,
|
||||
sfx = 11,
|
||||
drop = 64
|
||||
},
|
||||
|
||||
-- big mushroom
|
||||
[8] = {
|
||||
replacement = 16,
|
||||
[tile_big_mushroom] = {
|
||||
replacement = tile_mushroom_stump,
|
||||
sfx = 12,
|
||||
drop = 65
|
||||
},
|
||||
|
||||
-- cactus w/ flower
|
||||
[10] = {
|
||||
replacement = 15,
|
||||
[tile_flowering_cactus] = {
|
||||
replacement = tile_cactus_stump,
|
||||
sfx = 12,
|
||||
drop = 67
|
||||
},
|
||||
|
||||
-- cactus
|
||||
[13] = {
|
||||
replacement = 15,
|
||||
[tile_cactus] = {
|
||||
replacement = tile_cactus_stump,
|
||||
sfx = 12,
|
||||
drop = 66
|
||||
}
|
||||
|
@ -95,9 +141,17 @@ end
|
|||
-- this calculates everything about the world fresh every frame,
|
||||
-- but pico-8 handles this just fine!
|
||||
function draw_world(start_x, start_y)
|
||||
for x=0,15 do
|
||||
for y=0,15 do
|
||||
spr(get_tile(start_x-8+x, start_y-8+y), x*8, y*8)
|
||||
for x=0,7 do
|
||||
for y=0,7 do
|
||||
-- color the background for this segment
|
||||
rectfill(x*16, y*16, x*16+16, y*16+16,
|
||||
get_base_color(start_x-4+x, start_y-4+y))
|
||||
|
||||
-- now get the sprite, and render as long as it isn't 0
|
||||
local sprite = get_tile(start_x-4+x, start_y-4+y)
|
||||
if sprite ~= 0 then
|
||||
spr(sprite, x*16, y*16, 2, 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -141,8 +195,13 @@ function get_biome_name(pos_x, pos_y)
|
|||
return biome_metadata[(uid % #biome_metadata) + 1]
|
||||
end
|
||||
|
||||
-- get the background color for the current biome
|
||||
function get_base_color(x, y)
|
||||
local biome = get_biome_name(x, y)
|
||||
return biome_data[biome].base_color
|
||||
end
|
||||
|
||||
-- determine what sprite to render for a given position.
|
||||
-- pos_x and pos_y are global coordinates.
|
||||
function get_tile(pos_x, pos_y)
|
||||
-- lookup changes in the change buffer
|
||||
local modded_sprite = mod_buffer[get_mod_key(pos_x, pos_y)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue