Skip to content

Commit

Permalink
Updates to match docs tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Bradfield committed May 11, 2020
1 parent 3e79e18 commit 3531eee
Show file tree
Hide file tree
Showing 44 changed files with 333 additions and 625 deletions.
16 changes: 11 additions & 5 deletions HUD.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@ extends CanvasLayer

signal start_game


func show_message(text):
$MessageLabel.text = text
$MessageLabel.show()
$Message.text = text
$Message.show()
$MessageTimer.start()


func show_game_over():
show_message("Game Over")
yield($MessageTimer, "timeout")
$Message.text = "Dodge the\nCreeps!"
$Message.show()
yield(get_tree().create_timer(1), "timeout")
$StartButton.show()
$MessageLabel.text = "Dodge the\nCreeps!"
$MessageLabel.show()


func update_score(score):
$ScoreLabel.text = str(score)


func _on_StartButton_pressed():
$StartButton.hide()
emit_signal("start_game")


func _on_MessageTimer_timeout():
$MessageLabel.hide()
$Message.hide()
135 changes: 36 additions & 99 deletions HUD.tscn
Original file line number Diff line number Diff line change
@@ -1,126 +1,63 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://HUD.gd" type="Script" id=1]
[ext_resource path="res://fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=2]
[ext_resource path="res://dodge_assets/fonts/Xolonium-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://HUD.gd" type="Script" id=2]

[sub_resource type="DynamicFont" id=1]

size = 64
use_mipmaps = false
use_filter = false
font_data = ExtResource( 2 )
_sections_unfolded = [ "Font", "Settings" ]

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

size = 72
use_mipmaps = false
use_filter = false
font_data = ExtResource( 2 )
_sections_unfolded = [ "Font", "Settings" ]
[sub_resource type="InputEventAction" id=2]
action = "ui_select"

[sub_resource type="DynamicFont" id=3]

size = 48
use_mipmaps = false
use_filter = false
font_data = ExtResource( 2 )
_sections_unfolded = [ "Font", "Settings" ]
[sub_resource type="ShortCut" id=3]
shortcut = SubResource( 2 )

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

layer = 1
offset = Vector2( 0, 0 )
rotation = 0.0
scale = Vector2( 1, 1 )
transform = Transform2D( 1, 0, 0, 1, 0, 0 )
script = ExtResource( 1 )

[node name="ScoreLabel" type="Label" parent="." index="0"]

anchor_left = 0.5
anchor_top = 0.0
anchor_right = 0.5
anchor_bottom = 0.0
margin_left = -25.0
margin_right = 25.0
margin_bottom = 100.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
[node name="ScoreLabel" type="Label" parent="."]
anchor_right = 1.0
margin_bottom = 78.0
custom_fonts/font = SubResource( 1 )
text = "0"
align = 1
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Anchor", "Margin", "custom_fonts" ]
__meta__ = {
"_edit_use_anchors_": false
}

[node name="MessageLabel" type="Label" parent="." index="1"]

anchor_left = 0.5
[node name="Message" type="Label" parent="."]
anchor_top = 0.5
anchor_right = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
margin_left = -200.0
margin_top = -150.0
margin_right = 200.0
margin_bottom = 50.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
custom_fonts/font = SubResource( 2 )
text = "Dodge the
Creeps!"
margin_top = -79.5
margin_bottom = 79.5
custom_fonts/font = SubResource( 1 )
text = "Dodge the Creeps!"
align = 1
valign = 1
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Anchor", "Margin", "custom_fonts" ]

[node name="MessageTimer" type="Timer" parent="." index="2"]

process_mode = 1
wait_time = 2.0
one_shot = true
autostart = false

[node name="StartButton" type="Button" parent="." index="3"]
autowrap = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="StartButton" type="Button" parent="."]
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -100.0
margin_left = -90.0
margin_top = -200.0
margin_right = 100.0
margin_right = 90.0
margin_bottom = -100.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_fonts/font = SubResource( 3 )
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
custom_fonts/font = SubResource( 1 )
shortcut = SubResource( 3 )
text = "Start"
flat = false
align = 1
_sections_unfolded = [ "Anchor", "Margin", "Visibility", "custom_fonts" ]

[connection signal="timeout" from="MessageTimer" to="." method="_on_MessageTimer_timeout"]
__meta__ = {
"_edit_use_anchors_": false
}

[node name="MessageTimer" type="Timer" parent="."]
wait_time = 2.0
one_shot = true
[connection signal="pressed" from="StartButton" to="." method="_on_StartButton_pressed"]


[connection signal="timeout" from="MessageTimer" to="." method="_on_MessageTimer_timeout"]
44 changes: 28 additions & 16 deletions Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,52 @@ extends Node
export (PackedScene) var Mob
var score


func _ready():
randomize()


func game_over():
$ScoreTimer.stop()
$MobTimer.stop()
$HUD.show_game_over()
get_tree().call_group("mobs", "queue_free")
$Music.stop()
$DeathSound.play()


func new_game():
score = 0
$HUD.update_score(score)
$Player.start($StartPosition.position)
$StartTimer.start()
$HUD.update_score(score)
$HUD.show_message("Get Ready")
$Music.play()

func game_over():
$DeathSound.play()
$Music.stop()
$ScoreTimer.stop()
$MobTimer.stop()
$HUD.show_game_over()

func _on_MobTimer_timeout():
# choose a random location on the Path2D
$MobPath/MobSpawnLocation.set_offset(randi())
# Choose a random location on Path2D.
$MobPath/MobSpawnLocation.offset = randi()
# Create a Mob instance and add it to the scene.
var mob = Mob.instance()
add_child(mob)
var direction = $MobPath/MobSpawnLocation.rotation + PI/2
# Set the mob's direction perpendicular to the path direction.
var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
# Set the mob's position to a random location.
mob.position = $MobPath/MobSpawnLocation.position
# add some randomness to the direction
direction += rand_range(-PI/4, PI/4)
# Add some randomness to the direction.
direction += rand_range(-PI / 4, PI / 4)
mob.rotation = direction
mob.set_linear_velocity(Vector2(rand_range(mob.MIN_SPEED, mob.MAX_SPEED), 0).rotated(direction))
# Set the velocity (speed & direction).
mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)
mob.linear_velocity = mob.linear_velocity.rotated(direction)

func _on_StartTimer_timeout():
$MobTimer.start()
$ScoreTimer.start()

func _on_ScoreTimer_timeout():
score += 1
$HUD.update_score(score)


func _on_StartTimer_timeout():
$MobTimer.start()
$ScoreTimer.start()
Loading

0 comments on commit 3531eee

Please sign in to comment.