Merge branch 'telastrus/fall-damage' into 'master'

Rudimentary fall damage

See merge request veloren/veloren!417
This commit is contained in:
Forest Anderson 2019-08-07 02:51:43 +00:00
commit 2fb8306b98
4 changed files with 37 additions and 4 deletions

View File

@ -6,6 +6,7 @@ use specs_idvs::IDVStorage;
pub enum HealthSource {
Attack { by: Uid }, // TODO: Implement weapon
Suicide,
World,
Revive,
Command,
LevelUp,

View File

@ -1,4 +1,5 @@
use crate::{
comp::HealthSource,
comp::{
ActionState, Body, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Scale, Stats, Vel,
Wielding,
@ -41,6 +42,7 @@ impl<'a> System<'a> for Sys {
WriteStorage<'a, Pos>,
WriteStorage<'a, Vel>,
WriteStorage<'a, Ori>,
WriteStorage<'a, Stats>,
);
fn run(
@ -56,10 +58,11 @@ impl<'a> System<'a> for Sys {
mut positions,
mut velocities,
mut orientations,
mut stats,
): Self::SystemData,
) {
// Apply movement inputs
for (entity, a, scale, _, mut pos, mut vel, mut ori) in (
for (entity, a, scale, b, mut pos, mut vel, mut ori, mut stat) in (
&entities,
&action_states,
scales.maybe(),
@ -67,6 +70,7 @@ impl<'a> System<'a> for Sys {
&mut positions,
&mut velocities,
&mut orientations,
&mut stats,
)
.join()
{
@ -206,6 +210,11 @@ impl<'a> System<'a> for Sys {
// When the resolution direction is pointing upwards, we must be on the ground
if resolve_dir.z > 0.0 && vel.0.z <= 0.0 {
// Check for fall damage
let falldmg = (vel.0.z / 1.5 + 6.0) as i32;
if falldmg < 0 {
stat.health.change_by(falldmg, HealthSource::World);
}
on_ground = true;
}

View File

@ -82,6 +82,7 @@ widget_ids! {
fps_counter,
ping,
coordinates,
velocity,
loaded_distance,
// Game Version
@ -127,6 +128,7 @@ pub struct DebugInfo {
pub tps: f64,
pub ping_ms: f64,
pub coordinates: Option<comp::Pos>,
pub velocity: Option<comp::Vel>,
}
pub enum Event {
@ -498,7 +500,7 @@ impl Hud {
.font_id(self.fonts.opensans)
.font_size(14)
.set(self.ids.ping, ui_widgets);
// Players position
// Player's position
let coordinates_text = match debug_info.coordinates {
Some(coordinates) => format!("Coordinates: {:.1}", coordinates.0),
None => "Player has no Pos component".to_owned(),
@ -509,13 +511,24 @@ impl Hud {
.font_id(self.fonts.opensans)
.font_size(14)
.set(self.ids.coordinates, ui_widgets);
// Player's velocity
let velocity_text = match debug_info.velocity {
Some(velocity) => format!("Velocity: {:.1}", velocity.0),
None => "Player has no Vel component".to_owned(),
};
Text::new(&velocity_text)
.color(TEXT_COLOR)
.down_from(self.ids.coordinates, 5.0)
.font_id(self.fonts.opensans)
.font_size(14)
.set(self.ids.velocity, ui_widgets);
// Loaded distance
Text::new(&format!(
"View distance: {} chunks",
client.loaded_distance().unwrap_or(0)
))
.color(TEXT_COLOR)
.down_from(self.ids.coordinates, 5.0)
.down_from(self.ids.velocity, 5.0)
.font_id(self.fonts.opensans)
.font_size(14)
.set(self.ids.loaded_distance, ui_widgets);

View File

@ -7,7 +7,9 @@ use crate::{
Direction, Error, GlobalState, PlayState, PlayStateResult,
};
use client::{self, Client};
use common::{clock::Clock, comp, comp::Pos, msg::ClientState, terrain::Block, vol::ReadVol};
use common::{
clock::Clock, comp, comp::Pos, comp::Vel, msg::ClientState, terrain::Block, vol::ReadVol,
};
use log::error;
use specs::Join;
use std::{cell::RefCell, rc::Rc, time::Duration};
@ -287,6 +289,14 @@ impl PlayState for SessionState {
.read_storage::<Pos>()
.get(self.client.borrow().entity())
.cloned(),
velocity: self
.client
.borrow()
.state()
.ecs()
.read_storage::<Vel>()
.get(self.client.borrow().entity())
.cloned(),
},
&self.scene.camera(),
);