From 6b666c7f25121e61bf1c58ee65cb2cd0f254b887 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 24 Jul 2026 21:15:53 +0200 Subject: replaced all the sprites added the tilemap and improved the stats system so it can be split into multiple scripts --- Bullet.cs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'Bullet.cs') diff --git a/Bullet.cs b/Bullet.cs index aeefd94..e613849 100644 --- a/Bullet.cs +++ b/Bullet.cs @@ -2,15 +2,24 @@ using Godot; public partial class Bullet : Area2D { - [Export] public float Speed { get; set; } = 600.0f; - - // The player script will set this direction when the bullet spawns - public Vector2 Direction { get; set; } = Vector2.Zero; + [Export] public float Speed { get; set; } = 600.0f; + public Vector2 Direction { get; set; } = Vector2.Zero; - public override void _PhysicsProcess(double delta) - { - // Move the bullet over time. - // We multiply by delta to ensure movement is framerate-independent. - Position += Direction * Speed * (float)delta; - } -} \ No newline at end of file + public override void _Ready() + { + // Subscribe to the built-in BodyEntered event when the bullet is spawned + BodyEntered += OnBodyEntered; + } + + public override void _PhysicsProcess(double delta) + { + Position += Direction * Speed * (float)delta; + } + + // This method is triggered automatically when the bullet hits a physics body + private void OnBodyEntered(Node2D body) + { + // QueueFree safely deletes this node and all its children at the end of the current frame + QueueFree(); + } +} -- cgit v1.2.3