46 lines
1.3 KiB
GDScript
46 lines
1.3 KiB
GDScript
extends Node2D
|
|
|
|
@export var spawner : Spawner
|
|
var ship_scene = load("res://scene/ship.tscn")
|
|
var shoot_scene = load("res://scene/shoot.tscn")
|
|
|
|
func _on_area_2d_body_exited(body: Node2D) -> void:
|
|
if body.is_in_group("asteroid") and not body.is_in and body.delay_dup > 0.5:
|
|
spawner.spawn_duplicate(body)
|
|
body.queue_free()
|
|
|
|
|
|
func _on_area_2d_body_entered(body: Node2D) -> void:
|
|
pass
|
|
|
|
func _is_in_true(body: Node2D) -> void:
|
|
|
|
if body.is_in_group("asteroid") or body is Ship:
|
|
body.is_in = true
|
|
|
|
|
|
func _is_in_false(body: Node2D) -> void:
|
|
if body.is_in_group("asteroid"):
|
|
body.is_in = false
|
|
elif body is Ship:
|
|
body.is_in = false
|
|
var new_ship = ship_scene.instantiate()
|
|
new_ship.position = body.position.rotated(PI) *.95
|
|
new_ship.rotation = body.rotation
|
|
get_parent().call_deferred("add_child",new_ship)
|
|
spawner.player = new_ship
|
|
body.queue_free()
|
|
elif body is Shoot and not body.destroy:
|
|
body.is_in = false
|
|
var new_shoot = shoot_scene.instantiate()
|
|
new_shoot.position = body.position.rotated(PI)
|
|
new_shoot.direction = body.direction
|
|
new_shoot.rotation = body.rotation
|
|
new_shoot.time = body.time
|
|
get_parent().call_deferred("add_child",new_shoot)
|
|
body.queue_free()
|
|
|
|
|
|
func _on_wall_destroy_body_entered(body: Node2D) -> void:
|
|
body.queue_free()
|