Game #3: Space Shooter
This commit is contained in:
parent
a00e9b59c9
commit
f785a24c14
45 changed files with 927 additions and 0 deletions
10
space-shooter/Scenes/Stages/GameOver.gd
Normal file
10
space-shooter/Scenes/Stages/GameOver.gd
Normal file
|
@ -0,0 +1,10 @@
|
|||
extends Node
|
||||
|
||||
func _ready():
|
||||
var save_data = SaveLoad.load_save_data()
|
||||
$HiScore.text = "Hi-Score: " + str(save_data.hi_score)
|
||||
|
||||
func _process(_delta):
|
||||
if Input.is_action_just_pressed("ui_cancel"):
|
||||
# warning-ignore:return_value_discarded
|
||||
get_tree().change_scene("res://Scenes/Stages/MainMenu.tscn")
|
60
space-shooter/Scenes/Stages/GameOver.tscn
Normal file
60
space-shooter/Scenes/Stages/GameOver.tscn
Normal file
|
@ -0,0 +1,60 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Fonts/PixelFont.tres" type="DynamicFont" id=1]
|
||||
[ext_resource path="res://Scenes/Objects/Stars.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://Scenes/Stages/GameOver.gd" type="Script" id=3]
|
||||
|
||||
|
||||
|
||||
|
||||
[node name="GameOver" type="Node"]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
color = Color( 0, 0, 0, 1 )
|
||||
__meta__ = {
|
||||
"_edit_lock_": true,
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Stars" parent="." instance=ExtResource( 2 )]
|
||||
|
||||
[node name="GameOver" type="Label" parent="."]
|
||||
margin_top = 60.0
|
||||
margin_right = 320.0
|
||||
margin_bottom = 80.0
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
text = "GAME OVER"
|
||||
align = 1
|
||||
valign = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="HiScore" type="Label" parent="."]
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_top = -100.0
|
||||
margin_bottom = -80.0
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
text = "Hi-Score = 0"
|
||||
align = 1
|
||||
valign = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Info" type="Label" parent="."]
|
||||
margin_top = 100.0
|
||||
margin_right = 320.0
|
||||
margin_bottom = 120.0
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
text = "Press ESC to go back to the Main Menu"
|
||||
align = 1
|
||||
valign = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
10
space-shooter/Scenes/Stages/MainMenu.gd
Normal file
10
space-shooter/Scenes/Stages/MainMenu.gd
Normal file
|
@ -0,0 +1,10 @@
|
|||
extends Node
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
if Input.is_action_just_pressed("ui_select"):
|
||||
# warning-ignore:return_value_discarded
|
||||
get_tree().change_scene("res://Scenes/Stages/World.tscn")
|
||||
|
||||
if Input.is_action_just_pressed("ui_cancel"):
|
||||
get_tree().quit()
|
40
space-shooter/Scenes/Stages/MainMenu.tscn
Normal file
40
space-shooter/Scenes/Stages/MainMenu.tscn
Normal file
|
@ -0,0 +1,40 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Fonts/PixelFont.tres" type="DynamicFont" id=1]
|
||||
[ext_resource path="res://Scenes/Objects/Stars.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://Scenes/Stages/MainMenu.gd" type="Script" id=3]
|
||||
|
||||
|
||||
|
||||
|
||||
[node name="MainMenu" type="Node"]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
color = Color( 0, 0, 0, 1 )
|
||||
__meta__ = {
|
||||
"_edit_lock_": true,
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="CenterContainer"]
|
||||
margin_left = 121.0
|
||||
margin_top = 82.0
|
||||
margin_right = 199.0
|
||||
margin_bottom = 97.0
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
text = "Press Space to Start
|
||||
Press ESC to exit"
|
||||
align = 1
|
||||
|
||||
[node name="Stars" parent="." instance=ExtResource( 2 )]
|
||||
position = Vector2( 320, 80 )
|
25
space-shooter/Scenes/Stages/World.gd
Normal file
25
space-shooter/Scenes/Stages/World.gd
Normal file
|
@ -0,0 +1,25 @@
|
|||
extends Node
|
||||
|
||||
var score = 0 setget set_score
|
||||
onready var scoreLabel = $Score
|
||||
|
||||
|
||||
func set_score(value):
|
||||
score = value
|
||||
update_score(str(value))
|
||||
|
||||
func update_score(value):
|
||||
scoreLabel.text = "Score = " + value
|
||||
|
||||
func update_save_data():
|
||||
var save_data = SaveLoad.load_save_data()
|
||||
if score > save_data.hi_score:
|
||||
save_data.hi_score = score
|
||||
SaveLoad.store_save_data(save_data)
|
||||
|
||||
func _on_Ship_player_death():
|
||||
update_save_data()
|
||||
# Yield until the timer expires
|
||||
yield(get_tree().create_timer(1), "timeout")
|
||||
# warning-ignore:return_value_discarded
|
||||
get_tree().change_scene("res://Scenes/Stages/GameOver.tscn")
|
42
space-shooter/Scenes/Stages/World.tscn
Normal file
42
space-shooter/Scenes/Stages/World.tscn
Normal file
|
@ -0,0 +1,42 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/Objects/Ship.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://Scenes/Stages/World.gd" type="Script" id=2]
|
||||
[ext_resource path="res://Scenes/EnemySpawner.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://Fonts/PixelFont.tres" type="DynamicFont" id=4]
|
||||
[ext_resource path="res://Scenes/Objects/Stars.tscn" type="PackedScene" id=5]
|
||||
|
||||
[node name="World" type="Node" groups=[
|
||||
"World",
|
||||
]]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
color = Color( 0, 0, 0, 1 )
|
||||
__meta__ = {
|
||||
"_edit_lock_": true,
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Stars" parent="." instance=ExtResource( 5 )]
|
||||
|
||||
[node name="EnemySpawner" parent="." instance=ExtResource( 3 )]
|
||||
position = Vector2( 336, 0 )
|
||||
|
||||
[node name="Ship" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 32, 90 )
|
||||
|
||||
[node name="Score" type="Label" parent="."]
|
||||
margin_right = 320.0
|
||||
margin_bottom = 14.0
|
||||
custom_fonts/font = ExtResource( 4 )
|
||||
text = "Score = 0"
|
||||
align = 1
|
||||
valign = 1
|
||||
__meta__ = {
|
||||
"_edit_lock_": true,
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="player_death" from="Ship" to="." method="_on_Ship_player_death"]
|
Loading…
Add table
Add a link
Reference in a new issue