Added texture cache and sprite origins.
This commit is contained in:
@@ -27,7 +27,8 @@ public class Enemy02Green : EnemyShip
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02Green_Frame_{frame}_png_processed");
|
||||
//SpriteEffects spriteEffects = SpriteEffects.None;
|
||||
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
//args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ public class Enemy02Red : EnemyShip
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02Red_Frame_{frame}_png_processed");
|
||||
//SpriteEffects spriteEffects = SpriteEffects.None;
|
||||
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
//args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ public class Enemy02Teal : EnemyShip
|
||||
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Enemy02_Teal_Frame_{frame}_png_processed");
|
||||
//SpriteEffects spriteEffects = SpriteEffects.None;
|
||||
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
//args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
using AlienAttack.MonoGame.Things.Bullets;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Enemies;
|
||||
|
||||
public abstract class EnemyShip(int x, int y) : MoveableSprite(x, y)
|
||||
public abstract class EnemyShip : MoveableSprite
|
||||
{
|
||||
protected abstract int Health { get; set; }
|
||||
|
||||
public virtual int CrashDamage => 10;
|
||||
|
||||
public EnemyShip(int x, int y) : base(x, y)
|
||||
{
|
||||
Origin = new(32, 32);
|
||||
}
|
||||
|
||||
public override sealed void Update(SpriteUpdateContext context)
|
||||
{
|
||||
if (Health <= 0)
|
||||
@@ -22,7 +28,7 @@ public abstract class EnemyShip(int x, int y) : MoveableSprite(x, y)
|
||||
|
||||
TryMove(context);
|
||||
|
||||
if (YPosition > context.ViewTransform.ScreenHeight)
|
||||
if (YPosition - Origin.Y > context.ViewTransform.ScreenHeight)
|
||||
{
|
||||
IsDead = true;
|
||||
return;
|
||||
|
||||
@@ -29,7 +29,8 @@ public class GreenEnemy : EnemyShip
|
||||
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);
|
||||
//args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
@@ -56,8 +57,11 @@ public class GreenEnemy : EnemyShip
|
||||
|
||||
protected override void OnKilled(SpriteUpdateContext context)
|
||||
{
|
||||
int itemXPosition = (int)XPosition + 32 - Item.Width / 2;
|
||||
int itemYPosition = (int)YPosition + 32 - Item.Height / 2;
|
||||
//int itemXPosition = (int)XPosition + 32 - Item.Width / 2;
|
||||
//int itemYPosition = (int)YPosition + 32 - Item.Height / 2;
|
||||
|
||||
int itemXPosition = (int)XPosition;
|
||||
int itemYPosition = (int)YPosition;
|
||||
|
||||
switch (context.Random.Next(0, 5))
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Enemies.Mines;
|
||||
|
||||
@@ -9,12 +10,12 @@ public abstract class Mine : MoveableSprite
|
||||
public const int Height = 64;
|
||||
|
||||
protected float Rotation = 0;
|
||||
protected Vector2 Origin = new(30, 33);
|
||||
|
||||
protected abstract string CoverColor { get; }
|
||||
|
||||
public Mine(int x, int y) : base(x, y)
|
||||
{
|
||||
Origin = new(30, 33);
|
||||
BoundBox = new(10, 14, 40, 38);
|
||||
YVelocity = 1;
|
||||
XVelocity = 0;
|
||||
@@ -74,6 +75,18 @@ public abstract class Mine : MoveableSprite
|
||||
|
||||
CollisionBox = new Rectangle((int)XPosition + BoundBox.X - (int)Origin.X, (int)YPosition + BoundBox.Y - (int)Origin.Y, BoundBox.Width, BoundBox.Height);
|
||||
|
||||
float xDiff = (XPosition + Origin.X) - (context.Player.XPosition + context.Player.Origin.X);
|
||||
float yDiff = (YPosition + Origin.Y) - (context.Player.YPosition + context.Player.Origin.Y);
|
||||
|
||||
double distance = Math.Sqrt(xDiff * xDiff + yDiff * yDiff);
|
||||
|
||||
if (distance < 100)
|
||||
{
|
||||
IsDead = true;
|
||||
SpawnExplosion(context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (YPosition - Origin.Y > context.ViewTransform.ScreenHeight)
|
||||
{
|
||||
IsDead = true;
|
||||
@@ -87,4 +100,10 @@ public abstract class Mine : MoveableSprite
|
||||
Rotation = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnExplosion(SpriteUpdateContext context)
|
||||
{
|
||||
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
|
||||
context.AudioManager.PlayExplosion();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,8 @@ public class RedEnemy : EnemyShip
|
||||
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);
|
||||
//args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ public class TealEnemy : EnemyShip
|
||||
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);
|
||||
//args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1, spriteEffects, 1);
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1, spriteEffects, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user