|
| 1 | +# One Night in the City |
| 2 | + |
| 3 | +--- |
| 4 | + |
| 5 | +***About this tutorial*** |
| 6 | + |
| 7 | +*This tutorial is free and open source, and all code uses the MIT license - so you are free to do with it as you like. My hope is that you will enjoy the tutorial, and make great games!* |
| 8 | + |
| 9 | +*If you enjoy this and would like me to keep writing, please consider supporting [my Patreon](https://www.patreon.com/blackfuture).* |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +The next level of the game is a dark elven city. The design document is a bit sparse on details, but here's what we know: |
| 14 | + |
| 15 | +* It eventually leads to a portal to the Abyss. |
| 16 | +* Dark elves are infighty, back-stabbing maniacs and should behave as such. |
| 17 | +* Dark elven cities are surprisingly city-like, just deep underground. |
| 18 | +* Lighting will be important. |
| 19 | + |
| 20 | +## Generating a basic city |
| 21 | + |
| 22 | +The `level_builder` function in `map_builder/mod.rs` controls which map algorithm is called for a given level. Add a placeholder entry for a new map type: |
| 23 | + |
| 24 | +```rust |
| 25 | +pub fn level_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain { |
| 26 | + rltk::console::log(format!("Depth: {}", new_depth)); |
| 27 | + match new_depth { |
| 28 | + 1 => town_builder(new_depth, width, height), |
| 29 | + 2 => forest_builder(new_depth, width, height), |
| 30 | + 3 => limestone_cavern_builder(new_depth, width, height), |
| 31 | + 4 => limestone_deep_cavern_builder(new_depth, width, height), |
| 32 | + 5 => limestone_transition_builder(new_depth, width, height), |
| 33 | + 6 => dwarf_fort_builder(new_depth, width, height), |
| 34 | + 7 => mushroom_entrance(new_depth, width, height), |
| 35 | + 8 => mushroom_builder(new_depth, width, height), |
| 36 | + 9 => mushroom_exit(new_depth, width, height), |
| 37 | + 10 => dark_elf_city(new_depth, width, height), |
| 38 | + _ => random_builder(new_depth, width, height) |
| 39 | + } |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +At the top of the same file, add imports for a new builder module: |
| 44 | + |
| 45 | +```rust |
| 46 | +mod dark_elves; |
| 47 | +use dark_elves::*; |
| 48 | +``` |
| 49 | + |
| 50 | +And create the new `map_builders/dark_elves.rs` file with a placeholder builder in it: |
| 51 | + |
| 52 | +```rust |
| 53 | +use super::{BuilderChain, XStart, YStart, AreaStartingPosition, |
| 54 | + CullUnreachable, VoronoiSpawning, |
| 55 | + AreaEndingPosition, XEnd, YEnd, BspInteriorBuilder }; |
| 56 | + |
| 57 | +pub fn dark_elf_city(new_depth: i32, width: i32, height: i32) -> BuilderChain { |
| 58 | + println!("Dark elf builder"); |
| 59 | + let mut chain = BuilderChain::new(new_depth, width, height, "Dark Elven City"); |
| 60 | + chain.start_with(BspInteriorBuilder::new()); |
| 61 | + chain.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER)); |
| 62 | + chain.with(CullUnreachable::new()); |
| 63 | + chain.with(AreaStartingPosition::new(XStart::RIGHT, YStart::CENTER)); |
| 64 | + chain.with(AreaEndingPosition::new(XEnd::LEFT, YEnd::CENTER)); |
| 65 | + chain.with(VoronoiSpawning::new()); |
| 66 | + chain |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +That makes a not-at-all city like map (just a bsp interiors map) - but it's a good start. I chose this as the base builder because it doesn't waste any space. I like to imagine that the city is a big warren of interconnected rooms, with the poorer-elf housing in the dangerous spot (at the top). So we'll populate this level with relatively "normal" dark elves, and their slaves. |
| 71 | + |
| 72 | +## Adding some dark elves |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +**The source code for this chapter may be found [here](https://github.com/thebracket/rustrogueliketutorial/tree/master/chapter-74-darkcity)** |
| 79 | + |
| 80 | + |
| 81 | +[Run this chapter's example with web assembly, in your browser (WebGL2 required)](https://bfnightly.bracketproductions.com/rustbook/wasm/chapter-74-darkcity) |
| 82 | +--- |
| 83 | + |
| 84 | +Copyright (C) 2019, Herbert Wolverson. |
| 85 | + |
| 86 | +--- |
0 commit comments