Added texture cache and sprite origins.
This commit is contained in:
48
AlientAttack.MonoGame/Things/Asteroids/Asteroid.cs
Normal file
48
AlientAttack.MonoGame/Things/Asteroids/Asteroid.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,8 @@ public class Enemy02Green : EnemyShip
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02Green_Frame_{frame}_png_processed");
|
||||
//SpriteEffects spriteEffects = SpriteEffects.None;
|
||||
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
//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);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ public class Enemy02Red : EnemyShip
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02Red_Frame_{frame}_png_processed");
|
||||
//SpriteEffects spriteEffects = SpriteEffects.None;
|
||||
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
//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);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ public class Enemy02Teal : EnemyShip
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02_Teal_Frame_{frame}_png_processed");
|
||||
//SpriteEffects spriteEffects = SpriteEffects.None;
|
||||
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
//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);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
using AlienAttack.MonoGame.Things.Bullets;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Enemies;
|
||||
|
||||
public abstract class EnemyShip(int x, int y) : MoveableSprite(x, y)
|
||||
public abstract class EnemyShip : MoveableSprite
|
||||
{
|
||||
protected abstract int Health { get; set; }
|
||||
|
||||
public virtual int CrashDamage => 10;
|
||||
|
||||
public EnemyShip(int x, int y) : base(x, y)
|
||||
{
|
||||
Origin = new(32, 32);
|
||||
}
|
||||
|
||||
public override sealed void Update(SpriteUpdateContext context)
|
||||
{
|
||||
if (Health <= 0)
|
||||
@@ -22,7 +28,7 @@ public abstract class EnemyShip(int x, int y) : MoveableSprite(x, y)
|
||||
|
||||
TryMove(context);
|
||||
|
||||
if (YPosition > context.ViewTransform.ScreenHeight)
|
||||
if (YPosition - Origin.Y > context.ViewTransform.ScreenHeight)
|
||||
{
|
||||
IsDead = true;
|
||||
return;
|
||||
|
||||
@@ -29,7 +29,8 @@ public class GreenEnemy : EnemyShip
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Green_Frame_1_png_processed");
|
||||
SpriteEffects spriteEffects = SpriteEffects.None;
|
||||
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
//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);
|
||||
}
|
||||
@@ -56,8 +57,11 @@ public class GreenEnemy : EnemyShip
|
||||
|
||||
protected override void OnKilled(SpriteUpdateContext context)
|
||||
{
|
||||
int itemXPosition = (int)XPosition + 32 - Item.Width / 2;
|
||||
int itemYPosition = (int)YPosition + 32 - Item.Height / 2;
|
||||
//int itemXPosition = (int)XPosition + 32 - Item.Width / 2;
|
||||
//int itemYPosition = (int)YPosition + 32 - Item.Height / 2;
|
||||
|
||||
int itemXPosition = (int)XPosition;
|
||||
int itemYPosition = (int)YPosition;
|
||||
|
||||
switch (context.Random.Next(0, 5))
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Enemies.Mines;
|
||||
|
||||
@@ -9,12 +10,12 @@ public abstract class Mine : MoveableSprite
|
||||
public const int Height = 64;
|
||||
|
||||
protected float Rotation = 0;
|
||||
protected Vector2 Origin = new(30, 33);
|
||||
|
||||
protected abstract string CoverColor { get; }
|
||||
|
||||
public Mine(int x, int y) : base(x, y)
|
||||
{
|
||||
Origin = new(30, 33);
|
||||
BoundBox = new(10, 14, 40, 38);
|
||||
YVelocity = 1;
|
||||
XVelocity = 0;
|
||||
@@ -74,6 +75,18 @@ public abstract class Mine : MoveableSprite
|
||||
|
||||
CollisionBox = new Rectangle((int)XPosition + BoundBox.X - (int)Origin.X, (int)YPosition + BoundBox.Y - (int)Origin.Y, BoundBox.Width, BoundBox.Height);
|
||||
|
||||
float xDiff = (XPosition + Origin.X) - (context.Player.XPosition + context.Player.Origin.X);
|
||||
float yDiff = (YPosition + Origin.Y) - (context.Player.YPosition + context.Player.Origin.Y);
|
||||
|
||||
double distance = Math.Sqrt(xDiff * xDiff + yDiff * yDiff);
|
||||
|
||||
if (distance < 100)
|
||||
{
|
||||
IsDead = true;
|
||||
SpawnExplosion(context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (YPosition - Origin.Y > context.ViewTransform.ScreenHeight)
|
||||
{
|
||||
IsDead = true;
|
||||
@@ -87,4 +100,10 @@ public abstract class Mine : MoveableSprite
|
||||
Rotation = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnExplosion(SpriteUpdateContext context)
|
||||
{
|
||||
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
|
||||
context.AudioManager.PlayExplosion();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,8 @@ public class RedEnemy : EnemyShip
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Red_Frame_{frame}_png_processed");
|
||||
//SpriteEffects spriteEffects = SpriteEffects.None;
|
||||
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
//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);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ public class TealEnemy : EnemyShip
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Teal_Frame_{frame}_png_processed");
|
||||
//SpriteEffects spriteEffects = SpriteEffects.None;
|
||||
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
//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);
|
||||
}
|
||||
|
||||
@@ -3,17 +3,25 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things;
|
||||
|
||||
public class Explosion(int x, int y, float xVel, float yVel) : Sprite(x, y)
|
||||
public class Explosion : MoveableSprite
|
||||
{
|
||||
protected int CurrentFrame { get; private set; } = 1;
|
||||
protected int MaxFrames => 9;
|
||||
protected int AnimationThreshold => 3; //5;
|
||||
protected int CurrentThreshold { get; private set; } = 5;
|
||||
|
||||
public Explosion(int x, int y, float xVel, float yVel) : base(x, y)
|
||||
{
|
||||
Origin = new(32.5f, 32);
|
||||
XVelocity = xVel;
|
||||
YVelocity = yVel;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteDrawArgs args)
|
||||
{
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Explosion01_Frame_0{CurrentFrame}_png_processed");
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 1);
|
||||
//args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 1);
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1f, SpriteEffects.None, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
@@ -22,8 +30,8 @@ public class Explosion(int x, int y, float xVel, float yVel) : Sprite(x, y)
|
||||
{
|
||||
base.Update(context);
|
||||
|
||||
XPosition += xVel;
|
||||
YPosition += yVel;
|
||||
//XPosition += XVelocity;
|
||||
//YPosition += YVelocity;
|
||||
|
||||
if (CurrentThreshold > 0)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,8 @@ public abstract class Item : MoveableSprite
|
||||
public Item(int x, int y) : base(x, y)
|
||||
{
|
||||
YVelocity = .5f;
|
||||
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new Rectangle(0, 0, Width, Height);
|
||||
|
||||
_anchor = new Vector2(x, y);
|
||||
@@ -34,7 +36,7 @@ public abstract class Item : MoveableSprite
|
||||
|
||||
Texture2D texture = args.Content.Load<Texture2D>(TextureName);
|
||||
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), _scale, SpriteEffects.None, 1);
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, _scale, SpriteEffects.None, 1);
|
||||
}
|
||||
|
||||
public override void Update(SpriteUpdateContext context)
|
||||
|
||||
@@ -3,17 +3,24 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things;
|
||||
|
||||
public class MiniExplosion(int x, int y, float xVel, float yVel) : Sprite(x, y)
|
||||
public class MiniExplosion : MoveableSprite
|
||||
{
|
||||
protected int CurrentFrame { get; private set; } = 1;
|
||||
protected int MaxFrames => 9;
|
||||
protected int AnimationThreshold => 3; //5;
|
||||
protected int CurrentThreshold { get; private set; } = 5;
|
||||
|
||||
public MiniExplosion(int x, int y, float xVel, float yVel) : base(x, y)
|
||||
{
|
||||
Origin = new(32.5f, 32);
|
||||
XVelocity = xVel;
|
||||
YVelocity = yVel;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteDrawArgs args)
|
||||
{
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Explosion01_Frame_0{CurrentFrame}_png_processed");
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), .25f, SpriteEffects.None, 1);
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, .25f, SpriteEffects.None, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
@@ -22,8 +29,8 @@ public class MiniExplosion(int x, int y, float xVel, float yVel) : Sprite(x, y)
|
||||
{
|
||||
base.Update(context);
|
||||
|
||||
XPosition += xVel;
|
||||
YPosition += yVel;
|
||||
//XPosition += xVel;
|
||||
//YPosition += yVel;
|
||||
|
||||
if (CurrentThreshold > 0)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ public static class MuzzleMath
|
||||
public static Vector2 GetMuzzleWorld(Sprite owner, Vector2 muzzleLocalPx, float ownerScale = 1f)
|
||||
{
|
||||
// Assumes owner.Position is the top-left of the sprite
|
||||
return owner.Position + muzzleLocalPx * ownerScale;
|
||||
return owner.Position - owner.Origin + muzzleLocalPx * ownerScale;
|
||||
}
|
||||
|
||||
public static Vector2 CenterBulletOn(Vector2 muzzleWorld, int bulletW, int bulletH)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -8,6 +8,7 @@ public class Sprite(float x, float y)
|
||||
public float XPosition { get; protected set; } = x;
|
||||
public float YPosition { get; protected set; } = y;
|
||||
public Vector2 Position => new(XPosition, YPosition);
|
||||
public Vector2 Origin { get; protected set; }
|
||||
public Rectangle BoundBox { get; protected set; }
|
||||
|
||||
protected Rectangle CollisionBox;
|
||||
@@ -18,7 +19,8 @@ public class Sprite(float x, float y)
|
||||
|
||||
public virtual void Update(SpriteUpdateContext context)
|
||||
{
|
||||
CollisionBox = new Rectangle((int)XPosition + BoundBox.X, (int)YPosition + BoundBox.Y, BoundBox.Width, BoundBox.Height);
|
||||
//CollisionBox = new Rectangle((int)XPosition + BoundBox.X, (int)YPosition + BoundBox.Y, BoundBox.Width, BoundBox.Height);
|
||||
CollisionBox = new Rectangle((int)(Position.X - Origin.X) + BoundBox.X, (int)(Position.Y - Origin.Y) + BoundBox.Y, BoundBox.Width, BoundBox.Height);
|
||||
}
|
||||
|
||||
public bool Intersects(Sprite sprite)
|
||||
@@ -29,6 +31,28 @@ public class Sprite(float x, float y)
|
||||
public virtual void Draw(SpriteDrawArgs args)
|
||||
{
|
||||
//spriteBatch.Draw(Texture, Position, DrawColor);
|
||||
DrawCollisionBox(args);
|
||||
}
|
||||
|
||||
private void DrawCollisionBox(SpriteDrawArgs args)
|
||||
{
|
||||
//var pixel = DebugPixel; // static cached
|
||||
|
||||
Texture2D pixel = new Texture2D(args.SpriteBatch.GraphicsDevice, 1, 1);
|
||||
pixel.SetData(new[] { Color.White });
|
||||
|
||||
//Rectangle r = GetWorldCollisionBox();
|
||||
|
||||
Color c = Color.LimeGreen; // debug color
|
||||
|
||||
// Top
|
||||
args.SpriteBatch.Draw(pixel, new Rectangle(CollisionBox.X, CollisionBox.Y, CollisionBox.Width, 1), c);
|
||||
// Bottom
|
||||
args.SpriteBatch.Draw(pixel, new Rectangle(CollisionBox.X, CollisionBox.Bottom - 1, CollisionBox.Width, 1), c);
|
||||
// Left
|
||||
args.SpriteBatch.Draw(pixel, new Rectangle(CollisionBox.X, CollisionBox.Y, 1, CollisionBox.Height), c);
|
||||
// Right
|
||||
args.SpriteBatch.Draw(pixel, new Rectangle(CollisionBox.Right - 1, CollisionBox.Y, 1, CollisionBox.Height), c);
|
||||
}
|
||||
|
||||
public virtual void OnCollision(SpriteCollisionContext context)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using AlienAttack.MonoGame.Textures;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
@@ -8,4 +9,5 @@ public class SpriteDrawArgs(AlienAttackGame game)
|
||||
{
|
||||
public SpriteBatch SpriteBatch => game.SpriteBatch;
|
||||
public ContentManager Content => game.Content;
|
||||
public TextureCache Textures => game.Textures;
|
||||
}
|
||||
@@ -14,6 +14,7 @@ public class SpriteUpdateContext(AlienAttackGame game)
|
||||
public required GameTime GameTime { get; init; }
|
||||
public required ContentManager Content { get; init; }
|
||||
public AudioManager AudioManager => game.Audio;
|
||||
public required Player Player { get; init; }
|
||||
}
|
||||
|
||||
public class SpriteCollisionContext(AlienAttackGame game)
|
||||
|
||||
Reference in New Issue
Block a user