fuzzyworld

godot-shooter / commit

Changed instructions to be on-demand and have a simple fade-in/fade-out process.

ddae17d7940591024b1a35a47b86533c522b72aa · Pavel Safronov · 2023-11-07 16:03:51 -0800 · parents 04130db8f48e

Changed instructions to be on-demand and have a simple fade-in/fade-out process.
Fade-out can be customized per message, while the fade-in is static.
Added "consumed" signal to both power-ups, and started using this to announce to the user that they picked up a power-up.
 HUD.gd          | 16 +++++++++++++---
 HUD.tscn        | 53 ++++++++++++++++++++++++++++++++++++-----------------
 HealPowerUp.gd  |  2 ++
 SpeedPowerUp.gd |  2 ++
 Trails.tscn     |  2 +-
 World.gd        |  8 ++++++++
 World.tscn      |  1 +
 project.godot   |  1 +
 8 files changed, 64 insertions(+), 21 deletions(-)

diff --git a/HUD.gd b/HUD.gd
index b209ab7..a7d57f2 100644
--- a/HUD.gd
+++ b/HUD.gd
@@ -1,9 +1,8 @@
 extends Control
 
 export var score = 0
-
-func _ready() -> void:
-	$AnimationPlayer.play("instructions fade")
+onready var label = $CanvasLayer/Label
+onready var animation_player = $AnimationPlayer
 
 func _process(_delta: float) -> void:
 	$VBoxContainer/HBoxContainer/Score.text = "%s" % score
@@ -18,3 +17,14 @@ func _process(_delta: float) -> void:
 func restart():
 	var _error = get_tree().reload_current_scene()
 	get_tree().paused = false
+
+func show_message(message: String, duration_seconds: int = 2) -> void:
+	label.text = message
+	var animation_name = "message fade out"
+	var animation = animation_player.get_animation(animation_name)
+	animation.track_set_key_time(0, 1, duration_seconds)
+	animation_player.remove_animation(animation_name)
+	animation_player.add_animation(animation_name, animation)
+	
+	animation_player.queue("message fade in")
+	animation_player.queue(animation_name)
diff --git a/HUD.tscn b/HUD.tscn
index 96b65c9..adf5367 100644
--- a/HUD.tscn
+++ b/HUD.tscn
@@ -1,20 +1,36 @@
-[gd_scene load_steps=4 format=2]
+[gd_scene load_steps=5 format=2]
 
 [ext_resource path="res://Theme.tres" type="Theme" id=1]
 [ext_resource path="res://HUD.gd" type="Script" id=2]
 
+[sub_resource type="Animation" id=2]
+resource_name = "message fade in"
+length = 0.75
+tracks/0/type = "value"
+tracks/0/path = NodePath("CanvasLayer/Label:modulate")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0, 0.5 ),
+"transitions": PoolRealArray( 1, 5.65685 ),
+"update": 0,
+"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
+}
+
 [sub_resource type="Animation" id=1]
-resource_name = "instructions fade"
-length = 6.0
+resource_name = "message fade out"
+length = 5.0
 tracks/0/type = "value"
-tracks/0/path = NodePath("Label:modulate")
+tracks/0/path = NodePath("CanvasLayer/Label:modulate")
 tracks/0/interp = 1
 tracks/0/loop_wrap = true
 tracks/0/imported = false
 tracks/0/enabled = true
 tracks/0/keys = {
-"times": PoolRealArray( 0, 6 ),
-"transitions": PoolRealArray( 1, 1 ),
+"times": PoolRealArray( 0, 5 ),
+"transitions": PoolRealArray( 1, 5.65685 ),
 "update": 0,
 "values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
 }
