set up visibility system
This commit is contained in:
13
src/main.rs
13
src/main.rs
@@ -7,6 +7,8 @@ mod map;
|
||||
pub use map::*;
|
||||
mod components;
|
||||
pub use components::*;
|
||||
mod visibility_system;
|
||||
pub use visibility_system::VisibilitySystem;
|
||||
|
||||
#[macro_use]
|
||||
extern crate specs_derive;
|
||||
@@ -23,7 +25,7 @@ fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
|
||||
for (_player, pos) in (&mut players, &mut positions).join() {
|
||||
let x = min(79, max(0, pos.x + delta_x));
|
||||
let y = min(49, max(0, pos.y + delta_y));
|
||||
if map.tile_at(x,y) != TileType::Wall {
|
||||
if map.tile_at(x, y) != TileType::Wall {
|
||||
pos.x = x;
|
||||
pos.y = y;
|
||||
}
|
||||
@@ -69,8 +71,8 @@ impl<'a> System<'a> for LeftWalker {
|
||||
|
||||
impl State {
|
||||
fn run_systems(&mut self) {
|
||||
let mut lw = LeftWalker {};
|
||||
lw.run_now(&self.ecs);
|
||||
let mut vis = VisibilitySystem {};
|
||||
vis.run_now(&self.ecs);
|
||||
self.ecs.maintain();
|
||||
}
|
||||
}
|
||||
@@ -104,6 +106,7 @@ fn main() {
|
||||
gs.ecs.register::<Renderable>();
|
||||
gs.ecs.register::<LeftMover>();
|
||||
gs.ecs.register::<Player>();
|
||||
gs.ecs.register::<Viewshed>();
|
||||
|
||||
gs.ecs
|
||||
.create_entity()
|
||||
@@ -117,6 +120,10 @@ fn main() {
|
||||
bg: RGB::named(rltk::BLACK),
|
||||
})
|
||||
.with(Player {})
|
||||
.with(Viewshed {
|
||||
visible_tiles: Vec::new(),
|
||||
range: 8,
|
||||
})
|
||||
.build();
|
||||
|
||||
for i in 0..10 {
|
||||
|
||||
Reference in New Issue
Block a user