initial monster AI system
This commit is contained in:
parent
4f6151307c
commit
c454bab2b1
@ -24,3 +24,6 @@ pub struct Viewshed {
|
||||
pub range: i32,
|
||||
pub dirty: bool,
|
||||
}
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Monster {}
|
||||
|
||||
14
src/main.rs
14
src/main.rs
@ -9,6 +9,8 @@ mod components;
|
||||
pub use components::*;
|
||||
mod visibility_system;
|
||||
pub use visibility_system::VisibilitySystem;
|
||||
mod monster_ai_system;
|
||||
pub use monster_ai_system::MonsterAI;
|
||||
|
||||
#[macro_use]
|
||||
extern crate specs_derive;
|
||||
@ -60,6 +62,8 @@ impl State {
|
||||
fn run_systems(&mut self) {
|
||||
let mut vis = VisibilitySystem {};
|
||||
vis.run_now(&self.ecs);
|
||||
let mut mob = MonsterAI {};
|
||||
mob.run_now(&self.ecs);
|
||||
self.ecs.maintain();
|
||||
}
|
||||
}
|
||||
@ -75,7 +79,9 @@ impl GameState for State {
|
||||
let map = self.ecs.fetch::<Map>();
|
||||
for (pos, render) in (&positions, &renderables).join() {
|
||||
let idx = map.xy_idx(pos.x, pos.y);
|
||||
if map.visible_tiles[idx] { ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph); }
|
||||
if map.visible_tiles[idx] {
|
||||
ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -128,6 +134,7 @@ fn main() {
|
||||
gs.ecs.register::<Renderable>();
|
||||
gs.ecs.register::<Player>();
|
||||
gs.ecs.register::<Viewshed>();
|
||||
gs.ecs.register::<Monster>();
|
||||
|
||||
gs.ecs
|
||||
.create_entity()
|
||||
@ -153,8 +160,8 @@ fn main() {
|
||||
for room in map.rooms.iter().skip(1) {
|
||||
let (x, y) = room.center();
|
||||
let glyph = match rng.roll_dice(1, 2) {
|
||||
1 => { rltk::to_cp437('g') }
|
||||
_ => { rltk::to_cp437('o') }
|
||||
1 => rltk::to_cp437('g'),
|
||||
_ => rltk::to_cp437('o'),
|
||||
};
|
||||
gs.ecs
|
||||
.create_entity()
|
||||
@ -169,6 +176,7 @@ fn main() {
|
||||
range: 8,
|
||||
dirty: true,
|
||||
})
|
||||
.with(Monster {})
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
21
src/monster_ai_system.rs
Normal file
21
src/monster_ai_system.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use super::{Map, Monster, Position, Viewshed};
|
||||
use rltk::{console, field_of_view, Point};
|
||||
use specs::prelude::*;
|
||||
|
||||
pub struct MonsterAI {}
|
||||
|
||||
impl<'a> System<'a> for MonsterAI {
|
||||
type SystemData = (
|
||||
ReadStorage<'a, Viewshed>,
|
||||
ReadStorage<'a, Position>,
|
||||
ReadStorage<'a, Monster>,
|
||||
);
|
||||
|
||||
fn run(&mut self, data : Self::SystemData) {
|
||||
let (viewshed, pos, monster) = data;
|
||||
|
||||
for (viewshed, pos, monster) in (&viewshed, &pos, &monster).join() {
|
||||
console::log("Monster considers their own existence")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user