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

@@ -0,0 +1,48 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things.Asteroids;
public class Asteroid : MoveableSprite
{
public const int Width = 39;
public const int Height = 37;
protected float Rotation = 0;
public Asteroid(int x, int y) : base(x, y)
{
Origin = new(Width / 2, Height / 2);
BoundBox = new(0, 0, Width, Height);
YVelocity = 1;
XVelocity = 0;
}
public override void Draw(SpriteDrawArgs args)
{
Texture2D texture = args.Content.Load<Texture2D>("Sprites/Asteroid 01");
args.SpriteBatch.Draw(texture, Position, null, DrawColor, Rotation, Origin, 1f, SpriteEffects.None, 1);
base.Draw(args);
}
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;
}
}
}