set up visibility system
This commit is contained in:
parent
419ab1ba35
commit
2727f417ea
@ -1,4 +1,4 @@
|
||||
use rltk::RGB;
|
||||
use rltk::{RGB,Point};
|
||||
|
||||
use specs::prelude::*;
|
||||
|
||||
@ -20,3 +20,9 @@ pub struct LeftMover {}
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Player {}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Viewshed {
|
||||
pub visible_tiles : Vec<Point>,
|
||||
pub range : i32
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
15
src/visibility_system.rs
Normal file
15
src/visibility_system.rs
Normal file
@ -0,0 +1,15 @@
|
||||
extern crate specs;
|
||||
use specs::prelude::*;
|
||||
use super::{Viewshed, Position};
|
||||
|
||||
pub struct VisibilitySystem {}
|
||||
|
||||
impl<'a> System<'a> for VisibilitySystem {
|
||||
type SystemData = ( WriteStorage<'a, Viewshed>,
|
||||
WriteStorage<'a, Position>);
|
||||
|
||||
fn run(&mut self, (mut viewshed, pos) : Self::SystemData) {
|
||||
for (viewshed,pos) in (&mut viewshed, &pos).join() {
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user