Game #3: Space Shooter
This commit is contained in:
parent
a00e9b59c9
commit
f785a24c14
45 changed files with 927 additions and 0 deletions
21
space-shooter/Scenes/EnemySpawner.gd
Normal file
21
space-shooter/Scenes/EnemySpawner.gd
Normal file
|
@ -0,0 +1,21 @@
|
|||
extends Node2D
|
||||
|
||||
const Enemy = preload("res://Scenes/Objects/Enemy.tscn")
|
||||
onready var spawnPoints = $SpawnPoints
|
||||
|
||||
|
||||
func get_random_spawnpoint():
|
||||
var points = spawnPoints.get_children()
|
||||
points.shuffle()
|
||||
return points[0].global_position
|
||||
|
||||
|
||||
func spawn_enemy():
|
||||
var spawn_location = get_random_spawnpoint()
|
||||
var enemy = Enemy.instance()
|
||||
enemy.global_position = spawn_location
|
||||
get_tree().current_scene.add_child(enemy)
|
||||
|
||||
|
||||
func _on_Timer_timeout():
|
||||
spawn_enemy()
|
38
space-shooter/Scenes/EnemySpawner.tscn
Normal file
38
space-shooter/Scenes/EnemySpawner.tscn
Normal file
|
@ -0,0 +1,38 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/EnemySpawner.gd" type="Script" id=1]
|
||||
|
||||
|
||||
[node name="EnemySpawner" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="SpawnPoints" type="Node2D" parent="."]
|
||||
|
||||
[node name="Position2D" type="Position2D" parent="SpawnPoints"]
|
||||
position = Vector2( 0, 20 )
|
||||
|
||||
[node name="Position2D2" type="Position2D" parent="SpawnPoints"]
|
||||
position = Vector2( 0, 40 )
|
||||
|
||||
[node name="Position2D3" type="Position2D" parent="SpawnPoints"]
|
||||
position = Vector2( 0, 60 )
|
||||
|
||||
[node name="Position2D4" type="Position2D" parent="SpawnPoints"]
|
||||
position = Vector2( 0, 80 )
|
||||
|
||||
[node name="Position2D5" type="Position2D" parent="SpawnPoints"]
|
||||
position = Vector2( 0, 100 )
|
||||
|
||||
[node name="Position2D6" type="Position2D" parent="SpawnPoints"]
|
||||
position = Vector2( 0, 120 )
|
||||
|
||||
[node name="Position2D7" type="Position2D" parent="SpawnPoints"]
|
||||
position = Vector2( 0, 140 )
|
||||
|
||||
[node name="Position2D8" type="Position2D" parent="SpawnPoints"]
|
||||
position = Vector2( 0, 160 )
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
wait_time = 2.0
|
||||
autostart = true
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
|
46
space-shooter/Scenes/ExplosionEffect.tscn
Normal file
46
space-shooter/Scenes/ExplosionEffect.tscn
Normal file
|
@ -0,0 +1,46 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Sprites/Explosion.png" type="Texture" id=1]
|
||||
[ext_resource path="res://SFX/Explode.wav" type="AudioStream" id=2]
|
||||
|
||||
[sub_resource type="Animation" id=1]
|
||||
resource_name = "Explosion"
|
||||
length = 0.5
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath(".:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
|
||||
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ 0, 1, 2, 3, 4 ]
|
||||
}
|
||||
tracks/1/type = "method"
|
||||
tracks/1/path = NodePath(".")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0.5 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"values": [ {
|
||||
"args": [ ],
|
||||
"method": "queue_free"
|
||||
} ]
|
||||
}
|
||||
|
||||
[node name="ExplosionEffect" type="Sprite"]
|
||||
texture = ExtResource( 1 )
|
||||
hframes = 6
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
autoplay = "Explosion"
|
||||
anims/Explosion = SubResource( 1 )
|
||||
|
||||
[node name="ExplosionSound" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource( 2 )
|
||||
autoplay = true
|
5
space-shooter/Scenes/LaserHit.gd
Normal file
5
space-shooter/Scenes/LaserHit.gd
Normal file
|
@ -0,0 +1,5 @@
|
|||
extends Node2D
|
||||
|
||||
|
||||
func _on_Timer_timeout():
|
||||
queue_free()
|
37
space-shooter/Scenes/LaserHit.tscn
Normal file
37
space-shooter/Scenes/LaserHit.tscn
Normal file
|
@ -0,0 +1,37 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/LaserHit.gd" type="Script" id=1]
|
||||
[ext_resource path="res://SFX/Hit.wav" type="AudioStream" id=2]
|
||||
|
||||
[sub_resource type="ParticlesMaterial" id=1]
|
||||
lifetime_randomness = 1.0
|
||||
emission_shape = 1
|
||||
emission_sphere_radius = 1.0
|
||||
flag_disable_z = true
|
||||
spread = 180.0
|
||||
gravity = Vector3( 0, 0, 0 )
|
||||
initial_velocity = 25.0
|
||||
initial_velocity_random = 1.0
|
||||
orbit_velocity = 0.0
|
||||
orbit_velocity_random = 0.0
|
||||
scale = 1.5
|
||||
|
||||
[node name="LaserHit" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
wait_time = 3.0
|
||||
one_shot = true
|
||||
autostart = true
|
||||
|
||||
[node name="HitParticles" type="Particles2D" parent="."]
|
||||
emitting = false
|
||||
one_shot = true
|
||||
explosiveness = 1.0
|
||||
randomness = 1.0
|
||||
process_material = SubResource( 1 )
|
||||
|
||||
[node name="HitSound" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource( 2 )
|
||||
autoplay = true
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
|
9
space-shooter/Scenes/Music.tscn
Normal file
9
space-shooter/Scenes/Music.tscn
Normal file
|
@ -0,0 +1,9 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://Music/Music.ogg" type="AudioStream" id=1]
|
||||
|
||||
|
||||
[node name="Music" type="AudioStreamPlayer"]
|
||||
stream = ExtResource( 1 )
|
||||
volume_db = -2.0
|
||||
autoplay = true
|
18
space-shooter/Scenes/Objects/Bullet.gd
Normal file
18
space-shooter/Scenes/Objects/Bullet.gd
Normal file
|
@ -0,0 +1,18 @@
|
|||
extends RigidBody2D
|
||||
|
||||
|
||||
const LaserHit = preload("res://Scenes/LaserHit.tscn")
|
||||
|
||||
onready var laserSound = $LaserSound
|
||||
|
||||
func _ready():
|
||||
laserSound.play()
|
||||
|
||||
func _on_VisibilityNotifier2D_screen_exited():
|
||||
queue_free()
|
||||
|
||||
func create_hit_effect():
|
||||
var hit = LaserHit.instance()
|
||||
hit.global_position = global_position
|
||||
hit.get_node("HitParticles").emitting = true
|
||||
get_tree().current_scene.add_child(hit)
|
30
space-shooter/Scenes/Objects/Bullet.tscn
Normal file
30
space-shooter/Scenes/Objects/Bullet.tscn
Normal file
|
@ -0,0 +1,30 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/Objects/Bullet.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Sprites/Bullet.png" type="Texture" id=2]
|
||||
[ext_resource path="res://SFX/Laser.wav" type="AudioStream" id=3]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 4.07371, 3.0471 )
|
||||
|
||||
[node name="Bullet" type="RigidBody2D"]
|
||||
gravity_scale = 0.0
|
||||
linear_velocity = Vector2( 200, 0 )
|
||||
linear_damp = 0.0
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="Collisiion" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
|
||||
position = Vector2( 0.471259, 0.0496063 )
|
||||
scale = Vector2( 0.456811, 0.394803 )
|
||||
|
||||
[node name="LaserSound" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource( 3 )
|
||||
autoplay = true
|
||||
[connection signal="body_entered" from="." to="." method="_on_Bullet_body_entered"]
|
||||
[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_screen_exited"]
|
30
space-shooter/Scenes/Objects/Enemy.gd
Normal file
30
space-shooter/Scenes/Objects/Enemy.gd
Normal file
|
@ -0,0 +1,30 @@
|
|||
extends Area2D
|
||||
|
||||
const Explosion = preload("res://Scenes/ExplosionEffect.tscn")
|
||||
|
||||
export (int) var speed = 50
|
||||
export (int) var armor = 3
|
||||
|
||||
func _process(delta):
|
||||
position.x -= speed * delta
|
||||
|
||||
func _on_Enemy_body_entered(body):
|
||||
body.create_hit_effect()
|
||||
body.queue_free()
|
||||
armor -= 1
|
||||
|
||||
if armor <= 0:
|
||||
var root = get_tree().current_scene
|
||||
if root.is_in_group("World"):
|
||||
root.score += 10
|
||||
explode()
|
||||
queue_free()
|
||||
|
||||
func _on_VisibilityNotifier2D_screen_exited():
|
||||
queue_free()
|
||||
|
||||
|
||||
func explode():
|
||||
var explosion = Explosion.instance()
|
||||
explosion.global_position = global_position
|
||||
get_tree().current_scene.add_child(explosion)
|
19
space-shooter/Scenes/Objects/Enemy.tscn
Normal file
19
space-shooter/Scenes/Objects/Enemy.tscn
Normal file
|
@ -0,0 +1,19 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Scenes/Objects/Enemy.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Sprites/Enemy.png" type="Texture" id=2]
|
||||
|
||||
[node name="Enemy" type="Area2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="Collision" type="CollisionPolygon2D" parent="."]
|
||||
polygon = PoolVector2Array( -3, -7, -1, -7, -1, -5, 0, -5, 0, -6, 1, -6, 1, -7, 3, -7, 3, -6, 4, -6, 4, -5, 5, -5, 5, 5, 4, 5, 4, 6, 3, 6, 3, 7, 1, 7, 1, 6, 0, 6, 0, 5, -1, 5, -1, 7, -3, 7, -3, 6, -4, 6, -4, 5, -2, 5, -2, 3, -3, 3, -3, 2, -5, 2, -5, 1, -4, 1, -4, -1, -5, -1, -5, -2, -3, -2, -3, -3, -2, -3, -2, -5, -4, -5, -4, -6, -3, -6 )
|
||||
|
||||
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
|
||||
position = Vector2( 0, 4.17233e-07 )
|
||||
scale = Vector2( 0.6, 0.8 )
|
||||
[connection signal="body_entered" from="." to="." method="_on_Enemy_body_entered"]
|
||||
[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_screen_exited"]
|
39
space-shooter/Scenes/Objects/Ship.gd
Normal file
39
space-shooter/Scenes/Objects/Ship.gd
Normal file
|
@ -0,0 +1,39 @@
|
|||
extends Area2D
|
||||
|
||||
const Bullet = preload("res://Scenes/Objects/Bullet.tscn")
|
||||
const Explosion = preload("res://Scenes/ExplosionEffect.tscn")
|
||||
|
||||
export (int) var speed = 100
|
||||
|
||||
signal player_death
|
||||
|
||||
func _process(delta):
|
||||
if Input.is_action_pressed("ui_up"):
|
||||
position.y -= speed * delta
|
||||
|
||||
if Input.is_action_pressed("ui_down"):
|
||||
position.y += speed * delta
|
||||
|
||||
if Input.is_action_just_pressed("ui_select"):
|
||||
fire_bullet()
|
||||
|
||||
|
||||
func fire_bullet():
|
||||
var bullet = Bullet.instance()
|
||||
var root = get_tree().current_scene # World scene root node
|
||||
|
||||
bullet.global_position = global_position
|
||||
|
||||
root.add_child_below_node(root.get_node("Background"), bullet)
|
||||
|
||||
|
||||
func _on_Ship_area_entered(area):
|
||||
queue_free()
|
||||
area.queue_free()
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
var explosion = Explosion.instance()
|
||||
explosion.global_position = global_position
|
||||
get_tree().current_scene.call_deferred("add_child", explosion)
|
||||
emit_signal("player_death")
|
15
space-shooter/Scenes/Objects/Ship.tscn
Normal file
15
space-shooter/Scenes/Objects/Ship.tscn
Normal file
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://Sprites/Ship.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Scenes/Objects/Ship.gd" type="Script" id=2]
|
||||
|
||||
|
||||
[node name="Ship" type="Area2D"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="Collision" type="CollisionPolygon2D" parent="."]
|
||||
polygon = PoolVector2Array( -7, -4, -5, -4, -5, -3, -4, -3, -4, -7, -2, -7, -2, -6, -1, -6, -1, -5, 0, -5, 0, -4, 1, -4, 1, -3, 2, -3, 2, -2, 5, -2, 5, -1, 7, -1, 7, 1, 5, 1, 5, 2, 2, 2, 2, 3, 1, 3, 1, 4, 0, 4, 0, 5, -1, 5, -1, 6, -2, 6, -2, 7, -4, 7, -4, 3, -5, 3, -5, 4, -7, 4, -7, 2, -6, 2, -6, 1, -7, 1, -7, -1, -6, -1, -6, -2, -7, -2 )
|
||||
[connection signal="area_entered" from="." to="." method="_on_Ship_area_entered"]
|
19
space-shooter/Scenes/Objects/Stars.tscn
Normal file
19
space-shooter/Scenes/Objects/Stars.tscn
Normal file
|
@ -0,0 +1,19 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ParticlesMaterial" id=1]
|
||||
emission_shape = 2
|
||||
emission_box_extents = Vector3( 1, 90, 1 )
|
||||
flag_disable_z = true
|
||||
spread = 0.0
|
||||
gravity = Vector3( 0, 0, 0 )
|
||||
initial_velocity = -100.0
|
||||
initial_velocity_random = 0.5
|
||||
orbit_velocity = 0.0
|
||||
orbit_velocity_random = 0.0
|
||||
|
||||
[node name="Stars" type="Particles2D"]
|
||||
position = Vector2( 320, 90 )
|
||||
amount = 120
|
||||
lifetime = 10.0
|
||||
preprocess = 10.0
|
||||
process_material = SubResource( 1 )
|
28
space-shooter/Scenes/SaveLoad.gd
Normal file
28
space-shooter/Scenes/SaveLoad.gd
Normal file
|
@ -0,0 +1,28 @@
|
|||
extends Node
|
||||
|
||||
# Use user://save.json to automatically use user app config folders
|
||||
# Leaving as res to avoid storing json files for test games
|
||||
const SAVE_DATA_PATH = "res://save.json"
|
||||
|
||||
var default_save_data = {
|
||||
"hi_score": 0
|
||||
}
|
||||
|
||||
func store_save_data(data):
|
||||
var save_file = File.new()
|
||||
save_file.open(SAVE_DATA_PATH, File.WRITE)
|
||||
save_file.store_line(to_json(data))
|
||||
save_file.close()
|
||||
|
||||
func load_save_data():
|
||||
var save_file = File.new()
|
||||
|
||||
if not save_file.file_exists(SAVE_DATA_PATH):
|
||||
store_save_data(default_save_data)
|
||||
return default_save_data
|
||||
|
||||
save_file.open(SAVE_DATA_PATH, File.READ)
|
||||
var save_data = parse_json(save_file.get_as_text())
|
||||
save_file.close()
|
||||
|
||||
return save_data
|
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