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

@@ -30,9 +30,10 @@ public enum MoveFlag
Boost = 16
}
public class DrwaState
public record DrawState
{
public int Frame { get; init; }
public SpriteEffects SpriteEffects { get; init; }
}
public class Player : MoveableSprite
@@ -42,6 +43,8 @@ public class Player : MoveableSprite
protected ulong MoveThreshold = 0;
protected ICollection<IWeapon> ActiveWeapons = [];
protected DrawState DrawState;
protected int CurrentExhaustFrame = 1;
protected int MaxExhaustFrames = 6;
protected int ExhaustAnimationThreshold = 30;
@@ -51,7 +54,7 @@ public class Player : MoveableSprite
public int Health { get; protected set; }
public int Shield { get; protected set; }
public IReadOnlyList<Muzzle> Muzzles { get; } =
public IReadOnlyList<Muzzle> Muzzles { get; protected set; } =
[
new Muzzle(MuzzleId.Center, new Vector2(31.5f, 1f)),
new Muzzle(MuzzleId.Left, new Vector2(15f, 27f)),
@@ -60,6 +63,15 @@ public class Player : MoveableSprite
public Player(int x, int y) : base(x, y)
{
Origin = new(32, 32);
Muzzles =
[
new Muzzle(MuzzleId.Center, new Vector2(31.5f, 1f)),
new Muzzle(MuzzleId.Left, new Vector2(15f, 27f)),
new Muzzle(MuzzleId.Right, new Vector2(47f, 27f)),
];
BoundBox = new Rectangle(0, 0, 64, 64);
//ActiveWeapons.Add(new Minigun());
//ActiveWeapons.Add(new MinigunTripleSpreadFast());
@@ -67,6 +79,12 @@ public class Player : MoveableSprite
Health = 100;
Shield = 100;
DrawState = new()
{
Frame = 1,
SpriteEffects = SpriteEffects.None
};
// Weapon 1
WeaponDef weaponDef = new()
{
@@ -133,7 +151,9 @@ public class Player : MoveableSprite
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\PlayerRed_Frame_{frameNumber}");
//args.SpriteBatch.Draw(texture, Position, DrawColor);
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);
base.Draw(args);
}
private void DrawExhaust(SpriteDrawArgs args)