Added new enemy ships. Cleaned up enemy code.
This commit is contained in:
@@ -1,6 +1,67 @@
|
||||
namespace AlienAttack.MonoGame.Things.Enemies;
|
||||
using AlienAttack.MonoGame.Things.Bullets;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Enemies;
|
||||
|
||||
public abstract class EnemyShip(int x, int y) : MoveableSprite(x, y)
|
||||
{
|
||||
protected abstract int Health { get; set; }
|
||||
|
||||
public virtual int CrashDamage => 10;
|
||||
|
||||
public override sealed void Update(SpriteUpdateContext context)
|
||||
{
|
||||
if (Health <= 0)
|
||||
{
|
||||
IsDead = true;
|
||||
SpawnExplosion(context);
|
||||
OnKilled(context);
|
||||
return;
|
||||
}
|
||||
|
||||
base.Update(context);
|
||||
|
||||
TryMove(context);
|
||||
|
||||
if (YPosition > 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user