Added sprite rotation and scale. Refactored bullet classes.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class LaserBulletLarge : Bullet
|
||||
public const int Width = 8;
|
||||
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)
|
||||
{
|
||||
Origin = new(Width/2, Height/2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class LaserBulletMedium : Bullet
|
||||
public const int Width = 7;
|
||||
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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class LaserBulletSmall : Bullet
|
||||
public const int Width = 6;
|
||||
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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class MinigunBulletLarge : Bullet
|
||||
public const int Width = 9;
|
||||
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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class MinigunBulletMedium : Bullet
|
||||
public const int Width = 11;
|
||||
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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class MinigunBulletSmall : Bullet
|
||||
public const int Width = 11;
|
||||
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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class PlasmaBulletLarge : Bullet
|
||||
public const int Width = 9;
|
||||
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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class PlasmaBulletMedium : Bullet
|
||||
public const int Width = 8;
|
||||
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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class PlasmaBulletSmall : Bullet
|
||||
public const int Width = 7;
|
||||
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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class ProtonBulletLarge : Bullet
|
||||
public const int Width = 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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class ProtonBulletMedium : Bullet
|
||||
public const int Width = 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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
@@ -10,19 +7,12 @@ public class ProtonBulletSmall : Bullet
|
||||
public const int Width = 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)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user