Updated enemies. Added boost.
This commit is contained in:
89
AlientAttack.MonoGame/Things/Enemies/TealEnemy.cs
Normal file
89
AlientAttack.MonoGame/Things/Enemies/TealEnemy.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using AlienAttack.MonoGame.Things.Bullets;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Enemies;
|
||||
|
||||
internal class TealEnemy : MoveableSprite
|
||||
{
|
||||
protected int FireThreshold => 20;
|
||||
protected int CurrentFireThreshold { get; set; } = 20;
|
||||
protected int Health { get; set; } = 5;
|
||||
|
||||
public TealEnemy(int x, int y) : base(x, y)
|
||||
{
|
||||
BoundBox = new Rectangle(0, 0, 64, 64);
|
||||
YVelocity = 1;
|
||||
XVelocity = 3;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteDrawArgs args)
|
||||
{
|
||||
int frame = XVelocity > 0 ? 2 : XVelocity < 0 ? 3 : 1;
|
||||
SpriteEffects spriteEffects = XVelocity > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy01_Teal_Frame_{frame}_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)
|
||||
{
|
||||
if (XPosition + BoundBox.Width >= context.ViewTransform.ScreenWidth)
|
||||
{
|
||||
XPosition = context.ViewTransform.ScreenWidth - BoundBox.Width;
|
||||
XVelocity *= -1;
|
||||
}
|
||||
else if (XPosition <= 0)
|
||||
{
|
||||
XPosition = 0;
|
||||
XVelocity *= -1;
|
||||
}
|
||||
|
||||
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);
|
||||
TryFire(context);
|
||||
|
||||
base.Update(context);
|
||||
}
|
||||
|
||||
private void TryFire(SpriteUpdateContext context)
|
||||
{
|
||||
if (CurrentFireThreshold > 0)
|
||||
{
|
||||
CurrentFireThreshold--;
|
||||
}
|
||||
|
||||
if (CurrentFireThreshold == 0 && context.Random.Next(0, 50) == 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;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCollision(SpriteCollisionContext context)
|
||||
{
|
||||
if (context.Sprite is Bullet bullet && bullet.Owner is Player)
|
||||
{
|
||||
Health -= bullet.Damage;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user