Updated asteriods, mines, and explosions.
This commit is contained in:
47
AlientAttack.MonoGame/Things/Explosions/Explosion.cs
Normal file
47
AlientAttack.MonoGame/Things/Explosions/Explosion.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Explosions;
|
||||
|
||||
public class Explosion : MoveableSprite
|
||||
{
|
||||
protected int CurrentFrame { get; private set; } = 1;
|
||||
protected int MaxFrames => 9;
|
||||
protected int AnimationThreshold => 3;
|
||||
protected int CurrentThreshold { get; private set; } = 5;
|
||||
|
||||
public Explosion(int x, int y, float xVel, float yVel) : base(x, y)
|
||||
{
|
||||
Origin = new(32.5f, 32);
|
||||
XVelocity = xVel;
|
||||
YVelocity = yVel;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteDrawArgs args)
|
||||
{
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Explosion01_Frame_0{CurrentFrame}");
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, Scale, SpriteEffects.None, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
|
||||
public override void Update(SpriteUpdateContext context)
|
||||
{
|
||||
base.Update(context);
|
||||
|
||||
if (CurrentThreshold > 0)
|
||||
{
|
||||
CurrentThreshold--;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CurrentFrame == MaxFrames)
|
||||
{
|
||||
IsDead = true;
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentFrame++;
|
||||
CurrentThreshold = AnimationThreshold;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
AlientAttack.MonoGame/Things/Explosions/MineExplosion.cs
Normal file
11
AlientAttack.MonoGame/Things/Explosions/MineExplosion.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Explosions;
|
||||
|
||||
public class MineExplosion : Explosion
|
||||
{
|
||||
public MineExplosion(int x, int y, float xVel, float yVel) : base(x, y, xVel, yVel)
|
||||
{
|
||||
Scale = new(2, 2);
|
||||
}
|
||||
}
|
||||
48
AlientAttack.MonoGame/Things/Explosions/MiniExplosion.cs
Normal file
48
AlientAttack.MonoGame/Things/Explosions/MiniExplosion.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Explosions;
|
||||
|
||||
public class MiniExplosion : MoveableSprite
|
||||
{
|
||||
protected int CurrentFrame { get; private set; } = 1;
|
||||
protected int MaxFrames => 9;
|
||||
protected int AnimationThreshold => 3;
|
||||
protected int CurrentThreshold { get; private set; } = 5;
|
||||
|
||||
public MiniExplosion(int x, int y, float xVel, float yVel) : base(x, y)
|
||||
{
|
||||
Origin = new(32.5f, 32);
|
||||
XVelocity = xVel;
|
||||
YVelocity = yVel;
|
||||
Scale = new(.25f, .25f);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteDrawArgs args)
|
||||
{
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Explosion01_Frame_0{CurrentFrame}");
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, Scale, SpriteEffects.None, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
|
||||
public override void Update(SpriteUpdateContext context)
|
||||
{
|
||||
base.Update(context);
|
||||
|
||||
if (CurrentThreshold > 0)
|
||||
{
|
||||
CurrentThreshold--;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CurrentFrame == MaxFrames)
|
||||
{
|
||||
IsDead = true;
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentFrame++;
|
||||
CurrentThreshold = AnimationThreshold;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user