Made ship more responsive, refactored responsibility for hit/death into the thing that got hit/died

This commit is contained in:
Benjamin Morgan 2025-10-21 20:02:17 -06:00
parent cae134a054
commit baa57c4d33
3 changed files with 52 additions and 28 deletions

View file

@ -1,7 +1,5 @@
extends Area2D
var explosion = preload('res://Scenes/explosion.tscn')
var pop = preload("res://Sounds/Explosion.wav")
var speed = 750
var half_size: Vector2 # half of sprite dimensions (used for wrapping)
@ -17,21 +15,10 @@ func _physics_process(delta):
var rect = get_viewport_rect()
if position.x < -half_size.x or position.x > rect.size.x + half_size.x or position.y < -half_size.y or position.y > rect.size.y + half_size.y:
#print_debug("FREED")
queue_free()
func _on_body_entered(body):
if body.is_in_group("enemies"):
body.queue_free()
Utils.play_sound(pop, get_parent())
var boom = explosion.instantiate()
boom.position = body.global_position
boom.scale = body.scale
get_parent().add_child(boom)
Game.set_score(Game.score + 100)
body.hit()
queue_free()
#print_debug("KILLED")