81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
using AlienAttack.MonoGame.Things.Bullets;
|
|
using AlienAttack.MonoGame.Things.Items;
|
|
using AlienAttack.MonoGame.Things.Weapons;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AlienAttack.MonoGame.Things.Enemies;
|
|
|
|
public class GreenEnemy : EnemyShip
|
|
{
|
|
//Enemy01_Green_Frame_1_png_processed
|
|
|
|
protected ICollection<IWeapon> ActiveWeapons = [];
|
|
protected int FireThreshold => 20;
|
|
protected int CurrentFireThreshold { get; set; } = 20;
|
|
protected override int Health { get; set; } = 5;
|
|
|
|
public GreenEnemy(int x, int y) : base(x, y)
|
|
{
|
|
BoundBox = new Rectangle(0, 0, 64, 64);
|
|
YVelocity = 1;
|
|
ActiveWeapons.Add(new Minigun());
|
|
//ActiveWeapons.Add(new FastMinigun());
|
|
}
|
|
|
|
public override void Draw(SpriteDrawArgs args)
|
|
{
|
|
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Green_Frame_1_png_processed");
|
|
SpriteEffects spriteEffects = SpriteEffects.None;
|
|
|
|
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
|
|
|
base.Draw(args);
|
|
}
|
|
|
|
protected override void TryFire(SpriteUpdateContext context)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
|
|
protected override void OnKilled(SpriteUpdateContext context)
|
|
{
|
|
int itemXPosition = (int)XPosition + 32 - Item.Width / 2;
|
|
int itemYPosition = (int)YPosition + 32 - Item.Height / 2;
|
|
|
|
switch (context.Random.Next(0, 5))
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
} |