Skip to content

Commit

Permalink
part 05 hud
Browse files Browse the repository at this point in the history
  • Loading branch information
cbscribe committed May 3, 2019
1 parent 24eb3cb commit 9b31c6f
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ var Circle = preload("res://objects/Circle.tscn")
var Jumper = preload("res://objects/Jumper.tscn")

var player
var score = 0

func _ready():
randomize()
$HUD.hide()

func new_game():
score = 0
$HUD.update_score(score)
$Camera2D.position = $StartPosition.position
player = Jumper.instance()
player.position = $StartPosition.position
add_child(player)
player.connect("captured", self, "_on_Jumper_captured")
player.connect("died", self, "_on_Jumper_died")
spawn_circle($StartPosition.position)
$HUD.show()
$HUD.show_message("Go!")

func spawn_circle(_position=null):
var c = Circle.instance()
Expand All @@ -30,8 +36,11 @@ func _on_Jumper_captured(object):
$Camera2D.position = object.position
object.capture(player)
call_deferred("spawn_circle")
score += 1
$HUD.update_score(score)

func _on_Jumper_died():
get_tree().call_group("circles", "implode")
$Screens.game_over()
$HUD.hide()

5 changes: 4 additions & 1 deletion Main.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Main.gd" type="Script" id=1]
[ext_resource path="res://UI/Screens.tscn" type="PackedScene" id=2]
[ext_resource path="res://UI/HUD.tscn" type="PackedScene" id=3]

[node name="Main" type="Node"]
script = ExtResource( 1 )
Expand All @@ -17,4 +18,6 @@ smoothing_enabled = true
smoothing_speed = 8.0

[node name="Screens" parent="." instance=ExtResource( 2 )]

[node name="HUD" parent="." instance=ExtResource( 3 )]
[connection signal="start_game" from="Screens" to="." method="new_game"]
14 changes: 14 additions & 0 deletions UI/HUD.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends CanvasLayer

func show_message(text):
$Message.text = text
$AnimationPlayer.play("show_message")

func hide():
$ScoreBox.hide()

func show():
$ScoreBox.show()

func update_score(value):
$ScoreBox/HBoxContainer/Score.text = str(value)
138 changes: 138 additions & 0 deletions UI/HUD.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
[gd_scene load_steps=8 format=2]

[ext_resource path="res://UI/HUD.gd" type="Script" id=1]
[ext_resource path="res://assets/fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=2]
[ext_resource path="res://assets/fonts/xolonium_64.tres" type="DynamicFont" id=3]

[sub_resource type="DynamicFont" id=1]
size = 32
extra_spacing_top = 10
font_data = ExtResource( 2 )

[sub_resource type="DynamicFont" id=2]
size = 64
font_data = ExtResource( 2 )

[sub_resource type="Animation" id=3]
resource_name = "init"
length = 0.1
tracks/0/type = "value"
tracks/0/path = NodePath("Message:custom_fonts/font:size")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ 64 ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Message:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ false ]
}

[sub_resource type="Animation" id=4]
resource_name = "show_message"
length = 0.75
step = 0.01
tracks/0/type = "value"
tracks/0/path = NodePath("Message:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ true ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Message:custom_fonts/font:size")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.75 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 64, 200 ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("Message:modulate")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0, 0.75 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
}

[node name="HUD" type="CanvasLayer"]
script = ExtResource( 1 )

[node name="ScoreBox" type="MarginContainer" parent="."]
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -118.0
custom_constants/margin_right = 20
custom_constants/margin_top = 20
custom_constants/margin_left = 20
custom_constants/margin_bottom = 20

[node name="HBoxContainer" type="HBoxContainer" parent="ScoreBox"]
margin_left = 20.0
margin_top = 20.0
margin_right = 460.0
margin_bottom = 98.0
custom_constants/separation = 10
alignment = 2

[node name="Label" type="Label" parent="ScoreBox/HBoxContainer"]
margin_left = 199.0
margin_right = 295.0
margin_bottom = 78.0
size_flags_vertical = 5
custom_fonts/font = SubResource( 1 )
text = "Score"

[node name="Score" type="Label" parent="ScoreBox/HBoxContainer"]
margin_left = 305.0
margin_right = 440.0
margin_bottom = 78.0
size_flags_vertical = 5
custom_fonts/font = ExtResource( 3 )
text = "100"

[node name="Message" type="Label" parent="."]
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
margin_top = -39.0
margin_bottom = 39.0
grow_vertical = 2
custom_fonts/font = SubResource( 2 )
text = "Message"
align = 1
valign = 1
clip_text = true

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "init"
anims/init = SubResource( 3 )
anims/show_message = SubResource( 4 )
1 change: 0 additions & 1 deletion objects/Jumper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func _physics_process(delta):
position += velocity * delta

func die():

target = null
queue_free()

Expand Down

0 comments on commit 9b31c6f

Please sign in to comment.