82 lines
2.5 KiB
Haskell
82 lines
2.5 KiB
Haskell
module Dodge.Projectile.Create (
|
|
createShell,
|
|
PJStabiliser (..),
|
|
) where
|
|
|
|
import NewInt
|
|
--import Dodge.Data.ComposedItem
|
|
--import Dodge.Data.DoubleTree
|
|
import Dodge.Item.Location
|
|
import Data.Maybe
|
|
import Dodge.Data.World
|
|
import Geometry
|
|
import qualified IntMapHelp as IM
|
|
import LensHelp
|
|
|
|
data PJStabiliser
|
|
= StabOrthReduce
|
|
| StabSpinIncrease
|
|
|
|
|
|
-- assumes the mscreen is in your inventory
|
|
createShell ::Maybe (NewInt ItmInt)
|
|
-> Maybe (NewInt ItmInt)
|
|
-> Maybe PJStabiliser
|
|
-> ProjectileType
|
|
-> Payload -> Muzzle -> Creature -> World -> World
|
|
createShell mdetonator mscreen stab pjtype payload muz cr w = w
|
|
& updatescreen
|
|
& updatedetonator
|
|
& cWorld . lWorld . projectiles . at i
|
|
?~ Shell
|
|
{ _pjPos = pos
|
|
, _pjZ = 20
|
|
, _pjZVel = 5
|
|
, _pjVel = rotateV dir (V2 speed 0) + crvelcomponent
|
|
, _pjID = i
|
|
, _pjDir = dir
|
|
, _pjSpin = 0
|
|
, _pjPayload = payload
|
|
, _pjTimer = lifespan
|
|
, _pjUpdates =
|
|
anyspin <>
|
|
[ RemoteDirectionPU (lifespan - thrustdelay) 0
|
|
] <> thrustorgrav
|
|
, _pjType = pjtype
|
|
, _pjDetonatorID = mdetonator
|
|
, _pjScreenID = mscreen
|
|
}
|
|
where
|
|
crvelcomponent = case stab of
|
|
Just StabOrthReduce -> projV (cr ^. crPos - cr ^. crOldPos) (unitVectorAtAngle dir)
|
|
_ -> cr ^. crPos - cr ^. crOldPos
|
|
anyspin = case stab of
|
|
Just StabOrthReduce -> []
|
|
Just StabSpinIncrease -> [StartSpinPU (lifespan - 15) (_crID cr) 4]
|
|
_ -> [StartSpinPU (lifespan - 15) (_crID cr) 2]
|
|
speed = case pjtype of
|
|
Grenade {} -> 4
|
|
Rocket{} -> 1
|
|
RetiredProjectile -> 0
|
|
lifespan = 350
|
|
thrustorgrav = case pjtype of
|
|
Grenade {}-> [ApplyGravityPU]
|
|
Rocket{} -> [ThrustPU (lifespan - thrustdelay) 0]
|
|
RetiredProjectile -> []
|
|
thrustdelay = 20
|
|
updatedetonator = fromMaybe id $ do
|
|
screenid <- mdetonator
|
|
return $ pointerToItemID screenid . itUse . uaParams
|
|
. apProjectiles
|
|
.:~ i
|
|
updatescreen = fromMaybe id $ do
|
|
screenid <- mscreen
|
|
return $ pointerToItemID screenid . itUse . uaParams
|
|
. apProjectiles
|
|
.:~ i
|
|
-- . apLinkedProjectile
|
|
-- ?~ i
|
|
i = IM.newKey $ w ^. cWorld . lWorld . projectiles
|
|
dir = _crDir cr + _mzRot muz
|
|
pos = _crPos cr +.+ rotateV dir (_mzPos muz)
|