Add knockback

Former-commit-id: a703eb937ef7094a085548ca3197a575059855a0
This commit is contained in:
timokoesters 2019-05-19 22:46:53 +02:00
parent a0918d11b6
commit 30bf1cde10
3 changed files with 8 additions and 4 deletions

View File

@ -103,6 +103,7 @@ impl State {
ecs.register_synced::<comp::Actor>(); ecs.register_synced::<comp::Actor>();
ecs.register_synced::<comp::Player>(); ecs.register_synced::<comp::Player>();
ecs.register_synced::<comp::Stats>(); ecs.register_synced::<comp::Stats>();
ecs.register::<comp::phys::ForceUpdate>();
// Register unsynced (or synced by other means) components. // Register unsynced (or synced by other means) components.
ecs.register::<comp::phys::Pos>(); ecs.register::<comp::phys::Pos>();

View File

@ -5,7 +5,7 @@ use vek::*;
// Crate // Crate
use crate::{ use crate::{
comp::{ comp::{
phys::{Pos, Vel}, phys::{ForceUpdate, Pos, Vel},
Action, Actions, Control, Stats, Action, Actions, Control, Stats,
}, },
state::{DeltaTime, Time}, state::{DeltaTime, Time},
@ -23,11 +23,12 @@ impl<'a> System<'a> for Sys {
ReadStorage<'a, Pos>, ReadStorage<'a, Pos>,
WriteStorage<'a, Vel>, WriteStorage<'a, Vel>,
WriteStorage<'a, Stats>, WriteStorage<'a, Stats>,
WriteStorage<'a, ForceUpdate>,
); );
fn run( fn run(
&mut self, &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 (a, actions_a, pos_a) in (&entities, &mut actions, &positions).join() {
for event in actions_a.0.drain(..) { for event in actions_a.0.drain(..) {
@ -40,7 +41,10 @@ impl<'a> System<'a> for Sys {
continue; continue;
} }
if pos_a.0.distance_squared(pos_b.0) < 50.0 { 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);
} }
} }
} }

View File

@ -73,7 +73,6 @@ impl Server {
let (chunk_tx, chunk_rx) = mpsc::channel(); let (chunk_tx, chunk_rx) = mpsc::channel();
let mut state = State::new(); let mut state = State::new();
state.ecs_mut().register::<comp::phys::ForceUpdate>();
state state
.ecs_mut() .ecs_mut()
.add_resource(SpawnPoint(Vec3::new(16_384.0, 16_384.0, 280.0))); .add_resource(SpawnPoint(Vec3::new(16_384.0, 16_384.0, 280.0)));