76 lines
2.0 KiB
C#
76 lines
2.0 KiB
C#
using AlienAttack.MonoGame.Things.Bullets;
|
|
using AlienAttack.MonoGame.Things.Weapons;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Microsoft.Xna.Framework.Input;
|
|
|
|
namespace AlienAttack.MonoGame.Things.Enemies;
|
|
|
|
internal class RedEnemy : MoveableSprite
|
|
{
|
|
//Enemy01_Green_Frame_1_png_processed
|
|
|
|
protected int Health { get; set; } = 10;
|
|
|
|
public RedEnemy(int x, int y) : base(x, y)
|
|
{
|
|
BoundBox = new Rectangle(0, 0, 64, 64);
|
|
YVelocity = 2;
|
|
//ActiveWeapons.Add(new Minigun());
|
|
//ActiveWeapons.Add(new FastMinigun());
|
|
}
|
|
|
|
public override void Draw(SpriteDrawArgs args)
|
|
{
|
|
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Red_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);
|
|
}
|
|
|
|
public override void Update(SpriteUpdateContext context)
|
|
{
|
|
//YPosition += 2;
|
|
|
|
if (Health <= 0)
|
|
{
|
|
IsDead = true;
|
|
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
|
|
return;
|
|
}
|
|
|
|
if (YPosition > context.ViewTransform.ScreenHeight)
|
|
{
|
|
IsDead = true;
|
|
return;
|
|
}
|
|
|
|
//CheckMove(context);
|
|
CheckFire(context);
|
|
|
|
base.Update(context);
|
|
}
|
|
|
|
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)
|
|
{
|
|
Health -= bullet.Damage;
|
|
}
|
|
}
|
|
} |