28 lines
660 B
GDScript
28 lines
660 B
GDScript
extends Area2D
|
|
|
|
var velocity = Vector2(0, 0)
|
|
var rot_velocity = 0
|
|
var explosion = preload('res://Scenes/explosion.tscn')
|
|
var pop = preload("res://Sounds/Explosion5.wav")
|
|
|
|
func _ready() -> void:
|
|
connect("body_entered", _on_body_entered)
|
|
|
|
func _physics_process(delta):
|
|
position += velocity * delta
|
|
rotation += rot_velocity * delta
|
|
|
|
Utils.wrap_position(self)
|
|
|
|
func _on_body_entered(body):
|
|
if body.name == "Ship":
|
|
Game.set_lives(Game.lives - 1)
|
|
|
|
Utils.play_sound(pop, get_parent())
|
|
|
|
var boom = explosion.instantiate()
|
|
boom.position = body.global_position
|
|
boom.scale = Vector2(6, 6)
|
|
get_parent().add_child(boom)
|
|
body.reset()
|
|
queue_free()
|