Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | System_Error |
Hi all.
I have a scene (Enemy) that is spawned in with code on my Level scene. When it comes into contact with a player-shot projectile (LazerShot), it emits a signal, and is destroyed. Problem is, I don’t know how to have this signal {kill} connect to a child scene of Level.
Enemy.gd
extends Area2D
signal kill
export (int) var enemy_speed
func _ready():
set_process(true)
func _process(delta):
position -= Vector2(enemy_speed * delta, 0)
func _on_VisibilityNotifier2D_screen_exited():
if position.x < 0:
queue_free()
func _on_Enemy_area_shape_entered(area_id, area, area_shape, self_shape):
if area.has_method("lazershot"):
emit_signal("kill")
queue_free()
Level.gd
extends Node2D
const SCREEN_HEIGHT = 580
const SCREEN_WIDTH = 1010
signal game_over
var score
var finalscore
var EnergyShot = preload ('res://player-side/EnergyShot.tscn')
var eyeworm = preload ('res://Enemy.tscn')
var SpawnWaitTime = 5
func _ready():
randomize()
func _on_SpawnTimer_timeout():
var enemy = eyeworm.instance()
enemy.position = Vector2(SCREEN_WIDTH + 10, rand_range(0, SCREEN_HEIGHT))
add_child(enemy)
SpawnWaitTime -= 0.2
if (SpawnWaitTime < 1.2):
SpawnWaitTime = 1.2
$Node/SpawnTimer.set_wait_time(SpawnWaitTime)
func _on_SurvivalTimer_timeout():
score += 1
$HUD.score_count(score)
func _on_BaseArea_area_entered(area):
$Node/SpawnTimer.stop()
$Node/SurvivalTimer.stop()
$HUD.player_loss()
emit_signal('game_over')
$BaseArea/CollisionShape2D.disabled = true
get_tree().call_group("EyeWorms", "queue_free")
func _on_HUD_play_game():
score = 0
$Node/SurvivalTimer.start()
$Node/SpawnTimer.start()
$HUD.show_message("Survive!")
$BaseArea/CollisionShape2D.disabled = false