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;
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