Added sprite rotation and scale. Refactored bullet classes.

This commit is contained in:
2026-01-15 00:20:09 -05:00
parent 61d51f5188
commit 8e0a68efdf
25 changed files with 60 additions and 226 deletions

View File

@@ -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; 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; public Sprite Owner { get; init; }
protected float YVelocity = yVel; public int Damage { get; init; } = 0;
public Sprite Owner { get; protected set; } = owner;
public int Damage { get; protected set; } = 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) 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) public override void Update(SpriteUpdateContext context)
{ {
XPosition += XVelocity; Rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
YPosition += YVelocity;
if (XPosition + BoundBox.Width < 0 if (XPosition + BoundBox.Width < 0
|| XPosition > context.ViewTransform.ScreenWidth || XPosition > context.ViewTransform.ScreenWidth

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class LaserBulletLarge : Bullet
public const int Width = 8; public const int Width = 8;
public const int Height = 28; 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) public LaserBulletLarge(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width/2, Height/2); Origin = new(Width/2, Height/2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 3; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class LaserBulletMedium : Bullet
public const int Width = 7; public const int Width = 7;
public const int Height = 21; 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) public LaserBulletMedium(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 2; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class LaserBulletSmall : Bullet
public const int Width = 6; public const int Width = 6;
public const int Height = 18; 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) public LaserBulletSmall(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 1; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class MinigunBulletLarge : Bullet
public const int Width = 9; public const int Width = 9;
public const int Height = 27; 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) public MinigunBulletLarge(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 3; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class MinigunBulletMedium : Bullet
public const int Width = 11; public const int Width = 11;
public const int Height = 21; 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) public MinigunBulletMedium(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 2; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class MinigunBulletSmall : Bullet
public const int Width = 11; public const int Width = 11;
public const int Height = 21; 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) public MinigunBulletSmall(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 1; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class PlasmaBulletLarge : Bullet
public const int Width = 9; public const int Width = 9;
public const int Height = 31; 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) public PlasmaBulletLarge(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 3; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class PlasmaBulletMedium : Bullet
public const int Width = 8; public const int Width = 8;
public const int Height = 26; 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) public PlasmaBulletMedium(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 2; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class PlasmaBulletSmall : Bullet
public const int Width = 7; public const int Width = 7;
public const int Height = 24; 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) public PlasmaBulletSmall(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 1; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class ProtonBulletLarge : Bullet
public const int Width = 13; public const int Width = 13;
public const int Height = 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) public ProtonBulletLarge(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 3; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class ProtonBulletMedium : Bullet
public const int Width = 10; public const int Width = 10;
public const int Height = 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) public ProtonBulletMedium(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 2; 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);
}
} }

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things.Bullets; namespace AlienAttack.MonoGame.Things.Bullets;
@@ -10,19 +7,12 @@ public class ProtonBulletSmall : Bullet
public const int Width = 6; public const int Width = 6;
public const int Height = 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) public ProtonBulletSmall(float x, float y, float xVel, float yVel, Sprite owner) : base(x, y, xVel, yVel, owner)
{ {
Origin = new(Width / 2, Height / 2); Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height); BoundBox = new(0, 0, Width, Height);
Damage = 1; 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);
}
} }

View File

@@ -27,8 +27,7 @@ public class Enemy02Green : EnemyShip
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02Green_Frame_{frame}_png_processed"); Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02Green_Frame_{frame}_png_processed");
//SpriteEffects spriteEffects = SpriteEffects.None; //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, Scale, spriteEffects, 1);
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
base.Draw(args); base.Draw(args);
} }

View File

@@ -27,8 +27,7 @@ public class Enemy02Red : EnemyShip
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02Red_Frame_{frame}_png_processed"); Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02Red_Frame_{frame}_png_processed");
//SpriteEffects spriteEffects = SpriteEffects.None; //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, Scale, spriteEffects, 1);
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
base.Draw(args); base.Draw(args);
} }

View File

@@ -27,8 +27,7 @@ public class Enemy02Teal : EnemyShip
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02_Teal_Frame_{frame}_png_processed"); Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02_Teal_Frame_{frame}_png_processed");
//SpriteEffects spriteEffects = SpriteEffects.None; //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, Scale, spriteEffects, 1);
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
base.Draw(args); base.Draw(args);
} }

View File

@@ -29,8 +29,7 @@ public class GreenEnemy : EnemyShip
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Green_Frame_1_png_processed"); Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Green_Frame_1_png_processed");
SpriteEffects spriteEffects = SpriteEffects.None; 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, Scale, spriteEffects, 1);
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
base.Draw(args); base.Draw(args);
} }

View File

