Updated asteroids and mines. Updated ship class names. Added initial ship muzzle logic.

This commit is contained in:
2026-01-20 00:40:03 -05:00
parent e402c498d6
commit c1124a784d
15 changed files with 221 additions and 97 deletions

View File

@@ -0,0 +1,72 @@
using AlienAttack.MonoGame.Things.Bullets;
using AlienAttack.MonoGame.Things.Explosions;
namespace AlienAttack.MonoGame.Things.Enemies.Ships;
public abstract class EnemyShip : Ship
{
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)
{
IsDead = true;
SpawnExplosion(context);
OnKilled(context);
return;
}
base.Update(context);
TryMove(context);
if (YPosition - Origin.Y > context.ViewTransform.ScreenHeight)
{
IsDead = true;
return;
}
TryFire(context);
}
protected virtual void TryMove(SpriteUpdateContext context)
{
}
protected virtual void TryFire(SpriteUpdateContext context)
{
}
public override void OnCollision(SpriteCollisionContext context)
{
if (context.Sprite is Bullet bullet && bullet.Owner is Player)
{
Health -= bullet.Damage;
}
if (context.Sprite is Player)
{
Health = 0;
}
}
private void SpawnExplosion(SpriteUpdateContext context)
{
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
context.AudioManager.PlayExplosion();
}
protected virtual void OnKilled(SpriteUpdateContext context)
{
}
}

View File

@@ -0,0 +1,9 @@
using AlienAttack.MonoGame.Things.Muzzles;
using Microsoft.Xna.Framework;
namespace AlienAttack.MonoGame.Things.Enemies.Ships;
public abstract class Ship(int x, int y) : MoveableSprite(x, y)
{
public abstract Vector2 GetMuzzleLocal(MuzzleId muzzle);
}

View File

@@ -0,0 +1,84 @@
using AlienAttack.MonoGame.Things.Bullets;
using AlienAttack.MonoGame.Things.Items;
using AlienAttack.MonoGame.Things.Weapons;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
namespace AlienAttack.MonoGame.Things.Enemies.Ships.TypeA;
public class GreenShipTypeA : ShipTypeA
{
//Enemy01_Green_Frame_1_png_processed
protected ICollection<IWeapon> ActiveWeapons = [];
protected int FireThreshold => 20;
protected int CurrentFireThreshold { get; set; } = 20;
protected override int Health { get; set; } = 5;
public GreenShipTypeA(int x, int y) : base(x, y)
{
BoundBox = new Rectangle(0, 0, 64, 64);
YVelocity = 1;
ActiveWeapons.Add(new Minigun());
//ActiveWeapons.Add(new FastMinigun());
}
public override void Draw(SpriteDrawArgs args)
{
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, Origin, Scale, spriteEffects, 1);
base.Draw(args);
}
protected override void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)
{
CurrentFireThreshold--;
}
if (CurrentFireThreshold == 0 && context.Random.Next(0, 100) == 1)
{
float originX = XPosition + (BoundBox.Width / 2) - (7 / 2);
context.SpawnSprite(new MinigunBulletSmall(originX - 9, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
CurrentFireThreshold = FireThreshold;
context.AudioManager.PlayEnemyFire();
}
}
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;
int itemYPosition = (int)YPosition;
switch (context.Random.Next(0, 5))
{
case 0:
context.SpawnSprite(new Health(itemXPosition, itemYPosition));
break;
case 1:
context.SpawnSprite(new Shields(itemXPosition, itemYPosition));
break;
case 2:
context.SpawnSprite(new Ammo(itemXPosition, itemYPosition));
break;
case 3:
context.SpawnSprite(new Energy(itemXPosition, itemYPosition));
break;
case 4:
context.SpawnSprite(new Rockets(itemXPosition, itemYPosition));
break;
}
}
}

View File

@@ -0,0 +1,74 @@
using AlienAttack.MonoGame.Things.Bullets;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things.Enemies.Ships.TypeA;
public class RedShipTypeA : ShipTypeA
{
protected int FireThreshold => 20;
protected int CurrentFireThreshold { get; set; } = 20;
protected override int Health { get; set; } = 5;
public RedShipTypeA(int x, int y) : base(x, y)
{
BoundBox = new Rectangle(0, 0, 64, 64);
YVelocity = 1.5f;
}
public override void Draw(SpriteDrawArgs args)
{
int frame = XVelocity > 0 ? 2 : XVelocity < 0 ? 3 : 1;
SpriteEffects spriteEffects = XVelocity > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
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, Origin, Scale, spriteEffects, 1);
base.Draw(args);
}
protected override void TryMove(SpriteUpdateContext context)
{
//YPosition += 2;
//if (YPosition > context.ViewTransform.ScreenHeight / 5 - BoundBox.Y / 2)
//{
// if (YPosition < context.ViewTransform.ScreenHeight / 2 - BoundBox.Y / 2)
// {
// if (XPosition < context.ViewTransform.ScreenWidth / 2)
// {
// XVelocity = 2;
// }
// else if (XPosition > context.ViewTransform.ScreenWidth / 2)
// {
// XVelocity = -2;
// }
// }
// else
// {
// XVelocity = 0;
// }
//}
}
protected override void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)
{
CurrentFireThreshold--;
}
if (CurrentFireThreshold == 0 && context.Random.Next(0, 50) == 1)
{
float originX = XPosition + (BoundBox.Width / 2) - (7 / 2);
context.SpawnSprite(new MinigunBulletSmall(originX - 9, YPosition + BoundBox.Height - 12, -1, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 3, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 1, 2 + YVelocity, this));
CurrentFireThreshold = FireThreshold;
context.AudioManager.PlayEnemyFire();
}
}
}

