Refactor, add bullet modules and weapon effect modifiers
This commit is contained in:
+80
-70
@@ -18,6 +18,7 @@ import Dodge.Item.Weapon.TriggerType
|
||||
import Dodge.Item.Weapon.ExtraEffect
|
||||
import Dodge.Item.Weapon.UseEffect
|
||||
import Dodge.Item.Weapon.Laser
|
||||
import Dodge.Item.Weapon.Shell
|
||||
import Dodge.Default.Weapon
|
||||
import Dodge.Item.Weapon.Booster
|
||||
import Dodge.Item.Weapon.Grenade
|
||||
@@ -43,23 +44,22 @@ import qualified Data.Set as S
|
||||
--import qualified Data.Map as M
|
||||
|
||||
pistol :: Item
|
||||
pistol = Weapon
|
||||
pistol = defaultGun
|
||||
{ _itName = "PISTOL"
|
||||
, _itIdentity = Pistol
|
||||
, _wpMaxAmmo = 15
|
||||
, _wpLoadedAmmo = 15
|
||||
, _wpAmmo = GenericAmmo
|
||||
, _wpReloadTime = 40
|
||||
, _wpReloadState = 0
|
||||
, _itUseRate = 8
|
||||
, _itUseTime = 0
|
||||
, _itUse = \_ ->
|
||||
hammerCheck
|
||||
. shootWithSound 0
|
||||
. withRandomDir 0.1
|
||||
. withMuzFlare
|
||||
. withVelWthHiteff (30,0) 2
|
||||
$ destroyOnImpact bulHitCr bulHitWall' bulHitFF'
|
||||
, _itUse = useAmmoParams
|
||||
, _itUseModifiers =
|
||||
[ hammerCheckI
|
||||
, shootWithSoundI 0
|
||||
, withRandomDirI 0.1
|
||||
, withMuzFlareI
|
||||
]
|
||||
, _itLeftClickUse = Nothing
|
||||
, _wpSpread = 0.02
|
||||
, _wpRange = 20
|
||||
@@ -80,7 +80,20 @@ pistol = Weapon
|
||||
, _itInvColor = white
|
||||
, _itTargeting = Nothing
|
||||
, _itWorldTrigger = Nothing
|
||||
, _wpAmmo = basicBullet
|
||||
}
|
||||
basicBullet :: Ammo
|
||||
basicBullet = BulletAmmo
|
||||
{ _amString = "BULLET"
|
||||
, _amBulEff = destroyOnImpact bulHitCr bulHitWall' bulHitFF'
|
||||
, _amBulWth = 2
|
||||
, _amBulVel = (30,0)
|
||||
}
|
||||
useAmmoParams :: Item -> Creature -> World -> World
|
||||
useAmmoParams it = withVelWthHiteff (_amBulVel b) (_amBulWth b) (_amBulEff b)
|
||||
where
|
||||
b = _wpAmmo it
|
||||
|
||||
effectGun :: String -> (Creature -> World -> World) -> Item
|
||||
effectGun name eff = defaultGun
|
||||
{ _itName = name ++ "Gun"
|
||||
@@ -118,6 +131,7 @@ autoGun = defaultGun
|
||||
, _itScrollUp = incCharMode
|
||||
, _itScrollDown = decCharMode
|
||||
, _itInvDisplay = basicWeaponDisplay
|
||||
, _wpAmmo = basicBullet
|
||||
}
|
||||
autoFireMode, singleFireMode, autoGunNonTwistEff :: Creature -> World -> World
|
||||
autoFireMode = shootWithSound (fromIntegral autoGunSound)
|
||||
@@ -289,19 +303,25 @@ hvAutoGun = defaultAutoGun
|
||||
, _wpReloadState = 0
|
||||
, _itUseRate = 25
|
||||
, _itUseTime = 0
|
||||
, _itUse = \_ -> rateIncAB 24 10 (torqueBeforeForced 0.1 mkHvBul) $ torqueAfter 0.2 mkHvBul
|
||||
, _itUse = \it -> rateIncAB 24 10 (torqueBeforeForced 0.1 (mkHvBul it))
|
||||
(torqueAfter 0.2 (mkHvBul it))
|
||||
, _wpRange = 20
|
||||
, _itFloorPict = onLayer FlItLayer $ color orange $ polygon $ rectNESW 5 5 (-5) (-5)
|
||||
, _itAimingSpeed = 0.2
|
||||
, _itAimingRange = 1
|
||||
, _itEquipPict = pictureWeaponOnAim $ color orange $ polygon $ rectNESW 5 5 (-5) (-5)
|
||||
, _wpAmmo = BulletAmmo
|
||||
{_amString = "HVBULLET"
|
||||
, _amBulEff = penWalls hvBulHitCr' hvBulHitWall' bulHitFF'
|
||||
, _amBulWth = 6
|
||||
, _amBulVel = (80,0)
|
||||
}
|
||||
}
|
||||
where
|
||||
mkHvBul = withSound (fromIntegral longGunSound)
|
||||
mkHvBul it = withSound (fromIntegral longGunSound)
|
||||
. withThinSmoke
|
||||
. withMuzFlare
|
||||
. withVelWthHiteff (80,0) 6
|
||||
$ penWalls hvBulHitCr' hvBulHitWall' bulHitFF'
|
||||
$ useAmmoParams it
|
||||
ltAutoGun :: Item
|
||||
ltAutoGun = defaultAutoGun
|
||||
{ _itName = "AUTO-LT"
|
||||
@@ -337,11 +357,11 @@ miniGun = defaultAutoGun
|
||||
, _itUseRate = 2
|
||||
, _itUseTime = 0
|
||||
, _itUse = \_ -> withWarmUp 50 . torqueBefore 0.03 . withSidePush 50 . withRecoil 15
|
||||
. withRandomDir 0.1
|
||||
. withRandomOffset 9
|
||||
. withMuzFlare
|
||||
. withVelWthHiteff (30,0) 2
|
||||
$ destroyOnImpact bulBounceArmCr' bulHitWall' bulHitFF'
|
||||
. withRandomDir 0.1
|
||||
. withRandomOffset 9
|
||||
. withMuzFlare
|
||||
. withVelWthHiteff (30,0) 2
|
||||
$ destroyOnImpact bulBounceArmCr' bulHitWall' bulHitFF'
|
||||
, _wpRange = 20
|
||||
, _itFloorPict = onLayer FlItLayer $ color red $ polygon $ rectNESW 9 5 (-9) (-5)
|
||||
, _itAimingSpeed = 0.4
|
||||
@@ -529,6 +549,16 @@ aTeslaArc' cr w
|
||||
(sideOffset,g) = randomR (-5,5) $ _randGen w
|
||||
dir = _crDir cr
|
||||
|
||||
remoteShellPic' :: Projectile -> Picture
|
||||
remoteShellPic' pj
|
||||
| t > 40 = onLayerL [levLayer CrLayer - 2]
|
||||
$ uncurry translate pos $ rotate dir $ remoteShellPic t
|
||||
| otherwise = uncurry translate pos $ rotate dir $ remoteShellPic t
|
||||
where
|
||||
t = _pjTimer pj
|
||||
pos = _pjPos pj
|
||||
dir = _pjDir pj
|
||||
|
||||
remoteShellPic
|
||||
:: Int -- ^ Timer
|
||||
-> Picture
|
||||
@@ -735,13 +765,18 @@ fireRemoteLauncher cr w = setLocation
|
||||
cid = _crID cr
|
||||
dir = _crDir cr
|
||||
pos = _crPos cr +.+ rotateV dir (_crRad cr + 1,0)
|
||||
remRocket = IM.insert i $ Projectile
|
||||
remRocket = IM.insert i $ Shell
|
||||
{ _pjPos = pos
|
||||
, _pjStartPos = pos
|
||||
, _pjVel = rotateV dir (1,0)
|
||||
, _pjDraw = \_ -> blank
|
||||
, _pjDraw = remoteShellPic'
|
||||
, _pjID = i
|
||||
, _pjUpdate = \_ -> moveRemoteShell 50 i cid itid dir
|
||||
, _pjUpdate = \pj -> decTimMvVel pj . moveRemoteShell cid itid pj
|
||||
, _pjAcc = (0,0)
|
||||
, _pjDir = dir
|
||||
, _pjSpin = 0
|
||||
, _pjPayload = makeExplosionAt
|
||||
, _pjTimer = 50
|
||||
}
|
||||
j = _crInvSel cr
|
||||
newitid = IM.newKey $ _itemPositions w
|
||||
@@ -756,69 +791,44 @@ fireRemoteLauncher cr w = setLocation
|
||||
_ -> w'
|
||||
itid = fromMaybe newitid maybeitid
|
||||
|
||||
moveRemoteShell :: Int -> Int -> Int -> Int -> Float -> World -> World
|
||||
moveRemoteShell time i cid itid _ w
|
||||
moveRemoteShell :: Int -> Int -> Projectile -> World -> World
|
||||
moveRemoteShell cid itid pj w
|
||||
| time > 40 = if circOnSomeWall oldPos 4 w
|
||||
then doExplosion w
|
||||
else over (projectiles . ix i . pjPos) (+.+ vel)
|
||||
$ set (projectiles . ix i . pjDraw) (\_ -> piclow)
|
||||
$ set (projectiles . ix i . pjUpdate)
|
||||
(\_ -> moveRemoteShell (time-1) i cid itid newdir)
|
||||
$ setScope
|
||||
w
|
||||
then doExplosion w
|
||||
else w & setScope
|
||||
| time >= 20 = case thingHit of
|
||||
Just _ -> doExplosion w
|
||||
Nothing -> over (projectiles . ix i . pjPos) (+.+ vel)
|
||||
$ set (projectiles . ix i . pjDraw) (\_ -> pic)
|
||||
$ set (projectiles . ix i . pjUpdate)
|
||||
(\_ -> moveRemoteShell (time-1) i cid itid newdir)
|
||||
$ setScope
|
||||
w
|
||||
Nothing -> setScope w & projectiles . ix i . pjDir .~ newdir
|
||||
| time > -99 = case thingHit of
|
||||
Just _ -> doExplosion
|
||||
$ stopSoundFrom (ShellSound i)
|
||||
w
|
||||
Nothing -> over (projectiles . ix i . pjPos) (+.+ vel)
|
||||
$ set randGen g
|
||||
$ set (projectiles . ix i . pjDraw) (\_ -> pic)
|
||||
$ set (projectiles . ix i . pjUpdate) (\_ -> moveRemoteShell (time-1) i cid itid newdir)
|
||||
$ over (projectiles . ix i . pjVel) (\v -> accel +.+ frict *.* v)
|
||||
$ soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) 1 250
|
||||
$ smokeGen
|
||||
$ makeFlameletTimed oldPos (0.5 *.* rotateV (pi+sparkD) accel) Nothing 3 10
|
||||
$ setScope
|
||||
w
|
||||
Just _ -> doExplosion $ stopSoundFrom (ShellSound i) w
|
||||
Nothing -> w & set randGen g
|
||||
& projectiles . ix i %~
|
||||
( ( pjVel %~ ( (accel +.+) . (frict *.*) ) )
|
||||
. ( pjDir .~ newdir )
|
||||
)
|
||||
& soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) 1 250
|
||||
& smokeGen
|
||||
& makeFlameletTimed oldPos (0.5 *.* rotateV (pi+sparkD) accel) Nothing 3 10
|
||||
& setScope
|
||||
| time > -200 = case thingHit of
|
||||
Just _ -> doExplosion
|
||||
$ stopSoundFrom (ShellSound i)
|
||||
w
|
||||
Nothing -> over (projectiles . ix i . pjPos) (+.+ vel)
|
||||
$ set (projectiles . ix i . pjDraw) (\_ -> pic)
|
||||
$ set (projectiles . ix i . pjUpdate) (\_ -> moveRemoteShell (time-1) i cid itid newdir)
|
||||
$ setScope
|
||||
w
|
||||
| otherwise = doExplosion
|
||||
$ stopSoundFrom (ShellSound i)
|
||||
w
|
||||
Just _ -> doExplosion $ stopSoundFrom (ShellSound i) w
|
||||
Nothing -> setScope w
|
||||
| otherwise = doExplosion $ stopSoundFrom (ShellSound i) w
|
||||
where
|
||||
pj = _projectiles w IM.! i
|
||||
oldPos = _pjPos pj
|
||||
vel = _pjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
time = _pjTimer pj
|
||||
i = _pjID pj
|
||||
oldPos = _pjPos pj
|
||||
vel = _pjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
newdir
|
||||
| SDL.ButtonRight `S.member` _mouseButtons w
|
||||
&& w ^? creatures . ix cid . crInvSel == w ^? itemPositions . ix itid . itInvId
|
||||
= _cameraRot w + argV (_mousePos w)
|
||||
| otherwise = dir
|
||||
accel = rotateV newdir (2,0)
|
||||
(frict,g) = randomR (0.6,0.9) $ _randGen w
|
||||
(frict,g) = randomR (0.6,0.9) $ _randGen w
|
||||
(sparkD,_) = randomR (-0.5,0.5) $ _randGen w
|
||||
dir = argV vel
|
||||
pic = uncurry translate newPos
|
||||
$ rotate (argV accel) $ remoteShellPic time
|
||||
piclow = onLayerL [levLayer CrLayer - 2]
|
||||
$ uncurry translate newPos $ rotate (argV accel)
|
||||
$ remoteShellPic time
|
||||
hitCr = fst <$> collideCircCrsPoint oldPos newPos 4 w
|
||||
hitWl = fst <$> collideCircWalls' oldPos newPos 2 (wallsNearPoint newPos w)
|
||||
thingHit = hitCr <|> hitWl
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
module Dodge.Item.Weapon.Launcher
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Item.Weapon.TriggerType
|
||||
import Dodge.Default.Weapon
|
||||
import Dodge.Default.Shell
|
||||
import Dodge.SoundLogic.Synonyms
|
||||
import Picture
|
||||
import qualified IntMapHelp as IM
|
||||
import Dodge.WorldEvent.Explosion
|
||||
import Dodge.Picture.Layer
|
||||
import Dodge.Item.Draw
|
||||
import Geometry
|
||||
import Dodge.Default.Shell
|
||||
import Dodge.Item.Weapon.Shell
|
||||
import Dodge.Item.Weapon.TriggerType
|
||||
import Dodge.Base
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.WorldEvent.SpawnParticle
|
||||
import Dodge.WorldEvent.Cloud
|
||||
import Dodge.RandomHelp
|
||||
import Geometry
|
||||
import Picture
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
import Data.Maybe
|
||||
import Control.Lens
|
||||
@@ -45,7 +46,7 @@ launcher = defaultGun
|
||||
, _wpAmmo = defaultShellAmmo
|
||||
{ _amPayload = makeExplosionAt
|
||||
, _amString = ""
|
||||
, _amPjMove = basicAmPjMoves
|
||||
, _amPjParams = basicAmPjMoves
|
||||
, _amPjDraw = shellPic
|
||||
}
|
||||
}
|
||||
@@ -54,19 +55,58 @@ basicAmPjMoves :: [PjParam]
|
||||
basicAmPjMoves =
|
||||
[spinDrag
|
||||
,spinStart
|
||||
,thrustParam
|
||||
]
|
||||
spinDrag :: PjParam
|
||||
spinDrag = PjParam
|
||||
{ _pjMoveParam = \_ _ _ -> reduceSpinBy 0.995
|
||||
, _pjIntParam = 0
|
||||
, _pjDisplayParam = ("SPIN DRAG:" ++ ) . show
|
||||
{ _pjMoveParam = \i _ _ -> reduceSpinBy (1 - (fromIntegral i)*2 / 200)
|
||||
, _pjIntParam = 1
|
||||
, _pjDisplayParam = pjPadText "SPIN SLOWDOWN" . show
|
||||
, _pjMaxParam = 5
|
||||
}
|
||||
pjPadText :: String -> String -> String
|
||||
pjPadText s = (rightPad 12 ' ' s ++ ) . (' ':)
|
||||
spinStart :: PjParam
|
||||
spinStart = PjParam
|
||||
{ _pjMoveParam = \_ _ cr -> pjEffAtTime 35 $ trySpinByCID (_crID cr)
|
||||
, _pjIntParam = 0
|
||||
, _pjDisplayParam = ("SPIN START:" ++ ) . show
|
||||
{ _pjMoveParam = \i _ cr -> pjEffAtTime 35 $ trySpinByCID (_crID cr) i
|
||||
, _pjIntParam = 2
|
||||
, _pjDisplayParam = pjPadText "SPIN AMOUNT" . show
|
||||
, _pjMaxParam = 5
|
||||
}
|
||||
thrustParam :: PjParam
|
||||
thrustParam = PjParam
|
||||
{ _pjMoveParam = \i _ _ -> pjThrust i
|
||||
, _pjIntParam = 1
|
||||
, _pjDisplayParam = pjPadText "THRUST DELAY" . show
|
||||
, _pjMaxParam = 5
|
||||
}
|
||||
|
||||
pjThrust :: Int -> Projectile -> World -> World
|
||||
pjThrust i = pjEffTimeRange (st,et) $ doThrust
|
||||
where
|
||||
et | i == 0 = 36
|
||||
| otherwise = 40 - (fromIntegral i * 20)
|
||||
st = et - 100
|
||||
|
||||
doThrust :: Projectile -> World -> World
|
||||
doThrust pj w = w
|
||||
& randGen .~ g
|
||||
& projectiles . ix i . pjVel %~ (\v -> accel +.+ frict *.* v)
|
||||
& soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) 1 250
|
||||
& makeFlameletTimed (oldPos -.- vel) (vel +.+ rotateV (pi+sparkD) accel) Nothing 3 10
|
||||
& smokeGen
|
||||
where
|
||||
accel = _pjAcc pj
|
||||
i = _pjID pj
|
||||
oldPos = _pjPos pj
|
||||
vel = _pjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
(frict,g) = randomR (0.6,0.9) $ _randGen w
|
||||
(sparkD,_) = randomR (-0.2,0.2) $ _randGen w
|
||||
r1 = randInCirc 10 & evalState $ _randGen w
|
||||
smokeGen = makeSmokeCloudAt (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos))
|
||||
|
||||
|
||||
|
||||
flameLauncher :: Item
|
||||
flameLauncher = launcher & wpAmmo . amPayload .~ makeFlameExplosionAt
|
||||
@@ -86,7 +126,7 @@ aRocketWithItemParams it cr w = over projectiles (IM.insert i theShell) w
|
||||
i = IM.newKey $ _projectiles w
|
||||
pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir)
|
||||
dir = _crDir cr
|
||||
ammoMvs pj w' = foldr (\pjP -> (_pjMoveParam pjP) (_pjIntParam pjP) it cr pj) w' (_amPjMove am)
|
||||
ammoMvs pj w' = foldr (\pjP -> (_pjMoveParam pjP) (_pjIntParam pjP) it cr pj) w' (_amPjParams am)
|
||||
theShell = defaultShell
|
||||
{ _pjPos = pos
|
||||
, _pjStartPos = pos
|
||||
@@ -108,18 +148,10 @@ moveShell pj w
|
||||
then doExplode
|
||||
else w
|
||||
| isJust thingHit = doExplode
|
||||
| time >= 20 = w
|
||||
| time > -99 = w
|
||||
& randGen .~ g
|
||||
& projectiles . ix i . pjVel %~ (\v -> accel +.+ frict *.* v)
|
||||
& soundFromPos (ShellSound i) newPos (fromIntegral smokeTrailSound) 1 250
|
||||
& makeFlameletTimed (oldPos -.- vel) (vel +.+ rotateV (pi+sparkD) accel) Nothing 3 10
|
||||
& smokeGen
|
||||
| time > -200 = w
|
||||
| time > -300 = w
|
||||
| otherwise = doExplode
|
||||
where
|
||||
time = _pjTimer pj
|
||||
accel = _pjAcc pj
|
||||
doExplode = w
|
||||
& projectileExplosion oldPos
|
||||
& stopSoundFrom (ShellSound i)
|
||||
@@ -129,13 +161,9 @@ moveShell pj w
|
||||
vel = _pjVel pj
|
||||
projectileExplosion = _pjPayload pj
|
||||
newPos = oldPos +.+ vel
|
||||
(frict,g) = randomR (0.6,0.9) $ _randGen w
|
||||
(sparkD,_) = randomR (-0.2,0.2) $ _randGen w
|
||||
hitCr = fst <$> collideCircCrsPoint oldPos newPos 4 w
|
||||
hitWl = fst <$> collideCircWalls' oldPos newPos 2 (wallsNearPoint newPos w)
|
||||
thingHit = hitCr <|> hitWl
|
||||
r1 = randInCirc 10 & evalState $ _randGen w
|
||||
smokeGen = makeSmokeCloudAt (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos))
|
||||
|
||||
reduceSpinBy :: Float -> Projectile -> World -> World
|
||||
reduceSpinBy x pj = projectiles . ix (_pjID pj) . pjSpin *~ x
|
||||
@@ -151,16 +179,18 @@ shellPic pj
|
||||
pos = _pjPos pj
|
||||
t = _pjTimer pj
|
||||
|
||||
decTimMvVel :: Projectile -> World -> World
|
||||
decTimMvVel pj = projectiles . ix pjid %~
|
||||
( (pjTimer -~ 1)
|
||||
. (pjPos %~ (+.+ vel) )
|
||||
. (pjAcc %~ rotateV rot )
|
||||
)
|
||||
|
||||
pjEffTimeRange
|
||||
:: (Int,Int)
|
||||
-> (Projectile -> World -> World)
|
||||
-> Projectile
|
||||
-> World
|
||||
-> World
|
||||
pjEffTimeRange (st,et) f pj
|
||||
| t <= et && t >= st = f pj
|
||||
| otherwise = id
|
||||
where
|
||||
rot = _pjSpin pj
|
||||
vel = _pjVel pj
|
||||
pjid = _pjID pj
|
||||
t = _pjTimer pj
|
||||
|
||||
pjEffAtTime
|
||||
:: Int
|
||||
@@ -174,13 +204,15 @@ pjEffAtTime t f pj
|
||||
|
||||
trySpinByCID
|
||||
:: Int -- ^ creature id
|
||||
-> Int -- ^ Spin amount
|
||||
-> Projectile
|
||||
-> World
|
||||
-> World
|
||||
trySpinByCID cid pj w = w & projectiles . ix pjid . pjSpin .~ newSpin
|
||||
trySpinByCID cid i pj w = w & projectiles . ix pjid . pjSpin .~ newSpin
|
||||
where
|
||||
pjid = _pjID pj
|
||||
dir = argV $ _pjVel pj
|
||||
newSpin = case w ^? creatures . ix cid of
|
||||
Just cr -> negate $ min 0.2 $ max (-0.2) $ normalizeAnglePi (dir - _crDir cr) / 20
|
||||
Just cr -> negate $ min 0.2 $ max (-0.2) $ normalizeAnglePi (dir - _crDir cr) / spinFactor
|
||||
_ -> 0
|
||||
spinFactor = 5 * (6 - fromIntegral i)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
module Dodge.Item.Weapon.Shell
|
||||
where
|
||||
import Dodge.Data
|
||||
import Geometry.Vector
|
||||
|
||||
import Control.Lens
|
||||
decTimMvVel :: Projectile -> World -> World
|
||||
decTimMvVel pj = projectiles . ix pjid %~
|
||||
( (pjTimer -~ 1)
|
||||
. (pjPos %~ (+.+ vel) )
|
||||
. (pjAcc %~ rotateV rot )
|
||||
)
|
||||
where
|
||||
rot = _pjSpin pj
|
||||
vel = _pjVel pj
|
||||
pjid = _pjID pj
|
||||
|
||||
--pjAutoSpin :: Projectile -> World -> World
|
||||
--pjAutoSpin pj = projectiles . ix pjid %~
|
||||
-- ( (pjDir -~ 1)
|
||||
-- . (pjPos %~ (+.+ vel) )
|
||||
-- . (pjAcc %~ rotateV rot )
|
||||
-- )
|
||||
-- where
|
||||
-- rot = _pjSpin pj
|
||||
-- vel = _pjVel pj
|
||||
-- pjid = _pjID pj
|
||||
@@ -153,8 +153,7 @@ withSidePushAfter maxSide eff cr w = over (creatures . ix cid) push . eff cr $ w
|
||||
cid = _crID cr
|
||||
push = over crPos (+.+ rotateV (_crDir cr) (0,pushAmount / _crMass cr))
|
||||
(pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w
|
||||
{- |
|
||||
Applies a world effect and sound effect after an ammo check. -}
|
||||
{- | Applies a world effect and sound effect after an ammo check. -}
|
||||
shootWithSound
|
||||
:: Int -- ^ Sound identifier
|
||||
-> (Creature -> World -> World)
|
||||
@@ -178,6 +177,30 @@ shootWithSound soundid f cr w
|
||||
&& _itUseTime item == 0
|
||||
&& _wpLoadedAmmo item > 0
|
||||
reloadCondition = _wpLoadedAmmo item == 0
|
||||
{- | Applies a world effect and sound effect after an ammo check. -}
|
||||
shootWithSoundI
|
||||
:: Int -- ^ Sound identifier
|
||||
-> (Item -> Creature -> World -> World)
|
||||
-- ^ Shoot effect, takes creature id as input
|
||||
-> Item
|
||||
-> Creature
|
||||
-> World
|
||||
-> World
|
||||
shootWithSoundI soundid f item cr w
|
||||
| fireCondition = over (pointerToItem . wpLoadedAmmo) (\ammo -> ammo-1)
|
||||
$ soundOncePos soundid (_crPos cr)
|
||||
$ set (pointerToItem . itUseTime) (_itUseRate item)
|
||||
$ f item cr w
|
||||
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
||||
| otherwise = w
|
||||
where
|
||||
cid = _crID cr
|
||||
itRef = _crInvSel cr
|
||||
pointerToItem = creatures . ix cid . crInv . ix itRef
|
||||
fireCondition = _wpReloadState item == 0
|
||||
&& _itUseTime item == 0
|
||||
&& _wpLoadedAmmo item > 0
|
||||
reloadCondition = _wpLoadedAmmo item == 0
|
||||
{- |
|
||||
Applies a world effect after an item use cooldown check. -}
|
||||
useTimeCheck
|
||||
@@ -205,6 +228,19 @@ hammerCheck f cr w = case (_crInv cr IM.! _crInvSel cr) ^? itHammer of
|
||||
where
|
||||
cid = _crID cr
|
||||
setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itHammer .~ HammerDown
|
||||
{- | Applies a world effect after a hammer position check. -}
|
||||
hammerCheckI
|
||||
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
|
||||
-> Item
|
||||
-> Creature
|
||||
-> World
|
||||
-> World
|
||||
hammerCheckI f it cr w = case it ^? itHammer of
|
||||
Just HammerUp -> f it cr $ setHammerDown w
|
||||
_ -> setHammerDown w
|
||||
where
|
||||
cid = _crID cr
|
||||
setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itHammer .~ HammerDown
|
||||
{- | Applies a world effect after an ammo check. -}
|
||||
shoot
|
||||
:: (Creature -> World -> World)
|
||||
@@ -272,6 +308,17 @@ withMuzFlare f cr w = tempLightForAt 3 pos . muzzleFlashAt pos2 $ f cr w
|
||||
where
|
||||
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
|
||||
pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr)
|
||||
|
||||
withMuzFlareI
|
||||
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
|
||||
-> Item
|
||||
-> Creature
|
||||
-> World
|
||||
-> World
|
||||
withMuzFlareI f it cr w = tempLightForAt 3 pos . muzzleFlashAt pos2 $ f it cr w
|
||||
where
|
||||
pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
|
||||
pos2 = _crPos cr +.+ (2 * _crRad cr) *.* unitVectorAtAngle (_crDir cr)
|
||||
{- | Applies the effect to a randomly rotated creature. -}
|
||||
withRandomDir
|
||||
:: Float -- ^ Max possible rotation
|
||||
@@ -283,6 +330,18 @@ withRandomDir
|
||||
withRandomDir acc f cr w = f (cr & crDir +~ a) $ set randGen g w
|
||||
where
|
||||
(a, g) = randomR (-acc,acc) $ _randGen w
|
||||
{- | Applies the effect to a randomly rotated creature. -}
|
||||
withRandomDirI
|
||||
:: Float -- ^ Max possible rotation
|
||||
-> (Item -> Creature -> World -> World)
|
||||
-- ^ Underlying effect
|
||||
-> Item
|
||||
-> Creature
|
||||
-> World
|
||||
-> World
|
||||
withRandomDirI acc f it cr w = f it (cr & crDir +~ a) $ set randGen g w
|
||||
where
|
||||
(a, g) = randomR (-acc,acc) $ _randGen w
|
||||
{- | Creates a bullet with a given velocity, width, and 'HitEffect' -}
|
||||
withVelWthHiteff
|
||||
:: Point2 -- ^ Velocity, x direction is forward with respect to the creature
|
||||
|
||||
Reference in New Issue
Block a user