From f44d9ae48c24b551e7875595b43838ae164f8e10 Mon Sep 17 00:00:00 2001 From: Brian Bicknell Date: Tue, 6 Jan 2026 20:35:52 -0500 Subject: [PATCH] Added mines. --- AlientAttack.MonoGame/Content/Content.mgcb | 8 +- AlientAttack.MonoGame/GameLoops/GameLoop.cs | 19 ++++ .../Things/Enemies/Mines/BlueMine.cs | 6 ++ .../Things/Enemies/Mines/GreenMine.cs | 6 ++ .../Things/Enemies/Mines/Mine.cs | 90 +++++++++++++++++++ .../Things/Enemies/Mines/RedMine.cs | 6 ++ AlientAttack.MonoGame/Things/Player.cs | 2 +- 7 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 AlientAttack.MonoGame/Things/Enemies/Mines/BlueMine.cs create mode 100644 AlientAttack.MonoGame/Things/Enemies/Mines/GreenMine.cs create mode 100644 AlientAttack.MonoGame/Things/Enemies/Mines/Mine.cs create mode 100644 AlientAttack.MonoGame/Things/Enemies/Mines/RedMine.cs diff --git a/AlientAttack.MonoGame/Content/Content.mgcb b/AlientAttack.MonoGame/Content/Content.mgcb index 3e4d198..5aea3ad 100644 --- a/AlientAttack.MonoGame/Content/Content.mgcb +++ b/AlientAttack.MonoGame/Content/Content.mgcb @@ -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 diff --git a/AlientAttack.MonoGame/GameLoops/GameLoop.cs b/AlientAttack.MonoGame/GameLoops/GameLoop.cs index 9d248b8..ce7177d 100644 --- a/AlientAttack.MonoGame/GameLoops/GameLoop.cs +++ b/AlientAttack.MonoGame/GameLoops/GameLoop.cs @@ -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); + } } } } diff --git a/AlientAttack.MonoGame/Things/Enemies/Mines/BlueMine.cs b/AlientAttack.MonoGame/Things/Enemies/Mines/BlueMine.cs new file mode 100644 index 0000000..ef1e0ba --- /dev/null +++ b/AlientAttack.MonoGame/Things/Enemies/Mines/BlueMine.cs @@ -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"; +} \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Enemies/Mines/GreenMine.cs b/AlientAttack.MonoGame/Things/Enemies/Mines/GreenMine.cs new file mode 100644 index 0000000..0ad1e54 --- /dev/null +++ b/AlientAttack.MonoGame/Things/Enemies/Mines/GreenMine.cs @@ -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"; +} \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Enemies/Mines/Mine.cs b/AlientAttack.MonoGame/Things/Enemies/Mines/Mine.cs new file mode 100644 index 0000000..0825fed --- /dev/null +++ b/AlientAttack.MonoGame/Things/Enemies/Mines/Mine.cs @@ -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("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($"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; + } + } +} \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Enemies/Mines/RedMine.cs b/AlientAttack.MonoGame/Things/Enemies/Mines/RedMine.cs new file mode 100644 index 0000000..9c38aca --- /dev/null +++ b/AlientAttack.MonoGame/Things/Enemies/Mines/RedMine.cs @@ -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"; +} \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Player.cs b/AlientAttack.MonoGame/Things/Player.cs index c10265f..44f3476 100644 --- a/AlientAttack.MonoGame/Things/Player.cs +++ b/AlientAttack.MonoGame/Things/Player.cs @@ -71,7 +71,7 @@ public class Player : MoveableSprite WeaponDef weaponDef = new() { Name = "Weapon 1", - Bullet = BulletDefinitions.ProtonLarge, + Bullet = BulletDefinitions.LaserLarge, Pattern = ShotPatterns.TripleSpread, FireSfxKey = "" };