Allow for bullet drag

This commit is contained in:
2021-12-02 18:29:46 +00:00
parent 85ededc158
commit 8b8d75b016
35 changed files with 362 additions and 228 deletions
+11 -7
View File
@@ -9,8 +9,9 @@ module Dodge.Item.Weapon.AmmoParams
import Dodge.Data
import Dodge.Particle.Bullet.Spawn
import Geometry
import LensHelp
import Control.Lens
--import Control.Lens
useAmmoParamsRate :: Int
-> HammerType
@@ -32,28 +33,30 @@ defaultAimParams = AimParams
}
useAmmoParams :: Item -> Creature -> World -> World
useAmmoParams it = withVelWthHiteff (muzvel *.* _amBulVel b) (_amBulWth b) (_amBulEff b)
useAmmoParams it = withVelWthHiteff (muzvel *.* _amBulVel b) (_rifling $ _itParams it) (_amBulWth b) (_amBulEff b)
where
muzvel = _muzVel $ _itParams it
b = _aoType $ _itConsumption it
useAmmoParamsVelMod :: Float -> Item -> Creature -> World -> World
useAmmoParamsVelMod vfact it = withDelayedVelWthHiteff vfact (_amBulVel b) (_amBulWth b) (_amBulEff b)
useAmmoParamsVelMod vfact it = withDelayedVelWthHiteff vfact (_amBulVel b) (_rifling $ _itParams it)
(_amBulWth b) (_amBulEff b)
where
b = _aoType $ _itConsumption it
{- | Creates a bullet with a given velocity, width, and 'HitEffect' -}
withVelWthHiteff
:: Point2 -- ^ Velocity, x direction is forward with respect to the creature
-> Float -- ^ drag
-> Float -- ^ Bullet width
-> HitEffect -- ^ Bullet effect when hitting creature, wall etc
-> Creature
-> World
-> World
withVelWthHiteff vel width hiteff cr = over particles (newbul : )
withVelWthHiteff vel drag width hiteff cr = particles .:~ newbul
where
cid = _crID cr
newbul = aGenBulAt (Just cid) pos (rotateV dir vel) hiteff width
newbul = aGenBulAt (Just cid) pos (rotateV dir vel) drag hiteff width
dir = _crDir cr
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
@@ -61,15 +64,16 @@ withVelWthHiteff vel width hiteff cr = over particles (newbul : )
withDelayedVelWthHiteff
:: Float -- ^ Velocity factor for first step
-> Point2 -- ^ Velocity, x direction is forward with respect to the creature
-> Float -- ^ Drag
-> Float -- ^ Bullet width
-> HitEffect -- ^ Bullet effect when hitting creature, wall etc
-> Creature -- ^ Creature id
-> World
-> World
withDelayedVelWthHiteff vfact vel width hiteff cr = over particles (newbul : )
withDelayedVelWthHiteff vfact vel drag width hiteff cr = particles .:~ newbul
where
cid = _crID cr
newbul = aDelayedBulAt vfact (Just cid) pos (rotateV dir vel) hiteff width
newbul = aDelayedBulAt vfact (Just cid) pos (rotateV dir vel) drag hiteff width
dir = _crDir cr
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
+4 -3
View File
@@ -36,7 +36,8 @@ import qualified Data.IntMap.Strict as IM
teslaGun :: Item
teslaGun = defaultGun
{ _itName = "TESLA"
, _itIdentity = TeslaGun
, _itCombineType = TESLAGUN
-- , _itIdentity = TeslaGun
, _itConsumption = defaultAmmo
{ _ammoMax = 200
, _ammoLoaded = 200
@@ -63,7 +64,7 @@ teslaGunPic _ = noPic $ colorSH blue $
lasGun :: Item
lasGun = defaultAutoGun
{ _itName = "LASGUN ////"
, _itIdentity = LasGun
, _itCombineType = LASGUN
, _itConsumption = defaultAmmo
{ _ammoMax = 200
, _ammoLoaded = 200
@@ -119,7 +120,7 @@ lasGunPic it =
tractorGun :: Item
tractorGun = defaultAutoGun
{ _itName = "TRACTORGUN"
, _itIdentity = TractorGun
, _itCombineType = TRACTORGUN
, _itConsumption = defaultAmmo
{ _ammoMax = 10000
, _ammoLoaded = 10000
+1 -1
View File
@@ -112,7 +112,7 @@ maxT = 20
boosterGun :: Item
boosterGun = defaultGun
{ _itName = "BOOSTER"
, _itIdentity = Blinker
, _itCombineType = BOOSTER
, _itConsumption = defaultAmmo
{ _ammoMax = 100
, _ammoLoaded = 100
+1 -1
View File
@@ -37,7 +37,7 @@ bounceBullet = BulletAmmo
{ _amString = "BOUNCING"
, _amBulEff = destroyOnImpact bulHitCr bulBounceWall
, _amBulWth = 2
, _amBulVel = V2 10 0
, _amBulVel = V2 40 0
}
ltBullet :: AmmoType
ltBullet = BulletAmmo
+61 -8
View File
@@ -1,5 +1,8 @@
module Dodge.Item.Weapon.BulletGuns
( pistol
, bangStick
, bangRod
, bangCane
, autoGun
, multGun
, miniGun
@@ -36,7 +39,7 @@ import Control.Lens
autoGun :: Item
autoGun = defaultAutoGun
{ _itName = "AUTOGUN"
, _itIdentity = AutoGun
, _itCombineType = AUTOGUN
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _ammoMax = 30
@@ -72,6 +75,7 @@ autoGun = defaultAutoGun
, _itInvDisplay = basicWeaponDisplay
, _itParams = BulletShooter
{ _muzVel = 1
, _rifling = 0.9
, _bore = 2
, _gunBarrels = SingleBarrel 0.1
}
@@ -86,11 +90,48 @@ autoGunPic it = noPic $
<> translateSHf 0 (-1) (rotateSHx (negate $ pi/4) . upperPrismPoly 2 $ rectNESW (negate $ 3 + 0.25 * x) 0 3 (-5))
where
x = fromIntegral $ _ammoLoaded $ _itConsumption it
bangStick :: Item
bangStick = defaultGun
{ _itName = "BANGSTICK"
, _itCombineType = BANGSTICK
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _ammoMax = 1
, _ammoLoaded = 1
, _reloadTime = 20
, _reloadType = ActivePartial 1
}
, _itUse = useAmmoParamsRate 8 upHammer
[ ammoCheckI
, hammerCheckI
, useTimeCheck
, withSoundStart tap3S
, useAmmoAmount 1
, applyInaccuracy
, withMuzFlareI
]
, _itFloorPict = pistolPic
-- , _itZoom = defaultItZoom
, _itEquipPict = pictureWeaponAim pistolPic
, _itID = Nothing
, _itInvDisplay = basicWeaponDisplay
, _itInvColor = white
, _itTargeting = Nothing
, _itParams = BulletShooter
{ _muzVel = 0.8
, _rifling = 0.8
, _bore = 2
, _gunBarrels = SingleBarrel 0.05
}
, _itTweaks = defaultBulletSelTweak
}
bangCane = bangStick
bangRod = bangCane
pistol :: Item
pistol = defaultGun
{ _itName = "PISTOL"
, _itIdentity = Pistol
, _itCombineType = PISTOL
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _ammoMax = 15
@@ -116,6 +157,7 @@ pistol = defaultGun
, _itTargeting = Nothing
, _itParams = BulletShooter
{ _muzVel = 0.8
, _rifling = 0.8
, _bore = 2
, _gunBarrels = SingleBarrel 0.05
}
@@ -138,7 +180,7 @@ bulletClip x = rotateSHx (negate $ pi/4) . upperPrismPoly 2 $ rectNESW 3 0 (3 -
hvAutoGun :: Item
hvAutoGun = defaultAutoGun
{ _itName = "AUTO-HV"
, _itIdentity = HvAutoGun
, _itCombineType = HVAUTOGUN
, _itConsumption = defaultAmmo
{ _aoType = hvBullet
, _ammoMax = 100
@@ -178,7 +220,7 @@ hvAutoGunPic it =
ltAutoGun :: Item
ltAutoGun = defaultAutoGun
{ _itName = "AUTO-LT"
, _itIdentity = LtAutoGun
, _itCombineType = LTAUTOGUN
, _itConsumption = defaultAmmo
{ _aoType = ltBullet
, _ammoMax = 25
@@ -198,6 +240,7 @@ ltAutoGun = defaultAutoGun
, _itFloorPict = ltAutoGunPic
, _itParams = BulletShooter
{ _muzVel = 1
, _rifling = 0.8
, _bore = 2
, _gunBarrels = SingleBarrel autogunSpread
}
@@ -217,7 +260,7 @@ ltAutoGunPic it =
miniGun :: Item
miniGun = defaultAutoGun
{ _itName = "MINI-G"
, _itIdentity = MiniGun
, _itCombineType = MINIGUN
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _ammoMax = 1500
@@ -262,6 +305,14 @@ miniGun = defaultAutoGun
& useAim . aimStance .~ TwoHandTwist
& useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5}
, _itFloorPict = miniGunPictItem
, _itParams = BulletShooter
{ _muzVel = 1
, _rifling = 0.9
, _bore = 2
, _gunBarrels = MultiBarrel
{_brlSpread = RotatingBarrels 0.01
,_brlNum = 4}
}
, _itEquipPict = pictureWeaponAim miniGunPictItem
, _itTweaks = defaultBulletSelTweak
, _itInvSize = 4
@@ -316,7 +367,7 @@ miniGunPict spin am =
spreadGun :: Item
spreadGun = defaultGun
{ _itName = "SPREAD"
, _itIdentity = SpreadGun
, _itCombineType = SPREADGUN
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _ammoMax = 5
@@ -335,6 +386,7 @@ spreadGun = defaultGun
]
, _itParams = BulletShooter
{ _muzVel = 0.7
, _rifling = 0.8
, _bore = 2
, _gunBarrels = MultiBarrel
{_brlNum = 5
@@ -355,7 +407,7 @@ spreadGunPic it =
multGun :: Item
multGun = defaultGun
{ _itName = "MULTGUN"
, _itIdentity = MultGun
, _itCombineType = MULTGUN
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _ammoMax = 5
@@ -380,6 +432,7 @@ multGun = defaultGun
, _itFloorPict = multGunSPic
, _itParams = BulletShooter
{ _muzVel = 1
, _rifling = 0.9
, _bore = 3
, _gunBarrels = MultiBarrel
{_brlNum = 5
@@ -406,7 +459,7 @@ multGunSPic it =
longGun :: Item
longGun = defaultGun
{ _itName = "LONGGUN"
, _itIdentity = LongGun
, _itCombineType = LONGGUN
, _itConsumption = defaultAmmo
{ _aoType = hvBullet
, _ammoMax = 1
+1 -1
View File
@@ -21,7 +21,7 @@ import Control.Lens
lasDrones :: Item
lasDrones = defaultGun
{ _itName = "DRONES"
, _itIdentity = Generic
, _itCombineType = DRONELAUNCHER
, _itConsumption = defaultAmmo
{ _aoType = DroneAmmo { _amString = "LASDRONE" }
, _ammoMax = 2
+2 -2
View File
@@ -25,10 +25,10 @@ import Control.Lens
grenade :: Item
grenade = Throwable
{ _itName = "GRENADE " ++ show fuseTime
, _itCombineType = GRENADE
, _itInvSize = 1
, _itDimension = defaultItemDimension
, _itCurseStatus = Uncursed
, _itIdentity = Grenade
, _itMaxStack = 8
, _itAmount = 1
, _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
@@ -213,7 +213,7 @@ defaultThrowable = grenade
remoteBomb :: Item
remoteBomb = defaultThrowable
{ _itName = "REMOTEBOMB"
, _itIdentity = RemoteBomb
, _itCombineType = REMOTEBOMB
, _itMaxStack = 1
, _itAmount = 1
, _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2
@@ -23,6 +23,7 @@ basicWeaponDisplay it = [midPadL 10 ' ' thename (' ' : thenumber) ++ theparam]
Just' x -> show x ++ "R" ++ show (_ammoLoaded am)
Just am@ChargeableAmmo{} -> show $ _wpCharge am
Just x@ItemItselfConsumable{} -> show $ _itMaxStack' x
Just NoConsumption -> "NOCONSUMPTION"
Nothing -> ""
theparam = fromMaybe []
. listToMaybe
+2 -2
View File
@@ -37,7 +37,7 @@ import System.Random
launcher :: Item
launcher = defaultGun
{ _itName = "ROCKO"
, _itIdentity = Launcher
, _itCombineType = LAUNCHER
, _itConsumption = defaultAmmo
{ _aoType = defaultShellAmmo
{ _amPayload = makeExplosionAt
@@ -260,7 +260,7 @@ trySpinByCID cid i pj w = w & props . ix pjid . pjSpin .~ newSpin
remoteLauncher :: Item
remoteLauncher = defaultGun
{ _itName = "ROCKO-REM"
, _itIdentity = RemoteLauncher
, _itCombineType = LAUNCHER
, _itConsumption = defaultAmmo
{ _aoType = defaultShellAmmo
{ _amPayload = makeExplosionAt
+4 -4
View File
@@ -20,7 +20,7 @@ Sends out pulses that display walls. -}
radar :: Item
radar = defaultGun
{ _itName = "RADAR"
, _itIdentity = Generic
, _itCombineType = RADAR
, _itConsumption = defaultAmmo
{ _ammoMax = 100
, _ammoLoaded = 100
@@ -40,7 +40,7 @@ Sends out pulses that display creatures. -}
sonar :: Item
sonar = defaultGun
{ _itName = "SONAR"
, _itIdentity = Generic
, _itCombineType = RADAR
, _itConsumption = defaultAmmo
{ _ammoMax = 100
, _ammoLoaded = 100
@@ -59,7 +59,7 @@ sonar = defaultGun
Automatically sends out pulses that display creatures. -}
autoSonar :: Item
autoSonar = defaultEquipment
{ _itIdentity = Generic
{ _itCombineType = RADAR
, _itName = "AUTOSONAR"
, _itMaxStack = 1
, _itAmount = 1
@@ -73,7 +73,7 @@ autoSonar = defaultEquipment
Automatically sends out pulses that display walls. -}
autoRadar :: Item
autoRadar = defaultEquipment
{ _itIdentity = Generic
{ _itCombineType = RADAR
, _itName = "AUTORADAR"
, _itMaxStack = 1
, _itAmount = 1
+2 -2
View File
@@ -33,7 +33,7 @@ import System.Random
poisonSprayer :: Item
poisonSprayer = defaultAutoGun
{ _itName = "POISON"
, _itIdentity = PoisonSprayer
, _itCombineType = SPRAYER
, _itConsumption = defaultAmmo
{ _ammoMax = 500
, _ammoLoaded = 500
@@ -57,7 +57,7 @@ poisonSprayer = defaultAutoGun
flamer :: Item
flamer = defaultAutoGun
{ _itName = "FLAMER"
, _itIdentity = Flamethrower
, _itCombineType = SQUIRTER
, _itConsumption = defaultAmmo
{ _ammoMax = 250
, _ammoLoaded = 250
+4 -4
View File
@@ -19,7 +19,7 @@ import Control.Lens
rewindGun :: Item
rewindGun = defaultGun
{ _itName = "REWINDER"
, _itIdentity = Rewinder
, _itCombineType = REWINDER
, _itConsumption = ChargeableAmmo
{ _wpMaxCharge = 250
, _wpCharge = 0
@@ -55,7 +55,7 @@ useRewindGun _ _ w = case _rewindWorlds w of
shrinkGun :: Item
shrinkGun = defaultGun
{ _itName = "SHRINKER"
, _itIdentity = Generic
, _itCombineType = SHRINKER
, _itConsumption = defaultAmmo
{ _ammoMax = 100
, _ammoLoaded = 100
@@ -85,7 +85,7 @@ useShrinkGun cr invid w = if _itBool $ _itAttachment it
blinkGun :: Item
blinkGun = defaultGun
{ _itName = "BLINKER"
, _itIdentity = Blinker
, _itCombineType = BLINKER
, _itConsumption = defaultAmmo
{ _ammoMax = 100
, _ammoLoaded = 100
@@ -117,7 +117,7 @@ autoEffectGun name eff = defaultAutoGun
forceFieldGun :: Item
forceFieldGun = defaultGun
{ _itName = "FORCEFIELD"
, _itIdentity = ForceFieldGun
, _itCombineType = FORCEFIELD
, _itConsumption = defaultAmmo
{ _ammoMax = 100
, _ammoLoaded = 100