From b9a0bfe7b192e9ebe3ace30e090a1d679cb69ddd Mon Sep 17 00:00:00 2001 From: En Yi Date: Sat, 6 May 2023 11:49:12 +0800 Subject: [PATCH] Add ladder toggling Changelog: Ladder acts as one-way platform on top, not solid otherwise --- engine/editor_scene.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/engine/editor_scene.c b/engine/editor_scene.c index c585d28..c18d609 100644 --- a/engine/editor_scene.c +++ b/engine/editor_scene.c @@ -12,6 +12,7 @@ static Tile_t all_tiles[MAX_N_TILES] = {0}; enum EntitySpawnSelection { TOGGLE_TILE = 0, TOGGLE_ONEWAY, + TOGGLE_LADDER, SPAWN_CRATE, SPAWN_METAL_CRATE, }; @@ -47,6 +48,10 @@ static void level_scene_render_func(Scene_t* scene) { DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, MAROON); } + else if (tilemap.tiles[i].tile_type == LADDER) + { + DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, ORANGE); + } else if (tilemap.tiles[i].water_level > 0) { // Draw water tile @@ -263,6 +268,27 @@ static void toggle_block_system(Scene_t* scene) } tilemap.tiles[tile_idx].water_level = 0; break; + case TOGGLE_LADDER: + if (tilemap.tiles[tile_idx].tile_type == LADDER) + { + tilemap.tiles[tile_idx].tile_type = EMPTY_TILE; + tilemap.tiles[tile_idx].solid = NOT_SOLID; + } + else + { + tilemap.tiles[tile_idx].tile_type = LADDER; + int up_tile = tile_idx - tilemap.width; + if (up_tile > 0 && tilemap.tiles[up_tile].tile_type != LADDER) + { + tilemap.tiles[tile_idx].solid = ONE_WAY; + } + else + { + tilemap.tiles[tile_idx].solid = NOT_SOLID; + } + } + tilemap.tiles[tile_idx].water_level = 0; + break; case SPAWN_CRATE: spawn_crate(scene, tile_idx, false); break;