Added mines.

This commit is contained in:
2026-01-06 20:35:52 -05:00
parent 804c03b1d8
commit f44d9ae48c
7 changed files with 132 additions and 5 deletions

View File

@@ -0,0 +1,6 @@
namespace AlienAttack.MonoGame.Things.Enemies.Mines;
public class BlueMine(int x, int y) : Mine(x, y)
{
protected override string CoverColor => "Blue";
}

View File

@@ -0,0 +1,6 @@
namespace AlienAttack.MonoGame.Things.Enemies.Mines;
public class GreenMine(int x, int y) : Mine(x, y)
{
protected override string CoverColor => "Green";
}

View File

@@ -0,0 +1,90 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things.Enemies.Mines;
public abstract class Mine : MoveableSprite
{
public const int Width = 65;
public const int Height = 64;
protected float Rotation = 0;
protected Vector2 Origin = new(30, 33);
protected abstract string CoverColor { get; }
public Mine(int x, int y) : base(x, y)
{
BoundBox = new(10, 14, 40, 38);
YVelocity = 1;
XVelocity = 0;
}
public override void Draw(SpriteDrawArgs args)
{
DrawRotor(args);
DrawCover(args);
//DrawCollisionBox(args);
}
private void DrawRotor(SpriteDrawArgs args)
{
Texture2D texture = args.Content.Load<Texture2D>("Sprites/Rotor");
args.SpriteBatch.Draw(texture, Position, null, DrawColor, Rotation, Origin, 1f, SpriteEffects.None, 1);
}
private void DrawCover(SpriteDrawArgs args)
{
Texture2D texture = args.Content.Load<Texture2D>($"Sprites/Cover_{CoverColor}");
args.SpriteBatch.Draw(texture, Position, null, DrawColor, Rotation, Origin, 1f, SpriteEffects.None, 1);
}
private void DrawCollisionBox(SpriteDrawArgs args)
{
//var pixel = DebugPixel; // static cached
Texture2D pixel = new Texture2D(args.SpriteBatch.GraphicsDevice, 1, 1);
pixel.SetData(new[] { Color.White });
//Rectangle r = GetWorldCollisionBox();
Color c = Color.LimeGreen; // debug color
// Top
args.SpriteBatch.Draw(pixel, new Rectangle(CollisionBox.X, CollisionBox.Y, CollisionBox.Width, 1), c);
// Bottom
args.SpriteBatch.Draw(pixel, new Rectangle(CollisionBox.X, CollisionBox.Bottom - 1, CollisionBox.Width, 1), c);
// Left
args.SpriteBatch.Draw(pixel, new Rectangle(CollisionBox.X, CollisionBox.Y, 1, CollisionBox.Height), c);
// Right
args.SpriteBatch.Draw(pixel, new Rectangle(CollisionBox.Right - 1, CollisionBox.Y, 1, CollisionBox.Height), c);
}
//Rectangle GetWorldCollisionBox()
//{
// int x = (int)(XPosition - Origin.X + BoundBox.X);
// int y = (int)(YPosition - Origin.Y + BoundBox.Y);
// return new Rectangle(x, y, BoundBox.Width, BoundBox.Height);
//}
public override sealed void Update(SpriteUpdateContext context)
{
base.Update(context);
CollisionBox = new Rectangle((int)XPosition + BoundBox.X - (int)Origin.X, (int)YPosition + BoundBox.Y - (int)Origin.Y, BoundBox.Width, BoundBox.Height);
if (YPosition - Origin.Y > context.ViewTransform.ScreenHeight)
{
IsDead = true;
return;
}
Rotation += 0.01f;
if (Rotation > 360f)
{
Rotation = 0;
}
}
}

View File

@@ -0,0 +1,6 @@
namespace AlienAttack.MonoGame.Things.Enemies.Mines;
public class RedMine(int x, int y) : Mine(x, y)
{
protected override string CoverColor => "Red";
}

View File

@@ -71,7 +71,7 @@ public class Player : MoveableSprite
WeaponDef weaponDef = new()
{
Name = "Weapon 1",
Bullet = BulletDefinitions.ProtonLarge,
Bullet = BulletDefinitions.LaserLarge,
Pattern = ShotPatterns.TripleSpread,
FireSfxKey = ""
};