Skip to content

Commit

Permalink
Fixed cannon ball trail
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhawdge committed Nov 7, 2023
1 parent 3a708e5 commit 9568f88
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Components/Cannonball.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ internal class Cannonball
{
internal Vector2 Motion;
internal Team FiredBy;
internal float Duration = 8f;
internal float Elapsed = 0f;
}
internal enum Team
{
Expand Down
21 changes: 20 additions & 1 deletion Entities/Archetypes/EffectsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Sprite, Effect, LayerAir>();

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<Sprite, Effect, LayerAir>();
Expand All @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions Scenes/Levels/Systems/CannonBallSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using NovemberPirates.Systems;
using NovemberPirates.Utilities;
using Raylib_CsLo;
using System.Numerics;

namespace NovemberPirates.Scenes.Levels.Systems
{
Expand All @@ -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;

Expand Down

0 comments on commit 9568f88

Please sign in to comment.