Added configurable weapons.
This commit is contained in:
36
AlientAttack.MonoGame/Things/Weapons/ConfigurableWeapon.cs
Normal file
36
AlientAttack.MonoGame/Things/Weapons/ConfigurableWeapon.cs
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user