From 9568f88646bcdbb8ee5f5668685c0f1f32c6479d Mon Sep 17 00:00:00 2001 From: John Pavek Date: Tue, 7 Nov 2023 13:26:05 -0600 Subject: [PATCH] Fixed cannon ball trail --- Components/Cannonball.cs | 2 ++ Entities/Archetypes/EffectsBuilder.cs | 21 ++++++++++++++++++++- Scenes/Levels/Systems/CannonBallSystem.cs | 8 ++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Components/Cannonball.cs b/Components/Cannonball.cs index c1da1d7..2f36868 100644 --- a/Components/Cannonball.cs +++ b/Components/Cannonball.cs @@ -6,6 +6,8 @@ internal class Cannonball { internal Vector2 Motion; internal Team FiredBy; + internal float Duration = 8f; + internal float Elapsed = 0f; } internal enum Team { diff --git a/Entities/Archetypes/EffectsBuilder.cs b/Entities/Archetypes/EffectsBuilder.cs index 80fd81a..5282851 100644 --- a/Entities/Archetypes/EffectsBuilder.cs +++ b/Entities/Archetypes/EffectsBuilder.cs @@ -61,6 +61,25 @@ internal static void CreateWaterTrail(World world, Vector2 pos, Vector2 motion) effectEntity.Set(effect); } + internal static void CreateCannonTrail(World world, Vector2 pos) + { + var effectEntity = world.Create(); + + var effectSprite = new Sprite(TextureKey.WhitePixel, "Assets/Art/whitepixel", 1f, true); + effectSprite.Position = pos; + effectSprite.Color = new Color(255, 255, 255, 96); + effectEntity.Set(effectSprite); + + var effect = new Effect(); + effect.Fadeout = true; + effect.FadeStart = 1f; + + effect.Duration = 1f; + effectEntity.Set(effect); + + effectEntity.Set(new LayerAir()); + } + internal static void CreateAirTrail(World world, Vector2 pos, Vector2 motion, bool createTrail) { var effectEntity = world.Create(); @@ -78,7 +97,7 @@ internal static void CreateAirTrail(World world, Vector2 pos, Vector2 motion, bo effect.Duration = (createTrail ? 5f : 1f) * 3; if (createTrail) { - effect.WiggleTimerOffset = (float)Random.Shared.Next(0,2) ; + effect.WiggleTimerOffset = (float)Random.Shared.Next(0, 2); } effect.Motion = motion; effectEntity.Set(effect); diff --git a/Scenes/Levels/Systems/CannonBallSystem.cs b/Scenes/Levels/Systems/CannonBallSystem.cs index 7b63248..c0a514f 100644 --- a/Scenes/Levels/Systems/CannonBallSystem.cs +++ b/Scenes/Levels/Systems/CannonBallSystem.cs @@ -5,7 +5,6 @@ using NovemberPirates.Systems; using NovemberPirates.Utilities; using Raylib_CsLo; -using System.Numerics; namespace NovemberPirates.Scenes.Levels.Systems { @@ -24,8 +23,13 @@ internal override void Update(World world) var start = sprite.Position; sprite.Position += cannonball.Motion * Raylib.GetFrameTime(); + cannonball.Elapsed += Raylib.GetFrameTime(); + if (cannonball.Elapsed > cannonball.Duration) + { + world.Destroy(entity); + } - EffectsBuilder.CreateAirTrail(world, sprite.Position, Vector2.Zero, false); + EffectsBuilder.CreateCannonTrail(world, sprite.Position); var end = sprite.Position;