Skip to content
Snippets Groups Projects
Commit 177beff0 authored by ZERBIB TIMOTHEE's avatar ZERBIB TIMOTHEE
Browse files

Link hp labels to character's hp

parent 55883928
Branches
No related merge requests found
...@@ -3,21 +3,26 @@ const GAMEPATH = "/root/game/" ...@@ -3,21 +3,26 @@ const GAMEPATH = "/root/game/"
var posPv var posPv
var player var player
var my_id
func _ready(): func _ready():
posPv = Vector3(0,0,0) posPv = Vector3(0,0,0)
player = get_node("../../") player = get_node("../../")
var my_id = get_tree().get_network_unique_id() my_id = get_tree().get_network_unique_id()
if str(my_id) != str (player.get_name()) : update_printed_hp()
set_text('pv : 20% ')
func _process(delta): func _process(delta):
var cam = get_tree().get_root().get_camera() var cam = get_tree().get_root().get_camera()
posPv.x = player.get_global_transform().origin.x-1 posPv.x = player.get_global_transform().origin.x - 0.5
posPv.y = player.get_global_transform().origin.y+2 posPv.y = player.get_global_transform().origin.y + 2
var labelIdpos = cam.unproject_position(posPv) var labelIdpos = cam.unproject_position(posPv)
set_position(labelIdpos) set_position(labelIdpos)
# update the current hp labels
func update_printed_hp():
if str(my_id) != str (player.get_name()):
set_text(str(player.hp) + '%')
\ No newline at end of file
extends KinematicBody extends KinematicBody
var hp:int = 0
# Update the player's position based on the position computed by the remote scene on the server # Update the player's position based on the position computed by the remote scene on the server
puppet func getRemoteMovement(position:Vector3): puppet func getRemoteMovement(position:Vector3):
self.set_translation(position) self.set_translation(position)
# Feedback when hurt # Feedback when hurt
puppet func hurt(hpNow:int): puppet func hurt(hpNow:int):
print("You suffered a hit and are now at " + String(hpNow) + " !") hp = hpNow
print("You suffered a hit and are now at " + String(hp))
get_node("Labels/Hp").update_printed_hp()
# Feedback when killed # Feedback when killed
puppet func die(killerId:int): puppet func die(killerId:int):
...@@ -14,6 +21,4 @@ puppet func die(killerId:int): ...@@ -14,6 +21,4 @@ puppet func die(killerId:int):
# Hide the killed player (NB: the client is only about inputs and display) # Hide the killed player (NB: the client is only about inputs and display)
#self.set_visible(false) #self.set_visible(false)
\ No newline at end of file
...@@ -7,18 +7,18 @@ ...@@ -7,18 +7,18 @@
[node name="player" type="KinematicBody"] [node name="player" type="KinematicBody"]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="Labels " type="Control" parent="."] [node name="Labels" type="Control" parent="."]
margin_right = 40.0 margin_right = 40.0
margin_bottom = 40.0 margin_bottom = 40.0
[node name="Pseudo" type="Label" parent="Labels "] [node name="Pseudo" type="Label" parent="Labels"]
margin_right = 40.0 margin_right = 40.0
margin_bottom = 14.0 margin_bottom = 14.0
text = " text = "
" "
script = ExtResource( 2 ) script = ExtResource( 2 )
[node name="Hp" type="Label" parent="Labels "] [node name="Hp" type="Label" parent="Labels"]
margin_right = 40.0 margin_right = 40.0
margin_bottom = 14.0 margin_bottom = 14.0
script = ExtResource( 3 ) script = ExtResource( 3 )
......
...@@ -10,7 +10,6 @@ func _ready(): ...@@ -10,7 +10,6 @@ func _ready():
cam = get_tree().get_root().get_camera() cam = get_tree().get_root().get_camera()
posId = Vector3(0,0,0) posId = Vector3(0,0,0)
player = get_node("../../") player = get_node("../../")
print("Bonjour:",player)
var my_id = get_tree().get_network_unique_id() var my_id = get_tree().get_network_unique_id()
if str(my_id) != str (player.get_name()) : if str(my_id) != str (player.get_name()) :
...@@ -19,7 +18,7 @@ func _ready(): ...@@ -19,7 +18,7 @@ func _ready():
func _process(delta): func _process(delta):
posId.x = player.get_global_transform().origin.x-1.5 posId.x = player.get_global_transform().origin.x - 1.65
posId.y = player.get_global_transform().origin.y+3 posId.y = player.get_global_transform().origin.y + 2.7
var labelIdpos = cam.unproject_position(posId) var labelIdpos = cam.unproject_position(posId)
set_position(labelIdpos) set_position(labelIdpos)
extends Control extends Control
func _ready(): func _ready():
#gamestate.connect("connected_to_server", self, "_player_connected")
get_tree().connect("connected_to_server", self, "_player_connected") get_tree().connect("connected_to_server", self, "_player_connected")
get_tree().connect("connection_failed", self, "_connection_failed") get_tree().connect("connection_failed", self, "_connection_failed")
get_tree().connect("server_disconnected", self, "_player_disconnected") get_tree().connect("server_disconnected", self, "_player_disconnected")
...@@ -26,11 +25,11 @@ func _on_joinButton_pressed(): ...@@ -26,11 +25,11 @@ func _on_joinButton_pressed():
gamestate.joinServer(ip, port) gamestate.joinServer(ip, port)
#func _player_connected(): func _player_connected():
# print("You successfuly joined the server with the id " + str(gamestate.get_network_unique_id())) print("You successfuly joined the server with the id " + str(get_tree().get_network_unique_id()))
#
#func _connection_failed(): func _connection_failed():
# print("Connection failure") print("Connection failure")
#
#func _player_disconnected(): func _player_disconnected():
# print("You disconnected the server") print("You disconnected the server")
\ No newline at end of file \ No newline at end of file
...@@ -198,7 +198,7 @@ func secondaryAttack(): ...@@ -198,7 +198,7 @@ func secondaryAttack():
func hurt(damages:int, sourceId:int): func hurt(damages:int, sourceId:int):
hp += damages hp += damages
lastStrikerId = sourceId lastStrikerId = sourceId
rpc_unreliable_id(ownId, "hurt", hp) rpc_unreliable("hurt", hp)
func die(): func die():
rpc("die", lastStrikerId) rpc("die", lastStrikerId)
......
extends Node extends Node
master func sendPlayerInputs(movementInput:int, jumpInput:bool, jumpId:int, sprintInput:bool, attackStateInput:int): master func sendPlayerInputs(movementInput:int, jumpInput:bool, jumpId:int, sprintInput:bool, attackStateInput:int):
# Get the input from a client and send it to the matching remote player # Get the input from a client and send it to the matching remote player
var senderId:int = get_tree().get_rpc_sender_id() var senderId:int = get_tree().get_rpc_sender_id()
if gamestate.players.has(senderId): if gamestate.players.has(senderId):
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment