fuzzyworld

godot-shooter / commit

Adding level and objective text labels.

fa5168b2c0cc947a00e37dd7e6b9c5ff430c3f85 · Pavel Safronov · 2023-11-08 03:36:43 -0800 · parents 589bdfbf4bf4

Adding level and objective text labels.
 HUD.gd      | 11 +++++++++-
 HUD.tscn    | 68 ++++++++++++++++++++++++++++++++++++++++++++++---------------
 Player.gd   | 11 +++++-----
 Player.tscn |  4 ++--
 Theme.tres  |  4 ++--
 5 files changed, 72 insertions(+), 26 deletions(-)

diff --git a/HUD.gd b/HUD.gd
index 46fcafd..75ba09f 100644
--- a/HUD.gd
+++ b/HUD.gd
@@ -2,12 +2,21 @@ extends Control
 
 const Utils = preload("res://Utils.gd")
 export var score = 0
+export var level = 1
+export var objective = "1/17"
+
 onready var label = $CanvasLayer/Label
 onready var animation_player = $AnimationPlayer
+onready var score_label = $HBoxContainer/Score
+onready var level_label = $MarginContainer/HBoxContainer2/Level
+onready var objective_label = $MarginContainer/HBoxContainer2/Objective
+
 var message_count = 0
 
 func _process(_delta: float) -> void:
-	$VBoxContainer/HBoxContainer/Score.text = "%s" % score
+	score_label.text = "%s" % score
+	level_label.text = "%s" % level
+	objective_label.text = "%s" % objective
 	if Input.is_action_just_pressed("exit"):
 		if OS.get_name() == "OSX":
 			get_tree().quit()
diff --git a/HUD.tscn b/HUD.tscn
index b98556e..aa7a573 100644
--- a/HUD.tscn
+++ b/HUD.tscn
@@ -6,7 +6,7 @@
 [sub_resource type="Animation" id=2]
 resource_name = "message fade in"
 tracks/0/type = "value"
-tracks/0/path = NodePath("CanvasLayer/Label:modulate")
+tracks/0/path = NodePath("CanvasLayer/MessageLabel:modulate")
 tracks/0/interp = 1
 tracks/0/loop_wrap = true
 tracks/0/imported = false
@@ -18,7 +18,7 @@ tracks/0/keys = {
 "values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
 }
 tracks/1/type = "value"
-tracks/1/path = NodePath("CanvasLayer/Label:text")
+tracks/1/path = NodePath("CanvasLayer/MessageLabel:text")
 tracks/1/interp = 1
 tracks/1/loop_wrap = true
 tracks/1/imported = false