@@ -30,7 +46,9 @@ margin_right = 40.0
 margin_bottom = 40.0
 
 [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
-margin_right = 329.0
+margin_left = 20.0
+margin_top = 20.0
+margin_right = 278.0
 margin_bottom = 74.0
 
 [node name="ScoreText" type="Label" parent="VBoxContainer/HBoxContainer"]
@@ -45,20 +63,21 @@ margin_bottom = 74.0
 text = "100"
 uppercase = true
 
-[node name="CenterContainer" type="CenterContainer" parent="VBoxContainer"]
-margin_top = 78.0
-margin_right = 329.0
-margin_bottom = 152.0
-theme = ExtResource( 1 )
+[node name="CanvasLayer" type="CanvasLayer" parent="."]
 
-[node name="Label" type="Label" parent="VBoxContainer/CenterContainer"]
-margin_right = 329.0
-margin_bottom = 74.0
+[node name="Label" type="Label" parent="CanvasLayer"]
+anchor_left = 0.1
+anchor_top = 0.6
+anchor_right = 0.8
+anchor_bottom = 0.8
+margin_right = 40.0
+margin_bottom = 14.0
 theme = ExtResource( 1 )
 text = "Tap to move"
 align = 1
 valign = 1
+autowrap = true
 
 [node name="AnimationPlayer" type="AnimationPlayer" parent="."]
-root_node = NodePath("../VBoxContainer/CenterContainer")
-"anims/instructions fade" = SubResource( 1 )
+"anims/message fade in" = SubResource( 2 )
+"anims/message fade out" = SubResource( 1 )
diff --git a/HealPowerUp.gd b/HealPowerUp.gd
index 53278ff..e4601d3 100644
--- a/HealPowerUp.gd
+++ b/HealPowerUp.gd
@@ -1,6 +1,7 @@
 extends Node2D
 
 export var heal_amount = 1
+signal consumed
 
 func _ready() -> void:
 	$AnimationPlayer.play("fade_in")
@@ -9,3 +10,4 @@ func _on_Area2D_body_entered(body: Node) -> void:
 	if body.has_method("heal"):
 		body.heal(heal_amount)
 		$AnimationPlayer.play("fade_out")
+		emit_signal("consumed")
diff --git a/SpeedPowerUp.gd b/SpeedPowerUp.gd
index 98dea1f..4c379f5 100644
--- a/SpeedPowerUp.gd
+++ b/SpeedPowerUp.gd
@@ -1,6 +1,7 @@
 extends Node2D
 
 export var speed_amount = 10
+signal consumed
 
 func _ready() -> void:
 	$AnimationPlayer.play("fade_in")
@@ -9,3 +10,4 @@ func _on_Area2D_body_entered(body: Node) -> void:
 	if body.has_method("speed_up"):
 		body.speed_up()
 		$AnimationPlayer.play("fade_out")
+		emit_signal("consumed")
diff --git a/Trails.tscn b/Trails.tscn
index 1618389..4ae03c0 100644
--- a/Trails.tscn
+++ b/Trails.tscn
@@ -9,7 +9,7 @@ _data = [ Vector2( 0, 0.220721 ), 0.0, -0.0409159, 0, 0, Vector2( 0.781651, 0.24
 script = ExtResource( 1 )
 
 [node name="CanvasLayer" type="CanvasLayer" parent="."]
-layer = -100
+layer = -50
 follow_viewport_enable = true
 
 [node name="Trails" type="Line2D" parent="CanvasLayer"]
diff --git a/World.gd b/World.gd
index ca490dc..d042020 100644
--- a/World.gd
+++ b/World.gd
@@ -14,6 +14,11 @@ var min_items_dict = {
 
 func enemy_killed():
 	$UI/HUD.score += 1
+	$UI/HUD.show_message("Enemy killed!", .5)
+func health_consumed():
+	$UI/HUD.show_message("+1 health", 1)
+func speed_consumed():
+	$UI/HUD.show_message("+10 speed", 1)
 	
 func create_enemy():
 	var enemy = Enemy.instance()
@@ -27,12 +32,14 @@ func create_health():
 	var health = Health.instance()
 	health.position = get_new_item_pos(1 + randf())
 	health.connect("tree_exiting", self, "create_health")
+	health.connect("consumed", self, "health_consumed")
 	$Environment.call_deferred("add_child", health)
 
 func create_speed():
 	var speed = Speed.instance()
 	speed.position = get_new_item_pos(1 + randf())
 	speed.connect("tree_exiting", self, "create_speed")
+	speed.connect("consumed", self, "speed_consumed")
 	$Environment.call_deferred("add_child", speed)
 
 func _ready() -> void:
@@ -42,6 +49,7 @@ func _ready() -> void:
 		for n in count:
 			var function = funcref(self, creator)
 			function.call_func()
+	$UI/HUD.show_message("Tap/drag to move")
 
 func get_new_item_pos(dist_ratio: float = 1.0) -> Vector2:
 	var pos_angle = randi() % 360
diff --git a/World.tscn b/World.tscn
index a249a40..5374975 100644
--- a/World.tscn
+++ b/World.tscn
@@ -23,6 +23,7 @@ texture = ExtResource( 1 )
 shape = SubResource( 1 )
 
 [node name="Background" type="CanvasLayer" parent="."]
+layer = -100
 
 [node name="ParallaxBackground" type="ParallaxBackground" parent="Background"]
 scroll_ignore_camera_zoom = true
diff --git a/project.godot b/project.godot
index fab199b..6b360f6 100644
--- a/project.godot
+++ b/project.godot
@@ -54,6 +54,7 @@ window/stretch/aspect="keep"
 [gui]
 
 common/drop_mouse_on_gui_input_disabled=true
+theme/use_hidpi=true
 
 [input]