gameover functionality on timeout

This commit is contained in:
Sagi Dayan 2020-11-28 23:24:12 -05:00
parent e09bc4c02e
commit 7d167deb57
7 changed files with 131 additions and 17 deletions

View file

@ -39,6 +39,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://src/Actors/Enemy.gd"
}, {
"base": "Node2D",
"class": "GameOver",
"language": "GDScript",
"path": "res://src/Menu/GameOver.gd"
}, {
"base": "CanvasLayer",
"class": "HUD",
"language": "GDScript",
@ -81,6 +86,7 @@ _global_script_class_icons={
"CutScene": "",
"DialogBubble": "",
"Enemy": "",
"GameOver": "",
"HUD": "",
"Level": "",
"Player": "",

View file

@ -702,7 +702,7 @@ texture = ExtResource( 7 )
texture_scale = 3.07
color = Color( 0.854902, 0.952941, 0.682353, 1 )
range_height = -2048.0
range_item_cull_mask = 39
range_item_cull_mask = 47
shadow_enabled = true
shadow_item_cull_mask = 15

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://src/HUD/HUD.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/Menu/GameOver.tscn" type="PackedScene" id=2]
[ext_resource path="res://src/GameWorld/GameWorld.gd" type="Script" id=5]
[sub_resource type="Environment" id=1]
@ -13,6 +14,7 @@ script = ExtResource( 5 )
[node name="HUD" parent="." instance=ExtResource( 1 )]
layer = 2
GameOver = ExtResource( 2 )
[node name="Level" type="Node2D" parent="."]

View file

@ -3,15 +3,19 @@ class_name HUD
export var coins_amount:int = 0
export var PauseMenu: PackedScene;
export var GameOver: PackedScene;
onready var Lable = get_node("CoinsContainer/Label")
var _paused = false;
var _pause_ref;
var _data_ref = null;
var _can_pause_game:bool = true;
func _ready() -> void:
_data_ref = GameState.get_run_data()
var time_remaining = (GameState.GAME_TIMEOUT_MIN * 60) - _data_ref.time
$UI/TimeLabel.text = Utils.parse_seconds_to_display_str(time_remaining)
GameState.connect("on_new_game", self, "_on_new_game")
GameState.connect("on_game_over", self, "_on_game_over")
func _physics_process(delta: float) -> void:
_handle_pause()
@ -40,7 +44,7 @@ func _play_update_label_animation(player:AnimationPlayer):
player.play("updated")
func _handle_pause():
if Input.is_action_just_pressed("pause"):
if _can_pause_game and Input.is_action_just_pressed("pause"):
if _paused:
_pause_ref.dismiss()
else:
@ -53,3 +57,14 @@ func _handle_pause():
func _on_pause_menu_dismissed():
_paused = false
get_tree().paused = false
func _on_new_game():
_can_pause_game = true
func _on_game_over(player_timed_out:bool) -> void:
_can_pause_game = false
print("Plyer Timed out: %s" % [player_timed_out])
var game_over:GameOver = GameOver.instance()
add_child(game_over)
get_tree().paused = true

View file

@ -1,22 +1,34 @@
extends Node2D
signal dismissed
class_name GameOver
func _ready() -> void:
$CanvasLayer/VBoxContainer/NewGameBtn.grab_focus()
var run_data = GameState.get_run_data()
var score = run_data.score
$CanvasLayer/Scores/Coins/amount.text = str(run_data.coins)
$CanvasLayer/Scores/Lifes/amount.text = str(run_data.deaths)
$CanvasLayer/Scores/Orbs/amount.text = str(run_data.orbs)
var coin_score = run_data.coins * 10
var live_score = run_data.deaths * -2
var orbs_score = run_data.orbs * 100
$CanvasLayer/Scores/Coins/score.text = str(coin_score)
$CanvasLayer/Scores/Lifes/score.text = str(live_score)
$CanvasLayer/Scores/Orbs/score.text = str(orbs_score)
$CanvasLayer/Scores/Totals/total.text = str(score)
func _on_ExitToMainMenuBtn_pressed() -> void:
$AnimationPlayer.play_backwards("fade")
yield($AnimationPlayer, "animation_finished");
var next_scene = load("res://src/Menu/MainMenu.tscn")
AudioManager.play(AudioManager.Music.Intro, .2)
get_tree().change_scene_to(next_scene)
AudioManager.play_music(AudioManager.Music.Intro)
GameState.go_to_main_menu()
queue_free()
func _on_NewGameBtn_pressed() -> void:
$AnimationPlayer.play_backwards("fade")
yield($AnimationPlayer, "animation_finished");
emit_signal("dismissed")
get_tree().reload_current_scene()
GameState.start_new_game()
queue_free()
pass # Replace with function body.

View file

@ -1,11 +1,12 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=10 format=2]
[ext_resource path="res://assets/Theme/slkscr.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/SplashScreen/BLANK.png" type="Texture" id=2]
[ext_resource path="res://src/Menu/GameOver.gd" type="Script" id=3]
[ext_resource path="res://assets/Theme/menu_font.tres" type="DynamicFont" id=4]
[ext_resource path="res://src/Items/Coin.tscn" type="PackedScene" id=5]
[ext_resource path="res://assets/HUD/lifes_icon.png" type="Texture" id=6]
[ext_resource path="res://assets/HUD/coins_hud.png" type="Texture" id=7]
[ext_resource path="res://assets/HUD/orb_icon.png" type="Texture" id=9]
[sub_resource type="DynamicFont" id=1]
size = 25
@ -205,9 +206,16 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Coin" parent="CanvasLayer/Scores/Coins" instance=ExtResource( 5 )]
position = Vector2( 0, 11 )
scale = Vector2( 3, 3 )
[node name="Coin" type="TextureRect" parent="CanvasLayer/Scores/Coins"]
margin_left = -8.0
margin_top = -5.0
margin_right = 13.0
margin_bottom = 14.0
texture = ExtResource( 7 )
stretch_mode = 5
__meta__ = {
"_edit_use_anchors_": false
}
[node name="x" type="Label" parent="CanvasLayer/Scores/Coins"]
margin_left = 14.0
@ -250,8 +258,8 @@ __meta__ = {
[node name="Lifes" type="Control" parent="CanvasLayer/Scores"]
anchor_right = 1.0
margin_left = 20.0
margin_top = 46.0
margin_bottom = 46.0
margin_top = 26.0
margin_bottom = 26.0
__meta__ = {
"_edit_use_anchors_": false
}
@ -305,6 +313,64 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Orbs" type="Control" parent="CanvasLayer/Scores"]
anchor_right = 1.0
margin_left = 20.0
margin_top = 53.0
margin_bottom = 53.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Orb" type="TextureRect" parent="CanvasLayer/Scores/Orbs"]
margin_left = -8.0
margin_top = -5.0
margin_right = 13.0
margin_bottom = 14.0
texture = ExtResource( 9 )
stretch_mode = 5
__meta__ = {
"_edit_use_anchors_": false
}
[node name="x" type="Label" parent="CanvasLayer/Scores/Orbs"]
margin_left = 14.0
margin_top = -5.0
margin_right = 32.0
margin_bottom = 16.0
custom_fonts/font = ExtResource( 4 )
text = "x"
[node name="amount" type="Label" parent="CanvasLayer/Scores/Orbs"]
margin_left = 64.0
margin_top = -5.0
margin_right = 106.0
margin_bottom = 16.0
custom_fonts/font = ExtResource( 4 )
text = "500"
[node name="=" type="Label" parent="CanvasLayer/Scores/Orbs"]
margin_left = 192.0
margin_top = -5.0
margin_right = 210.0
margin_bottom = 16.0
custom_fonts/font = ExtResource( 4 )
text = "="
__meta__ = {
"_edit_use_anchors_": false
}
[node name="score" type="Label" parent="CanvasLayer/Scores/Orbs"]
margin_left = 274.0
margin_top = -5.0
margin_right = 330.0
margin_bottom = 16.0
custom_fonts/font = ExtResource( 4 )
text = "5000"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Totals" type="Control" parent="CanvasLayer/Scores"]
anchor_right = 1.0
margin_left = 20.0

View file

@ -2,6 +2,8 @@ extends Node
signal scene_changed
signal player_just_died
signal on_game_over
signal on_new_game
enum States{
INTRO,
INTRO_CUTSCENE,
@ -72,7 +74,15 @@ func _physics_process(delta: float) -> void:
if _state == States.GAME:
_run_data.time += delta
_data.statistics.total_time_played += delta
if _run_data.time >= GAME_TIMEOUT_MIN * 60:
game_over(true)
func game_over(timed_out:bool):
print("**************Game OVER******************")
_state = States.GAME_OVER
var cleared_bonus = 10000 if not timed_out else 0
_run_data.score = cleared_bonus + (_run_data.coins * 10) + (_run_data.deaths * -2) + (_run_data.orbs * 100)
emit_signal("on_game_over", timed_out)
func load_data():
var data_file = File.new()
var e = data_file.open_encrypted_with_pass(_SAVE_FILE_PATH, File.READ, _ENCRYPTION_KEY)
@ -100,6 +110,7 @@ func save_data():
pass
func start_new_game(from_main_menu:bool=false, change_music:bool=true):
get_tree().paused = false
for key in _run_data.keys():
_run_data[key] = 0
var state = States.INTRO_CUTSCENE if from_main_menu else States.NEW_GAME
@ -109,6 +120,7 @@ func start_new_game(from_main_menu:bool=false, change_music:bool=true):
if change_music: AudioManager.play_music(AudioManager.Music.PreGame, delay)
_change_scene(state, delay)
yield(self, "scene_changed")
emit_signal("on_new_game")
# get_tree().change_scene_to(load(_SCENES[_state]))
@ -124,6 +136,7 @@ func get_run_data():
func get_state():
return int(_state)
func go_to_main_menu():
get_tree().paused = false
save_data()
_change_scene(States.MAIN_MENU)
yield(self, "scene_changed")