mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 12:06:37 +00:00
75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using MonoGame.Extended.Shapes;
|
|
using MonoGame.Extended.Sprites;
|
|
using MonoGame.Extended.TextureAtlases;
|
|
|
|
namespace SpaceGame.Entities
|
|
{
|
|
public class Meteor : Entity
|
|
{
|
|
public Meteor(TextureRegion2D textureRegion, Vector2 position, Vector2 velocity, float rotationSpeed, int size)
|
|
{
|
|
_sprite = new Sprite(textureRegion);
|
|
_boundingCircle = new CircleF(_sprite.Position, _radius * size);
|
|
|
|
Position = position;
|
|
Velocity = velocity;
|
|
RotationSpeed = rotationSpeed;
|
|
HealthPoints = 1;
|
|
Size = size;
|
|
}
|
|
|
|
private const float _radius = 55f / 4f;
|
|
private readonly Sprite _sprite;
|
|
|
|
public int HealthPoints { get; private set; }
|
|
public float RotationSpeed { get; private set; }
|
|
public Vector2 Velocity { get; set; }
|
|
public int Size { get; private set; }
|
|
|
|
public Vector2 Position
|
|
{
|
|
get { return _sprite.Position; }
|
|
set
|
|
{
|
|
_sprite.Position = value;
|
|
_boundingCircle.Center = _sprite.Position;
|
|
}
|
|
}
|
|
|
|
public float Rotation
|
|
{
|
|
get { return _sprite.Rotation; }
|
|
set { _sprite.Rotation = value; }
|
|
}
|
|
|
|
private CircleF _boundingCircle;
|
|
public CircleF BoundingCircle => _boundingCircle;
|
|
|
|
public void Damage(int damage)
|
|
{
|
|
HealthPoints -= damage;
|
|
|
|
if (HealthPoints <= 0)
|
|
Destroy();
|
|
}
|
|
|
|
public override void Update(GameTime gameTime)
|
|
{
|
|
var deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
|
|
Position += Velocity * deltaTime;
|
|
Rotation += RotationSpeed * deltaTime;
|
|
}
|
|
|
|
public override void Draw(SpriteBatch spriteBatch)
|
|
{
|
|
spriteBatch.Draw(_sprite);
|
|
}
|
|
|
|
public bool Contains(Vector2 position)
|
|
{
|
|
return _boundingCircle.Contains(position);
|
|
}
|
|
}
|
|
} |