Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter4: Return rooms and map from new_map_rooms_and_corridors fn. #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions book/src/chapter_4.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ So now, in the spirit of the [original libtcod tutorial](http://rogueliketutoria
We'll start with a new function:

```rust
pub fn new_map_rooms_and_corridors() -> Vec<TileType> {
pub fn new_map_rooms_and_corridors() -> (Vec<Rect>, Vec<TileType>) {
let mut map = vec![TileType::Wall; 80*50];

map
(Vec::new(), map)
}
```

Expand Down Expand Up @@ -100,7 +100,7 @@ Notice that we are using `for y in room.y1 +1 ..= room.y2` - that's an *inclusiv
With these two bits of code, we can create a new rectangle anywhere with `Rect::new(x, y, width, height)`. We can add it to the map as floors with `apply_room_to_map(rect, map)`. That's enough to add a couple of test rooms. Our map function now looks like this:

```rust
pub fn new_map_rooms_and_corridors() -> Vec<TileType> {
pub fn new_map_rooms_and_corridors() -> (Vec<Rect>, Vec<TileType>) {
let mut map = vec![TileType::Wall; 80*50];

let room1 = Rect::new(20, 15, 10, 15);
Expand All @@ -109,7 +109,7 @@ pub fn new_map_rooms_and_corridors() -> Vec<TileType> {
apply_room_to_map(&room1, &mut map);
apply_room_to_map(&room2, &mut map);

map
(vec![room1, room2], map)
}
```

Expand Down Expand Up @@ -148,7 +148,7 @@ Then we add a call, `apply_horizontal_tunnel(&mut map, 25, 40, 23);` to our map
Now we can use that to make a random dungeon. We'll modify our function as follows:

```rust
pub fn new_map_rooms_and_corridors() -> Vec<TileType> {
pub fn new_map_rooms_and_corridors() -> (Vec<Rect>, Vec<TileType>) {
let mut map = vec![TileType::Wall; 80*50];

let mut rooms : Vec<Rect> = Vec::new();
Expand All @@ -174,7 +174,7 @@ pub fn new_map_rooms_and_corridors() -> Vec<TileType> {
}
}

map
(rooms, map)
}
```

Expand Down