@@ -34,7 +34,7 @@ tracks/1/keys = {
 resource_name = "message fade out"
 length = 2.0
 tracks/0/type = "value"
-tracks/0/path = NodePath("CanvasLayer/Label:modulate")
+tracks/0/path = NodePath("CanvasLayer/MessageLabel:modulate")
 tracks/0/interp = 1
 tracks/0/loop_wrap = true
 tracks/0/imported = false
@@ -49,32 +49,68 @@ tracks/0/keys = {
 [node name="HUD" type="Control"]
 anchor_right = 1.0
 anchor_bottom = 1.0
+margin_left = 10.0
+margin_top = 10.0
+margin_right = -10.0
+margin_bottom = -10.0
 theme = ExtResource( 1 )
 script = ExtResource( 2 )
 
-[node name="VBoxContainer" type="VBoxContainer" parent="."]
-margin_right = 40.0
-margin_bottom = 40.0
-
-[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
+[node name="HBoxContainer" type="HBoxContainer" parent="."]
 margin_right = 282.0
 margin_bottom = 74.0
 
-[node name="ScoreText" type="Label" parent="VBoxContainer/HBoxContainer"]
-margin_right = 192.0
-margin_bottom = 74.0
+[node name="ScoreText" type="Label" parent="HBoxContainer"]
+margin_top = 9.0
+margin_right = 143.0
+margin_bottom = 65.0
 text = "Score: "
 
-[node name="Score" type="Label" parent="VBoxContainer/HBoxContainer"]
-margin_left = 200.0
-margin_right = 282.0
-margin_bottom = 74.0
+[node name="Score" type="Label" parent="HBoxContainer"]
+margin_left = 151.0
+margin_top = 9.0
+margin_right = 212.0
+margin_bottom = 65.0
 text = "100"
 uppercase = true
 
+[node name="MarginContainer" type="MarginContainer" parent="."]
+anchor_top = 1.0
+anchor_right = 1.0
+anchor_bottom = 1.0
+margin_top = -74.0
+
+[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer"]
+margin_right = 480.0
+margin_bottom = 74.0
+
+[node name="LevelText" type="Label" parent="MarginContainer/HBoxContainer2"]
+margin_top = 9.0
+margin_right = 118.0
+margin_bottom = 65.0
+text = "Level:"
+
+[node name="Level" type="Label" parent="MarginContainer/HBoxContainer2"]
+margin_left = 126.0
+margin_top = 9.0
+margin_right = 139.0
+margin_bottom = 65.0
+text = "1"
+
+[node name="Objective" type="Label" parent="MarginContainer/HBoxContainer2"]
+visible = false
+margin_left = 407.0
+margin_right = 480.0
+margin_bottom = 74.0
+size_flags_horizontal = 10
+size_flags_vertical = 1
+text = "1/17"
+align = 2
+valign = 2
+
 [node name="CanvasLayer" type="CanvasLayer" parent="."]
 
-[node name="Label" type="Label" parent="CanvasLayer"]
+[node name="MessageLabel" type="Label" parent="CanvasLayer"]
 modulate = Color( 1, 1, 1, 0 )
 anchor_left = 0.1
 anchor_top = 0.6
diff --git a/Player.gd b/Player.gd
index 95bce87..f30202b 100644
--- a/Player.gd
+++ b/Player.gd
@@ -73,16 +73,17 @@ func hurt(damage_amount: int = 1):
 		shield_active = false
 		$Graphics/Alive/Shield/Sprite/AnimationPlayer.play("fade out")
 		emit_signal("shield_changed", shield_active)
+		
 		var timer = Timer.new()
-		add_child(timer)
 		timer.wait_time = shield_restart_period_seconds
 		timer.one_shot = true
 		timer.connect("timeout", self, "enable_shield")
+		add_child(timer)
 		timer.start()
-		return
-	health -= damage_amount
-	if health <= 0:
-		kill()
+	else:
+		health -= damage_amount
+		if health <= 0:
+			kill()
 
 func turn_towards(pos: Vector2):
 	var to_dir = (pos - global_position).normalized()
diff --git a/Player.tscn b/Player.tscn
index 25fd651..e1ca400 100644
--- a/Player.tscn
+++ b/Player.tscn
@@ -9,7 +9,7 @@
 [ext_resource path="res://assets/kenney_crosshair-pack/PNG/White Retina/crosshair120.png" type="Texture" id=7]
 
 [sub_resource type="CircleShape2D" id=7]
-radius = 61.0
+radius = 36.0
 
 [sub_resource type="Gradient" id=2]
 colors = PoolColorArray( 1, 0, 0, 1, 1, 0, 0, 0 )
@@ -93,7 +93,7 @@ tracks/2/keys = {
 "times": PoolRealArray( 0, 0.7, 1 ),
 "transitions": PoolRealArray( 1, 1, 1 ),
 "update": 0,
-"values": [ Vector2( 1, 1 ), Vector2( 0.8, 0.8 ), Vector2( 1, 1 ) ]
+"values": [ Vector2( 0.7, 0.7 ), Vector2( 0.6, 0.6 ), Vector2( 0.7, 0.7 ) ]
 }
 
 [sub_resource type="Animation" id=5]
diff --git a/Theme.tres b/Theme.tres
index 6fbeb7c..4c0a715 100644
--- a/Theme.tres
+++ b/Theme.tres
@@ -3,8 +3,8 @@
 [ext_resource path="res://assets/Unique.ttf" type="DynamicFontData" id=1]
 
 [sub_resource type="DynamicFont" id=1]
-size = 64
-outline_size = 3
+size = 48
+outline_size = 2
 outline_color = Color( 1, 0, 0, 1 )
 use_mipmaps = true
 use_filter = true