Added new enemy ships. Cleaned up enemy code.
This commit is contained in:
@@ -8,7 +8,7 @@ public class TealEnemy : 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 TealEnemy(int x, int y) : base(x, y)
|
||||
{
|
||||
@@ -29,7 +29,7 @@ public class TealEnemy : EnemyShip
|
||||
base.Draw(args);
|
||||
}
|
||||
|
||||
public override void Update(SpriteUpdateContext context)
|
||||
protected override void TryMove(SpriteUpdateContext context)
|
||||
{
|
||||
if (XPosition + BoundBox.Width >= context.ViewTransform.ScreenWidth)
|
||||
{
|
||||
@@ -41,39 +41,9 @@ public class TealEnemy : EnemyShip
|
||||
XPosition = 0;
|
||||
XVelocity *= -1;
|
||||
}
|
||||
|
||||
if (Health <= 0)
|
||||
{
|
||||
IsDead = true;
|
||||
SpawnExplosion(context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (YPosition > context.ViewTransform.ScreenHeight)
|
||||
{
|
||||
IsDead = true;
|
||||
return;
|
||||
}
|
||||
|
||||
//CheckMove(context);
|
||||
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)
|
||||
{
|
||||
@@ -84,25 +54,16 @@ public class TealEnemy : EnemyShip
|
||||
{
|
||||
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, 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();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user