Add project files.
This commit is contained in:
8
AlientAttack.MonoGame/Things/Weapons/IWeapon.cs
Normal file
8
AlientAttack.MonoGame/Things/Weapons/IWeapon.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace AlienAttack.MonoGame.Things.Weapons;
|
||||
|
||||
public interface IWeapon
|
||||
{
|
||||
int FireThreshold { get; }
|
||||
void UpdateFireThreshold();
|
||||
bool TryFire(Sprite owner, SpriteUpdateContext context);
|
||||
}
|
||||
43
AlientAttack.MonoGame/Things/Weapons/Minigun.cs
Normal file
43
AlientAttack.MonoGame/Things/Weapons/Minigun.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using AlienAttack.MonoGame.Things.Bullets;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace AlienAttack.MonoGame.Things.Weapons;
|
||||
|
||||
public class Minigun : Weapon
|
||||
{
|
||||
public override int FireThreshold => 15;
|
||||
|
||||
public override void Fire(Sprite owner, SpriteUpdateContext context)
|
||||
{
|
||||
// Calculate bullet spawn positions relative to the player's bounding box
|
||||
int x1 = (int)owner.XPosition + 12;
|
||||
int x2 = (int)owner.XPosition + owner.BoundBox.Width - 20;
|
||||
int y = (int)owner.YPosition + 6;
|
||||
|
||||
// Create bullets with velocity (0, -4)
|
||||
MinigunBulletSmall bullet1 = new(x1, y, 0, -6, owner);
|
||||
MinigunBulletSmall bullet2 = new(x2, y, 0, -6, owner);
|
||||
|
||||
// Queue the bullets for spawning
|
||||
context.SpawnSprite(bullet1);
|
||||
context.SpawnSprite(bullet2);
|
||||
}
|
||||
}
|
||||
|
||||
public class FastMinigun : Weapon
|
||||
{
|
||||
public override int FireThreshold => 10;
|
||||
|
||||
public override void Fire(Sprite owner, SpriteUpdateContext context)
|
||||
{
|
||||
// Calculate bullet spawn positions relative to the player's bounding box
|
||||
float x = (owner.Position.X - (7/2) + owner.BoundBox.Width / 2);
|
||||
float y = owner.YPosition - 16;
|
||||
|
||||
// Create bullets with velocity (0, -4)
|
||||
MinigunBulletSmall bullet = new(x, y, 0, -6, owner);
|
||||
|
||||
// Queue the bullets for spawning
|
||||
context.SpawnSprite(bullet);
|
||||
}
|
||||
}
|
||||
26
AlientAttack.MonoGame/Things/Weapons/Weapon.cs
Normal file
26
AlientAttack.MonoGame/Things/Weapons/Weapon.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace AlienAttack.MonoGame.Things.Weapons;
|
||||
|
||||
public abstract class Weapon : IWeapon
|
||||
{
|
||||
public abstract int FireThreshold { get; }
|
||||
public int CurrentFireThreshold { get; private set; }
|
||||
|
||||
public void UpdateFireThreshold()
|
||||
{
|
||||
if (CurrentFireThreshold > 0)
|
||||
CurrentFireThreshold--;
|
||||
}
|
||||
|
||||
public bool TryFire(Sprite owner, SpriteUpdateContext context)
|
||||
{
|
||||
if (CurrentFireThreshold > 0)
|
||||
return false;
|
||||
|
||||
Fire(owner, context);
|
||||
CurrentFireThreshold = FireThreshold;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void Fire(Sprite owner, SpriteUpdateContext context);
|
||||
}
|
||||
Reference in New Issue
Block a user