@@ -9,8 +9,6 @@ public abstract class Mine : MoveableSprite
public const int Width = 65; public const int Width = 65;
public const int Height = 64; public const int Height = 64;
protected float Rotation = 0;
protected abstract string CoverColor { get; } protected abstract string CoverColor { get; }
public Mine(int x, int y) : base(x, y) public Mine(int x, int y) : base(x, y)
@@ -25,7 +23,6 @@ public abstract class Mine : MoveableSprite
{ {
DrawRotor(args); DrawRotor(args);
DrawCover(args); DrawCover(args);
//DrawCollisionBox(args);
} }
private void DrawRotor(SpriteDrawArgs 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); 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) public override sealed void Update(SpriteUpdateContext context)
{ {
base.Update(context); base.Update(context);

View File

@@ -23,8 +23,7 @@ public class RedEnemy : EnemyShip
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Red_Frame_{frame}_png_processed"); Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Red_Frame_{frame}_png_processed");
//SpriteEffects spriteEffects = SpriteEffects.None; //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, Scale, spriteEffects, 1);
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
base.Draw(args); base.Draw(args);
} }

View File

@@ -24,8 +24,7 @@ public class TealEnemy : EnemyShip
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Teal_Frame_{frame}_png_processed"); Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Teal_Frame_{frame}_png_processed");
//SpriteEffects spriteEffects = SpriteEffects.None; //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, Scale, spriteEffects, 1);
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
base.Draw(args); base.Draw(args);
} }

View File

@@ -14,8 +14,6 @@ public abstract class Turret : MoveableSprite
public const int GunWidth = 8; public const int GunWidth = 8;
public const int GunHeight = 38; public const int GunHeight = 38;
protected float Rotation = 0;
protected Vector2 MountOrigin = new(MountWidth / 2, MountHeight /2); protected Vector2 MountOrigin = new(MountWidth / 2, MountHeight /2);
protected Vector2 TurretOrigin = new(TurretWidth / 2, TurretHeight / 2); protected Vector2 TurretOrigin = new(TurretWidth / 2, TurretHeight / 2);
protected Vector2 GunOrigin = new(GunWidth / 2, GunHeight / 2); protected Vector2 GunOrigin = new(GunWidth / 2, GunHeight / 2);
@@ -34,7 +32,6 @@ public abstract class Turret : MoveableSprite
DrawMount(args); DrawMount(args);
DrawTurret(args); DrawTurret(args);
DrawGun(args); DrawGun(args);
//DrawCollisionBox(args);
} }
private void DrawMount(SpriteDrawArgs 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); 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) public override sealed void Update(SpriteUpdateContext context)
{ {
base.Update(context); base.Update(context);

View File

@@ -1,5 +1,4 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things; namespace AlienAttack.MonoGame.Things;

View File

@@ -1,6 +1,6 @@
namespace AlienAttack.MonoGame.Things; 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 XVelocity { get; protected set; } = 0;
public float YVelocity { get; protected set; } = 0; public float YVelocity { get; protected set; } = 0;

View File

@@ -8,7 +8,9 @@ public class Sprite(float x, float y)
public float XPosition { get; protected set; } = x; public float XPosition { get; protected set; } = x;
public float YPosition { get; protected set; } = y; public float YPosition { get; protected set; } = y;
public Vector2 Position => new(XPosition, YPosition); public Vector2 Position => new(XPosition, YPosition);
public float Rotation { get; protected set; }
public Vector2 Origin { get; protected set; } public Vector2 Origin { get; protected set; }
public Vector2 Scale { get; protected set; } = new(1, 1);
public Rectangle BoundBox { get; protected set; } public Rectangle BoundBox { get; protected set; }
protected Rectangle CollisionBox; protected Rectangle CollisionBox;
@@ -31,8 +33,12 @@ public class Sprite(float x, float y)
public virtual void Draw(SpriteDrawArgs args) public virtual void Draw(SpriteDrawArgs args)
{ {
//spriteBatch.Draw(Texture, Position, DrawColor); //spriteBatch.Draw(Texture, Position, DrawColor);
if (args.ShowCollisionBox)
{
DrawCollisionBox(args); DrawCollisionBox(args);
} }
}
private void DrawCollisionBox(SpriteDrawArgs args) private void DrawCollisionBox(SpriteDrawArgs args)
{ {

View File

@@ -1,7 +1,6 @@
using AlienAttack.MonoGame.Textures; using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System;
namespace AlienAttack.MonoGame.Things; namespace AlienAttack.MonoGame.Things;
@@ -10,4 +9,5 @@ public class SpriteDrawArgs(AlienAttackGame game)
public SpriteBatch SpriteBatch => game.SpriteBatch; public SpriteBatch SpriteBatch => game.SpriteBatch;
public ContentManager Content => game.Content; public ContentManager Content => game.Content;
public TextureCache Textures => game.Textures; public TextureCache Textures => game.Textures;
public bool ShowCollisionBox { get; init; }
} }