Added new enemy ships. Cleaned up enemy code.

This commit is contained in:
2026-01-05 09:16:58 -05:00
parent 7f47e2617c
commit 804c03b1d8
9 changed files with 333 additions and 169 deletions

View File

@@ -8,7 +8,7 @@ public class RedEnemy : EnemyShip
{
protected int FireThreshold => 20;
protected int CurrentFireThreshold { get; set; } = 20;
protected int Health { get; set; } = 5;
protected override int Health { get; set; } = 5;
public RedEnemy(int x, int y) : base(x, y)
{
@@ -28,7 +28,7 @@ public class RedEnemy : EnemyShip
base.Draw(args);
}
public override void Update(SpriteUpdateContext context)
protected override void TryMove(SpriteUpdateContext context)
{
//YPosition += 2;
//if (YPosition > context.ViewTransform.ScreenHeight / 5 - BoundBox.Y / 2)
@@ -49,38 +49,9 @@ public class RedEnemy : EnemyShip
// XVelocity = 0;
// }
//}
if (Health <= 0)
{
IsDead = true;
SpawnExplosion(context);
return;
}
if (YPosition > context.ViewTransform.ScreenHeight)
{
IsDead = true;
return;
}
TryFire(context);
base.Update(context);
}
private void SpawnExplosion(SpriteUpdateContext context)
{
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
//int number = context.Random.Next(1, 7);
//SoundEffect soundEffect = context.Content.Load<SoundEffect>(@$"Sfx\Explosions\EXPLDsgn_Explosion Impact_0{number}_SFRMS_SCIWPNS");
//soundEffect.Play(0.95f, (float)(context.Random.NextDouble() * 0.1 - 0.05), 0);
context.AudioManager.PlayExplosion();
}
private void TryFire(SpriteUpdateContext context)
protected override void TryFire(SpriteUpdateContext context)
{
if (CurrentFireThreshold > 0)
{
@@ -100,17 +71,4 @@ public class RedEnemy : EnemyShip
context.AudioManager.PlayEnemyFire();
}
}
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;
}
}
}