add visuals and camera - chapter 5
This commit is contained in:
+28
-11
@@ -2,7 +2,7 @@ pub use crate::prelude::*;
|
||||
|
||||
const NUM_TILES: usize = (SCREEN_WIDTH * SCREEN_HEIGHT) as usize;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub enum TileType {
|
||||
Floor,
|
||||
Wall,
|
||||
@@ -39,16 +39,33 @@ impl Map {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&self, ctx: &mut BTerm) {
|
||||
for y in 0..SCREEN_HEIGHT {
|
||||
for x in 0..SCREEN_WIDTH {
|
||||
let idx = map_idx(x, y);
|
||||
match self.tiles[idx] {
|
||||
TileType::Floor => {
|
||||
ctx.set(x, y, YELLOW, BLACK, to_cp437('.'));
|
||||
}
|
||||
TileType::Wall => {
|
||||
ctx.set(x, y, GREEN, BLACK, to_cp437('#'));
|
||||
pub fn render(&self, ctx: &mut BTerm, camera: &Camera) {
|
||||
ctx.set_active_console(0);
|
||||
|
||||
for y in camera.top_y..camera.bottom_y {
|
||||
for x in camera.left_x..camera.right_x {
|
||||
if self.in_bounds(Point::new(x, y)) {
|
||||
let idx = map_idx(x, y);
|
||||
|
||||
match self.tiles[idx] {
|
||||
TileType::Wall => {
|
||||
ctx.set(
|
||||
x - camera.left_x,
|
||||
y - camera.top_y,
|
||||
WHITE,
|
||||
BLACK,
|
||||
to_cp437('#'),
|
||||
);
|
||||
}
|
||||
TileType::Floor => {
|
||||
ctx.set(
|
||||
x - camera.left_x,
|
||||
y - camera.top_y,
|
||||
WHITE,
|
||||
BLACK,
|
||||
to_cp437('.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user