Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

player names WIP #31

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions scenes/component/health_component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ signal health_changed
@onready var explosion_animation: AnimatedSprite2D = get_parent().find_child("Explosion")
@onready var tank_body: Marker2D = get_parent().find_child("TankBody")
@onready var tank_barrel: Marker2D = get_parent().find_child("Barrel")
@onready var health_bar: PanelContainer = get_parent().find_child("PanelContainer")
@onready var health_bar: PanelContainer = get_parent().find_child("HealthBar")
@onready var player_name: Label = get_parent().find_child("PlayerName")
@onready var collision: CollisionShape2D = get_parent().find_child("CollisionShape2D")
@onready var hit_collision: CollisionShape2D = get_parent().find_child("HurtboxComponent").find_child("CollisionShape2D2")

@export var max_health: float = 100
var current_health


func _ready():
current_health = max_health
respawn_timer.timeout.connect(respawn)
Expand Down Expand Up @@ -43,6 +43,7 @@ func check_death(id, enemy_id):
tank_body.visible = false
tank_barrel.visible = false
health_bar.visible = false
player_name.visible = false
collision.disabled = true
hit_collision.disabled = true
explosion_animation.play()
Expand All @@ -63,6 +64,7 @@ func respawn():
tank_body.visible = true
tank_barrel.visible = true
health_bar.visible = true
player_name.visible = true
collision.disabled = false
hit_collision.disabled = false

2 changes: 1 addition & 1 deletion scenes/game_object/player/health_bar.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=2 format=3 uid="uid://mbsht4dt5quk"]
[gd_scene load_steps=2 format=3 uid="uid://dubcod0jv5c7t"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_f63c4"]
bg_color = Color(0.0313726, 0.729412, 0, 1)
Expand Down
15 changes: 14 additions & 1 deletion scenes/game_object/player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ const ACCELERATION_SMOOTHING = 25
var can_boost = true

@onready var health_component : HealthComponent = $HealthComponent
@onready var health_bar : ProgressBar = $PanelContainer/ProgressBar
@onready var health_bar : ProgressBar = $HealthBar/ProgressBar
@onready var barrel_tip: Marker2D = $Barrel
@onready var tank_body: Sprite2D = $TankBody/Sprite2D
@onready var barrel_color: Sprite2D = $Barrel/Sprite2D
@onready var boost_timer: Timer = $BoostTimer
@export var boost_icons: Array[TextureRect]
@onready var player_name : Label = $PlayerName

@onready var previous_movement: Vector2 = Vector2.ZERO

Expand All @@ -23,7 +24,14 @@ func _ready():
health_component.health_changed.connect(on_health_changed)
var tank_color = GameManager.players[player_id].color
set_tank_texture.rpc(player_id, tank_color)
set_player_name.rpc(player_id)

@rpc("any_peer", "call_local")
func set_player_name(player_id):
if $MultiplayerSynchronizer.get_multiplayer_authority() == player_id:
player_name.text = GameManager.players[player_id].name
else:
get_node("../%s/PlayerName" % player_id).text = GameManager.players[player_id].name

@rpc("any_peer", "call_local")
func set_tank_texture(id, tank_color):
Expand Down Expand Up @@ -76,6 +84,11 @@ func apply_boost(direction: Vector2):
@rpc("any_peer", "call_local")
func update_health_display():
health_bar.value = health_component.get_health_value()
if health_bar.value <= 0:
health_bar.visible = false
return
elif !health_bar.visible:
health_bar.visible = true

func on_health_changed():
update_health_display.rpc()
Expand Down
11 changes: 9 additions & 2 deletions scenes/game_object/player/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[ext_resource type="Texture2D" uid="uid://8ip3d3virahl" path="res://scenes/game_object/player/tankGreen_barrel3_outline.png" id="3_vvwhs"]
[ext_resource type="Script" path="res://scenes/game_object/player/Barrel.gd" id="4_yiyg3"]
[ext_resource type="PackedScene" uid="uid://dp7s6opobih82" path="res://scenes/component/hurtbox_component.tscn" id="5_fvhfs"]
[ext_resource type="PackedScene" uid="uid://mbsht4dt5quk" path="res://scenes/game_object/player/health_bar.tscn" id="7_p6dmh"]
[ext_resource type="PackedScene" uid="uid://dubcod0jv5c7t" path="res://scenes/game_object/player/health_bar.tscn" id="7_p6dmh"]
[ext_resource type="Texture2D" uid="uid://qy1axfax8jfx" path="res://assets/sprites/Effects/Explosion1/explosion1.png" id="8_xuf46"]
[ext_resource type="Texture2D" uid="uid://ct43tpf4bhlam" path="res://assets/sprites/Effects/Explosion1/explosion2.png" id="9_n372a"]
[ext_resource type="Texture2D" uid="uid://1bj57cp5m24g" path="res://assets/sprites/Effects/Explosion1/explosion3.png" id="10_ytrhg"]
Expand Down Expand Up @@ -172,7 +172,14 @@ process_mode = 3
wait_time = 4.0
one_shot = true

[node name="PanelContainer" parent="." instance=ExtResource("7_p6dmh")]
[node name="PlayerName" type="Label" parent="."]
offset_left = -21.0
offset_top = -54.0
offset_right = 23.0
offset_bottom = -31.0
horizontal_alignment = 1

[node name="HealthBar" parent="." instance=ExtResource("7_p6dmh")]

[node name="Explosion" type="AnimatedSprite2D" parent="."]
process_mode = 3
Expand Down
1 change: 1 addition & 0 deletions scenes/world.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[ext_resource type="Texture2D" uid="uid://bee43w1v6ob6t" path="res://assets/environment/terrainTiles_default.png" id="1_jft5n"]
[ext_resource type="PackedScene" uid="uid://bam04hog13mtt" path="res://scenes/game_object/player/player.tscn" id="2_kcqh6"]
[ext_resource type="AudioStream" uid="uid://djf04umoxsx8s" path="res://assets/audio/music/KTANKBYE_MAP_TRACK.mp3" id="3_ecdtc"]
[ext_resource type="PackedScene" uid="uid://bsqs1ftdnl6xb" path="res://scenes/manager/bullet_manager.tscn" id="3_hvrp0"]
[ext_resource type="PackedScene" uid="uid://b7ukeajhup4b5" path="res://scenes/component/consumable_spawn_component.tscn" id="4_68m35"]
[ext_resource type="FontFile" uid="uid://djtfqcs4ix7x7" path="res://resources/DIGITALDREAMFAT.ttf" id="4_u7bnn"]
[ext_resource type="Texture2D" uid="uid://o3jfx650hwjl" path="res://assets/environment/onlyObjects_default.png" id="5_0cr42"]
Expand Down