Added configurable weapons.

This commit is contained in:
2026-01-03 21:49:27 -05:00
parent 79fd63c3ce
commit e8e31bb143
37 changed files with 332 additions and 88 deletions

View File

@@ -0,0 +1,36 @@
using AlienAttack.MonoGame.Things.Muzzles;
namespace AlienAttack.MonoGame.Things.Weapons;
public class ConfigurableWeapon(WeaponDef def, WeaponState state) : Weapon
{
public override int FireThreshold => state.FireThreshold;
public override void Fire(Sprite owner, SpriteUpdateContext context)
{
if (owner is not Player player) return;
foreach (var shot in def.Pattern.Shots)
{
// muzzle local -> world
var muzzleLocal = player.GetMuzzleLocal(shot.Muzzle); // make a fast lookup
var muzzleWorld = MuzzleMath.GetMuzzleWorld(player, muzzleLocal);
// speed upgrade
float vx = shot.Velocity.X * state.SpeedMultiplier;
float vy = shot.Velocity.Y * state.SpeedMultiplier;
// center bullet on muzzle + pattern offset
var pos = MuzzleMath.CenterBulletOn(muzzleWorld, def.Bullet.Width, def.Bullet.Height) + shot.Offset;
var bullet = def.Bullet.Create(pos.X, pos.Y, vx, vy, owner);
// optional: apply damage bonus generically
//bullet.Damage += state.DamageBonus;
context.SpawnSprite(bullet);
}
context.AudioManager.PlayPlayerFire(); // or use _def.FireSfxKey -> audio routing
}
}