Separate out concrete part of world

This commit is contained in:
2022-07-25 12:10:50 +01:00
parent 3354d108be
commit b2efbd2b3e
134 changed files with 933 additions and 930 deletions
+2 -2
View File
@@ -22,7 +22,7 @@ fireShell it cr = makeShell it cr
spinamount = _shellSpinAmount params
thrustdelay = _shellThrustDelay params
makeShell :: Item -> Creature -> [ProjectileUpdate] -> World -> World
makeShell it cr theupdate w = w & projectiles %~ IM.insert i Shell
makeShell it cr theupdate w = w & cWorld . projectiles %~ IM.insert i Shell
{ _prjPos = pos
, _prjZ = 20
, _prjStartPos = pos
@@ -38,7 +38,7 @@ makeShell it cr theupdate w = w & projectiles %~ IM.insert i Shell
, _prjMITID = _itID it
}
where
i = IM.newKey $ _props w
i = IM.newKey $ _props (_cWorld w)
dir = _crDir cr
pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0)
am = _itConsumption it
+19 -19
View File
@@ -46,7 +46,7 @@ updateRemoteShell pj w
doExplode = w
& usePayload (_prjPayload pj) oldPos
& stopSoundFrom (ShellSound i)
& projectiles %~ IM.delete i
& cWorld . projectiles %~ IM.delete i
i = _prjID pj
oldPos = _prjPos pj
vel = _prjVel pj
@@ -58,15 +58,15 @@ explodeRemoteRocket'
-> World
-> World
explodeRemoteRocket' mitid thepj w = w
& projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
& cWorld . projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
& usePayload (_prjPayload thepj) (_prjPos thepj)
& updateitem
where
updateitem = fromMaybe (projectiles . at pjid .~ Nothing) $ do
updateitem = fromMaybe (cWorld . projectiles . at pjid .~ Nothing) $ do
itid <- mitid
itpos <- w ^? itemPositions . ix itid
itpos <- w ^? cWorld . itemPositions . ix itid
return $ (pointToItem itpos . itUse . rUse .~ HeldDoNothing)
. (projectiles . ix pjid . prjUpdates .~ [PJRetireRemote itid 30 pjid])
. (cWorld . projectiles . ix pjid . prjUpdates .~ [PJRetireRemote itid 30 pjid])
pjid = _prjID thepj
updateShell :: Proj -> World -> World
@@ -82,7 +82,7 @@ updateShell pj w
doExplode = w
& usePayload (_prjPayload pj) oldPos
& stopSoundFrom (ShellSound i)
& projectiles %~ IM.delete i
& cWorld . projectiles %~ IM.delete i
i = _prjID pj
oldPos = _prjPos pj
vel = _prjVel pj
@@ -108,7 +108,7 @@ upProjectile pu pj = case pu of
| 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
PJRetireRemote _ _ pjid -> cWorld . projectiles . ix pjid . prjUpdates . ix 0 . pjuTimer -~ 1
where
time = _prjTimer pj
act st et = time <= st && time >= et
@@ -116,26 +116,26 @@ upProjectile pu pj = case pu of
retireRemoteProj'' :: Int -> Int -> World -> World
retireRemoteProj'' itid pjid w = w
& pointToItem (_itemPositions w IM.! itid) %~
& pointToItem (_itemPositions (_cWorld w) IM.! itid) %~
( (itScope . scopePos .~ V2 0 0)
. (itUse . rUse .~ HeldFireRemoteShell)
)
& props %~ IM.delete pjid
& cWorld . props %~ IM.delete pjid
setRemoteDir :: Int -> Int -> Proj -> World -> World
setRemoteDir cid itid pj w = w & projectiles . ix i . prjDir .~ newdir
setRemoteDir cid itid pj w = w & cWorld . projectiles . ix i . prjDir .~ newdir
where
i = _prjID pj
newdir
| SDL.ButtonRight `M.member` _mouseButtons w
&& w ^? creatures . ix cid . crInvSel . iselPos == w ^? itemPositions . ix itid . ipInvID
= _cameraRot w + argV (_mousePos w)
| SDL.ButtonRight `M.member` _mouseButtons (_cWorld w)
&& w ^? cWorld . creatures . ix cid . crInvSel . iselPos == w ^? cWorld . itemPositions . ix itid . ipInvID
= _cameraRot (_cWorld w) + argV (_mousePos (_cWorld w))
| otherwise = _prjDir pj
doThrust' :: Proj -> World -> World
doThrust' pj w = w
& randGen .~ g
& projectiles . ix i . prjVel %~ (\v -> accel +.+ frict *.* v)
& cWorld . projectiles . ix i . prjVel %~ (\v -> accel +.+ frict *.* v)
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& makeFlamelet (oldPos -.- vel) 0 (vel +.+ rotateV (pi+sparkD) accel) 3 10
& shellTrailCloud (addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)))
@@ -155,11 +155,11 @@ trySpinByCID'
-> Proj
-> World
-> World
trySpinByCID' cid i pj w = w & projectiles . ix pjid . prjSpin .~ newSpin
trySpinByCID' cid i pj w = w & cWorld . projectiles . ix pjid . prjSpin .~ newSpin
where
pjid = _prjID pj
dir = argV $ _prjVel pj
newSpin = case w ^? creatures . ix cid of
newSpin = case w ^? cWorld . creatures . ix cid of
Just cr -> negate $ min 0.2 $ max (-0.2) $ normalizeAnglePi (dir - _crDir cr) / spinFactor
_ -> 0
spinFactor = 5 * (6 - fromIntegral i)
@@ -169,9 +169,9 @@ pjTrack' itid pj w = rotateToTarget pj w
where
rotateToTarget _ = fromMaybe id $ do
tpos <- w ^? itPoint . itTargeting . tgPos . _Just
return $ projectiles . ix (_prjID pj) . prjSpin .~ turnToAmount 0.15 (_prjPos pj) tpos
return $ cWorld . projectiles . ix (_prjID pj) . prjSpin .~ turnToAmount 0.15 (_prjPos pj) tpos
(argV $ _prjAcc pj)
itPoint = pointToItem $ _itemPositions w IM.! itid
itPoint = pointToItem $ _itemPositions (_cWorld w) IM.! itid
reduceSpinBy' :: Float -> Proj -> World -> World
reduceSpinBy' x pj = projectiles . ix (_prjID pj) . prjSpin *~ x
reduceSpinBy' x pj = cWorld . projectiles . ix (_prjID pj) . prjSpin *~ x