Updated asteriods, mines, and explosions.

This commit is contained in:
2026-01-18 22:11:20 -05:00
parent 8e0a68efdf
commit e402c498d6
21 changed files with 338 additions and 102 deletions

View File

@@ -1,27 +1,28 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Things.Bullets;
using AlienAttack.MonoGame.Things.Explosions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things.Asteroids;
public class Asteroid : MoveableSprite
public abstract class Asteroid : MoveableSprite
{
public const int Width = 39;
public const int Height = 37;
protected abstract int MaxHealth { get; }
protected abstract string TextureName { get; }
protected float Rotation = 0;
protected int Health { get; set; }
protected float RotationSpeed { get; set; } = 1f;
public Asteroid(int x, int y) : base(x, y)
{
Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height);
YVelocity = 1;
XVelocity = 0;
Health = MaxHealth;
RotationSpeed = 1f;
}
public override void Draw(SpriteDrawArgs args)
{
Texture2D texture = args.Content.Load<Texture2D>("Sprites/Asteroid 01");
args.SpriteBatch.Draw(texture, Position, null, DrawColor, Rotation, Origin, 1f, SpriteEffects.None, 1);
Texture2D texture = args.Textures.Get(TextureName);
args.SpriteBatch.Draw(texture, Position, null, DrawColor, Rotation, Origin, Scale, SpriteEffects.None, 1);
base.Draw(args);
}
@@ -32,17 +33,33 @@ public class Asteroid : MoveableSprite
CollisionBox = new Rectangle((int)XPosition + BoundBox.X - (int)Origin.X, (int)YPosition + BoundBox.Y - (int)Origin.Y, BoundBox.Width, BoundBox.Height);
if (Health <= 0)
{
IsDead = true;
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
context.AudioManager.PlayExplosion();
return;
}
if (YPosition - Origin.Y > context.ViewTransform.ScreenHeight)
{
IsDead = true;
return;
}
Rotation += 0.01f;
Rotation = MathHelper.WrapAngle(Rotation + RotationSpeed * context.DeltaTime);
}
if (Rotation > 360f)
public override void OnCollision(SpriteCollisionContext context)
{
if (context.Sprite is Bullet bullet && bullet.Owner is Player)
{
Rotation = 0;
Health -= bullet.Damage;
}
if (context.Sprite is Player)
{
Health = 0;
}
}
}

View File

@@ -0,0 +1,20 @@
using AlienAttack.MonoGame.Textures;
namespace AlienAttack.MonoGame.Things.Asteroids;
public class AsteroidVariantA : Asteroid
{
public const int Width = 39;
public const int Height = 37;
protected override string TextureName => TextureNames.Asteriods.VariantA;
protected override int MaxHealth => 8;
public AsteroidVariantA(int x, int y) : base(x, y)
{
Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height);
YVelocity = 1;
XVelocity = 0;
}
}

View File

@@ -0,0 +1,20 @@
using AlienAttack.MonoGame.Textures;
namespace AlienAttack.MonoGame.Things.Asteroids;
public class AsteroidVariantB : Asteroid
{
public const int Width = 26;
public const int Height = 28;
protected override string TextureName => TextureNames.Asteriods.VariantB;
protected override int MaxHealth => 4;
public AsteroidVariantB(int x, int y) : base(x, y)
{
Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height);
YVelocity = 2;
XVelocity = 0;
}
}

View File

@@ -0,0 +1,20 @@
using AlienAttack.MonoGame.Textures;
namespace AlienAttack.MonoGame.Things.Asteroids;
public class AsteroidVariantC : Asteroid
{
public const int Width = 37;
public const int Height = 36;
protected override string TextureName => TextureNames.Asteriods.VariantC;
protected override int MaxHealth => 5;
public AsteroidVariantC(int x, int y) : base(x, y)
{
Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height);
YVelocity = 1.5f;
XVelocity = 0;
}
}

View File

@@ -0,0 +1,20 @@
using AlienAttack.MonoGame.Textures;
namespace AlienAttack.MonoGame.Things.Asteroids;
public class AsteroidVariantD : Asteroid
{
public const int Width = 44;
public const int Height = 35;
protected override string TextureName => TextureNames.Asteriods.VariantD;
protected override int MaxHealth => 10;
public AsteroidVariantD(int x, int y) : base(x, y)
{
Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height);
YVelocity = .5f;
XVelocity = 0;
}
}