Add own health number
This commit is contained in:
parent
9535227e6f
commit
2e71105ea2
@ -12,7 +12,13 @@ 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", "effects", "dead_cam_target", "respawn_label", "camera_origin", "weapon_node", "pause_panel", "exit_to_lobby", "settings_panel", "scoreboard", "chatbox")]
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_7awel"]
|
||||
font_size = 32
|
||||
font_color = Color(1, 0, 0, 1)
|
||||
outline_size = 10
|
||||
outline_color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="player" type="LocalPlayer" unique_id=863055906 node_paths=PackedStringArray("camera", "soldier_mesh", "collider", "effects", "dead_cam_target", "respawn_label", "camera_origin", "weapon_node", "pause_panel", "exit_to_lobby", "settings_panel", "scoreboard", "chatbox", "health_label")]
|
||||
look_sensitivity = 1.5
|
||||
camera = NodePath("camera_3d")
|
||||
move_speed = 5.0
|
||||
@ -28,6 +34,7 @@ exit_to_lobby = NodePath("pause_menu/v_box_container/exit_to_lobby")
|
||||
settings_panel = NodePath("settings")
|
||||
scoreboard = NodePath("scoreboard")
|
||||
chatbox = NodePath("chat_box")
|
||||
health_label = NodePath("health_label")
|
||||
health = 100
|
||||
collision_mask = 4
|
||||
|
||||
@ -157,12 +164,31 @@ metadata/_edit_lock_ = true
|
||||
|
||||
[node name="chat_box" parent="." unique_id=1125601400 instance=ExtResource("5_cv68x")]
|
||||
in_game = true
|
||||
text_alignment = 2
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -500.0
|
||||
offset_top = -300.0
|
||||
offset_right = 0.0
|
||||
offset_bottom = 0.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
|
||||
[node name="health_label" type="Label" parent="." unique_id=651212450]
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -300.0
|
||||
offset_bottom = 0.0
|
||||
offset_left = 34.0
|
||||
offset_top = -45.0
|
||||
offset_right = 74.0
|
||||
offset_bottom = -22.0
|
||||
grow_vertical = 0
|
||||
text = "100"
|
||||
label_settings = SubResource("LabelSettings_7awel")
|
||||
vertical_alignment = 2
|
||||
|
||||
[connection signal="pressed" from="pause_menu/v_box_container/settings" to="settings" method="open"]
|
||||
[connection signal="pressed" from="pause_menu/v_box_container/exit_to_lobby" to="." method="exit_to_lobby"]
|
||||
|
||||
@ -213,6 +213,8 @@ pub struct LocalPlayer {
|
||||
#[export]
|
||||
chatbox: Option<Gd<ChatBox>>,
|
||||
#[export]
|
||||
health_label: Option<Gd<Label>>,
|
||||
#[export]
|
||||
health: i32,
|
||||
|
||||
pub player_id: Option<u16>,
|
||||
@ -337,6 +339,9 @@ impl IPlayer for LocalPlayer {
|
||||
s.kill(source);
|
||||
}
|
||||
}
|
||||
if let Some(health_label) = &mut s.health_label {
|
||||
health_label.set_text(&s.health.max(0).to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -110,7 +110,6 @@ impl Weapon for Raygun {
|
||||
|
||||
if deal_damage && let Some(target) = target {
|
||||
if let Ok(mut shootable) = target.collider.clone().try_dynify::<dyn Shootable>() {
|
||||
godot_print!("{}", target.collider);
|
||||
self.run_deferred(move |_| {
|
||||
shootable.dyn_bind_mut().on_shoot(
|
||||
DamageSource::Player(player_id),
|
||||
@ -214,7 +213,6 @@ impl Weapon for Shotgun {
|
||||
let delta = collider_pos - from;
|
||||
|
||||
if let Ok(mut shootable) = collider.clone().try_dynify::<dyn Shootable>() {
|
||||
godot_print!("{} ({})", collider, delta.length());
|
||||
self.run_deferred(move |_| {
|
||||
shootable.dyn_bind_mut().on_shoot(
|
||||
DamageSource::Player(player_id),
|
||||
|
||||
@ -4,6 +4,7 @@ use godot::{
|
||||
classes::{
|
||||
Engine, IVBoxContainer, InputEvent, LineEdit, RichTextLabel, ScrollContainer, VBoxContainer,
|
||||
},
|
||||
global::HorizontalAlignment,
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
@ -14,7 +15,7 @@ use crate::{
|
||||
};
|
||||
|
||||
#[derive(GodotClass)]
|
||||
#[class(base=VBoxContainer, init, tool)]
|
||||
#[class(base=VBoxContainer, tool)]
|
||||
pub struct ChatBox {
|
||||
#[export]
|
||||
scroll: Option<Gd<ScrollContainer>>,
|
||||
@ -24,6 +25,8 @@ pub struct ChatBox {
|
||||
line_edit: Option<Gd<LineEdit>>,
|
||||
#[export]
|
||||
pub in_game: bool,
|
||||
#[export]
|
||||
text_alignment: HorizontalAlignment,
|
||||
|
||||
scroll_on_next_update: bool,
|
||||
|
||||
@ -32,6 +35,18 @@ pub struct ChatBox {
|
||||
|
||||
#[godot_api]
|
||||
impl IVBoxContainer for ChatBox {
|
||||
fn init(base: Base<VBoxContainer>) -> ChatBox {
|
||||
ChatBox {
|
||||
scroll: None,
|
||||
messages: None,
|
||||
line_edit: None,
|
||||
in_game: false,
|
||||
text_alignment: HorizontalAlignment::LEFT,
|
||||
scroll_on_next_update: false,
|
||||
base,
|
||||
}
|
||||
}
|
||||
|
||||
fn ready(&mut self) {
|
||||
if !Engine::singleton().is_editor_hint() {
|
||||
self.run_deferred(|s| {
|
||||
@ -96,7 +111,8 @@ impl ChatBox {
|
||||
#[signal]
|
||||
pub fn on_closed();
|
||||
|
||||
fn on_new_message(&mut self, message: Gd<RichTextLabel>) {
|
||||
fn on_new_message(&mut self, mut message: Gd<RichTextLabel>) {
|
||||
message.set_horizontal_alignment(self.text_alignment);
|
||||
if let Some(messages) = &mut self.messages {
|
||||
messages.add_child(&message);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user