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