Commit a091c53b authored by Nathan Lovato's avatar Nathan Lovato

Refactor code for the tutorial

parent 2e1ee110
......@@ -7,11 +7,13 @@ onready var foreground :Node2D = $Foreground
onready var gnu := $Gnu
onready var score_board := $UI/ScoreBoard
const ScoreLoader = preload("res://ScoreBoard/ScoreLoader.gd")
var waiting_to_restart :bool = false
func _ready() -> void:
pillar_spawner.connect("pillar_checkpoint_reached", self, "increase_score")
score_label.setup(pillar_spawner)
gnu.connect("died", self, "_on_Gnu_died")
......@@ -19,20 +21,22 @@ func _unhandled_input(event) -> void:
if waiting_to_restart:
if event.is_action_pressed("ui_accept") or event.is_action_pressed("tap"):
get_tree().reload_current_scene()
if event.is_action_pressed("reset"):
if event.is_action_pressed("reset") and OS.is_debug_build():
get_tree().reload_current_scene()
func increase_score() -> void:
score_label.score += 1
func _on_Gnu_died() -> void:
"""Play fade out animations, update the score, and show the scoreboard"""
foreground.fade_out()
yield(get_tree().create_timer(0.3), "timeout")
# Can't use an AnimationPlayer because the pillars are toplevel nodes
get_tree().call_group('pillar', 'fade_out')
yield(get_tree().create_timer(0.3), "timeout")
score_label.fade_out()
yield(get_tree().create_timer(0.6), "timeout")
score_board.start(score_label.score)
var loader := ScoreLoader.new()
loader.register(score_label.score)
var scores :Array = loader.get_scores()
score_board.start(scores)
waiting_to_restart = true
......@@ -12,20 +12,20 @@
[ext_resource path="res://SpriteSpawner/Fence.tscn" type="PackedScene" id=10]
[ext_resource path="res://ScoreBoard/ScoreBoard.tscn" type="PackedScene" id=11]
[sub_resource type="Gradient" id=2]
[sub_resource type="Gradient" id=1]
offsets = PoolRealArray( 0, 0.26699, 0.76699, 1 )
colors = PoolColorArray( 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 )
[sub_resource type="GradientTexture" id=3]
gradient = SubResource( 2 )
[sub_resource type="GradientTexture" id=2]
gradient = SubResource( 1 )
[sub_resource type="Curve" id=4]
[sub_resource type="Curve" id=3]
_data = [ Vector2( 0, 0.528988 ), 0.0, 1.40242, 0, 0, Vector2( 0.331339, 0.687388 ), 0.956195, 0.956195, 0, 0, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=5]
curve = SubResource( 4 )
[sub_resource type="CurveTexture" id=4]
curve = SubResource( 3 )
[sub_resource type="ParticlesMaterial" id=6]
[sub_resource type="ParticlesMaterial" id=5]
emission_shape = 2
emission_box_extents = Vector3( 540, 20, 1 )
flag_disable_z = true
......@@ -43,12 +43,11 @@ angle = 310.1
angle_random = 1.0
scale = 0.97
scale_random = 0.39
scale_curve = SubResource( 5 )
color_ramp = SubResource( 3 )
scale_curve = SubResource( 4 )
color_ramp = SubResource( 2 )
hue_variation_random = 1.0
[sub_resource type="Animation" id=1]
resource_name = "fade_out"
[sub_resource type="Animation" id=6]
length = 0.6
tracks/0/type = "value"
tracks/0/path = NodePath(".:modulate")
......@@ -81,7 +80,7 @@ amount = 40
lifetime = 3.0
preprocess = 2.0
visibility_rect = Rect2( -640, -100.058, 1280, 200 )
process_material = SubResource( 6 )
process_material = SubResource( 5 )
texture = ExtResource( 3 )
[node name="ScoreLabel" parent="Background" instance=ExtResource( 4 )]
......@@ -106,7 +105,6 @@ sprite_scene = ExtResource( 9 )
[node name="SpawnPosition" type="Position2D" parent="Foreground/GroundSpawner"]
[node name="FenceSpawner" type="Node2D" parent="Foreground"]
editor/display_folded = true
position = Vector2( -180, 1700 )
z_index = 100
script = ExtResource( 8 )
......@@ -115,7 +113,7 @@ sprite_scene = ExtResource( 10 )
[node name="SpawnPosition" type="Position2D" parent="Foreground/FenceSpawner"]
[node name="AnimationPlayer" type="AnimationPlayer" parent="Foreground"]
anims/fade_out = SubResource( 1 )
anims/fade_out = SubResource( 6 )
[node name="UI" type="CanvasLayer" parent="."]
......
......@@ -2,18 +2,16 @@ extends Control
onready var scores_column = $Column/ScoresColumn
const ROW_COUNT = 3
const ScoreRow = preload("ScoreRow.tscn")
const ScoreLoader = preload("ScoreLoader.gd")
var scores := []
func start(player_score:int):
var score_loader := ScoreLoader.new()
score_loader.register(player_score)
var scores = score_loader.get_scores()
for i in range(10):
func start(scores:Array) -> void:
"""Builds a list of ScoreRows and plays their start animation"""
for i in range(ROW_COUNT):
var row = ScoreRow.instance()
scores_column.add_child(row)
row.setup(i, scores[i])
......
......@@ -16,7 +16,6 @@ func setup(index:int, score:Dictionary={}) -> void:
func start() -> void:
"""Plays a fade-in animation"""
animation_player.play("fade_in")
......
......@@ -9,8 +9,8 @@ const WHITE_TRANSPARENT := Color('00ffffff')
var score := 0 setget set_score
func _ready() -> void:
modulate = WHITE_SEMI_TRANSPARENT
func setup(pillar_spawner) -> void:
pillar_spawner.connect("pillar_checkpoint_reached", self, "_on_PillarSpawner_pillar_checkpoint_reached")
func set_score(value) -> void:
......@@ -30,3 +30,11 @@ func fade_out():
modulate, WHITE_TRANSPARENT, 0.6,
Tween.TRANS_QUAD, Tween.EASE_IN)
tween.start()
func _ready() -> void:
modulate = WHITE_SEMI_TRANSPARENT
func _on_PillarSpawner_pillar_checkpoint_reached() -> void:
self.score += 1
......@@ -7,10 +7,10 @@ extents = Vector2( 260, 20 )
[node name="Fence" type="Sprite"]
texture = ExtResource( 1 )
offset = Vector2( 271, -60 )
offset = Vector2( 241, -60 )
[node name="VisibilityEnabler2D" type="VisibilityNotifier2D" parent="."]
position = Vector2( 530, 0 )
position = Vector2( 520, 0 )
[node name="Area2D" type="StaticBody2D" parent="."]
collision_layer = 2
......
game/assets/fence.png

55 KB | W: | H:

game/assets/fence.png

98.3 KB | W: | H:

game/assets/fence.png
game/assets/fence.png
game/assets/fence.png
game/assets/fence.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment