feat(bow): make arrows stick to walls

This commit is contained in:
timokoesters 2019-09-29 10:37:07 +02:00
parent 469349a426
commit ba3db852f7
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
3 changed files with 17 additions and 4 deletions

View File

@ -11,6 +11,7 @@ pub enum Effect {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Projectile { pub struct Projectile {
pub hit_ground: Vec<Effect>, pub hit_ground: Vec<Effect>,
pub hit_wall: Vec<Effect>,
pub hit_entity: Vec<Effect>, pub hit_entity: Vec<Effect>,
} }

View File

@ -145,6 +145,7 @@ impl<'a> System<'a> for Sys {
dir: controller.look_dir, dir: controller.look_dir,
projectile: Projectile { projectile: Projectile {
hit_ground: vec![projectile::Effect::Stick], hit_ground: vec![projectile::Effect::Stick],
hit_wall: vec![projectile::Effect::Stick],
hit_entity: vec![ hit_entity: vec![
projectile::Effect::Damage(10), projectile::Effect::Damage(10),
projectile::Effect::Vanish, projectile::Effect::Vanish,

View File

@ -38,10 +38,6 @@ impl<'a> System<'a> for Sys {
) )
.join() .join()
{ {
if let Some(vel) = velocities.get(entity) {
ori.0 = vel.0.normalized();
}
// Hit ground // Hit ground
if physics.on_ground { if physics.on_ground {
for effect in projectile.hit_ground.drain(..) { for effect in projectile.hit_ground.drain(..) {
@ -53,6 +49,17 @@ impl<'a> System<'a> for Sys {
} }
} }
} }
// Hit wall
if physics.on_wall.is_some() {
for effect in projectile.hit_wall.drain(..) {
match effect {
projectile::Effect::Stick => {
velocities.remove(entity);
}
_ => {}
}
}
}
// Hit entity // Hit entity
if let Some(other) = physics.touch_entity { if let Some(other) = physics.touch_entity {
for effect in projectile.hit_entity.drain(..) { for effect in projectile.hit_entity.drain(..) {
@ -72,6 +79,10 @@ impl<'a> System<'a> for Sys {
} }
} }
} }
if let Some(vel) = velocities.get(entity) {
ori.0 = vel.0.normalized();
}
} }
} }
} }