mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
fall damage + velocity debug
This commit is contained in:
@ -8,7 +8,7 @@ mod inventory;
|
|||||||
mod last;
|
mod last;
|
||||||
mod phys;
|
mod phys;
|
||||||
mod player;
|
mod player;
|
||||||
mod stats;
|
pub mod stats;
|
||||||
mod visual;
|
mod visual;
|
||||||
|
|
||||||
// Reexports
|
// Reexports
|
||||||
|
@ -6,6 +6,7 @@ use specs_idvs::IDVStorage;
|
|||||||
pub enum HealthSource {
|
pub enum HealthSource {
|
||||||
Attack { by: Uid }, // TODO: Implement weapon
|
Attack { by: Uid }, // TODO: Implement weapon
|
||||||
Suicide,
|
Suicide,
|
||||||
|
World, //ZA WARUDO!
|
||||||
Revive,
|
Revive,
|
||||||
Command,
|
Command,
|
||||||
LevelUp,
|
LevelUp,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
comp::HealthSource,
|
||||||
comp::{
|
comp::{
|
||||||
ActionState, Body, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Scale, Stats, Vel,
|
ActionState, Body, Jumping, MoveDir, OnGround, Ori, Pos, Rolling, Scale, Stats, Vel,
|
||||||
Wielding,
|
Wielding,
|
||||||
@ -41,6 +42,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
WriteStorage<'a, Pos>,
|
WriteStorage<'a, Pos>,
|
||||||
WriteStorage<'a, Vel>,
|
WriteStorage<'a, Vel>,
|
||||||
WriteStorage<'a, Ori>,
|
WriteStorage<'a, Ori>,
|
||||||
|
WriteStorage<'a, Stats>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
@ -56,10 +58,11 @@ impl<'a> System<'a> for Sys {
|
|||||||
mut positions,
|
mut positions,
|
||||||
mut velocities,
|
mut velocities,
|
||||||
mut orientations,
|
mut orientations,
|
||||||
|
mut stats,
|
||||||
): Self::SystemData,
|
): Self::SystemData,
|
||||||
) {
|
) {
|
||||||
// Apply movement inputs
|
// 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,
|
&entities,
|
||||||
&action_states,
|
&action_states,
|
||||||
scales.maybe(),
|
scales.maybe(),
|
||||||
@ -67,6 +70,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
&mut positions,
|
&mut positions,
|
||||||
&mut velocities,
|
&mut velocities,
|
||||||
&mut orientations,
|
&mut orientations,
|
||||||
|
&mut stats,
|
||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
{
|
{
|
||||||
@ -206,6 +210,12 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
// When the resolution direction is pointing upwards, we must be on the ground
|
// When the resolution direction is pointing upwards, we must be on the ground
|
||||||
if resolve_dir.z > 0.0 && vel.0.z <= 0.0 {
|
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 {
|
||||||
|
//println!("fall damage: {}", falldmg);
|
||||||
|
stat.health.change_by(falldmg, HealthSource::World);
|
||||||
|
}
|
||||||
on_ground = true;
|
on_ground = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@ widget_ids! {
|
|||||||
fps_counter,
|
fps_counter,
|
||||||
ping,
|
ping,
|
||||||
coordinates,
|
coordinates,
|
||||||
|
velocity,
|
||||||
loaded_distance,
|
loaded_distance,
|
||||||
|
|
||||||
// Game Version
|
// Game Version
|
||||||
@ -127,6 +128,7 @@ pub struct DebugInfo {
|
|||||||
pub tps: f64,
|
pub tps: f64,
|
||||||
pub ping_ms: f64,
|
pub ping_ms: f64,
|
||||||
pub coordinates: Option<comp::Pos>,
|
pub coordinates: Option<comp::Pos>,
|
||||||
|
pub velocity: Option<comp::Vel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
@ -498,7 +500,7 @@ impl Hud {
|
|||||||
.font_id(self.fonts.opensans)
|
.font_id(self.fonts.opensans)
|
||||||
.font_size(14)
|
.font_size(14)
|
||||||
.set(self.ids.ping, ui_widgets);
|
.set(self.ids.ping, ui_widgets);
|
||||||
// Players position
|
// Player's position
|
||||||
let coordinates_text = match debug_info.coordinates {
|
let coordinates_text = match debug_info.coordinates {
|
||||||
Some(coordinates) => format!("Coordinates: {:.1}", coordinates.0),
|
Some(coordinates) => format!("Coordinates: {:.1}", coordinates.0),
|
||||||
None => "Player has no Pos component".to_owned(),
|
None => "Player has no Pos component".to_owned(),
|
||||||
@ -509,13 +511,24 @@ impl Hud {
|
|||||||
.font_id(self.fonts.opensans)
|
.font_id(self.fonts.opensans)
|
||||||
.font_size(14)
|
.font_size(14)
|
||||||
.set(self.ids.coordinates, ui_widgets);
|
.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
|
// Loaded distance
|
||||||
Text::new(&format!(
|
Text::new(&format!(
|
||||||
"View distance: {} chunks",
|
"View distance: {} chunks",
|
||||||
client.loaded_distance().unwrap_or(0)
|
client.loaded_distance().unwrap_or(0)
|
||||||
))
|
))
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.down_from(self.ids.coordinates, 5.0)
|
.down_from(self.ids.velocity, 5.0)
|
||||||
.font_id(self.fonts.opensans)
|
.font_id(self.fonts.opensans)
|
||||||
.font_size(14)
|
.font_size(14)
|
||||||
.set(self.ids.loaded_distance, ui_widgets);
|
.set(self.ids.loaded_distance, ui_widgets);
|
||||||
|
@ -7,7 +7,9 @@ use crate::{
|
|||||||
Direction, Error, GlobalState, PlayState, PlayStateResult,
|
Direction, Error, GlobalState, PlayState, PlayStateResult,
|
||||||
};
|
};
|
||||||
use client::{self, Client};
|
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 log::error;
|
||||||
use specs::Join;
|
use specs::Join;
|
||||||
use std::{cell::RefCell, rc::Rc, time::Duration};
|
use std::{cell::RefCell, rc::Rc, time::Duration};
|
||||||
@ -287,6 +289,14 @@ impl PlayState for SessionState {
|
|||||||
.read_storage::<Pos>()
|
.read_storage::<Pos>()
|
||||||
.get(self.client.borrow().entity())
|
.get(self.client.borrow().entity())
|
||||||
.cloned(),
|
.cloned(),
|
||||||
|
velocity: self
|
||||||
|
.client
|
||||||
|
.borrow()
|
||||||
|
.state()
|
||||||
|
.ecs()
|
||||||
|
.read_storage::<Vel>()
|
||||||
|
.get(self.client.borrow().entity())
|
||||||
|
.cloned(),
|
||||||
},
|
},
|
||||||
&self.scene.camera(),
|
&self.scene.camera(),
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user