Added texture cache and sprite origins.

This commit is contained in:
2026-01-14 23:09:13 -05:00
parent fcb4f1cf05
commit 61d51f5188
36 changed files with 319 additions and 83 deletions

View File

@@ -1,7 +1,4 @@
using AlienAttack.MonoGame.Things.Items;
using AlienAttack.MonoGame.Things.Muzzles;
using Microsoft.Xna.Framework;
using System;
namespace AlienAttack.MonoGame.Things.Bullets;

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class LaserBulletLarge : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Laser_Large");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.LaserLarge);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class LaserBulletMedium : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Laser_Medium");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.LaserMedium);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class LaserBulletSmall : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Laser_Small");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.LaserSmall);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class MinigunBulletLarge : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Minigun_Large");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.MinigunLarge);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class MinigunBulletMedium : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Minigun_Medium");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.MinigunMedium);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class MinigunBulletSmall : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Minigun_Small");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.MinigunSmall);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class PlasmaBulletLarge : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Plasma_Large");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.PlasmaLarge);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class PlasmaBulletMedium : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Plasma_Medium");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.PlasmaMedium);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class PlasmaBulletSmall : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Plasma_Small");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.PlasmaSmall);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class ProtonBulletLarge : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Proton_Large");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.ProtonLarge);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class ProtonBulletMedium : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Proton_Medium");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.ProtonMedium);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using AlienAttack.MonoGame.Textures;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,17 +12,17 @@ public class ProtonBulletSmall : Bullet
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.Content.Load<Texture2D>(@$"Sprites\Proton_Small");
Texture2D texture = args.Textures.Get(TextureNames.Bullets.ProtonSmall);
float rotation = MathF.Atan2(YVelocity, XVelocity) + MathF.PI / 2f;
Vector2 origin = new(texture.Width / 2f, texture.Height / 2f);
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);
}
}