Separate out ammo data

This commit is contained in:
2022-07-20 15:01:01 +01:00
parent 8142899be1
commit 2755a4ffdd
14 changed files with 242 additions and 262 deletions
+49 -2
View File
@@ -1,5 +1,6 @@
{-# OPTIONS_GHC -Wno-unused-imports #-}
module Dodge.Projectile.Update where
import Dodge.Item.Weapon.Launcher
import Dodge.Data
import Dodge.Payload
import Dodge.Reloading.Action
@@ -30,7 +31,43 @@ import Control.Lens
updateProjectile :: Proj -> World -> World
updateProjectile pj = case pj of
Shell{} -> updateShell pj . decTimMvVel pj . upsProjectile pj
RemoteShell{} -> updateShell pj . decTimMvVel pj . upsProjectile pj
RemoteShell{} -> updateRemoteShell pj . decTimMvVel pj . upsProjectile pj
updateRemoteShell :: Proj -> World -> World
updateRemoteShell pj w
| time > 340 = if circOnSomeWall oldPos 4 w
then doExplode
else w
| anythingHitCirc 2 oldPos newPos w = doExplode
| time > 0 = w
| otherwise = doExplode
where
time = _prjTimer pj
doExplode = w
& usePayload (_prjPayload pj) oldPos
& stopSoundFrom (ShellSound i)
& projectiles %~ IM.delete i
i = _prjID pj
oldPos = _prjPos pj
vel = _prjVel pj
newPos = oldPos +.+ vel
explodeRemoteRocket'
:: Maybe Int -- ^ Item id
-> Proj
-> World
-> World
explodeRemoteRocket' mitid thepj w = w
& projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
& usePayload (_prjPayload thepj) (_prjPos thepj)
& updateitem
where
updateitem = fromMaybe (projectiles . at pjid .~ Nothing) $ do
itid <- mitid
itpos <- w ^? itemPositions . ix itid
return $ (pointToItem itpos . itUse . rUse .~ (\_ _ -> id))
. (projectiles . ix pjid . prjUpdates .~ [PJRetireRemote itid 30 pjid])
pjid = _prjID thepj
updateShell :: Proj -> World -> World
updateShell pj w
@@ -52,7 +89,7 @@ updateShell pj w
newPos = oldPos +.+ vel
upsProjectile :: Proj -> World -> World
upsProjectile pj w' = foldr (\pu -> upProjectile pu pj) w' (_prjUpdates pj)
upsProjectile pj w' = foldr (`upProjectile` pj) w' (_prjUpdates pj)
upProjectile :: ProjectileUpdate -> Proj -> World -> World
upProjectile pu pj = case pu of
@@ -70,11 +107,21 @@ upProjectile pu pj = case pu of
| act st et -> setRemoteDir cid itid pj
| otherwise -> id
PJSetScope itid -> setRemoteScope itid (_prjPos pj)
PJRetireRemote itid 0 pjid -> retireRemoteProj'' itid pjid
PJRetireRemote _ _ pjid -> projectiles . ix pjid . prjUpdates . ix 0 . pjuTimer -~ 1
where
time = _prjTimer pj
act st et = time <= st && time >= et
ain t = time == t
retireRemoteProj'' :: Int -> Int -> World -> World
retireRemoteProj'' itid pjid w = w
& pointToItem (_itemPositions w IM.! itid) %~
( (itScope . scopePos .~ V2 0 0)
. (itUse . rUse .~ fireRemoteShell)
)
& props %~ IM.delete pjid
setRemoteDir :: Int -> Int -> Proj -> World -> World
setRemoteDir cid itid pj w = w & projectiles . ix i . prjDir .~ newdir
where