Added new enemy ships. Cleaned up enemy code.
This commit is contained in:
@@ -14,7 +14,7 @@ public class GreenEnemy : EnemyShip
|
||||
protected ICollection<IWeapon> ActiveWeapons = [];
|
||||
protected int FireThreshold => 20;
|
||||
protected int CurrentFireThreshold { get; set; } = 20;
|
||||
protected int Health { get; set; } = 5;
|
||||
protected override int Health { get; set; } = 5;
|
||||
|
||||
public GreenEnemy(int x, int y) : base(x, y)
|
||||
{
|
||||
@@ -34,43 +34,8 @@ public class GreenEnemy : EnemyShip
|
||||
base.Draw(args);
|
||||
}
|
||||
|
||||
public override void Update(SpriteUpdateContext context)
|
||||
protected override void TryFire(SpriteUpdateContext context)
|
||||
{
|
||||
//YPosition += 1;
|
||||
|
||||
if (Health <= 0)
|
||||
{
|
||||
IsDead = true;
|
||||
SpawnExplosion(context);
|
||||
|
||||
switch (context.Random.Next(0, 5))
|
||||
{
|
||||
case 0:
|
||||
context.SpawnSprite(new Health((int)XPosition, (int)YPosition));
|
||||
break;
|
||||
case 1:
|
||||
context.SpawnSprite(new Shields((int)XPosition, (int)YPosition));
|
||||
break;
|
||||
case 2:
|
||||
context.SpawnSprite(new Ammo((int)XPosition, (int)YPosition));
|
||||
break;
|
||||
case 3:
|
||||
context.SpawnSprite(new Energy((int)XPosition, (int)YPosition));
|
||||
break;
|
||||
case 4:
|
||||
context.SpawnSprite(new Rockets((int)XPosition, (int)YPosition));
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (YPosition > context.ViewTransform.ScreenHeight)
|
||||
{
|
||||
IsDead = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (CurrentFireThreshold > 0)
|
||||
{
|
||||
CurrentFireThreshold--;
|
||||
@@ -87,48 +52,30 @@ public class GreenEnemy : EnemyShip
|
||||
|
||||
context.AudioManager.PlayEnemyFire();
|
||||
}
|
||||
|
||||
//CheckMove(context);
|
||||
CheckFire(context);
|
||||
|
||||
base.Update(context);
|
||||
}
|
||||
|
||||
private void SpawnExplosion(SpriteUpdateContext context)
|
||||
protected override void OnKilled(SpriteUpdateContext context)
|
||||
{
|
||||
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
|
||||
int itemXPosition = (int)XPosition + 32 - Item.Width / 2;
|
||||
int itemYPosition = (int)YPosition + 32 - Item.Height / 2;
|
||||
|
||||
//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 CheckFire(SpriteUpdateContext context)
|
||||
{
|
||||
//foreach (IWeapon weapon in ActiveWeapons)
|
||||
//{
|
||||
// weapon.UpdateFireThreshold();
|
||||
//}
|
||||
|
||||
//foreach (IWeapon weapon in ActiveWeapons)
|
||||
//{
|
||||
// weapon.TryFire(this, context);
|
||||
//}
|
||||
}
|
||||
|
||||
public override void OnCollision(SpriteCollisionContext context)
|
||||
{
|
||||
if (context.Sprite is Bullet bullet && bullet.Owner is Player)
|
||||
switch (context.Random.Next(0, 5))
|
||||
{
|
||||
Health -= bullet.Damage;
|
||||
}
|
||||
|
||||
if (context.Sprite is Player)
|
||||
{
|
||||
Health = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user