added labels for health and time
This commit is contained in:
parent
5050fa8cd8
commit
3805756269
@ -6,6 +6,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://bhsvqyhsemekq" path="res://scenes/player.tscn" id="3_k3dxm"]
|
||||
[ext_resource type="Script" uid="uid://gkpbb5sf4gu7" path="res://scripts/area_2d.gd" id="3_v0i7m"]
|
||||
[ext_resource type="PackedScene" uid="uid://dvdwk2je7ryqr" path="res://scenes/slime.tscn" id="6_6sh32"]
|
||||
[ext_resource type="PackedScene" uid="uid://nprvldtu15fe" path="res://scenes/ui.tscn" id="7_ejswk"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_8ifkp"]
|
||||
texture = ExtResource("3_eh8dd")
|
||||
@ -431,5 +432,9 @@ position = Vector2(204, 371)
|
||||
[node name="Slime2" parent="Enemies" unique_id=2077610743 instance=ExtResource("6_6sh32")]
|
||||
position = Vector2(705, 243)
|
||||
|
||||
[node name="UI" type="CanvasLayer" parent="." unique_id=1754077689]
|
||||
|
||||
[node name="Control" parent="UI" unique_id=1267369317 instance=ExtResource("7_ejswk")]
|
||||
|
||||
[connection signal="body_entered" from="area" to="area" method="_on_body_entered"]
|
||||
[connection signal="triggerActiveSignal" from="area" to="." method="_on_area_2d_trigger_active_signal"]
|
||||
|
||||
46
scenes/ui.tscn
Normal file
46
scenes/ui.tscn
Normal file
@ -0,0 +1,46 @@
|
||||
[gd_scene format=3 uid="uid://nprvldtu15fe"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c6402h5oth0i3" path="res://scripts/ui.gd" id="1_nt7q6"]
|
||||
|
||||
[node name="Control" type="Control" unique_id=1267369317]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_nt7q6")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="." unique_id=1912230201]
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 23.0
|
||||
grow_horizontal = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer" unique_id=1969892715]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer/HBoxContainer" unique_id=718250745]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="health" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer" unique_id=135697385]
|
||||
layout_mode = 2
|
||||
text = "health: "
|
||||
|
||||
[node name="MarginContainer3" type="MarginContainer" parent="VBoxContainer/HBoxContainer" unique_id=1151577280]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="time" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer3" unique_id=194025908]
|
||||
layout_mode = 2
|
||||
text = "time: "
|
||||
|
||||
[node name="MarginContainer2" type="MarginContainer" parent="VBoxContainer/HBoxContainer" unique_id=2064326436]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="crates" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer2" unique_id=1419249039]
|
||||
layout_mode = 2
|
||||
text = "crates: "
|
||||
@ -3,6 +3,7 @@ extends Node2D
|
||||
signal destroy(body)
|
||||
signal level_change_signal(level)
|
||||
signal damage_player_signal(damage, player_health)
|
||||
signal time_change(remaining_time)
|
||||
|
||||
var levels = ["res://scenes/level1.tscn","res://scenes/level2.tscn","res://scenes/level3.tscn"]
|
||||
var current_level_index = 0
|
||||
@ -29,15 +30,17 @@ func _ready():
|
||||
|
||||
func timer_tick():
|
||||
time_available -= 1
|
||||
time_change.emit(time_available)
|
||||
if time_available <= 0:
|
||||
print("you lose")
|
||||
level_change_signal.emit(levels[current_level_index])
|
||||
reset()
|
||||
|
||||
func reset():
|
||||
print("reset")
|
||||
time_available = level_times[current_level_index]
|
||||
if player:
|
||||
player.health = player_stats.starting_health
|
||||
player.set_health(player_stats.starting_health)
|
||||
|
||||
func stop():
|
||||
timer.stop()
|
||||
@ -63,7 +66,7 @@ func set_crate_num(count: int):
|
||||
reset()
|
||||
|
||||
func _on_slime_damage(body, slime):
|
||||
damage_player_signal.emit(enemies[slime]["damage"])
|
||||
damage_player_signal.emit(enemies[slime]["damage"], player.health)
|
||||
|
||||
func add_enemy(slime):
|
||||
var enemy_stat = {
|
||||
|
||||
@ -18,7 +18,7 @@ var shove_target: RigidBody2D
|
||||
enum State { IDLE, RUN, JUMP, APEX, FALL, HURT, DYING, DEAD }
|
||||
var state: State = State.IDLE
|
||||
var up_jump:bool = false
|
||||
var health:int = 4
|
||||
var health:int = 0;
|
||||
|
||||
func _ready():
|
||||
new_player.emit(self)
|
||||
@ -129,6 +129,7 @@ func _on_graphic_animation_finished() -> void:
|
||||
pass
|
||||
|
||||
func damage_player(damage: int):
|
||||
print("player::damager_player: " + str(damage) + " health: " + str(self.health))
|
||||
if self.state != State.DYING and self.state != State.DEAD:
|
||||
self.health -= damage
|
||||
if self.health <= 0:
|
||||
@ -137,3 +138,7 @@ func damage_player(damage: int):
|
||||
else:
|
||||
print("player hurt")
|
||||
self.state = State.HURT
|
||||
|
||||
func set_health(health: int):
|
||||
print("setting health: " + str(health))
|
||||
self.health = health
|
||||
|
||||
@ -4,13 +4,15 @@ class_name SceneManager extends Node2D
|
||||
var grenade = preload("res://scenes/grenade.tscn")
|
||||
@onready var enemies = $"../Enemies"
|
||||
@onready var player = $"../player"
|
||||
@onready var control: Control = $"../UI/Control"
|
||||
|
||||
func _ready() -> void:
|
||||
print("scene manager is ready")
|
||||
GameController.destroy.connect(destroy)
|
||||
GameController.level_change_signal.connect(change_scene)
|
||||
GameController.damage_player_signal.connect(damage_player)
|
||||
# player.player_dead.connect(GameController._on_player_dead)
|
||||
GameController.damage_player_signal.connect(control.update_health)
|
||||
GameController.time_change.connect(control.update_time)
|
||||
build_level()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
@ -22,6 +24,9 @@ func build_level() -> void:
|
||||
update_enemies()
|
||||
if player:
|
||||
GameController.player = player
|
||||
player.set_health(GameController.player_stats.health)
|
||||
# todo: bug, calling too early I think
|
||||
# control.update_health(1, GameController.player_stats.health)
|
||||
if not player.player_dead.is_connected(GameController._on_player_dead):
|
||||
print("hooking up player dead signal")
|
||||
player.player_dead.connect(GameController._on_player_dead)
|
||||
@ -58,8 +63,5 @@ func destroy(body):
|
||||
if body is BrownBox:
|
||||
body.queue_free()
|
||||
|
||||
func damage_player(damage: int):
|
||||
func damage_player(damage: int, _health:int):
|
||||
player.damage_player(damage)
|
||||
|
||||
#func player_dead_animation_finished():
|
||||
#change_scene()
|
||||
|
||||
16
scripts/ui.gd
Normal file
16
scripts/ui.gd
Normal file
@ -0,0 +1,16 @@
|
||||
extends Control
|
||||
@onready var health_label: Label = $VBoxContainer/HBoxContainer/MarginContainer/health
|
||||
@onready var time: Label = $VBoxContainer/HBoxContainer/MarginContainer3/time
|
||||
@onready var crates: Label = $VBoxContainer/HBoxContainer/MarginContainer2/crates
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func update_health(damage:int, health:int):
|
||||
self.health_label.text = "health: " + str(health)
|
||||
|
||||
func update_time(remaining_time: int):
|
||||
self.time.text = "time: " + str(remaining_time)
|
||||
1
scripts/ui.gd.uid
Normal file
1
scripts/ui.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://c6402h5oth0i3
|
||||
Loading…
Reference in New Issue
Block a user