Add WantsToAttack component
- Add player intent to attack when bumping an enemy
This commit is contained in:
parent
4aa39bfd6a
commit
e203c6000d
src
@ -29,3 +29,9 @@ pub struct Health {
|
|||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct Name(pub String);
|
pub struct Name(pub String);
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
pub struct WantsToAttack {
|
||||||
|
pub attacker: Entity,
|
||||||
|
pub victim: Entity,
|
||||||
|
}
|
||||||
|
@ -19,17 +19,41 @@ pub fn player_input(
|
|||||||
_ => Point::new(0, 0),
|
_ => Point::new(0, 0),
|
||||||
};
|
};
|
||||||
|
|
||||||
players.iter_mut(ecs).for_each(|(entity, pos)| {
|
let (player_entity, destination) = players
|
||||||
let destination = *pos + delta;
|
.iter(ecs)
|
||||||
|
.find_map(|(entity, pos)| Some((*entity, *pos + delta)))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut enemies = <(Entity, &Point)>::query().filter(component::<Enemy>());
|
||||||
|
|
||||||
|
if delta.x != 0 || delta.y != 0 {
|
||||||
|
let mut hit_something = false;
|
||||||
|
enemies
|
||||||
|
.iter(ecs)
|
||||||
|
.filter(|(_, pos)| **pos == destination)
|
||||||
|
.for_each(|(entity, _)| {
|
||||||
|
hit_something = true;
|
||||||
|
|
||||||
commands.push((
|
commands.push((
|
||||||
(),
|
(),
|
||||||
WantsToMove {
|
WantsToAttack {
|
||||||
entity: *entity,
|
attacker: player_entity,
|
||||||
destination,
|
victim: *entity,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if !hit_something {
|
||||||
|
commands.push((
|
||||||
|
(),
|
||||||
|
WantsToMove {
|
||||||
|
entity: player_entity,
|
||||||
|
destination,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*turn_state = TurnState::PlayerTurn;
|
*turn_state = TurnState::PlayerTurn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user