Cleanup
This commit is contained in:
+103
-86
@@ -1,32 +1,33 @@
|
||||
{-# OPTIONS_GHC -Wno-unused-imports #-}
|
||||
|
||||
module Dodge.Projectile.Update where
|
||||
import Dodge.Item.Weapon.Launcher
|
||||
|
||||
--import qualified Data.Set as S
|
||||
|
||||
import Control.Lens
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Base
|
||||
import Dodge.Data
|
||||
import Dodge.Payload
|
||||
import Dodge.Reloading.Action
|
||||
import Dodge.EnergyBall
|
||||
import Dodge.Default.Weapon
|
||||
import Dodge.EnergyBall
|
||||
import Dodge.Item.Location
|
||||
import Dodge.SoundLogic.LoadSound
|
||||
import Dodge.Item.Weapon.Shell
|
||||
import Dodge.Item.Weapon.Launcher
|
||||
import Dodge.Item.Weapon.Remote
|
||||
import Dodge.Item.Weapon.Shell
|
||||
import Dodge.Item.Weapon.TriggerType
|
||||
import Dodge.Movement.Turn
|
||||
import Dodge.Base
|
||||
import Dodge.Zone
|
||||
import Dodge.Payload
|
||||
import Dodge.Reloading.Action
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.SoundLogic.LoadSound
|
||||
import Dodge.WorldEvent.Cloud
|
||||
import RandomHelp
|
||||
import Dodge.Zone
|
||||
import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
import qualified Streaming.Prelude as S
|
||||
--import qualified Data.Set as S
|
||||
import qualified Data.Map.Strict as M
|
||||
import RandomHelp
|
||||
import qualified SDL
|
||||
import Data.Maybe
|
||||
import Control.Lens
|
||||
|
||||
import qualified Streaming.Prelude as S
|
||||
|
||||
updateProjectile :: Proj -> World -> World
|
||||
updateProjectile pj = case pj of
|
||||
@@ -35,65 +36,72 @@ updateProjectile pj = case pj of
|
||||
|
||||
updateRemoteShell :: Proj -> World -> World
|
||||
updateRemoteShell pj w
|
||||
| time > 340 = if circOnSomeWall oldPos 4 w
|
||||
then doExplode
|
||||
else w
|
||||
| time > 340 =
|
||||
if circOnSomeWall oldPos 4 w
|
||||
then doExplode
|
||||
else w
|
||||
| anythingHitCirc 2 oldPos newPos w = doExplode
|
||||
| time > 0 = w
|
||||
| otherwise = doExplode
|
||||
where
|
||||
where
|
||||
time = _prjTimer pj
|
||||
doExplode = w
|
||||
& usePayload (_prjPayload pj) oldPos
|
||||
& stopSoundFrom (ShellSound i)
|
||||
& cWorld . projectiles %~ IM.delete i
|
||||
doExplode =
|
||||
w
|
||||
& usePayload (_prjPayload pj) oldPos
|
||||
& stopSoundFrom (ShellSound i)
|
||||
& cWorld . projectiles %~ IM.delete i
|
||||
i = _prjID pj
|
||||
oldPos = _prjPos pj
|
||||
vel = _prjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
oldPos = _prjPos pj
|
||||
vel = _prjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
|
||||
explodeRemoteRocket'
|
||||
:: Maybe Int -- ^ Item id
|
||||
-> Proj
|
||||
-> World
|
||||
-> World
|
||||
explodeRemoteRocket' mitid thepj w = w
|
||||
& cWorld . projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
|
||||
& usePayload (_prjPayload thepj) (_prjPos thepj)
|
||||
& updateitem
|
||||
where
|
||||
explodeRemoteRocket' ::
|
||||
-- | Item id
|
||||
Maybe Int ->
|
||||
Proj ->
|
||||
World ->
|
||||
World
|
||||
explodeRemoteRocket' mitid thepj w =
|
||||
w
|
||||
& cWorld . projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
|
||||
& usePayload (_prjPayload thepj) (_prjPos thepj)
|
||||
& updateitem
|
||||
where
|
||||
updateitem = fromMaybe (cWorld . projectiles . at pjid .~ Nothing) $ do
|
||||
itid <- mitid
|
||||
itpos <- w ^? cWorld . itemPositions . ix itid
|
||||
return $ (pointToItem itpos . itUse . rUse .~ HeldDoNothing)
|
||||
. (cWorld . projectiles . ix pjid . prjUpdates .~ [PJRetireRemote itid 30 pjid])
|
||||
return $
|
||||
(pointerToItem itpos . itUse . rUse .~ HeldDoNothing)
|
||||
. (cWorld . projectiles . ix pjid . prjUpdates .~ [PJRetireRemote itid 30 pjid])
|
||||
pjid = _prjID thepj
|
||||
|
||||
updateShell :: Proj -> World -> World
|
||||
updateShell pj w
|
||||
| time > 340 = if circOnSomeWall oldPos 4 w
|
||||
then doExplode
|
||||
else w
|
||||
| time > 340 =
|
||||
if circOnSomeWall oldPos 4 w
|
||||
then doExplode
|
||||
else w
|
||||
| anythingHitCirc 2 oldPos newPos w = doExplode
|
||||
| time > 0 = w
|
||||
| otherwise = doExplode
|
||||
where
|
||||
where
|
||||
time = _prjTimer pj
|
||||
doExplode = w
|
||||
& usePayload (_prjPayload pj) oldPos
|
||||
& stopSoundFrom (ShellSound i)
|
||||
& cWorld . projectiles %~ IM.delete i
|
||||
doExplode =
|
||||
w
|
||||
& usePayload (_prjPayload pj) oldPos
|
||||
& stopSoundFrom (ShellSound i)
|
||||
& cWorld . projectiles %~ IM.delete i
|
||||
i = _prjID pj
|
||||
oldPos = _prjPos pj
|
||||
vel = _prjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
oldPos = _prjPos pj
|
||||
vel = _prjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
|
||||
upsProjectile :: Proj -> World -> World
|
||||
upsProjectile pj w' = foldr (`upProjectile` pj) w' (_prjUpdates pj)
|
||||
|
||||
upProjectile :: ProjectileUpdate -> Proj -> World -> World
|
||||
upProjectile pu pj = case pu of
|
||||
PJThrust st et
|
||||
PJThrust st et
|
||||
| act st et -> doThrust' pj
|
||||
| otherwise -> id
|
||||
PJSpin t cid spinamount
|
||||
@@ -115,52 +123,56 @@ upProjectile pu pj = case pu of
|
||||
ain t = time == t
|
||||
|
||||
retireRemoteProj'' :: Int -> Int -> World -> World
|
||||
retireRemoteProj'' itid pjid w = w
|
||||
& pointToItem (_itemPositions (_cWorld w) IM.! itid) %~
|
||||
( (itScope . scopePos .~ V2 0 0)
|
||||
. (itUse . rUse .~ HeldFireRemoteShell)
|
||||
)
|
||||
& cWorld . props %~ IM.delete pjid
|
||||
retireRemoteProj'' itid pjid w =
|
||||
w
|
||||
& pointerToItem (_itemPositions (_cWorld w) IM.! itid)
|
||||
%~ ( (itScope . scopePos .~ V2 0 0)
|
||||
. (itUse . rUse .~ HeldFireRemoteShell)
|
||||
)
|
||||
& cWorld . props %~ IM.delete pjid
|
||||
|
||||
setRemoteDir :: Int -> Int -> Proj -> World -> World
|
||||
setRemoteDir cid itid pj w = w & cWorld . projectiles . ix (_prjID pj) . prjDir .~ newdir
|
||||
where
|
||||
--i = _prjID pj
|
||||
newdir
|
||||
newdir
|
||||
| SDL.ButtonRight `M.member` _mouseButtons w
|
||||
&& w ^? cWorld . creatures . ix cid . crInvSel . iselPos
|
||||
== w ^? cWorld . itemPositions . ix itid . ipInvID
|
||||
= _cameraRot (_cWorld w) + argV (_mousePos w)
|
||||
&& w ^? cWorld . creatures . ix cid . crInvSel . iselPos
|
||||
== w ^? cWorld . itemPositions . ix itid . ipInvID =
|
||||
_cameraRot (_cWorld w) + argV (_mousePos w)
|
||||
| otherwise = _prjDir pj
|
||||
|
||||
doThrust' :: Proj -> World -> World
|
||||
doThrust' pj w = w
|
||||
& randGen .~ g
|
||||
& 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)))
|
||||
doThrust' pj w =
|
||||
w
|
||||
& randGen .~ g
|
||||
& 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)))
|
||||
where
|
||||
accel = _prjAcc pj
|
||||
i = _prjID pj
|
||||
oldPos = _prjPos pj
|
||||
vel = _prjVel pj
|
||||
newPos = oldPos +.+ vel
|
||||
(frict,g) = randomR (0.6,0.9) $ _randGen w
|
||||
(sparkD,_) = randomR (-0.2,0.2) $ _randGen w
|
||||
accel = _prjAcc pj
|
||||
i = _prjID pj
|
||||
oldPos = _prjPos pj
|
||||
vel = _prjVel 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
|
||||
|
||||
trySpinByCID'
|
||||
:: Int -- ^ creature id
|
||||
-> Int -- ^ Spin amount
|
||||
-> Proj
|
||||
-> World
|
||||
-> World
|
||||
trySpinByCID' ::
|
||||
-- | creature id
|
||||
Int ->
|
||||
-- | Spin amount
|
||||
Int ->
|
||||
Proj ->
|
||||
World ->
|
||||
World
|
||||
trySpinByCID' cid i pj w = w & cWorld . projectiles . ix pjid . prjSpin .~ newSpin
|
||||
where
|
||||
pjid = _prjID pj
|
||||
dir = argV $ _prjVel pj
|
||||
newSpin = case w ^? cWorld . creatures . ix cid of
|
||||
dir = argV $ _prjVel pj
|
||||
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)
|
||||
@@ -170,9 +182,14 @@ pjTrack' itid pj w = rotateToTarget pj w
|
||||
where
|
||||
rotateToTarget _ = fromMaybe id $ do
|
||||
tpos <- w ^? itPoint . itTargeting . tgPos . _Just
|
||||
return $ cWorld . projectiles . ix (_prjID pj) . prjSpin .~ turnToAmount 0.15 (_prjPos pj) tpos
|
||||
(argV $ _prjAcc pj)
|
||||
itPoint = pointToItem $ _itemPositions (_cWorld w) IM.! itid
|
||||
return $
|
||||
cWorld . projectiles . ix (_prjID pj) . prjSpin
|
||||
.~ turnToAmount
|
||||
0.15
|
||||
(_prjPos pj)
|
||||
tpos
|
||||
(argV $ _prjAcc pj)
|
||||
itPoint = pointerToItem $ _itemPositions (_cWorld w) IM.! itid
|
||||
|
||||
reduceSpinBy' :: Float -> Proj -> World -> World
|
||||
reduceSpinBy' x pj = cWorld . projectiles . ix (_prjID pj) . prjSpin *~ x
|
||||
reduceSpinBy' x pj = cWorld . projectiles . ix (_prjID pj) . prjSpin *~ x
|
||||
|
||||
Reference in New Issue
Block a user