mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
🐛 use 8-bit integer for synced health, damage scaling and display updates
This commit is contained in:
parent
f1df203a76
commit
547c97bfba
|
|
@ -17,7 +17,7 @@ class_name ExplosiveDamageComponent extends Area3D
|
|||
## Emitted when the scale tween is finished
|
||||
signal finished
|
||||
|
||||
@export var damage : float = .35
|
||||
@export var damage : float = 89
|
||||
@export var impulse_force : int = 1000
|
||||
var damage_dealer : MatchParticipant
|
||||
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ class_name HealthComponent extends Area3D
|
|||
|
||||
@export var match_participant : MatchParticipant
|
||||
|
||||
@export var max_health : float = 1.
|
||||
@export var health : float = 1.:
|
||||
set(value):
|
||||
health = value
|
||||
health_changed.emit(value)
|
||||
@export var max_health : int = 255
|
||||
@export var health : int = 255:
|
||||
set(new_health):
|
||||
health = new_health
|
||||
health_changed.emit(new_health)
|
||||
|
||||
signal health_zeroed(killer_id : int)
|
||||
signal health_changed(value : float)
|
||||
signal health_changed(new_health : int)
|
||||
|
||||
func _ready() -> void:
|
||||
# only collide with the "Damage" layer, disable monitoring completely
|
||||
|
|
@ -33,17 +33,17 @@ func _ready() -> void:
|
|||
call_deferred("heal_full")
|
||||
|
||||
@rpc("call_local", "reliable")
|
||||
func damage(amount : float, damage_dealer_player_id : int, damage_dealer_team_id : int) -> void:
|
||||
func damage(amount : int, damage_dealer_player_id : int, damage_dealer_team_id : int) -> void:
|
||||
if (damage_dealer_team_id == match_participant.team_id) and (damage_dealer_player_id != match_participant.player_id):
|
||||
return
|
||||
|
||||
health = clampf(health - amount, 0.0, max_health)
|
||||
if health == 0.0:
|
||||
health = clampi(health - amount, 0, max_health)
|
||||
if health == 0:
|
||||
health_zeroed.emit(damage_dealer_player_id)
|
||||
|
||||
@rpc("call_local", "reliable")
|
||||
func _heal(amount : float) -> void:
|
||||
health = clampf(health + amount, 0.0, max_health)
|
||||
func _heal(amount : int) -> void:
|
||||
health = clampi(health + amount, 0, max_health)
|
||||
|
||||
func heal_full() -> void:
|
||||
if not is_multiplayer_authority():
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ class_name Player extends RigidBody3D
|
|||
enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
|
||||
|
||||
signal died(player : Player, killer_id : int)
|
||||
signal energy_changed(energy : float)
|
||||
|
||||
@export var iff : IFF
|
||||
@export var health_component : HealthComponent
|
||||
|
|
@ -67,8 +66,8 @@ func _ready() -> void:
|
|||
match_participant.player_id_changed.connect(input.update_multiplayer_authority)
|
||||
match_participant.username_changed.connect(iff._on_username_changed)
|
||||
|
||||
health_component.health_changed.connect(hud._on_health_changed)
|
||||
health_component.health_changed.connect(iff._on_health_changed)
|
||||
health_component.health_changed.connect(hud.health_bar.set_value)
|
||||
health_component.health_changed.connect(iff.health_bar.set_value)
|
||||
health_component.health_changed.emit(health_component.health)
|
||||
health_component.health_zeroed.connect(die)
|
||||
|
||||
|
|
@ -153,11 +152,10 @@ func _update_jetpack_energy(delta : float) -> void:
|
|||
energy -= energy_drain_rate * delta
|
||||
else:
|
||||
energy += energy_charge_rate * delta
|
||||
|
||||
energy = clamp(energy, 0, energy_max)
|
||||
energy_changed.emit(energy)
|
||||
hud.energy_bar.value = energy
|
||||
|
||||
func _handle_movement() -> void:
|
||||
func _integrate_forces(_state : PhysicsDirectBodyState3D) -> void:
|
||||
# retrieve user's direction vector
|
||||
var _input_dir : Vector2 = input.direction
|
||||
# compute direction in local space
|
||||
|
|
@ -199,9 +197,6 @@ func _handle_movement() -> void:
|
|||
|
||||
_jumping = false
|
||||
|
||||
func _integrate_forces(_state : PhysicsDirectBodyState3D) -> void:
|
||||
_handle_movement()
|
||||
|
||||
func _update_third_person_animations() -> void:
|
||||
if _is_pawn():
|
||||
return
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
[ext_resource type="PackedScene" uid="uid://bbeecp3jusppn" path="res://interfaces/hud/iffs/IFF.tscn" id="2_s5wgp"]
|
||||
[ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="3_ccety"]
|
||||
[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/resources/collider.tres" id="4_8kvcy"]
|
||||
[ext_resource type="Script" path="res://entities/components/match_participant.gd" id="6_lrose"]
|
||||
[ext_resource type="Script" path="res://entities/components/inventory.gd" id="8_768qh"]
|
||||
[ext_resource type="PackedScene" uid="uid://drbefw6akui2v" path="res://entities/player/vanguard.tscn" id="8_eiy7q"]
|
||||
[ext_resource type="Script" path="res://entities/components/flag_carry_component.gd" id="8_pdfbn"]
|
||||
|
|
@ -17,6 +16,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://b0xql5hi0b52y" path="res://entities/weapons/chaingun/chaingun.tscn" id="15_io0a3"]
|
||||
[ext_resource type="PackedScene" uid="uid://cstl7yxc75572" path="res://entities/weapons/grenade_launcher/grenade_launcher.tscn" id="16_4xs2j"]
|
||||
[ext_resource type="PackedScene" uid="uid://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="18_7nkei"]
|
||||
[ext_resource type="Script" path="res://entities/components/match_participant.gd" id="18_t2jrs"]
|
||||
[ext_resource type="Script" path="res://entities/player/inputs_sync.gd" id="18_v4iu1"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"]
|
||||
|
|
@ -374,7 +374,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
|
|||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
|
||||
|
||||
[node name="Barrels" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/ChainGun" index="3"]
|
||||
transform = Transform3D(-1, -1.49012e-08, 8.801e-08, 8.19564e-08, -3.72529e-09, 1, 0, 1, -7.45058e-09, 5.96046e-08, 0, -0.55315)
|
||||
transform = Transform3D(-1, 0, 8.9407e-08, 8.47504e-08, 0, 1, 0, 1, -3.72529e-09, -5.96046e-08, 0, -0.55315)
|
||||
|
||||
[node name="Skeleton3D" parent="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/GrenadeLauncher/Armature" index="0"]
|
||||
bones/0/rotation = Quaternion(0, 0.707107, 0.707107, 0)
|
||||
|
|
@ -436,13 +436,11 @@ script = ExtResource("18_v4iu1")
|
|||
replication_config = SubResource("SceneReplicationConfig_5j4ew")
|
||||
|
||||
[node name="MatchParticipant" type="Node" parent="."]
|
||||
script = ExtResource("6_lrose")
|
||||
script = ExtResource("18_t2jrs")
|
||||
|
||||
[node name="MatchParticipantSync" type="MultiplayerSynchronizer" parent="MatchParticipant"]
|
||||
replication_config = SubResource("SceneReplicationConfig_7na0c")
|
||||
|
||||
[connection signal="energy_changed" from="." to="HUD" method="_on_player_energy_changed"]
|
||||
|
||||
[editable path="ThirdPerson/Mesh"]
|
||||
[editable path="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/SpaceGun"]
|
||||
[editable path="ThirdPerson/Mesh/Node/Skeleton3D/HandAttachment/SpaceGun/Mesh"]
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func _physics_process(delta : float) -> void:
|
|||
if collider is Player:
|
||||
if is_multiplayer_authority():
|
||||
assert(shooter)
|
||||
collider.health_component.damage.rpc(.1, shooter.player_id, shooter.team_id)
|
||||
collider.health_component.damage.rpc(25, shooter.player_id, shooter.team_id)
|
||||
queue_free()
|
||||
|
||||
## This method is a parameterized constructor for the [ChainGunProjectile] scene of the [ChainGun]
|
||||
|
|
|
|||
|
|
@ -18,27 +18,11 @@ script/source = "# This file is part of open-fpsz.
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class_name HUD extends CanvasLayer
|
||||
extends CanvasLayer
|
||||
|
||||
@export_category(\"Vitals\")
|
||||
@export var _health_bar : ProgressBar
|
||||
@export var _energy_bar : ProgressBar
|
||||
|
||||
func _ready() -> void:
|
||||
_update_health_bar(1.)
|
||||
_update_energy_bar(1.)
|
||||
|
||||
func _update_energy_bar(energy : float) -> void:
|
||||
_energy_bar.value = energy
|
||||
|
||||
func _update_health_bar(health : float) -> void:
|
||||
_health_bar.value = health
|
||||
|
||||
func _on_health_changed(new_health : float) -> void:
|
||||
_update_health_bar(new_health)
|
||||
|
||||
func _on_player_energy_changed(new_energy : float) -> void:
|
||||
_update_energy_bar(new_energy)
|
||||
@export var health_bar : ProgressBar
|
||||
@export var energy_bar : ProgressBar
|
||||
@export var debug_label : Label
|
||||
"
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_w8l21"]
|
||||
|
|
@ -91,10 +75,10 @@ corner_radius_bottom_right = 3
|
|||
corner_radius_bottom_left = 3
|
||||
anti_aliasing = false
|
||||
|
||||
[node name="HUD" type="CanvasLayer" node_paths=PackedStringArray("_health_bar", "_energy_bar")]
|
||||
[node name="HUD" type="CanvasLayer" node_paths=PackedStringArray("health_bar", "energy_bar")]
|
||||
script = SubResource("GDScript_2vxif")
|
||||
_health_bar = NodePath("MarginContainer/HBoxContainer/VBoxContainer/HealthBar")
|
||||
_energy_bar = NodePath("MarginContainer/HBoxContainer/VBoxContainer/EnergyBar")
|
||||
health_bar = NodePath("MarginContainer/HBoxContainer/VBoxContainer/HealthBar")
|
||||
energy_bar = NodePath("MarginContainer/HBoxContainer/VBoxContainer/EnergyBar")
|
||||
|
||||
[node name="DebugLabel" type="Label" parent="."]
|
||||
offset_left = 20.0
|
||||
|
|
@ -146,7 +130,8 @@ layout_mode = 2
|
|||
mouse_filter = 2
|
||||
theme_override_styles/background = ExtResource("1_gmv44")
|
||||
theme_override_styles/fill = ExtResource("2_6ejsl")
|
||||
max_value = 1.0
|
||||
max_value = 255.0
|
||||
step = 1.0
|
||||
value = 1.0
|
||||
show_percentage = false
|
||||
|
||||
|
|
|
|||
|
|
@ -2,20 +2,22 @@
|
|||
|
||||
[ext_resource type="Script" path="res://interfaces/hud/iffs/iff.gd" id="1_g6kgb"]
|
||||
[ext_resource type="Shader" uid="uid://n2dcb4l0qun2" path="res://interfaces/progress_bar/resources/visual_shader.res" id="2_8cjkh"]
|
||||
[ext_resource type="Script" path="res://interfaces/progress_bar/progress_bar_3d.gd" id="3_vss6w"]
|
||||
[ext_resource type="PackedScene" uid="uid://chy8tm6hvummq" path="res://interfaces/progress_bar/ProgressBar3D.tscn" id="2_h0pl8"]
|
||||
[ext_resource type="Texture2D" uid="uid://cpb6vpa0c74rl" path="res://interfaces/waypoint/assets/waypoint.svg" id="4_lrbtk"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wrx5m"]
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_4quui"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("2_8cjkh")
|
||||
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_b6wb8"]
|
||||
material = SubResource("ShaderMaterial_wrx5m")
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_ks8vt"]
|
||||
resource_local_to_scene = true
|
||||
material = SubResource("ShaderMaterial_4quui")
|
||||
size = Vector2(0.35, 0.025)
|
||||
center_offset = Vector3(0, 0.09, 0)
|
||||
|
||||
[node name="IFF" type="Node3D"]
|
||||
script = ExtResource("1_g6kgb")
|
||||
value = 128.0
|
||||
border = 0.4
|
||||
billboard = 1
|
||||
|
||||
|
|
@ -27,16 +29,12 @@ fixed_size = true
|
|||
text = "Username"
|
||||
font_size = 24
|
||||
|
||||
[node name="HealthBar" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000610828, 0.0127701, -0.000638008)
|
||||
instance_shader_parameters/background = Color(0, 0, 0, 0.5)
|
||||
[node name="ProgressBar3D" parent="." instance=ExtResource("2_h0pl8")]
|
||||
instance_shader_parameters/billboard = 1
|
||||
instance_shader_parameters/border = 0.0
|
||||
instance_shader_parameters/fill = Color(1, 1, 1, 1)
|
||||
instance_shader_parameters/progress = 1.0
|
||||
instance_shader_parameters/size = Vector2(0.35, 0.025)
|
||||
mesh = SubResource("QuadMesh_b6wb8")
|
||||
script = ExtResource("3_vss6w")
|
||||
mesh = SubResource("QuadMesh_ks8vt")
|
||||
border = 0.0
|
||||
billboard = 1
|
||||
fill = Color(1, 1, 1, 1)
|
||||
|
|
|
|||
|
|
@ -25,10 +25,22 @@ signal border_changed(new_border : float)
|
|||
# If `true`, the waypoint fades as the camera get closer.
|
||||
#@export var fade : bool = true
|
||||
|
||||
## The current value for the pgroess bar.
|
||||
@export_range(0., 1.) var value : float = 1.:
|
||||
## The minimum [member value].
|
||||
@export var min_value : float = 0.:
|
||||
set(new_value):
|
||||
value = new_value
|
||||
min_value = new_value
|
||||
value = value
|
||||
|
||||
## The maximum [member value].
|
||||
@export var max_value : float = 255.:
|
||||
set(new_value):
|
||||
max_value = new_value
|
||||
value = value
|
||||
|
||||
## Current value.
|
||||
@export var value : float = 255.:
|
||||
set(new_value):
|
||||
value = clampf(new_value, min_value, max_value)
|
||||
health_changed.emit(value)
|
||||
|
||||
## The border for the progress bar.
|
||||
|
|
@ -63,32 +75,7 @@ signal border_changed(new_border : float)
|
|||
|
||||
@onready var label : Label3D = $Username
|
||||
@onready var chevron : Sprite3D = $Chevron
|
||||
@onready var hbar : ProgressBar3D = $HealthBar
|
||||
|
||||
func _on_billboard_changed(new_billboard : int) -> void:
|
||||
label.billboard = new_billboard as BaseMaterial3D.BillboardMode
|
||||
hbar.billboard = new_billboard
|
||||
chevron.billboard = new_billboard as BaseMaterial3D.BillboardMode
|
||||
|
||||
func _on_border_changed(new_border : float) -> void:
|
||||
hbar.border = new_border
|
||||
|
||||
func _on_username_changed(new_username : String) -> void:
|
||||
# The label's text can only be set once the node is ready.
|
||||
if is_inside_tree():
|
||||
label.text = new_username
|
||||
|
||||
func _on_background_changed(color : Color) -> void:
|
||||
label.outline_modulate = color
|
||||
hbar.background = color
|
||||
|
||||
func _on_fill_changed(color : Color) -> void:
|
||||
label.modulate = color
|
||||
hbar.fill = color
|
||||
chevron.modulate = color
|
||||
|
||||
func _on_health_changed(new_value : float) -> void:
|
||||
hbar.value = new_value
|
||||
@onready var health_bar : ProgressBar3D = $ProgressBar3D
|
||||
|
||||
func _enter_tree() -> void:
|
||||
if not username_changed.is_connected(_on_username_changed):
|
||||
|
|
@ -103,3 +90,28 @@ func _enter_tree() -> void:
|
|||
border_changed.connect(_on_border_changed)
|
||||
if not billboard_changed.is_connected(_on_billboard_changed):
|
||||
billboard_changed.connect(_on_billboard_changed)
|
||||
|
||||
func _on_billboard_changed(new_billboard : int) -> void:
|
||||
label.billboard = new_billboard as BaseMaterial3D.BillboardMode
|
||||
health_bar.billboard = new_billboard
|
||||
chevron.billboard = new_billboard as BaseMaterial3D.BillboardMode
|
||||
|
||||
func _on_border_changed(new_border : float) -> void:
|
||||
health_bar.border = new_border
|
||||
|
||||
func _on_username_changed(new_username : String) -> void:
|
||||
# The label's text can only be set once the node is ready.
|
||||
if is_inside_tree():
|
||||
label.text = new_username
|
||||
|
||||
func _on_background_changed(color : Color) -> void:
|
||||
label.outline_modulate = color
|
||||
health_bar.background = color
|
||||
|
||||
func _on_fill_changed(color : Color) -> void:
|
||||
label.modulate = color
|
||||
health_bar.fill = color
|
||||
chevron.modulate = color
|
||||
|
||||
func _on_health_changed(new_value : float) -> void:
|
||||
health_bar.value = new_value
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ render_priority = 0
|
|||
shader = ExtResource("1_07e5d")
|
||||
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_fwm7g"]
|
||||
resource_local_to_scene = true
|
||||
material = SubResource("ShaderMaterial_4quui")
|
||||
size = Vector2(1, 0.1)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
## A progress bar using a single quad mesh and a shader.
|
||||
@tool
|
||||
## An efficient progress bar in 3D using a quad mesh and a shader.
|
||||
class_name ProgressBar3D extends MeshInstance3D
|
||||
|
||||
## Emitted when value has been changed.
|
||||
|
|
@ -22,36 +22,53 @@ signal value_changed(new_value : float)
|
|||
const progress_bar_shader : VisualShader = preload(
|
||||
"res://interfaces/progress_bar/resources/visual_shader.res")
|
||||
|
||||
## Current value.
|
||||
@export_range(0., 1.) var value : float = 1.:
|
||||
## The minimum [member value].
|
||||
@export var min_value : float = 0.:
|
||||
set(new_value):
|
||||
value = new_value
|
||||
min_value = new_value
|
||||
value = value
|
||||
|
||||
## The maximum [member value].
|
||||
@export var max_value : float = 255.:
|
||||
set(new_value):
|
||||
max_value = new_value
|
||||
value = value
|
||||
|
||||
## The current value.
|
||||
@export var value : float = 255.:
|
||||
set = set_value
|
||||
|
||||
func set_value(new_value : float) -> void:
|
||||
value = clampf(new_value, min_value, max_value)
|
||||
_update_shader_params()
|
||||
value_changed.emit(value)
|
||||
|
||||
## The size of the border.
|
||||
@export_range(0., 1.) var border : float = .2:
|
||||
set(new_border):
|
||||
border = new_border
|
||||
_update_shader_params()
|
||||
|
||||
## The billboard mode, see [member BaseMaterial3D.BillboardMode] for more details.
|
||||
@export_enum("Disabled", "Enabled", "Y-Billboard") var billboard : int = 2:
|
||||
set(new_billboard):
|
||||
billboard = new_billboard
|
||||
_update_shader_params()
|
||||
|
||||
## Fill color.
|
||||
## The fill color.
|
||||
@export var fill : Color = Color.GREEN:
|
||||
set(value):
|
||||
fill = value
|
||||
_update_shader_params()
|
||||
|
||||
## Background color.
|
||||
## The background color.
|
||||
@export var background : Color = Color(0, 0, 0, 0.5):
|
||||
set(value):
|
||||
background = value
|
||||
_update_shader_params()
|
||||
|
||||
## setup mesh, material and shader when entering the node tree
|
||||
## Setup the [QuadMesh], [ShaderMaterial] and [VisualShader]
|
||||
## when entering the node tree
|
||||
func _enter_tree() -> void:
|
||||
# set default mesh
|
||||
if not mesh:
|
||||
|
|
@ -73,11 +90,11 @@ func _enter_tree() -> void:
|
|||
# update shader params once
|
||||
mesh.emit_changed()
|
||||
|
||||
## This method updates shader params
|
||||
## This method updates instance shader params
|
||||
func _update_shader_params() -> void:
|
||||
set_instance_shader_parameter("background", background)
|
||||
set_instance_shader_parameter("billboard", billboard)
|
||||
set_instance_shader_parameter("border", border)
|
||||
set_instance_shader_parameter("fill", fill)
|
||||
set_instance_shader_parameter("progress", value)
|
||||
set_instance_shader_parameter("progress", value / max_value)
|
||||
set_instance_shader_parameter("size", mesh.size)
|
||||
|
|
|
|||
Loading…
Reference in a new issue