mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fix red effect
Former-commit-id: 1fd90a40aaaccb98aeb34715ee7cad5c0b3b3de7
This commit is contained in:
parent
ad5dcb4158
commit
a0918d11b6
@ -5,13 +5,13 @@ use specs::{Component, FlaggedStorage, NullStorage, VecStorage};
|
||||
pub struct Health {
|
||||
pub current: u32,
|
||||
pub maximum: u32,
|
||||
pub last_change: Option<(i32, Time)>,
|
||||
pub last_change: Option<(i32, f64)>,
|
||||
}
|
||||
|
||||
impl Health {
|
||||
pub fn change_by(&mut self, amount: i32, current_time: Time) {
|
||||
pub fn change_by(&mut self, amount: i32) {
|
||||
self.current = (self.current as i32 + amount).max(0) as u32;
|
||||
self.last_change = dbg!(Some((amount, current_time)));
|
||||
self.last_change = Some((amount, 0.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ pub struct TimeOfDay(f64);
|
||||
|
||||
/// A resource that stores the tick (i.e: physics) time.
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
|
||||
pub struct Time(f64);
|
||||
pub struct Time(pub f64);
|
||||
|
||||
/// A resource that stores the time since the previous tick.
|
||||
#[derive(Default)]
|
||||
|
@ -4,7 +4,10 @@ use vek::*;
|
||||
|
||||
// Crate
|
||||
use crate::{
|
||||
comp::{phys::Pos, Action, Actions, Control, Stats},
|
||||
comp::{
|
||||
phys::{Pos, Vel},
|
||||
Action, Actions, Control, Stats,
|
||||
},
|
||||
state::{DeltaTime, Time},
|
||||
};
|
||||
|
||||
@ -18,21 +21,26 @@ impl<'a> System<'a> for Sys {
|
||||
Read<'a, DeltaTime>,
|
||||
WriteStorage<'a, Actions>,
|
||||
ReadStorage<'a, Pos>,
|
||||
WriteStorage<'a, Vel>,
|
||||
WriteStorage<'a, Stats>,
|
||||
);
|
||||
|
||||
fn run(&mut self, (entities, time, dt, mut actions, positions, mut stats): Self::SystemData) {
|
||||
for (a, mut actions_a, pos_a) in (&entities, &mut actions, &positions).join() {
|
||||
fn run(
|
||||
&mut self,
|
||||
(entities, time, dt, mut actions, positions, mut velocities, mut stats): Self::SystemData,
|
||||
) {
|
||||
for (a, actions_a, pos_a) in (&entities, &mut actions, &positions).join() {
|
||||
for event in actions_a.0.drain(..) {
|
||||
match event {
|
||||
Action::Attack => {
|
||||
for (b, pos_b, stat_b) in (&entities, &positions, &mut stats).join() {
|
||||
for (b, pos_b, stat_b, vel_b) in
|
||||
(&entities, &positions, &mut stats, &mut velocities).join()
|
||||
{
|
||||
if a == b {
|
||||
continue;
|
||||
}
|
||||
if pos_a.0.distance_squared(pos_b.0) < 50.0 {
|
||||
&mut stat_b.hp.change_by(-60, *time); // TODO: variable damage
|
||||
&stat_b.hp;
|
||||
stat_b.hp.change_by(-60); // TODO: variable damage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ impl<'a> System<'a> for Sys {
|
||||
fn run(&mut self, (dt, mut animation_infos): Self::SystemData) {
|
||||
for (mut animation_info) in (&mut animation_infos).join() {
|
||||
animation_info.time += dt.0 as f64;
|
||||
&animation_info.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,19 @@ pub struct Sys;
|
||||
impl<'a> System<'a> for Sys {
|
||||
type SystemData = (
|
||||
Entities<'a>,
|
||||
ReadStorage<'a, Stats>,
|
||||
Read<'a, DeltaTime>,
|
||||
WriteStorage<'a, Stats>,
|
||||
WriteStorage<'a, Dying>,
|
||||
);
|
||||
|
||||
fn run(&mut self, (entities, stats, mut dyings): Self::SystemData) {
|
||||
for (entity, stat) in (&entities, &stats).join() {
|
||||
fn run(&mut self, (entities, dt, mut stats, mut dyings): Self::SystemData) {
|
||||
for (entity, mut stat) in (&entities, &mut stats).join() {
|
||||
if stat.hp.current == 0 {
|
||||
dyings.insert(entity, Dying);
|
||||
}
|
||||
if let Some(change) = &mut stat.hp.last_change {
|
||||
change.1 += dt.0 as f64;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -358,6 +358,15 @@ impl FigureMgr {
|
||||
)
|
||||
.join()
|
||||
{
|
||||
// Change in health as color!
|
||||
let col = stats
|
||||
.and_then(|stats| stats.hp.last_change)
|
||||
.map(|(change_by, time)| {
|
||||
Rgba::broadcast(1.0)
|
||||
+ Rgba::new(0.0, -1.0, -1.0, 0.0).map(|c| (c / (1.0 + 5.0 * time)) as f32)
|
||||
})
|
||||
.unwrap_or(Rgba::broadcast(1.0));
|
||||
|
||||
match actor {
|
||||
comp::Actor::Character { body, .. } => match body {
|
||||
Body::Humanoid(body) => {
|
||||
@ -396,8 +405,7 @@ impl FigureMgr {
|
||||
};
|
||||
|
||||
state.skeleton.interpolate(&target_skeleton);
|
||||
|
||||
state.update(renderer, pos.0, dir.0, Rgba::white());
|
||||
state.update(renderer, pos.0, dir.0, col);
|
||||
}
|
||||
Body::Quadruped(body) => {
|
||||
let state = self.quadruped_states.entry(entity).or_insert_with(|| {
|
||||
@ -426,21 +434,6 @@ impl FigureMgr {
|
||||
};
|
||||
|
||||
state.skeleton.interpolate(&target_skeleton);
|
||||
|
||||
// Change in health as color!
|
||||
let col = stats
|
||||
.and_then(|stats| stats.hp.last_change)
|
||||
.map(|(change_by, change_time)| Rgba::new(1.0, 0.7, 0.7, 1.0))
|
||||
.unwrap_or(Rgba::broadcast(1.0));
|
||||
|
||||
// Change in health as color!
|
||||
let col = stats
|
||||
.and_then(|stats| stats.hp.last_change)
|
||||
.map(|(change_by, change_time)| Rgba::new(1.0, 0.7, 0.7, 1.0))
|
||||
.unwrap_or(Rgba::broadcast(1.0));
|
||||
|
||||
state.update(renderer, pos.0, dir.0, col);
|
||||
|
||||
state.update(renderer, pos.0, dir.0, col);
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user