diff options
| author | alex <[email protected]> | 2026-07-24 21:15:53 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-24 21:15:53 +0200 |
| commit | 6b666c7f25121e61bf1c58ee65cb2cd0f254b887 (patch) | |
| tree | de012eb81e45de014bf451ab1e8e741ef5abf3c5 /Bullet.cs | |
| parent | 7e0c071a0d86563f9d450bf9073e06006abfa86e (diff) | |
| download | godot-testing-6b666c7f25121e61bf1c58ee65cb2cd0f254b887.tar.xz godot-testing-6b666c7f25121e61bf1c58ee65cb2cd0f254b887.zip | |
replaced all the sprites added the tilemap and improved the stats system so it can be split into multiple scripts
Diffstat (limited to 'Bullet.cs')
| -rw-r--r-- | Bullet.cs | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -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(); + } +} |
