Finish chapter 2.7

This commit is contained in:
Timothy Warren 2021-11-02 09:25:48 -04:00
parent a17cc6f2e6
commit ce80b34c2e

View File

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