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)]
pub struct Projectile {
pub hit_ground: Vec<Effect>,
pub hit_wall: Vec<Effect>,
pub hit_entity: Vec<Effect>,
}

View File

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

View File

@ -38,10 +38,6 @@ impl<'a> System<'a> for Sys {
)
.join()
{
if let Some(vel) = velocities.get(entity) {
ori.0 = vel.0.normalized();
}
// Hit ground
if physics.on_ground {
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
if let Some(other) = physics.touch_entity {
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();
}
}
}
}