Updated asteriods, mines, and explosions.
This commit is contained in:
@@ -1,27 +1,28 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using AlienAttack.MonoGame.Things.Bullets;
|
||||
using AlienAttack.MonoGame.Things.Explosions;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Asteroids;
|
||||
|
||||
public class Asteroid : MoveableSprite
|
||||
public abstract class Asteroid : MoveableSprite
|
||||
{
|
||||
public const int Width = 39;
|
||||
public const int Height = 37;
|
||||
protected abstract int MaxHealth { get; }
|
||||
protected abstract string TextureName { get; }
|
||||
|
||||
protected float Rotation = 0;
|
||||
protected int Health { get; set; }
|
||||
protected float RotationSpeed { get; set; } = 1f;
|
||||
|
||||
public Asteroid(int x, int y) : base(x, y)
|
||||
{
|
||||
Origin = new(Width / 2, Height / 2);
|
||||
BoundBox = new(0, 0, Width, Height);
|
||||
YVelocity = 1;
|
||||
XVelocity = 0;
|
||||
Health = MaxHealth;
|
||||
RotationSpeed = 1f;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteDrawArgs args)
|
||||
{
|
||||
Texture2D texture = args.Content.Load<Texture2D>("Sprites/Asteroid 01");
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, Rotation, Origin, 1f, SpriteEffects.None, 1);
|
||||
Texture2D texture = args.Textures.Get(TextureName);
|
||||
args.SpriteBatch.Draw(texture, Position, null, DrawColor, Rotation, Origin, Scale, SpriteEffects.None, 1);
|
||||
|
||||
base.Draw(args);
|
||||
}
|
||||
@@ -32,17 +33,33 @@ public class Asteroid : MoveableSprite
|
||||
|
||||
CollisionBox = new Rectangle((int)XPosition + BoundBox.X - (int)Origin.X, (int)YPosition + BoundBox.Y - (int)Origin.Y, BoundBox.Width, BoundBox.Height);
|
||||
|
||||
if (Health <= 0)
|
||||
{
|
||||
IsDead = true;
|
||||
context.SpawnSprite(new Explosion((int)XPosition, (int)YPosition, XVelocity, YVelocity));
|
||||
context.AudioManager.PlayExplosion();
|
||||
return;
|
||||
}
|
||||
|
||||
if (YPosition - Origin.Y > context.ViewTransform.ScreenHeight)
|
||||
{
|
||||
IsDead = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Rotation += 0.01f;
|
||||
Rotation = MathHelper.WrapAngle(Rotation + RotationSpeed * context.DeltaTime);
|
||||
}
|
||||
|
||||
if (Rotation > 360f)
|
||||
public override void OnCollision(SpriteCollisionContext context)
|
||||
{
|
||||
if (context.Sprite is Bullet bullet && bullet.Owner is Player)
|
||||
{
|
||||
Rotation = 0;
|
||||
Health -= bullet.Damage;
|
||||
}
|
||||
|
||||
if (context.Sprite is Player)
|
||||
{
|
||||
Health = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user