Updated weapon logic. Fixed player CheckMove logic.

This commit is contained in:
2026-08-24 19:46:04 -04:00
parent c1124a784d
commit e42b11c6fc
10 changed files with 279 additions and 73 deletions

View File

@@ -20,7 +20,25 @@ public class GreenShipTypeA : ShipTypeA
{
BoundBox = new Rectangle(0, 0, 64, 64);
YVelocity = 1;
ActiveWeapons.Add(new Minigun());
WeaponDef weaponDef = new()
{
Name = "Weapon 1",
Bullet = BulletDefinitions.MinigunSmall,
Pattern = ShotPatterns.ReverseDouble,
FireSfxKey = ""
};
WeaponState weasponState = new()
{
FireThreshold = 20,
SpeedMultiplier = 1f,
DamageBonus = 0
};
ConfigurableWeapon configurableWeapon = new(weaponDef, weasponState);
ActiveWeapons.Add(configurableWeapon);
//ActiveWeapons.Add(new FastMinigun());
}
@@ -36,21 +54,34 @@ public class GreenShipTypeA : ShipTypeA
protected override void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)
//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();
//}
foreach (IWeapon weapon in ActiveWeapons)
{
CurrentFireThreshold--;
weapon.UpdateFireThreshold();
}
if (CurrentFireThreshold == 0 && context.Random.Next(0, 100) == 1)
if (context.Random.Next(0, 100) != 1)
return;
foreach (IWeapon weapon in ActiveWeapons)
{
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();
weapon.TryFire(this, context);
}
}

View File

@@ -1,6 +1,8 @@
using AlienAttack.MonoGame.Things.Bullets;
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;
@@ -9,11 +11,31 @@ public class RedShipTypeA : ShipTypeA
protected int FireThreshold => 20;
protected int CurrentFireThreshold { get; set; } = 20;
protected override int Health { get; set; } = 5;
protected ICollection<IWeapon> ActiveWeapons = [];
public RedShipTypeA(int x, int y) : base(x, y)
{
BoundBox = new Rectangle(0, 0, 64, 64);
YVelocity = 1.5f;
WeaponDef weaponDef = new()
{
Name = "Weapon 1",
Bullet = BulletDefinitions.MinigunSmall,
Pattern = ShotPatterns.ReverseTripleSpread,
FireSfxKey = ""
};
WeaponState weasponState = new()
{
FireThreshold = 20,
SpeedMultiplier = 1f,
DamageBonus = 0
};
ConfigurableWeapon configurableWeapon = new(weaponDef, weasponState);
ActiveWeapons.Add(configurableWeapon);
}
public override void Draw(SpriteDrawArgs args)
@@ -53,22 +75,35 @@ public class RedShipTypeA : ShipTypeA
protected override void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)
//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();
//}
foreach (IWeapon weapon in ActiveWeapons)
{
CurrentFireThreshold--;
weapon.UpdateFireThreshold();
}
if (CurrentFireThreshold == 0 && context.Random.Next(0, 50) == 1)
if (context.Random.Next(0, 50) != 1)
return;
foreach (IWeapon weapon in ActiveWeapons)
{
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();
weapon.TryFire(this, context);
}
}
}

View File

@@ -1,6 +1,8 @@
using AlienAttack.MonoGame.Things.Bullets;
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;
@@ -9,12 +11,32 @@ public class TealShipTypeA : ShipTypeA
protected int FireThreshold => 20;
protected int CurrentFireThreshold { get; set; } = 20;
protected override int Health { get; set; } = 5;
protected ICollection<IWeapon> ActiveWeapons = [];
public TealShipTypeA(int x, int y) : base(x, y)
{
BoundBox = new Rectangle(0, 0, 64, 64);
YVelocity = 1;
XVelocity = 3;
WeaponDef weaponDef = new()
{
Name = "Weapon 1",
Bullet = BulletDefinitions.ProtonLarge,
Pattern = ShotPatterns.ReverseTripleSpread,
FireSfxKey = ""
};
WeaponState weasponState = new()
{
FireThreshold = 20,
SpeedMultiplier = 1f,
DamageBonus = 0
};
ConfigurableWeapon configurableWeapon = new(weaponDef, weasponState);
ActiveWeapons.Add(configurableWeapon);
}
public override void Draw(SpriteDrawArgs args)
@@ -45,25 +67,38 @@ public class TealShipTypeA : ShipTypeA
protected override void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)
//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();
//}
foreach (IWeapon weapon in ActiveWeapons)
{
CurrentFireThreshold--;
weapon.UpdateFireThreshold();
}
if (CurrentFireThreshold == 0 && context.Random.Next(0, 50) == 1)
if (context.Random.Next(0, 50) != 1)
return;
foreach (IWeapon weapon in ActiveWeapons)
{
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();
weapon.TryFire(this, context);
}
}
}