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

@@ -1385,7 +1385,7 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Sprites/Cover_Blue_png_processed.png
/build:Sprites/Cover_Blue_png_processed.png;Sprites/Cover_Blue.png
#begin Sprites/Cover_Green_png_processed.png
/importer:TextureImporter
@@ -1397,7 +1397,7 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Sprites/Cover_Green_png_processed.png
/build:Sprites/Cover_Green_png_processed.png;Sprites/Cover_Green.png
#begin Sprites/Cover_Red_png_processed.png
/importer:TextureImporter
@@ -1409,7 +1409,7 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Sprites/Cover_Red_png_processed.png
/build:Sprites/Cover_Red_png_processed.png;Sprites/Cover_Red.png
#begin Sprites/Enemy01_Green_Frame_1_png_processed.png
/importer:TextureImporter
@@ -2561,5 +2561,5 @@
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Sprites/Rotor_png_processed.png
/build:Sprites/Rotor_png_processed.png;Sprites/Rotor.png

View File

@@ -1,5 +1,6 @@
using AlienAttack.MonoGame.Things;
using AlienAttack.MonoGame.Things.Enemies;
using AlienAttack.MonoGame.Things.Enemies.Mines;
using AlienAttack.MonoGame.Things.Stars;
using AlienAttack.MonoGame.View;
using Microsoft.Xna.Framework;
@@ -362,6 +363,24 @@ internal class GameLoop : GameLoopBase
Sprites.Add(enemy);
_spawnNewEnemyThreshold = 100 + _random.Next(0, 100);
}
else if (randomNumber == 6)
{
GreenMine enemy = new(_random.Next(0, ViewTransform.ScreenWidth - Mine.Width), -Mine.Height);
Sprites.Add(enemy);
_spawnNewEnemyThreshold = 100 + _random.Next(0, 100);
}
else if (randomNumber == 7)
{
RedMine enemy = new(_random.Next(0, ViewTransform.ScreenWidth - Mine.Width), -Mine.Height);
Sprites.Add(enemy);
_spawnNewEnemyThreshold = 100 + _random.Next(0, 100);
}
else if (randomNumber == 8)
{
BlueMine enemy = new(_random.Next(0, ViewTransform.ScreenWidth - Mine.Width), -Mine.Height);
Sprites.Add(enemy);
_spawnNewEnemyThreshold = 100 + _random.Next(0, 100);
}
}
}
}

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 = ""
};