From eef254e2bed8ab849ea7da7da18cfedbd63cf3a7 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 28 Jan 2022 12:28:42 -0500 Subject: [PATCH] Implement start of Mushroom Forest entrance --- src/colors.rs | 6 +++--- src/map/themes.rs | 29 ++++++++++++++++++++++++++++- src/map_builders.rs | 3 +++ src/map_builders/mushroom_forest.rs | 26 ++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/map_builders/mushroom_forest.rs diff --git a/src/colors.rs b/src/colors.rs index 6c36b33..126e734 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -15,6 +15,9 @@ pub const BLACK: RGB = new(0., 0., 0.); /// RGB: (102, 102, 102) pub const DARK_GRAY: RGB = new(0.4, 0.4, 0.4); +/// RGB: (128, 128, 128) +pub const MID_GRAY: RGB = new(0.5, 0.5, 0.5); + /// HEX: #999 /// RGB: (153, 153, 153) pub const BOX_GRAY: RGB = new(0.6, 0.6, 0.6); @@ -70,9 +73,6 @@ pub const GREEN: RGB = new(0., 1., 0.); /// RGB: (255, 0, 255) pub const MAGENTA: RGB = new(1., 0., 1.); -/// RGB: (128, 128, 128) -pub const MID_GRAY: RGB = new(0.5, 0.5, 0.5); - /// RGB: (255, 165, 0) pub const ORANGE: RGB = new(1., 0.647, 0.); diff --git a/src/map/themes.rs b/src/map/themes.rs index 165a194..ff1ca4a 100644 --- a/src/map/themes.rs +++ b/src/map/themes.rs @@ -6,6 +6,14 @@ use crate::colors; pub fn tile_glyph(idx: usize, map: &Map) -> (FontCharType, RGB, RGB) { let (glyph, mut fg, mut bg) = match map.depth { + 7 => { + let x = idx as i32 % map.width; + if x > map.width - 16 { + get_tile_glyph_default(idx, map) + } else { + get_mushroom_glyph(idx, map) + } + } 5 => { let x = idx as i32 % map.width; if x < map.width / 2 { @@ -74,7 +82,26 @@ fn get_forest_glyph(idx: usize, map: &Map) -> (FontCharType, RGB, RGB) { (glyph, fg, bg) } -fn get_tile_glyph_default(idx: usize, map: &Map) -> (rltk::FontCharType, RGB, RGB) { +fn get_mushroom_glyph(idx: usize, map: &Map) -> (FontCharType, RGB, RGB) { + let bg = colors::BLACK; + + let (glyph, fg) = match map.tiles[idx] { + TileType::Wall => (to_cp437('♠'), colors::MAGENTA), + TileType::Bridge => (to_cp437('.'), colors::GREEN), + TileType::Road => (to_cp437('≡'), colors::CHOCOLATE), + TileType::Grass => (to_cp437('"'), colors::GREEN), + TileType::ShallowWater => (to_cp437('~'), colors::CYAN), + TileType::DeepWater => (to_cp437('~'), colors::BLUE), + TileType::Gravel => (to_cp437(';'), colors::MID_GRAY), + TileType::DownStairs => (to_cp437('>'), colors::CYAN), + TileType::UpStairs => (to_cp437('<'), colors::CYAN), + _ => (to_cp437('"'), colors::FOREST_GREEN), + }; + + (glyph, fg, bg) +} + +fn get_tile_glyph_default(idx: usize, map: &Map) -> (FontCharType, RGB, RGB) { let mut bg = colors::BLACK; let (glyph, mut fg) = match map.tiles[idx] { diff --git a/src/map_builders.rs b/src/map_builders.rs index f0b38fb..35dede0 100644 --- a/src/map_builders.rs +++ b/src/map_builders.rs @@ -13,6 +13,7 @@ mod dwarf_fort; mod forest; mod limestone_cavern; mod maze; +mod mushroom_forest; mod prefab_builder; mod room_based_spawner; mod room_based_stairs; @@ -50,6 +51,7 @@ use limestone_cavern::{ limestone_cavern_builder, limestone_deep_cavern_builder, limestone_transition_builder, }; use maze::MazeBuilder; +use mushroom_forest::*; use prefab_builder::PrefabBuilder; use room_based_spawner::RoomBasedSpawner; use room_based_stairs::RoomBasedStairs; @@ -357,6 +359,7 @@ pub fn level_builder( 4 => limestone_deep_cavern_builder(new_depth, rng, width, height), 5 => limestone_transition_builder(new_depth, rng, width, height), 6 => dwarf_fort_builder(new_depth, rng, width, height), + 7 => mushroom_entrance(new_depth, rng, width, height), _ => random_builder(new_depth, rng, width, height), } } diff --git a/src/map_builders/mushroom_forest.rs b/src/map_builders/mushroom_forest.rs new file mode 100644 index 0000000..a169c7b --- /dev/null +++ b/src/map_builders/mushroom_forest.rs @@ -0,0 +1,26 @@ +use super::prefab_builder::prefab_sections::UNDERGROUND_FORT; +use super::{ + AreaEndingPosition, AreaStartingPosition, BuilderChain, CellularAutomataBuilder, + CullUnreachable, PrefabBuilder, VoronoiSpawning, WaveformCollapseBuilder, XEnd, XStart, YEnd, + YStart, +}; + +pub fn mushroom_entrance( + new_depth: i32, + _rng: &mut ::rltk::RandomNumberGenerator, + width: i32, + height: i32, +) -> BuilderChain { + let mut chain = BuilderChain::new(new_depth, width, height, "Into the Mushroom Grove"); + chain + .start_with(CellularAutomataBuilder::new()) + .with(WaveformCollapseBuilder::new()) + .with(AreaStartingPosition::new(XStart::Center, YStart::Center)) + .with(CullUnreachable::new()) + .with(AreaStartingPosition::new(XStart::Right, YStart::Center)) + .with(AreaEndingPosition::new(XEnd::Left, YEnd::Center)) + .with(VoronoiSpawning::new()) + .with(PrefabBuilder::sectional(UNDERGROUND_FORT)); + + chain +}