Added texture cache and sprite origins.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user