Add chasing system
This commit is contained in:
parent
2310dd9218
commit
65cde7d8ab
@ -35,3 +35,6 @@ pub struct WantsToAttack {
|
||||
pub attacker: Entity,
|
||||
pub victim: Entity,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct ChasingPlayer;
|
||||
|
46
src/map.rs
46
src/map.rs
@ -38,4 +38,50 @@ impl Map {
|
||||
Some(map_idx(point.x, point.y))
|
||||
}
|
||||
}
|
||||
|
||||
fn valid_exit(&self, loc: Point, delta: Point) -> Option<usize> {
|
||||
let destination = loc + delta;
|
||||
if self.in_bounds(destination) && self.can_enter_tile(destination) {
|
||||
let idx = self.point2d_to_index(destination);
|
||||
Some(idx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Algorithm2D for Map {
|
||||
fn dimensions(&self) -> Point {
|
||||
Point::new(SCREEN_WIDTH, SCREEN_HEIGHT)
|
||||
}
|
||||
|
||||
fn in_bounds(&self, point: Point) -> bool {
|
||||
self.in_bounds(point)
|
||||
}
|
||||
}
|
||||
|
||||
impl BaseMap for Map {
|
||||
fn get_available_exits(&self, idx: usize) -> SmallVec<[(usize, f32); 10]> {
|
||||
let mut exits = SmallVec::new();
|
||||
let location = self.index_to_point2d(idx);
|
||||
|
||||
if let Some(idx) = self.valid_exit(location, Point::new(-1, 0)) {
|
||||
exits.push((idx, 1.0));
|
||||
}
|
||||
if let Some(idx) = self.valid_exit(location, Point::new(1, 0)) {
|
||||
exits.push((idx, 1.0));
|
||||
}
|
||||
if let Some(idx) = self.valid_exit(location, Point::new(0, -1)) {
|
||||
exits.push((idx, 1.0));
|
||||
}
|
||||
if let Some(idx) = self.valid_exit(location, Point::new(0, 1)) {
|
||||
exits.push((idx, 1.0));
|
||||
}
|
||||
|
||||
exits
|
||||
}
|
||||
|
||||
fn get_pathing_distance(&self, idx1: usize, idx2: usize) -> f32 {
|
||||
DistanceAlg::Pythagoras.distance2d(self.index_to_point2d(idx1), self.index_to_point2d(idx2))
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ pub fn spawn_monster(ecs: &mut World, rng: &mut RandomNumberGenerator, pos: Poin
|
||||
color: ColorPair::new(WHITE, BLACK),
|
||||
glyph,
|
||||
},
|
||||
MovingRandomly,
|
||||
ChasingPlayer,
|
||||
Health {
|
||||
current: hp,
|
||||
max: hp,
|
||||
|
@ -1,3 +1,4 @@
|
||||
mod chasing;
|
||||
mod combat;
|
||||
mod end_turn;
|
||||
mod entity_render;
|
||||
@ -37,6 +38,7 @@ pub fn build_player_scheduler() -> Schedule {
|
||||
|
||||
pub fn build_monster_scheduler() -> Schedule {
|
||||
Schedule::builder()
|
||||
.add_system(chasing::chasing_system())
|
||||
.add_system(random_move::random_move_system())
|
||||
.flush()
|
||||
.add_system(combat::combat_system())
|
||||
|
Loading…
Reference in New Issue
Block a user