From 4275c24b38fa65d9009732861834f263156a13d4 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Sun, 19 May 2019 22:46:53 +0200 Subject: [PATCH] Add knockback Former-commit-id: a703eb937ef7094a085548ca3197a575059855a0 --- common/src/state.rs | 1 + common/src/sys/action.rs | 10 +++++++--- server/src/lib.rs | 1 - 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/common/src/state.rs b/common/src/state.rs index 192dedf9d1..8b9b4e7965 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -103,6 +103,7 @@ impl State { ecs.register_synced::(); ecs.register_synced::(); ecs.register_synced::(); + ecs.register::(); // Register unsynced (or synced by other means) components. ecs.register::(); diff --git a/common/src/sys/action.rs b/common/src/sys/action.rs index 404ddcb8a7..b8b55a046f 100644 --- a/common/src/sys/action.rs +++ b/common/src/sys/action.rs @@ -5,7 +5,7 @@ use vek::*; // Crate use crate::{ comp::{ - phys::{Pos, Vel}, + phys::{ForceUpdate, Pos, Vel}, Action, Actions, Control, Stats, }, state::{DeltaTime, Time}, @@ -23,11 +23,12 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Pos>, WriteStorage<'a, Vel>, WriteStorage<'a, Stats>, + WriteStorage<'a, ForceUpdate>, ); fn run( &mut self, - (entities, time, dt, mut actions, positions, mut velocities, mut stats): Self::SystemData, + (entities, time, dt, mut actions, positions, mut velocities, mut stats, mut force_updates): Self::SystemData, ) { for (a, actions_a, pos_a) in (&entities, &mut actions, &positions).join() { for event in actions_a.0.drain(..) { @@ -40,7 +41,10 @@ impl<'a> System<'a> for Sys { continue; } if pos_a.0.distance_squared(pos_b.0) < 50.0 { - stat_b.hp.change_by(-60); // TODO: variable damage + stat_b.hp.change_by(-10); // TODO: variable damage + vel_b.0 += (pos_b.0 - pos_a.0).normalized() * 20.0; + vel_b.0.z = 20.0; + force_updates.insert(b, ForceUpdate); } } } diff --git a/server/src/lib.rs b/server/src/lib.rs index adfac612ff..9dcf47acc7 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -73,7 +73,6 @@ impl Server { let (chunk_tx, chunk_rx) = mpsc::channel(); let mut state = State::new(); - state.ecs_mut().register::(); state .ecs_mut() .add_resource(SpawnPoint(Vec3::new(16_384.0, 16_384.0, 280.0)));