Skip to content

Commit

Permalink
Placeholder for C74.
Browse files Browse the repository at this point in the history
  • Loading branch information
thebracket committed Apr 21, 2020
1 parent 73590f0 commit 78700de
Show file tree
Hide file tree
Showing 132 changed files with 15,579 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ members = [
"chapter-70-missiles",
"chapter-71-logging",
"chapter-72-textlayers",
"chapter-73-systems"
"chapter-73-systems",
"chapter-74-darkcity"
]

[profile.dev]
Expand Down
86 changes: 86 additions & 0 deletions book/src/chapter_74.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# One Night in the City

---

***About this tutorial***

*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!*

*If you enjoy this and would like me to keep writing, please consider supporting [my Patreon](https://www.patreon.com/blackfuture).*

---

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:

* It eventually leads to a portal to the Abyss.
* Dark elves are infighty, back-stabbing maniacs and should behave as such.
* Dark elven cities are surprisingly city-like, just deep underground.
* Lighting will be important.

## Generating a basic city

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:

```rust
pub fn level_builder(new_depth: i32, width: i32, height: i32) -> BuilderChain {
rltk::console::log(format!("Depth: {}", new_depth));
match new_depth {
1 => town_builder(new_depth, width, height),
2 => forest_builder(new_depth, width, height),
3 => limestone_cavern_builder(new_depth, width, height),
4 => limestone_deep_cavern_builder(new_depth, width, height),
5 => limestone_transition_builder(new_depth, width, height),
6 => dwarf_fort_builder(new_depth, width, height),
7 => mushroom_entrance(new_depth, width, height),
8 => mushroom_builder(new_depth, width, height),
9 => mushroom_exit(new_depth, width, height),
10 => dark_elf_city(new_depth, width, height),
_ => random_builder(new_depth, width, height)
}
}
```

At the top of the same file, add imports for a new builder module:

```rust
mod dark_elves;
use dark_elves::*;
```

And create the new `map_builders/dark_elves.rs` file with a placeholder builder in it:

```rust
use super::{BuilderChain, XStart, YStart, AreaStartingPosition,
CullUnreachable, VoronoiSpawning,
AreaEndingPosition, XEnd, YEnd, BspInteriorBuilder };

pub fn dark_elf_city(new_depth: i32, width: i32, height: i32) -> BuilderChain {
println!("Dark elf builder");
let mut chain = BuilderChain::new(new_depth, width, height, "Dark Elven City");
chain.start_with(BspInteriorBuilder::new());
chain.with(AreaStartingPosition::new(XStart::CENTER, YStart::CENTER));
chain.with(CullUnreachable::new());
chain.with(AreaStartingPosition::new(XStart::RIGHT, YStart::CENTER));
chain.with(AreaEndingPosition::new(XEnd::LEFT, YEnd::CENTER));
chain.with(VoronoiSpawning::new());
chain
}
```

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.

## Adding some dark elves



---

**The source code for this chapter may be found [here](https://github.com/thebracket/rustrogueliketutorial/tree/master/chapter-74-darkcity)**


[Run this chapter's example with web assembly, in your browser (WebGL2 required)](https://bfnightly.bracketproductions.com/rustbook/wasm/chapter-74-darkcity)
---

Copyright (C) 2019, Herbert Wolverson.

---
16 changes: 16 additions & 0 deletions chapter-74-darkcity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "chapter-74-darkcity"
version = "0.1.0"
authors = ["Herbert Wolverson <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rltk = { version = "0.8.0", features = ["serde"] }
specs = { version = "0.16.1", features = ["serde"] }
specs-derive = "0.4.1"
serde= { version = "^1.0.44", features = ["derive"] }
serde_json = "^1.0.44"
lazy_static = "1.4.0"
regex = "1.3.6"
Loading

0 comments on commit 78700de

Please sign in to comment.