Add respawn timer ui element
This commit is contained in:
parent
3c0353c76e
commit
c6d59ffb04
@ -8,7 +8,7 @@ glow_enabled = true
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_oh8vq"]
|
||||
|
||||
[node name="player" type="LocalPlayer" unique_id=863055906 node_paths=PackedStringArray("camera", "soldier_mesh", "collider", "splorch", "dead_cam_target")]
|
||||
[node name="player" type="LocalPlayer" unique_id=863055906 node_paths=PackedStringArray("camera", "soldier_mesh", "collider", "splorch", "dead_cam_target", "respawn_label")]
|
||||
look_sensitivity = 1.5
|
||||
camera = NodePath("camera_3d")
|
||||
move_speed = 5.0
|
||||
@ -16,6 +16,7 @@ soldier_mesh = NodePath("soldier_m")
|
||||
collider = NodePath("collision_shape_3d2")
|
||||
splorch = NodePath("splorch")
|
||||
dead_cam_target = NodePath("dead_camera_target")
|
||||
respawn_label = NodePath("respawn_label")
|
||||
health = 100
|
||||
collision_mask = 4
|
||||
|
||||
@ -37,3 +38,17 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.16157162, 1.4223524, 0)
|
||||
|
||||
[node name="dead_camera_target" type="Node3D" parent="." unique_id=559969559]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.9069022, 0.4213412, 0, -0.4213412, 0.9069022, 0, 2.3258846, 1.5254744)
|
||||
|
||||
[node name="respawn_label" type="Label" parent="." unique_id=595642200]
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -20.0
|
||||
offset_top = -11.5
|
||||
offset_right = 20.0
|
||||
offset_bottom = 11.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
@ -464,7 +464,6 @@ impl Game {
|
||||
pub fn on_death(&mut self, player_id: u16) {
|
||||
if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer {
|
||||
if let PeerKind::Server(peer, _) = peer {
|
||||
godot_print!("Sent kill!");
|
||||
peer.broadcast_reliable(Kill(player_id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,8 +3,8 @@ use std::{f32::consts::PI, ops::Neg};
|
||||
use godot::{
|
||||
classes::{
|
||||
AudioStreamPlayer3D, Camera3D, CharacterBody3D, CollisionShape3D, GpuParticles3D,
|
||||
ICharacterBody3D, Input, InputEvent, InputEventMouseMotion, PhysicsRayQueryParameters3D,
|
||||
input::MouseMode,
|
||||
ICharacterBody3D, Input, InputEvent, InputEventMouseMotion, Label,
|
||||
PhysicsRayQueryParameters3D, input::MouseMode,
|
||||
},
|
||||
obj::WithBaseField,
|
||||
prelude::*,
|
||||
@ -12,6 +12,7 @@ use godot::{
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
game_manager::Game,
|
||||
net::{
|
||||
network_manager::{
|
||||
NetworkManager,
|
||||
@ -97,6 +98,8 @@ pub struct LocalPlayer {
|
||||
#[export]
|
||||
dead_cam_target: Option<Gd<Node3D>>,
|
||||
#[export]
|
||||
respawn_label: Option<Gd<Label>>,
|
||||
#[export]
|
||||
health: i32,
|
||||
|
||||
pub player_id: Option<u16>,
|
||||
@ -251,6 +254,17 @@ impl ICharacterBody3D for LocalPlayer {
|
||||
fn process(&mut self, delta: f64) {
|
||||
if self.is_dead {
|
||||
self.dead_for += delta;
|
||||
|
||||
if let Some(label) = &mut self.respawn_label {
|
||||
let respawn_timer = if let Some(game) = Game::singleton() {
|
||||
game.bind().respawn_timer
|
||||
} else {
|
||||
0.
|
||||
};
|
||||
|
||||
let time_remaining = respawn_timer - self.dead_for;
|
||||
label.set_text(&format!("Respawn in\n{:.2}", time_remaining));
|
||||
}
|
||||
}
|
||||
|
||||
self.shoot_cd -= delta;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user