From 8e0a68efdf5c695fe899bcba507f05939601a371 Mon Sep 17 00:00:00 2001 From: Brian Bicknell Date: Thu, 15 Jan 2026 00:20:09 -0500 Subject: [PATCH] Added sprite rotation and scale. Refactored bullet classes. --- .../Things/Bullets/Bullet.cs | 29 +++++++++++------ .../Things/Bullets/LaserBulletLarge.cs | 14 ++------ .../Things/Bullets/LaserBulletMedium.cs | 14 ++------ .../Things/Bullets/LaserBulletSmall.cs | 14 ++------ .../Things/Bullets/MinigunBulletLarge.cs | 14 ++------ .../Things/Bullets/MinigunBulletMedium.cs | 14 ++------ .../Things/Bullets/MinigunBulletSmall.cs | 14 ++------ .../Things/Bullets/PlasmaBulletLarge.cs | 14 ++------ .../Things/Bullets/PlasmaBulletMedium.cs | 14 ++------ .../Things/Bullets/PlasmaBulletSmall.cs | 14 ++------ .../Things/Bullets/ProtonBulletLarge.cs | 14 ++------ .../Things/Bullets/ProtonBulletMedium.cs | 14 ++------ .../Things/Bullets/ProtonBulletSmall.cs | 14 ++------ .../Things/Enemies/Enemy02Green.cs | 3 +- .../Things/Enemies/Enemy02Red.cs | 3 +- .../Things/Enemies/Enemy02Teal.cs | 3 +- .../Things/Enemies/GreenEnemy.cs | 3 +- .../Things/Enemies/Mines/Mine.cs | 32 ------------------- .../Things/Enemies/RedEnemy.cs | 3 +- .../Things/Enemies/TealEnemy.cs | 3 +- .../Things/Enemies/Turrets/Turret.cs | 24 -------------- AlientAttack.MonoGame/Things/MiniExplosion.cs | 3 +- .../Things/MoveableSprite.cs | 2 +- AlientAttack.MonoGame/Things/Sprite.cs | 8 ++++- .../Things/SpriteDrawArgs.cs | 2 +- 25 files changed, 60 insertions(+), 226 deletions(-) diff --git a/AlientAttack.MonoGame/Things/Bullets/Bullet.cs b/AlientAttack.MonoGame/Things/Bullets/Bullet.cs index 5ec8746..204a86d 100644 --- a/AlientAttack.MonoGame/Things/Bullets/Bullet.cs +++ b/AlientAttack.MonoGame/Things/Bullets/Bullet.cs @@ -1,23 +1,34 @@ -using AlienAttack.MonoGame.Things.Items; +using AlienAttack.MonoGame.Textures; +using AlienAttack.MonoGame.Things.Items; +using Microsoft.Xna.Framework.Graphics; +using System; namespace AlienAttack.MonoGame.Things.Bullets; -public class Bullet(float x, float y, float xVel, float yVel, Sprite owner) : Sprite(x, y) +public abstract class Bullet : MoveableSprite { - protected float XVelocity = xVel; - protected float YVelocity = yVel; - public Sprite Owner { get; protected set; } = owner; - public int Damage { get; protected set; } = 0; + public Sprite Owner { get; init; } + public int Damage { get; init; } = 0; + + protected abstract string TextureName { get; } + + public Bullet(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y) + { + XVelocity = xVel; + YVelocity = yVel; + Owner = owner; + } public override void Draw(SpriteDrawArgs args) { - base.Draw(args); + Texture2D texture = args.Textures.Get(TextureName); + + args.SpriteBatch.Draw(texture, Position, null, DrawColor, Rotation, Origin, Scale, SpriteEffects.None, 1); } public override void Update(SpriteUpdateContext context) { - XPosition += XVelocity; - YPosition += YVelocity; + Rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; if (XPosition + BoundBox.Width < 0 || XPosition > context.ViewTransform.ScreenWidth diff --git a/AlientAttack.MonoGame/Things/Bullets/LaserBulletLarge.cs b/AlientAttack.MonoGame/Things/Bullets/LaserBulletLarge.cs index 865f86e..6b3bae6 100644 --- a/AlientAttack.MonoGame/Things/Bullets/LaserBulletLarge.cs +++ b/AlientAttack.MonoGame/Things/Bullets/LaserBulletLarge.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class LaserBulletLarge : Bullet public const int Width = 8; public const int Height = 28; + protected override string TextureName => TextureNames.Bullets.LaserLarge; + public LaserBulletLarge(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width/2, Height/2); BoundBox = new(0, 0, Width, Height); Damage = 3; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.LaserLarge); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/LaserBulletMedium.cs b/AlientAttack.MonoGame/Things/Bullets/LaserBulletMedium.cs index eb554d0..704da36 100644 --- a/AlientAttack.MonoGame/Things/Bullets/LaserBulletMedium.cs +++ b/AlientAttack.MonoGame/Things/Bullets/LaserBulletMedium.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class LaserBulletMedium : Bullet public const int Width = 7; public const int Height = 21; + protected override string TextureName => TextureNames.Bullets.LaserMedium; + public LaserBulletMedium(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 2; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.LaserMedium); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/LaserBulletSmall.cs b/AlientAttack.MonoGame/Things/Bullets/LaserBulletSmall.cs index 07e019f..23732fa 100644 --- a/AlientAttack.MonoGame/Things/Bullets/LaserBulletSmall.cs +++ b/AlientAttack.MonoGame/Things/Bullets/LaserBulletSmall.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class LaserBulletSmall : Bullet public const int Width = 6; public const int Height = 18; + protected override string TextureName => TextureNames.Bullets.LaserSmall; + public LaserBulletSmall(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 1; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.LaserSmall); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/MinigunBulletLarge.cs b/AlientAttack.MonoGame/Things/Bullets/MinigunBulletLarge.cs index 0cb6631..938159a 100644 --- a/AlientAttack.MonoGame/Things/Bullets/MinigunBulletLarge.cs +++ b/AlientAttack.MonoGame/Things/Bullets/MinigunBulletLarge.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class MinigunBulletLarge : Bullet public const int Width = 9; public const int Height = 27; + protected override string TextureName => TextureNames.Bullets.MinigunLarge; + public MinigunBulletLarge(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 3; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.MinigunLarge); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/MinigunBulletMedium.cs b/AlientAttack.MonoGame/Things/Bullets/MinigunBulletMedium.cs index fa36ee5..7a38b2f 100644 --- a/AlientAttack.MonoGame/Things/Bullets/MinigunBulletMedium.cs +++ b/AlientAttack.MonoGame/Things/Bullets/MinigunBulletMedium.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class MinigunBulletMedium : Bullet public const int Width = 11; public const int Height = 21; + protected override string TextureName => TextureNames.Bullets.MinigunMedium; + public MinigunBulletMedium(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 2; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.MinigunMedium); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/MinigunBulletSmall.cs b/AlientAttack.MonoGame/Things/Bullets/MinigunBulletSmall.cs index 2bf9b82..e5f13d4 100644 --- a/AlientAttack.MonoGame/Things/Bullets/MinigunBulletSmall.cs +++ b/AlientAttack.MonoGame/Things/Bullets/MinigunBulletSmall.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class MinigunBulletSmall : Bullet public const int Width = 11; public const int Height = 21; + protected override string TextureName => TextureNames.Bullets.MinigunSmall; + public MinigunBulletSmall(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 1; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.MinigunSmall); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletLarge.cs b/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletLarge.cs index 21ac5ab..65f6397 100644 --- a/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletLarge.cs +++ b/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletLarge.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class PlasmaBulletLarge : Bullet public const int Width = 9; public const int Height = 31; + protected override string TextureName => TextureNames.Bullets.PlasmaLarge; + public PlasmaBulletLarge(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 3; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.PlasmaLarge); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletMedium.cs b/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletMedium.cs index b317abf..feb005b 100644 --- a/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletMedium.cs +++ b/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletMedium.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class PlasmaBulletMedium : Bullet public const int Width = 8; public const int Height = 26; + protected override string TextureName => TextureNames.Bullets.PlasmaMedium; + public PlasmaBulletMedium(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 2; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.PlasmaMedium); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletSmall.cs b/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletSmall.cs index 4237559..cd02c64 100644 --- a/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletSmall.cs +++ b/AlientAttack.MonoGame/Things/Bullets/PlasmaBulletSmall.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class PlasmaBulletSmall : Bullet public const int Width = 7; public const int Height = 24; + protected override string TextureName => TextureNames.Bullets.PlasmaSmall; + public PlasmaBulletSmall(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 1; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.PlasmaSmall); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/ProtonBulletLarge.cs b/AlientAttack.MonoGame/Things/Bullets/ProtonBulletLarge.cs index d07d76c..876b1d3 100644 --- a/AlientAttack.MonoGame/Things/Bullets/ProtonBulletLarge.cs +++ b/AlientAttack.MonoGame/Things/Bullets/ProtonBulletLarge.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class ProtonBulletLarge : Bullet public const int Width = 13; public const int Height = 13; + protected override string TextureName => TextureNames.Bullets.ProtonLarge; + public ProtonBulletLarge(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 3; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.ProtonLarge); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/ProtonBulletMedium.cs b/AlientAttack.MonoGame/Things/Bullets/ProtonBulletMedium.cs index 42cf3f9..b9c13e2 100644 --- a/AlientAttack.MonoGame/Things/Bullets/ProtonBulletMedium.cs +++ b/AlientAttack.MonoGame/Things/Bullets/ProtonBulletMedium.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class ProtonBulletMedium : Bullet public const int Width = 10; public const int Height = 10; + protected override string TextureName => TextureNames.Bullets.ProtonMedium; + public ProtonBulletMedium(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 2; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.ProtonMedium); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Bullets/ProtonBulletSmall.cs b/AlientAttack.MonoGame/Things/Bullets/ProtonBulletSmall.cs index b4273da..47eac35 100644 --- a/AlientAttack.MonoGame/Things/Bullets/ProtonBulletSmall.cs +++ b/AlientAttack.MonoGame/Things/Bullets/ProtonBulletSmall.cs @@ -1,7 +1,4 @@ using AlienAttack.MonoGame.Textures; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things.Bullets; @@ -10,19 +7,12 @@ public class ProtonBulletSmall : Bullet public const int Width = 6; public const int Height = 6; + protected override string TextureName => TextureNames.Bullets.ProtonSmall; + public ProtonBulletSmall(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner) { Origin = new(Width / 2, Height / 2); BoundBox = new(0, 0, Width, Height); Damage = 1; } - - public override void Draw(SpriteDrawArgs args) - { - Texture2D texture = args.Textures.Get(TextureNames.Bullets.ProtonSmall); - - float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f; - - args.SpriteBatch.Draw(texture, Position, null, DrawColor, rotation, Origin, 1f, SpriteEffects.None, 1); - } } \ No newline at end of file diff --git a/AlientAttack.MonoGame/Things/Enemies/Enemy02Green.cs b/AlientAttack.MonoGame/Things/Enemies/Enemy02Green.cs index ec54566..f56235a 100644 --- a/AlientAttack.MonoGame/Things/Enemies/Enemy02Green.cs +++ b/AlientAttack.MonoGame/Things/Enemies/Enemy02Green.cs @@ -27,8 +27,7 @@ public class Enemy02Green : EnemyShip Texture2D texture = args.Content.Load(@$"Sprites\Enemy02Green_Frame_{frame}_png_processed"); //SpriteEffects spriteEffects = SpriteEffects.None; - //args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1); - args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1); + args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, Scale, spriteEffects, 1); base.Draw(args); } diff --git a/AlientAttack.MonoGame/Things/Enemies/Enemy02Red.cs b/AlientAttack.MonoGame/Things/Enemies/Enemy02Red.cs index b116670..ce3542a 100644 --- a/AlientAttack.MonoGame/Things/Enemies/Enemy02Red.cs +++ b/AlientAttack.MonoGame/Things/Enemies/Enemy02Red.cs @@ -27,8 +27,7 @@ public class Enemy02Red : EnemyShip Texture2D texture = args.Content.Load(@$"Sprites\Enemy02Red_Frame_{frame}_png_processed"); //SpriteEffects spriteEffects = SpriteEffects.None; - //args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1); - args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1); + args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, Scale, spriteEffects, 1); base.Draw(args); } diff --git a/AlientAttack.MonoGame/Things/Enemies/Enemy02Teal.cs b/AlientAttack.MonoGame/Things/Enemies/Enemy02Teal.cs index 17e187f..b1b7eb0 100644 --- a/AlientAttack.MonoGame/Things/Enemies/Enemy02Teal.cs +++ b/AlientAttack.MonoGame/Things/Enemies/Enemy02Teal.cs @@ -27,8 +27,7 @@ public class Enemy02Teal : EnemyShip Texture2D texture = args.Content.Load(@$"Sprites\Enemy02_Teal_Frame_{frame}_png_processed"); //SpriteEffects spriteEffects = SpriteEffects.None; - //args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1); - args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1); + args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, Scale, spriteEffects, 1); base.Draw(args); } diff --git a/AlientAttack.MonoGame/Things/Enemies/GreenEnemy.cs b/AlientAttack.MonoGame/Things/Enemies/GreenEnemy.cs index d3d1142..62c608f 100644 --- a/AlientAttack.MonoGame/Things/Enemies/GreenEnemy.cs +++ b/AlientAttack.MonoGame/Things/Enemies/GreenEnemy.cs @@ -29,8 +29,7 @@ public class GreenEnemy : EnemyShip Texture2D texture = args.Content.Load(@$"Sprites\Enemy01_Green_Frame_1_png_processed"); SpriteEffects spriteEffects = SpriteEffects.None; - //args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1); - args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1); + args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, Scale, spriteEffects, 1); base.Draw(args); } diff --git a/AlientAttack.MonoGame/Things/Enemies/Mines/Mine.cs b/AlientAttack.MonoGame/Things/Enemies/Mines/Mine.cs index db67a2d..28e9894 100644 --- a/AlientAttack.MonoGame/Things/Enemies/Mines/Mine.cs +++ b/AlientAttack.MonoGame/Things/Enemies/Mines/Mine.cs @@ -9,8 +9,6 @@ public abstract class Mine : MoveableSprite public const int Width = 65; public const int Height = 64; - protected float Rotation = 0; - protected abstract string CoverColor { get; } public Mine(int x, int y) : base(x, y) @@ -25,7 +23,6 @@ public abstract class Mine : MoveableSprite { DrawRotor(args); DrawCover(args); - //DrawCollisionBox(args); } private void DrawRotor(SpriteDrawArgs args) @@ -40,35 +37,6 @@ public abstract class Mine : MoveableSprite 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); diff --git a/AlientAttack.MonoGame/Things/Enemies/RedEnemy.cs b/AlientAttack.MonoGame/Things/Enemies/RedEnemy.cs index 5d4465d..562b892 100644 --- a/AlientAttack.MonoGame/Things/Enemies/RedEnemy.cs +++ b/AlientAttack.MonoGame/Things/Enemies/RedEnemy.cs @@ -23,8 +23,7 @@ public class RedEnemy : EnemyShip Texture2D texture = args.Content.Load(@$"Sprites\Enemy01_Red_Frame_{frame}_png_processed"); //SpriteEffects spriteEffects = SpriteEffects.None; - //args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1); - args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1); + args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, Scale, spriteEffects, 1); base.Draw(args); } diff --git a/AlientAttack.MonoGame/Things/Enemies/TealEnemy.cs b/AlientAttack.MonoGame/Things/Enemies/TealEnemy.cs index cc65e8a..62b095f 100644 --- a/AlientAttack.MonoGame/Things/Enemies/TealEnemy.cs +++ b/AlientAttack.MonoGame/Things/Enemies/TealEnemy.cs @@ -24,8 +24,7 @@ public class TealEnemy : EnemyShip Texture2D texture = args.Content.Load(@$"Sprites\Enemy01_Teal_Frame_{frame}_png_processed"); //SpriteEffects spriteEffects = SpriteEffects.None; - //args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1); - args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1); + args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, Scale, spriteEffects, 1); base.Draw(args); } diff --git a/AlientAttack.MonoGame/Things/Enemies/Turrets/Turret.cs b/AlientAttack.MonoGame/Things/Enemies/Turrets/Turret.cs index 2ad7fb5..fe9bd2f 100644 --- a/AlientAttack.MonoGame/Things/Enemies/Turrets/Turret.cs +++ b/AlientAttack.MonoGame/Things/Enemies/Turrets/Turret.cs @@ -14,8 +14,6 @@ public abstract class Turret : MoveableSprite public const int GunWidth = 8; public const int GunHeight = 38; - protected float Rotation = 0; - protected Vector2 MountOrigin = new(MountWidth / 2, MountHeight /2); protected Vector2 TurretOrigin = new(TurretWidth / 2, TurretHeight / 2); protected Vector2 GunOrigin = new(GunWidth / 2, GunHeight / 2); @@ -34,7 +32,6 @@ public abstract class Turret : MoveableSprite DrawMount(args); DrawTurret(args); DrawGun(args); - //DrawCollisionBox(args); } private void DrawMount(SpriteDrawArgs args) @@ -55,27 +52,6 @@ public abstract class Turret : MoveableSprite args.SpriteBatch.Draw(texture, Position, null, DrawColor, Rotation, GunOrigin, 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); - } - public override sealed void Update(SpriteUpdateContext context) { base.Update(context); diff --git a/AlientAttack.MonoGame/Things/MiniExplosion.cs b/AlientAttack.MonoGame/Things/MiniExplosion.cs index d47d787..686b45e 100644 --- a/AlientAttack.MonoGame/Things/MiniExplosion.cs +++ b/AlientAttack.MonoGame/Things/MiniExplosion.cs @@ -1,5 +1,4 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Graphics; namespace AlienAttack.MonoGame.Things; diff --git a/AlientAttack.MonoGame/Things/MoveableSprite.cs b/AlientAttack.MonoGame/Things/MoveableSprite.cs index 514e18c..b5f284b 100644 --- a/AlientAttack.MonoGame/Things/MoveableSprite.cs +++ b/AlientAttack.MonoGame/Things/MoveableSprite.cs @@ -1,6 +1,6 @@ namespace AlienAttack.MonoGame.Things; -public class MoveableSprite(int x, int y) : Sprite(x, y) +public class MoveableSprite(float x, float y) : Sprite(x, y) { public float XVelocity { get; protected set; } = 0; public float YVelocity { get; protected set; } = 0; diff --git a/AlientAttack.MonoGame/Things/Sprite.cs b/AlientAttack.MonoGame/Things/Sprite.cs index ac5812f..ddf9bd8 100644 --- a/AlientAttack.MonoGame/Things/Sprite.cs +++ b/AlientAttack.MonoGame/Things/Sprite.cs @@ -8,7 +8,9 @@ public class Sprite(float x, float y) public float XPosition { get; protected set; } = x; public float YPosition { get; protected set; } = y; public Vector2 Position => new(XPosition, YPosition); + public float Rotation { get; protected set; } public Vector2 Origin { get; protected set; } + public Vector2 Scale { get; protected set; } = new(1, 1); public Rectangle BoundBox { get; protected set; } protected Rectangle CollisionBox; @@ -31,7 +33,11 @@ public class Sprite(float x, float y) public virtual void Draw(SpriteDrawArgs args) { //spriteBatch.Draw(Texture, Position, DrawColor); - DrawCollisionBox(args); + + if (args.ShowCollisionBox) + { + DrawCollisionBox(args); + } } private void DrawCollisionBox(SpriteDrawArgs args) diff --git a/AlientAttack.MonoGame/Things/SpriteDrawArgs.cs b/AlientAttack.MonoGame/Things/SpriteDrawArgs.cs index 29b8e81..93d79f6 100644 --- a/AlientAttack.MonoGame/Things/SpriteDrawArgs.cs +++ b/AlientAttack.MonoGame/Things/SpriteDrawArgs.cs @@ -1,7 +1,6 @@ using AlienAttack.MonoGame.Textures; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; -using System; namespace AlienAttack.MonoGame.Things; @@ -10,4 +9,5 @@ public class SpriteDrawArgs(AlienAttackGame game) public SpriteBatch SpriteBatch => game.SpriteBatch; public ContentManager Content => game.Content; public TextureCache Textures => game.Textures; + public bool ShowCollisionBox { get; init; } } \ No newline at end of file