Updated enemies. Added boost.

This commit is contained in:
2025-12-20 21:51:24 -05:00
parent f7e3fe0a47
commit ecdc501752
10 changed files with 464 additions and 279 deletions

View File

@@ -1,29 +1,27 @@
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;
protected int FireThreshold => 20;
protected int CurrentFireThreshold { get; set; } = 20;
protected int Health { get; set; } = 5;
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;
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_Red_Frame_{frame}_png_processed");
//SpriteEffects spriteEffects = SpriteEffects.None;
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
@@ -33,6 +31,24 @@ internal class RedEnemy : MoveableSprite
public override void Update(SpriteUpdateContext context)
{
//YPosition += 2;
//if (YPosition > context.ViewTransform.ScreenHeight / 5 - BoundBox.Y / 2)
//{
// if (YPosition < context.ViewTransform.ScreenHeight / 2 - BoundBox.Y / 2)
// {
// if (XPosition < context.ViewTransform.ScreenWidth / 2)
// {
// XVelocity = 2;
// }
// else if (XPosition > context.ViewTransform.ScreenWidth / 2)
// {
// XVelocity = -2;
// }
// }
// else
// {
// XVelocity = 0;
// }
//}
if (Health <= 0)
{
@@ -47,23 +63,27 @@ internal class RedEnemy : MoveableSprite
return;
}
//CheckMove(context);
CheckFire(context);
TryFire(context);
base.Update(context);
}
private void CheckFire(SpriteUpdateContext context)
private void TryFire(SpriteUpdateContext context)
{
//foreach (IWeapon weapon in ActiveWeapons)
//{
// weapon.UpdateFireThreshold();
//}
if (CurrentFireThreshold > 0)
{
CurrentFireThreshold--;
}
//foreach (IWeapon weapon in ActiveWeapons)
//{
// weapon.TryFire(this, context);
//}
if (CurrentFireThreshold == 0 && context.Random.Next(0, 20) == 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)