View File

@@ -0,0 +1,18 @@
using AlienAttack.MonoGame.Things.Muzzles;
using Microsoft.Xna.Framework;
namespace AlienAttack.MonoGame.Things.Enemies.Ships.TypeA;
public abstract class ShipTypeA(int x, int y) : EnemyShip(x, y)
{
public override Vector2 GetMuzzleLocal(MuzzleId muzzle)
{
return muzzle switch
{
MuzzleId.Left => new(20, 49),
MuzzleId.Center => new(31.5f, 49),
MuzzleId.Right => new(43, 49),
_ => new(),
};
}
}

View File

@@ -0,0 +1,69 @@
using AlienAttack.MonoGame.Things.Bullets;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things.Enemies.Ships.TypeA;
public class TealShipTypeA : ShipTypeA
{
protected int FireThreshold => 20;
protected int CurrentFireThreshold { get; set; } = 20;
protected override int Health { get; set; } = 5;
public TealShipTypeA(int x, int y) : base(x, y)
{
BoundBox = new Rectangle(0, 0, 64, 64);
YVelocity = 1;
XVelocity = 3;
}
public override void Draw(SpriteDrawArgs args)
{
int frame = XVelocity > 0 ? 2 : XVelocity < 0 ? 3 : 1;
SpriteEffects spriteEffects = XVelocity > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
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, Origin, Scale, spriteEffects, 1);
base.Draw(args);
}
protected override void TryMove(SpriteUpdateContext context)
{
if (XPosition + BoundBox.Width >= context.ViewTransform.ScreenWidth)
{
XPosition = context.ViewTransform.ScreenWidth - BoundBox.Width;
XVelocity *= -1;
}
else if (XPosition <= 0)
{
XPosition = 0;
XVelocity *= -1;
}
}
protected override void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)
{
CurrentFireThreshold--;
}
if (CurrentFireThreshold == 0 && context.Random.Next(0, 50) == 1)
{
float originX = XPosition + (BoundBox.Width / 2) - (7 / 2);
//context.SpawnSprite(new MinigunBulletSmall(originX - 9, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
//context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX - 9, YPosition + BoundBox.Height - 12, -1, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 3, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 1, 2 + YVelocity, this));
CurrentFireThreshold = FireThreshold;
context.AudioManager.PlayEnemyFire();
}
}
}

View File

@@ -0,0 +1,71 @@
using AlienAttack.MonoGame.Things.Bullets;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things.Enemies.Ships.TypeB;
public class GreenShipTypeB : ShipTypeB
{
public const int Width = 64;
public const int Height = 64;
protected int FireThreshold => 20;
protected int CurrentFireThreshold { get; set; } = 20;
protected override int Health { get; set; } = 5;
public GreenShipTypeB(int x, int y) : base(x, y)
{
BoundBox = new(0, 0, Width, Height);
YVelocity = 2;
XVelocity = 0;
}
public override void Draw(SpriteDrawArgs args)
{
int frame = XVelocity > 0 ? 2 : XVelocity < 0 ? 3 : 1;
SpriteEffects spriteEffects = XVelocity > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02Green_Frame_{frame}_png_processed");
//SpriteEffects spriteEffects = SpriteEffects.None;
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, Scale, spriteEffects, 1);
base.Draw(args);
}
protected override void TryMove(SpriteUpdateContext context)
{
if (XPosition + BoundBox.Width >= context.ViewTransform.ScreenWidth)
{
XPosition = context.ViewTransform.ScreenWidth - BoundBox.Width;
XVelocity *= -1;
}
else if (XPosition <= 0)
{
XPosition = 0;
XVelocity *= -1;
}
}
protected override void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)
{
CurrentFireThreshold--;
}
if (CurrentFireThreshold == 0 && context.Random.Next(0, 30) == 1)
{
float originX = XPosition + (BoundBox.Width / 2) - (7 / 2);
//context.SpawnSprite(new MinigunBulletSmall(originX - 9, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
//context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX - 9, YPosition + BoundBox.Height - 12, -1, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 3, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 1, 2 + YVelocity, this));
CurrentFireThreshold = FireThreshold;
context.AudioManager.PlayEnemyFire();
}
}
}

