Finish chapter 2.7
This commit is contained in:
parent
a17cc6f2e6
commit
ce80b34c2e
26
src/map.rs
26
src/map.rs
@ -3,9 +3,9 @@ use rltk::{Algorithm2D, BaseMap, Point, RandomNumberGenerator, Rltk, SmallVec, R
|
|||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
|
|
||||||
const MAPWIDTH: usize = 80;
|
const MAP_WIDTH: usize = 80;
|
||||||
const MAPHEIGHT: usize = 50;
|
const MAP_HEIGHT: usize = 43;
|
||||||
const MAPCOUNT: usize = MAPHEIGHT * MAPWIDTH;
|
const MAP_COUNT: usize = MAP_HEIGHT * MAP_WIDTH;
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
pub enum TileType {
|
pub enum TileType {
|
||||||
@ -62,14 +62,14 @@ impl Map {
|
|||||||
/// This gives a handful of random rooms and corridors joining them together
|
/// This gives a handful of random rooms and corridors joining them together
|
||||||
pub fn new_map_rooms_and_corridors() -> Map {
|
pub fn new_map_rooms_and_corridors() -> Map {
|
||||||
let mut map = Map {
|
let mut map = Map {
|
||||||
tiles: vec![TileType::Wall; MAPCOUNT],
|
tiles: vec![TileType::Wall; MAP_COUNT],
|
||||||
rooms: Vec::new(),
|
rooms: Vec::new(),
|
||||||
width: 80,
|
width: MAP_WIDTH as i32,
|
||||||
height: 50,
|
height: MAP_HEIGHT as i32,
|
||||||
revealed_tiles: vec![false; MAPCOUNT],
|
revealed_tiles: vec![false; MAP_COUNT],
|
||||||
visible_tiles: vec![false; MAPCOUNT],
|
visible_tiles: vec![false; MAP_COUNT],
|
||||||
blocked: vec![false; MAPCOUNT],
|
blocked: vec![false; MAP_COUNT],
|
||||||
tile_content: vec![Vec::new(); MAPCOUNT],
|
tile_content: vec![Vec::new(); MAP_COUNT],
|
||||||
};
|
};
|
||||||
|
|
||||||
const MAX_ROOMS: i32 = 30;
|
const MAX_ROOMS: i32 = 30;
|
||||||
@ -81,8 +81,8 @@ impl Map {
|
|||||||
for _ in 0..MAX_ROOMS {
|
for _ in 0..MAX_ROOMS {
|
||||||
let w = rng.range(MIN_SIZE, MAX_SIZE);
|
let w = rng.range(MIN_SIZE, MAX_SIZE);
|
||||||
let h = rng.range(MIN_SIZE, MAX_SIZE);
|
let h = rng.range(MIN_SIZE, MAX_SIZE);
|
||||||
let x = rng.roll_dice(1, 80 - w - 1) - 1;
|
let x = rng.roll_dice(1, map.width - w - 1) - 1;
|
||||||
let y = rng.roll_dice(1, 50 - h - 1) - 1;
|
let y = rng.roll_dice(1, map.height - h - 1) - 1;
|
||||||
|
|
||||||
let new_room = Rect::new(x, y, w, h);
|
let new_room = Rect::new(x, y, w, h);
|
||||||
let mut ok = true;
|
let mut ok = true;
|
||||||
@ -228,7 +228,7 @@ pub fn draw_map(ecs: &World, ctx: &mut Rltk) {
|
|||||||
|
|
||||||
// Move to the next set of coordinates
|
// Move to the next set of coordinates
|
||||||
x += 1;
|
x += 1;
|
||||||
if x > 79 {
|
if x > MAP_WIDTH as i32 -1 {
|
||||||
x = 0;
|
x = 0;
|
||||||
y += 1;
|
y += 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user