With the Alien Attack game in the current state there is an issue that makes the player scoring incorrect. If the aliens get past the player without being destroyed by the player or a rocket they will be destroyed by the Deathzone which calls the alien die() function. This in turn increases the player score which is not correct. I had a think about this and came up with the following solution:
In enemy.gd I modified the died signal by adding a byPlayer parameter which is set to true if the player killed the alien and false otherwise:
extends Area2D
signal died(byPlayer)
@export var speed = 200
func _physics_process(delta):
global_position.x += -speed*delta
func die(byPlayer):
emit_signal("died", byPlayer)
queue_free()
func _on_body_entered(body):
body.take_damage()
die(true)
In rocket.gd pass true as the byPlayer argument
func _on_area_entered(area):
queue_free()
area.die(true)
In game.gd
Modified the following function to pass false as the byPlayer argument:
func _on_deathzone_area_entered(area):
area.die(false)
Finally, in game.gd I could then determine if the alien was killed by the player:
func _on_enemy_died(byPlayer):
if byPlayer:
score += 100