Game #3: Space Shooter
This commit is contained in:
parent
a00e9b59c9
commit
f785a24c14
45 changed files with 927 additions and 0 deletions
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 )
|
Loading…
Add table
Add a link
Reference in a new issue