View File

@@ -0,0 +1,71 @@
using AlienAttack.MonoGame.Things.Bullets;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things.Enemies.Ships.TypeB;
public class RedShipTypeB : ShipTypeB
{
public const int Width = 64;
public const int Height = 64;
protected int FireThreshold => 20;
protected int CurrentFireThreshold { get; set; } = 20;
protected override int Health { get; set; } = 5;
public RedShipTypeB(int x, int y) : base(x, y)
{
BoundBox = new(0, 0, Width, Height);
YVelocity = 3;
XVelocity = 0;
}
public override void Draw(SpriteDrawArgs args)
{
int frame = XVelocity > 0 ? 2 : XVelocity < 0 ? 3 : 1;
SpriteEffects spriteEffects = XVelocity > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02Red_Frame_{frame}_png_processed");
//SpriteEffects spriteEffects = SpriteEffects.None;
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, Scale, spriteEffects, 1);
base.Draw(args);
}
protected override void TryMove(SpriteUpdateContext context)
{
if (XPosition + BoundBox.Width >= context.ViewTransform.ScreenWidth)
{
XPosition = context.ViewTransform.ScreenWidth - BoundBox.Width;
XVelocity *= -1;
}
else if (XPosition <= 0)
{
XPosition = 0;
XVelocity *= -1;
}
}
protected override void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)
{
CurrentFireThreshold--;
}
if (CurrentFireThreshold == 0 && context.Random.Next(0, 30) == 1)
{
float originX = XPosition + (BoundBox.Width / 2) - (7 / 2);
//context.SpawnSprite(new MinigunBulletSmall(originX - 9, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
//context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX - 9, YPosition + BoundBox.Height - 12, -1, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 3, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 1, 2 + YVelocity, this));
CurrentFireThreshold = FireThreshold;
context.AudioManager.PlayEnemyFire();
}
}
}

View File

@@ -0,0 +1,19 @@
using AlienAttack.MonoGame.Things.Muzzles;
using Microsoft.Xna.Framework;
namespace AlienAttack.MonoGame.Things.Enemies.Ships.TypeB;
public abstract class ShipTypeB(int x, int y) : EnemyShip(x, y)
{
// TODO
public override Vector2 GetMuzzleLocal(MuzzleId muzzle)
{
return muzzle switch
{
MuzzleId.Left => new(20, 49),
MuzzleId.Center => new(31.5f, 49),
MuzzleId.Right => new(43, 49),
_ => new(),
};
}
}

View File

@@ -0,0 +1,71 @@
using AlienAttack.MonoGame.Things.Bullets;
using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things.Enemies.Ships.TypeB;
public class TealShipTypeB : ShipTypeB
{
public const int Width = 64;
public const int Height = 64;
protected int FireThreshold => 20;
protected int CurrentFireThreshold { get; set; } = 20;
protected override int Health { get; set; } = 5;
public TealShipTypeB(int x, int y) : base(x, y)
{
BoundBox = new(0, 0, Width, Height);
YVelocity = 1;
XVelocity = 4;
}
public override void Draw(SpriteDrawArgs args)
{
int frame = XVelocity > 0 ? 2 : XVelocity < 0 ? 3 : 1;
SpriteEffects spriteEffects = XVelocity > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
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, Origin, Scale, spriteEffects, 1);
base.Draw(args);
}
protected override void TryMove(SpriteUpdateContext context)
{
if (XPosition + BoundBox.Width >= context.ViewTransform.ScreenWidth)
{
XPosition = context.ViewTransform.ScreenWidth - BoundBox.Width;
XVelocity *= -1;
}
else if (XPosition <= 0)
{
XPosition = 0;
XVelocity *= -1;
}
}
protected override void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)
{
CurrentFireThreshold--;
}
if (CurrentFireThreshold == 0 && context.Random.Next(0, 30) == 1)
{
float originX = XPosition + (BoundBox.Width / 2) - (7 / 2);
//context.SpawnSprite(new MinigunBulletSmall(originX - 9, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
//context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 0, 2 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX - 9, YPosition + BoundBox.Height - 12, -1, 3 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 3, YPosition + BoundBox.Height - 12, 0, 3 + YVelocity, this));
context.SpawnSprite(new MinigunBulletSmall(originX + 14, YPosition + BoundBox.Height - 12, 1, 3 + YVelocity, this));
CurrentFireThreshold = FireThreshold;
context.AudioManager.PlayEnemyFire();
}
}
}