add visuals and camera - chapter 5
This commit is contained in:
@@ -1,42 +1,69 @@
|
||||
mod map;
|
||||
mod player;
|
||||
mod map_builder;
|
||||
mod camera;
|
||||
|
||||
mod prelude {
|
||||
pub use bracket_lib::prelude::*;
|
||||
pub use crate::map::*;
|
||||
pub use crate::player::*;
|
||||
pub use crate::map_builder::*;
|
||||
pub use crate::camera::*;
|
||||
|
||||
pub const SCREEN_WIDTH: i32 = 80;
|
||||
pub const SCREEN_HEIGHT: i32 = 50;
|
||||
|
||||
pub const DISPLAY_WIDTH: i32 = SCREEN_WIDTH / 2;
|
||||
pub const DISPLAY_HEIGHT: i32 = SCREEN_HEIGHT / 2;
|
||||
}
|
||||
|
||||
const FONT_PATH: &str = "dungeonfont.png";
|
||||
|
||||
use prelude::*;
|
||||
|
||||
struct State {
|
||||
map: Map,
|
||||
player: Player,
|
||||
camera: Camera,
|
||||
}
|
||||
|
||||
impl State {
|
||||
fn new() -> Self {
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
let mb = MapBuilder::new(&mut rng);
|
||||
|
||||
return Self {
|
||||
map: Map::new(),
|
||||
player: Player::new(Point { x: SCREEN_WIDTH / 2, y: SCREEN_HEIGHT / 2 }),
|
||||
map: mb.map,
|
||||
player: Player::new(mb.player_start),
|
||||
camera: Camera::new(mb.player_start),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl GameState for State {
|
||||
fn tick(&mut self, ctx: &mut BTerm) {
|
||||
ctx.set_active_console(0);
|
||||
ctx.cls();
|
||||
self.player.update(ctx, &self.map);
|
||||
self.map.render(ctx);
|
||||
self.player.render(ctx);
|
||||
ctx.set_active_console(1);
|
||||
ctx.cls();
|
||||
|
||||
self.player.update(ctx, &self.map, &mut self.camera);
|
||||
self.map.render(ctx, &self.camera);
|
||||
self.player.render(ctx, &self.camera);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> BError {
|
||||
let context = BTermBuilder::simple80x50().with_title("Dungeon Crawler").with_fps_cap(30.0).build()?;
|
||||
let context = BTermBuilder::new()
|
||||
.with_title("Dungeon Crawler")
|
||||
.with_fps_cap(30.0)
|
||||
.with_dimensions(DISPLAY_WIDTH, DISPLAY_HEIGHT)
|
||||
.with_tile_dimensions(32, 32)
|
||||
.with_resource_path("resources/")
|
||||
.with_font(FONT_PATH, 32, 32)
|
||||
.with_simple_console(DISPLAY_WIDTH, DISPLAY_HEIGHT, FONT_PATH)
|
||||
.with_simple_console_no_bg(DISPLAY_WIDTH, DISPLAY_HEIGHT, FONT_PATH)
|
||||
.build()?;
|
||||
|
||||
return main_loop(context, State::new());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user