Separate out ammo data
This commit is contained in:
@@ -1,25 +1,55 @@
|
||||
module Dodge.Projectile.Create where
|
||||
import Dodge.Data
|
||||
--import Dodge.Item.Weapon.Shell
|
||||
--import Dodge.Base.Collide
|
||||
--import Dodge.Base
|
||||
--import Dodge.Payload
|
||||
--import Dodge.SoundLogic
|
||||
--import Dodge.Movement.Turn
|
||||
--import Dodge.Item.Location
|
||||
import Dodge.Item.Location
|
||||
--import Dodge.EnergyBall
|
||||
--import Dodge.WorldEvent.Cloud
|
||||
--import LensHelp
|
||||
--import qualified IntMapHelp as IM
|
||||
--import Geometry
|
||||
import LensHelp
|
||||
import qualified IntMapHelp as IM
|
||||
import Geometry
|
||||
--import RandomHelp
|
||||
--
|
||||
|
||||
--import Data.Maybe
|
||||
|
||||
createProjectile :: ProjectileCreate -> Item -> Creature -> World -> World
|
||||
createProjectile pt = case pt of
|
||||
CreateShell -> undefined
|
||||
--CreateRemoteShell -> undefined
|
||||
CreateShell -> fireShell
|
||||
CreateTrackingShell -> fireTrackingShell
|
||||
|
||||
fireShell :: Item -> Creature -> World -> World
|
||||
fireShell it cr = makeShell it cr
|
||||
[ PJSpin 335 (_crID cr) spinamount
|
||||
, PJThrust (350 - thrustdelay) 0
|
||||
, PJReduceSpin (1-fromIntegral spindrag*2 / 200)
|
||||
]
|
||||
where
|
||||
params = _itParams it
|
||||
spindrag = _shellSpinDrag params
|
||||
spinamount = _shellSpinAmount params
|
||||
thrustdelay = _shellThrustDelay params
|
||||
makeShell :: Item -> Creature -> [ProjectileUpdate] -> World -> World
|
||||
makeShell it cr theupdate w = w & projectiles %~ IM.insert i Shell
|
||||
{ _prjPos = pos
|
||||
, _prjZ = 20
|
||||
, _prjStartPos = pos
|
||||
, _prjVel = rotateV dir (V2 1 0)
|
||||
, _prjDraw = DrawShell
|
||||
, _prjID = i
|
||||
, _prjAcc = rotateV dir (V2 3 0)
|
||||
, _prjDir = dir
|
||||
, _prjSpin = 0
|
||||
, _prjPayload = _amPayload $ _laAmmoType am
|
||||
, _prjTimer = 350
|
||||
, _prjUpdates = theupdate
|
||||
, _prjMITID = _itID it
|
||||
}
|
||||
where
|
||||
i = IM.newKey $ _props w
|
||||
dir = _crDir cr
|
||||
pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0)
|
||||
am = _itConsumption it
|
||||
|
||||
--fireShell :: Item -> Creature -> World -> World
|
||||
--fireShell it cr = makeShell it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
|
||||
@@ -159,3 +189,17 @@ createProjectile pt = case pt of
|
||||
-- | otherwise = id
|
||||
-- where
|
||||
-- t = _prjTimer pj
|
||||
fireTrackingShell :: Item -> Creature -> World -> World
|
||||
fireTrackingShell it cr w = addTrackRocket w'
|
||||
where
|
||||
(w',itid) = getHeldItemLoc cr w
|
||||
addTrackRocket = makeShell it cr
|
||||
[ PJSpin 335 (_crID cr) spinamount
|
||||
, PJTrack (350 - thrustdelay) 0 itid
|
||||
, PJThrust (350 - thrustdelay) 0
|
||||
, PJReduceSpin (1-fromIntegral spindrag*2 / 200)
|
||||
]
|
||||
spinamount = _shellSpinAmount params
|
||||
thrustdelay = _shellThrustDelay params
|
||||
spindrag = _shellSpinDrag params
|
||||
params = _itParams it
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user