gameover functionality on timeout
This commit is contained in:
parent
e09bc4c02e
commit
7d167deb57
7 changed files with 131 additions and 17 deletions
|
@ -39,6 +39,11 @@ _global_script_classes=[ {
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Actors/Enemy.gd"
|
"path": "res://src/Actors/Enemy.gd"
|
||||||
}, {
|
}, {
|
||||||
|
"base": "Node2D",
|
||||||
|
"class": "GameOver",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://src/Menu/GameOver.gd"
|
||||||
|
}, {
|
||||||
"base": "CanvasLayer",
|
"base": "CanvasLayer",
|
||||||
"class": "HUD",
|
"class": "HUD",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
|
@ -81,6 +86,7 @@ _global_script_class_icons={
|
||||||
"CutScene": "",
|
"CutScene": "",
|
||||||
"DialogBubble": "",
|
"DialogBubble": "",
|
||||||
"Enemy": "",
|
"Enemy": "",
|
||||||
|
"GameOver": "",
|
||||||
"HUD": "",
|
"HUD": "",
|
||||||
"Level": "",
|
"Level": "",
|
||||||
"Player": "",
|
"Player": "",
|
||||||
|
|
|
@ -702,7 +702,7 @@ texture = ExtResource( 7 )
|
||||||
texture_scale = 3.07
|
texture_scale = 3.07
|
||||||
color = Color( 0.854902, 0.952941, 0.682353, 1 )
|
color = Color( 0.854902, 0.952941, 0.682353, 1 )
|
||||||
range_height = -2048.0
|
range_height = -2048.0
|
||||||
range_item_cull_mask = 39
|
range_item_cull_mask = 47
|
||||||
shadow_enabled = true
|
shadow_enabled = true
|
||||||
shadow_item_cull_mask = 15
|
shadow_item_cull_mask = 15
|
||||||
|
|
||||||
|
|
|
@ -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/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]
|
[ext_resource path="res://src/GameWorld/GameWorld.gd" type="Script" id=5]
|
||||||
|
|
||||||
[sub_resource type="Environment" id=1]
|
[sub_resource type="Environment" id=1]
|
||||||
|
@ -13,6 +14,7 @@ script = ExtResource( 5 )
|
||||||
|
|
||||||
[node name="HUD" parent="." instance=ExtResource( 1 )]
|
[node name="HUD" parent="." instance=ExtResource( 1 )]
|
||||||
layer = 2
|
layer = 2
|
||||||
|
GameOver = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Level" type="Node2D" parent="."]
|
[node name="Level" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,19 @@ class_name HUD
|
||||||
|
|
||||||
export var coins_amount:int = 0
|
export var coins_amount:int = 0
|
||||||
export var PauseMenu: PackedScene;
|
export var PauseMenu: PackedScene;
|
||||||
|
export var GameOver: PackedScene;
|
||||||
onready var Lable = get_node("CoinsContainer/Label")
|
onready var Lable = get_node("CoinsContainer/Label")
|
||||||
|
|
||||||
var _paused = false;
|
var _paused = false;
|
||||||
var _pause_ref;
|
var _pause_ref;
|
||||||
var _data_ref = null;
|
var _data_ref = null;
|
||||||
|
var _can_pause_game:bool = true;
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_data_ref = GameState.get_run_data()
|
_data_ref = GameState.get_run_data()
|
||||||
var time_remaining = (GameState.GAME_TIMEOUT_MIN * 60) - _data_ref.time
|
var time_remaining = (GameState.GAME_TIMEOUT_MIN * 60) - _data_ref.time
|
||||||
$UI/TimeLabel.text = Utils.parse_seconds_to_display_str(time_remaining)
|
$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:
|
func _physics_process(delta: float) -> void:
|
||||||
_handle_pause()
|
_handle_pause()
|
||||||
|
@ -40,7 +44,7 @@ func _play_update_label_animation(player:AnimationPlayer):
|
||||||
player.play("updated")
|
player.play("updated")
|
||||||
|
|
||||||
func _handle_pause():
|
func _handle_pause():
|
||||||
if Input.is_action_just_pressed("pause"):
|
if _can_pause_game and Input.is_action_just_pressed("pause"):
|
||||||
if _paused:
|
if _paused:
|
||||||
_pause_ref.dismiss()
|
_pause_ref.dismiss()
|
||||||
else:
|
else:
|
||||||
|
@ -53,3 +57,14 @@ func _handle_pause():
|
||||||
func _on_pause_menu_dismissed():
|
func _on_pause_menu_dismissed():
|
||||||
_paused = false
|
_paused = false
|
||||||
get_tree().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
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,34 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
class_name GameOver
|
||||||
signal dismissed
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
$CanvasLayer/VBoxContainer/NewGameBtn.grab_focus()
|
$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:
|
func _on_ExitToMainMenuBtn_pressed() -> void:
|
||||||
$AnimationPlayer.play_backwards("fade")
|
$AnimationPlayer.play_backwards("fade")
|
||||||
yield($AnimationPlayer, "animation_finished");
|
yield($AnimationPlayer, "animation_finished");
|
||||||
var next_scene = load("res://src/Menu/MainMenu.tscn")
|
AudioManager.play_music(AudioManager.Music.Intro)
|
||||||
AudioManager.play(AudioManager.Music.Intro, .2)
|
GameState.go_to_main_menu()
|
||||||
get_tree().change_scene_to(next_scene)
|
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
|
||||||
func _on_NewGameBtn_pressed() -> void:
|
func _on_NewGameBtn_pressed() -> void:
|
||||||
$AnimationPlayer.play_backwards("fade")
|
$AnimationPlayer.play_backwards("fade")
|
||||||
yield($AnimationPlayer, "animation_finished");
|
yield($AnimationPlayer, "animation_finished");
|
||||||
emit_signal("dismissed")
|
GameState.start_new_game()
|
||||||
get_tree().reload_current_scene()
|
queue_free()
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
|
@ -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/Theme/slkscr.ttf" type="DynamicFontData" id=1]
|
||||||
[ext_resource path="res://assets/SplashScreen/BLANK.png" type="Texture" id=2]
|
[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://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://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/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]
|
[sub_resource type="DynamicFont" id=1]
|
||||||
size = 25
|
size = 25
|
||||||
|
@ -205,9 +206,16 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Coin" parent="CanvasLayer/Scores/Coins" instance=ExtResource( 5 )]
|
[node name="Coin" type="TextureRect" parent="CanvasLayer/Scores/Coins"]
|
||||||
position = Vector2( 0, 11 )
|
margin_left = -8.0
|
||||||
scale = Vector2( 3, 3 )
|
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"]
|
[node name="x" type="Label" parent="CanvasLayer/Scores/Coins"]
|
||||||
margin_left = 14.0
|
margin_left = 14.0
|
||||||
|
@ -250,8 +258,8 @@ __meta__ = {
|
||||||
[node name="Lifes" type="Control" parent="CanvasLayer/Scores"]
|
[node name="Lifes" type="Control" parent="CanvasLayer/Scores"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
margin_left = 20.0
|
margin_left = 20.0
|
||||||
margin_top = 46.0
|
margin_top = 26.0
|
||||||
margin_bottom = 46.0
|
margin_bottom = 26.0
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
@ -305,6 +313,64 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_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"]
|
[node name="Totals" type="Control" parent="CanvasLayer/Scores"]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
margin_left = 20.0
|
margin_left = 20.0
|
||||||
|
|
|
@ -2,6 +2,8 @@ extends Node
|
||||||
|
|
||||||
signal scene_changed
|
signal scene_changed
|
||||||
signal player_just_died
|
signal player_just_died
|
||||||
|
signal on_game_over
|
||||||
|
signal on_new_game
|
||||||
enum States{
|
enum States{
|
||||||
INTRO,
|
INTRO,
|
||||||
INTRO_CUTSCENE,
|
INTRO_CUTSCENE,
|
||||||
|
@ -72,7 +74,15 @@ func _physics_process(delta: float) -> void:
|
||||||
if _state == States.GAME:
|
if _state == States.GAME:
|
||||||
_run_data.time += delta
|
_run_data.time += delta
|
||||||
_data.statistics.total_time_played += 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():
|
func load_data():
|
||||||
var data_file = File.new()
|
var data_file = File.new()
|
||||||
var e = data_file.open_encrypted_with_pass(_SAVE_FILE_PATH, File.READ, _ENCRYPTION_KEY)
|
var e = data_file.open_encrypted_with_pass(_SAVE_FILE_PATH, File.READ, _ENCRYPTION_KEY)
|
||||||
|
@ -100,6 +110,7 @@ func save_data():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func start_new_game(from_main_menu:bool=false, change_music:bool=true):
|
func start_new_game(from_main_menu:bool=false, change_music:bool=true):
|
||||||
|
get_tree().paused = false
|
||||||
for key in _run_data.keys():
|
for key in _run_data.keys():
|
||||||
_run_data[key] = 0
|
_run_data[key] = 0
|
||||||
var state = States.INTRO_CUTSCENE if from_main_menu else States.NEW_GAME
|
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)
|
if change_music: AudioManager.play_music(AudioManager.Music.PreGame, delay)
|
||||||
_change_scene(state, delay)
|
_change_scene(state, delay)
|
||||||
yield(self, "scene_changed")
|
yield(self, "scene_changed")
|
||||||
|
emit_signal("on_new_game")
|
||||||
# get_tree().change_scene_to(load(_SCENES[_state]))
|
# get_tree().change_scene_to(load(_SCENES[_state]))
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,6 +136,7 @@ func get_run_data():
|
||||||
func get_state():
|
func get_state():
|
||||||
return int(_state)
|
return int(_state)
|
||||||
func go_to_main_menu():
|
func go_to_main_menu():
|
||||||
|
get_tree().paused = false
|
||||||
save_data()
|
save_data()
|
||||||
_change_scene(States.MAIN_MENU)
|
_change_scene(States.MAIN_MENU)
|
||||||
yield(self, "scene_changed")
|
yield(self, "scene_changed")
|
||||||
|
|
Loading…
Reference in a new issue