Commit 21b19c29 authored by Nathan Lovato's avatar Nathan Lovato
Browse files

Refactor end game, add fade animation and scoreboard

parent fc385999
Pipeline #5069 passed with stage
in 4 minutes and 55 seconds
# SPDX-License-Identifier: GPL-3.0-or-later
extends Node2D
onready var pillar_spawner := $PillarSpawner
onready var score_label : Label = $BackgroundLayer/ScoreLabel
onready var pillar_spawner := $Foreground/PillarSpawner
onready var score_label :Label = $Background/ScoreLabel
onready var foreground :Node2D = $Foreground
onready var gnu := $Gnu
onready var score_board := $UI/ScoreBoard
var score := 0
func _ready() -> void:
pillar_spawner.connect("pillar_checkpoint_reached", self, "increase_score")
gnu.connect("died", self, "_on_Gnu_died")
func _unhandled_input(event) -> void:
......@@ -18,3 +20,13 @@ func _unhandled_input(event) -> void:
func increase_score() -> void:
score_label.score += 1
func _on_Gnu_died() -> void:
foreground.fade_out()
yield(get_tree().create_timer(0.3), "timeout")
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)
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=12 format=2]
[ext_resource path="res://Game.gd" type="Script" id=1]
[ext_resource path="res://assets/bg.png" type="Texture" id=2]
[ext_resource path="res://ScoreLabel/ScoreLabel.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/ground.png" type="Texture" id=4]
[ext_resource path="res://PillarSpawner/PillarSpawner.tscn" type="PackedScene" id=5]
[ext_resource path="res://Gnu/Gnu.tscn" type="PackedScene" id=6]
[ext_resource path="res://Gnu/Gnu.tscn" type="PackedScene" id=4]
[ext_resource path="res://Foreground.gd" type="Script" id=5]
[ext_resource path="res://PillarSpawner/PillarSpawner.tscn" type="PackedScene" id=6]
[ext_resource path="res://SpriteSpawner/SpriteSpawner.gd" type="Script" id=7]
[ext_resource path="res://SpriteSpawner/GroundSprite.tscn" type="PackedScene" id=8]
[ext_resource path="res://SpriteSpawner/Fence.tscn" type="PackedScene" id=9]
[ext_resource path="res://ScoreBoard/ScoreBoard.tscn" type="PackedScene" id=10]
[sub_resource type="Animation" id=1]
resource_name = "fade_out"
length = 0.6
tracks/0/type = "value"
tracks/0/path = NodePath(".: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.6 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
}
[node name="Game" type="Node2D"]
script = ExtResource( 1 )
[node name="BackgroundLayer" type="CanvasLayer" parent="."]
[node name="Background" type="CanvasLayer" parent="."]
layer = -10
[node name="Sky" type="Sprite" parent="BackgroundLayer"]
[node name="Sky" type="Sprite" parent="Background"]
texture = ExtResource( 2 )
offset = Vector2( 540, 960 )
[node name="ScoreLabel" parent="BackgroundLayer" instance=ExtResource( 3 )]
[node name="ScoreLabel" parent="Background" instance=ExtResource( 3 )]
[node name="ParallaxBackground2" type="ParallaxBackground" parent="."]
layer = -2
scale = Vector2( 0.66, 1 )
transform = Transform2D( 0.66, 0, 0, 1, 0, 0 )
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground2"]
visible = false
motion_scale = Vector2( 0.8, 1 )
[node name="ground2" type="Sprite" parent="ParallaxBackground2/ParallaxLayer"]
modulate = Color( 0.878431, 0.286275, 0.643137, 1 )
position = Vector2( 424.242, 1520 )
scale = Vector2( 0.787037, 0.787037 )
texture = ExtResource( 4 )
region_rect = Rect2( 758, 159, 311, 122 )
[node name="PillarSpawner" parent="." instance=ExtResource( 5 )]
position = Vector2( 0, 950 )
[node name="Gnu" parent="." instance=ExtResource( 6 )]
[node name="Gnu" parent="." instance=ExtResource( 4 )]
position = Vector2( 190, 960 )
z_index = 1
[node name="Area2D" type="Area2D" parent="."]
position = Vector2( 0, 1930 )
[node name="Foreground" type="Node2D" parent="."]
script = ExtResource( 5 )
[node name="GroundSpawner" type="Node2D" parent="."]
[node name="PillarSpawner" parent="Foreground" instance=ExtResource( 6 )]
position = Vector2( 0, 950 )
[node name="GroundSpawner" type="Node2D" parent="Foreground"]
editor/display_folded = true
position = Vector2( -180, 1930 )
z_index = 100
script = ExtResource( 7 )
sprite_scene = ExtResource( 8 )
[node name="SpawnPosition" type="Position2D" parent="GroundSpawner"]
[node name="SpawnPosition" type="Position2D" parent="Foreground/GroundSpawner"]
[node name="FenceSpawner" type="Node2D" parent="."]
[node name="FenceSpawner" type="Node2D" parent="Foreground"]
editor/display_folded = true
position = Vector2( -180, 1700 )
z_index = 100
script = ExtResource( 7 )
sprite_scene = ExtResource( 9 )
[node name="SpawnPosition" type="Position2D" parent="FenceSpawner"]
[node name="SpawnPosition" type="Position2D" parent="Foreground/FenceSpawner"]
[node name="AnimationPlayer" type="AnimationPlayer" parent="Foreground"]
anims/fade_out = SubResource( 1 )
[node name="UI" type="CanvasLayer" parent="."]
[node name="ScoreBoard" parent="UI" instance=ExtResource( 10 )]
visible = false
extends KinematicBody2D
signal died
onready var tween : Tween = $Tween
onready var sprite : Sprite = $Sprite
onready var collision_shape : CollisionShape2D = $CollisionShape2D
......@@ -73,11 +75,9 @@ func die() -> void:
sprite.scale, Vector2(), 0.4,
Tween.TRANS_QUAD, Tween.EASE_OUT)
tween.start()
func _on_Tween_tween_completed(object, key) -> void:
if key == ':scale':
self._active = false
yield(tween, "tween_completed")
self._active = false
emit_signal('died')
func _set_active(value) -> void:
......
......@@ -34,4 +34,3 @@ shape = SubResource( 1 )
[node name="Tween" type="Tween" parent="."]
[connection signal="tween_completed" from="Tween" to="." method="_on_Tween_tween_completed"]
......@@ -4,6 +4,7 @@ signal checkpoint_reached
onready var notifier : VisibilityNotifier2D = $VisibilityNotifier2D
onready var checkpoint : Area2D = $Checkpoint
onready var anim_player :AnimationPlayer = $AnimationPlayer
func _ready() -> void:
......@@ -17,3 +18,7 @@ func _ready() -> void:
func _on_Checkpoint_body_entered(body) -> void:
emit_signal("checkpoint_reached")
func fade_out():
anim_player.play("fade_out")
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://Pillar/Pillar.gd" type="Script" id=1]
[ext_resource path="res://assets/pillar_top.png" type="Texture" id=2]
......@@ -7,7 +7,25 @@
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 20, 240 )
[node name="Pillar" type="StaticBody2D"]
[sub_resource type="Animation" id=2]
resource_name = "fade_out"
length = 0.6
tracks/0/type = "value"
tracks/0/path = NodePath(".: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.6 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
}
[node name="Pillar" type="StaticBody2D" groups=[
"pillar",
]]
collision_layer = 2
collision_mask = 0
script = ExtResource( 1 )
......@@ -43,3 +61,6 @@ shape = SubResource( 1 )
position = Vector2( 140, 0 )
rect = Rect2( -20, -20, 40, 40 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/fade_out = SubResource( 2 )
......@@ -10,4 +10,5 @@ script = ExtResource( 1 )
[node name="SpawnArea" type="Node2D" parent="."]
script = ExtResource( 2 )
min_extents = 60.0
max_extents = 400.0
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