add knockback localevent

This commit is contained in:
AdamWhitehurst 2020-03-15 07:20:42 -06:00
parent 598a4c6cbb
commit 52059d83d3
2 changed files with 10 additions and 0 deletions

View File

@ -47,6 +47,7 @@ pub enum SfxEvent {
pub enum LocalEvent {
Jump(EcsEntity),
Knockback(EcsEntity),
WallLeap {
entity: EcsEntity,
wall_dir: Vec3<f32>,

View File

@ -334,6 +334,7 @@ impl State {
let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all();
for event in events {
let mut velocities = self.ecs.write_storage::<comp::Vel>();
let mut orientations = self.ecs.write_storage::<comp::Ori>();
let mut controllers = self.ecs.write_storage::<comp::Controller>();
match event {
LocalEvent::Jump(entity) => {
@ -341,6 +342,14 @@ impl State {
vel.0.z = HUMANOID_JUMP_ACCEL;
}
},
LocalEvent::Knockback(entity) => {
if let Some(vel) = velocities.get_mut(entity) {
if let Some(ori) = orientations.get_mut(entity) {
vel.0 = -ori.0 * 10.0;
vel.0.z = HUMANOID_JUMP_ACCEL;
}
}
},
LocalEvent::WallLeap { entity, wall_dir } => {
if let (Some(vel), Some(_controller)) =
(velocities.get_mut(entity), controllers.get_mut(entity))