Skip to content
Snippets Groups Projects
Commit 03e2615c authored by STAVRIDIS ADONIS's avatar STAVRIDIS ADONIS :speech_balloon:
Browse files

#106 hp broadcast to everyone

parent 27a881dc
Branches
Tags
No related merge requests found
extends Label
const GAMEPATH = "/root/game/"
var hp:int
var posPv
var player
var my_id
func _ready():
hp = 0
posPv = Vector3(0,0,0)
player = get_node("../../")
my_id = get_tree().get_network_unique_id()
update_printed_hp()
update_printed_hp(hp)
func _process(_delta):
......@@ -22,6 +24,7 @@ func _process(_delta):
# update the current hp labels
func update_printed_hp():
if str(my_id) != str (player.get_name()):
set_text(str(player.hp) + '%')
func update_printed_hp(newHp:int):
hp = newHp
set_text(String(hp) + ' %')
extends KinematicBody
var hp:int = 0
var currentDirection:int = 1
var model
......@@ -25,10 +24,9 @@ puppet func turn(direction:int):
# Feedback when hurt
puppet func hurt(hpNow:int):
hp = hpNow
puppet func hurt(hp:int):
print("You suffered a hit and are now at " + String(hp))
get_node("Labels/Hp").update_printed_hp()
get_node("Labels/Hp").update_printed_hp(hp)
# Feedback when killed
......
......@@ -3,5 +3,5 @@
[ext_resource path="res://models/player/playerArrow/playerArrow.png" type="Texture" id=1]
[node name="playerArrow" type="Sprite3D"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.75, 0 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.5, 0 )
texture = ExtResource( 1 )
......@@ -292,8 +292,14 @@ func hurt(damages:int, sourceId:int, direction:Vector3, strength:float):
lastStrikerId = sourceId
# Feedback on the player's client
rpc_unreliable_id(ownId, "hurt", hp)
broadcastHp(hp)
# Send Hp
func broadcastHp(hp:int):
rpc("hurt", hp)
# Make player die
func die():
rpc("die", lastStrikerId)
self.queue_free()
......
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