Work on rocket/grenade launcher

This commit is contained in:
2024-12-27 21:46:46 +00:00
parent 0ef28c132e
commit 5c749bff63
19 changed files with 400 additions and 324 deletions
+35 -18
View File
@@ -1,5 +1,5 @@
module Dodge.Projectile.Create (
createShell,
-- createShell,
createGShell,
) where
@@ -23,8 +23,10 @@ homingDrawType ht = case ht of
createShell :: ProjectileHoming
-> Maybe (NewInt ItmInt)
-> Maybe (NewInt ItmInt)
-> Bool
-> ProjectileType
-> Payload -> Muzzle -> Creature -> World -> World
createShell homing mdetonator mscreen payload muz cr w = w
createShell homing mdetonator mscreen smokestatus pjtype payload muz cr w = w
& updatescreen
& updatedetonator
& cWorld . lWorld . projectiles . at i
@@ -39,27 +41,30 @@ createShell homing mdetonator mscreen payload muz cr w = w
, _prjDir = dir
, _prjSpin = 0
, _prjPayload = payload
, _prjTimer = 350
, _prjTimer = lifespan
, _prjUpdates =
[ CollisionEffectPU (homing ^? phRemoteID) mdetonator mscreen
, TimePU
, StartSpinPU 335 (_crID cr) spinamount
, RemoteDirectionPU (350 - thrustdelay) 0 homing
, ThrustPU (350 - thrustdelay) 0
, RemoteDirectionPU (lifespan - thrustdelay) 0 homing
, ThrustPU (lifespan - thrustdelay) 0 smokestatus
, ReduceSpinPU (1 - spindrag * 2 / 200)
]
, _prjType = pjtype
}
where
lifespan = 350
spindrag = 1
spinamount = 2
thrustdelay = 20
updatedetonator = fromMaybe id $ do
screenid <- mdetonator
return $ pointerToItemID screenid . itUse . uaParams
. apLinkedProjectile
?~ i
. apProjectiles
.:~ i
updatescreen = fromMaybe id $ do
screenid <- homing ^? phRemoteID
--screenid <- homing ^? phRemoteID
screenid <- mscreen
return $ pointerToItemID screenid . itUse . uaParams
. apLinkedProjectile
?~ i
@@ -71,8 +76,10 @@ createShell homing mdetonator mscreen payload muz cr w = w
createGShell :: ProjectileHoming
-> Maybe (NewInt ItmInt)
-> Maybe (NewInt ItmInt)
-> Bool
-> ProjectileType
-> Payload -> Muzzle -> Creature -> World -> World
createGShell homing mdetonator mscreen payload muz cr w = w
createGShell homing mdetonator mscreen smokestatus pjtype payload muz cr w = w
& updatescreen
& updatedetonator
& cWorld . lWorld . projectiles . at i
@@ -80,34 +87,44 @@ createGShell homing mdetonator mscreen payload muz cr w = w
{ _prjPos = pos
, _prjZ = 20
, _prjZVel = 5
, _prjVel = rotateV dir (V2 4 0) + cr ^. crPos - cr ^. crOldPos
, _prjVel = rotateV dir (V2 speed 0) + cr ^. crPos - cr ^. crOldPos
, _prjDraw = homingDrawType homing
, _prjID = i
, _prjAcc = rotateV dir (V2 3 0)
, _prjDir = dir
, _prjSpin = 0
, _prjPayload = payload
, _prjTimer = 350
, _prjTimer = lifespan
, _prjUpdates =
[ CollisionEffectPU (homing ^? phRemoteID) mdetonator mscreen
, TimePU
, StartSpinPU 335 (_crID cr) spinamount
, RemoteDirectionPU (350 - thrustdelay) 0 homing
, StartSpinPU (lifespan - 15) (_crID cr) spinamount
, RemoteDirectionPU (lifespan - thrustdelay) 0 homing
, ReduceSpinPU (1 - spindrag * 2 / 200)
, ApplyGravityPU
]
] <> thrustorgrav
, _prjType = pjtype
}
where
speed = case pjtype of
Grenade -> 4
Rocket -> 1
lifespan = case pjtype of
Grenade -> 150
Rocket -> 350
thrustorgrav = case pjtype of
Grenade -> [ApplyGravityPU]
Rocket -> [ThrustPU (lifespan - thrustdelay) 0 smokestatus]
spindrag = 1
spinamount = 2
thrustdelay = 20
updatedetonator = fromMaybe id $ do
screenid <- mdetonator
return $ pointerToItemID screenid . itUse . uaParams
. apLinkedProjectile
?~ i
. apProjectiles
.:~ i
updatescreen = fromMaybe id $ do
screenid <- homing ^? phRemoteID
--screenid <- homing ^? phRemoteID
screenid <- mscreen
return $ pointerToItemID screenid . itUse . uaParams
. apLinkedProjectile
?~ i
+11 -8
View File
@@ -3,6 +3,7 @@ module Dodge.Projectile.Update (
updateProjectile,
) where
import Data.List (delete)
import LensHelp
import Control.Monad
import Data.Foldable
@@ -28,8 +29,8 @@ upProjectile pu pj = case pu of
CollisionEffectPU mcontrolid mdetonatorid mscreenid -> shellCollisionCheck
mcontrolid mdetonatorid mscreenid pj
TimePU -> decTimMvVel pj
ThrustPU st et
| act st et -> doThrust pj
ThrustPU st et smoke
| act st et -> doThrust pj smoke
| otherwise -> id
StartSpinPU t cid spinamount
| time == t -> trySpinByCID cid spinamount pj
@@ -100,20 +101,22 @@ destroyProjectile mitid pjid w =
guard $ itm == pjid
return $ pointerToItemLocation loc . itUse . uaParams . apLinkedProjectile .~ Nothing
doThrust :: Projectile -> World -> World
doThrust pj w =
doThrust :: Projectile -> Bool -> World -> World
doThrust pj smoke w =
w
& randGen .~ g
& cWorld . lWorld . projectiles . ix i . prjVel %~ (\v -> accel +.+ frict *.* v)
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& makeFlamelet (oldPos -.- vel) (vel +.+ rotateV (pi + sparkD) accel) 3 10
& shellTrailCloud
trailage
lifetime
trailfadetime
(addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)))
where
trailage = fst . randomR (300, 500) $ _randGen w
trailfadetime = fst . randomR (100, 300) $ _randGen w
lifetime = fst . randomR lt $ _randGen w
lt | smoke = (50, 200)
| otherwise = (300,500)
trailfadetime = fst . randomR (100,300) $ _randGen w
accel = _prjAcc pj
i = _prjID pj
oldPos = _prjPos pj
@@ -198,7 +201,7 @@ explodeShell controlid mdetid screenid pj w =
where
updatedetonator = fromMaybe id $ do
detid <- mdetid
return $ pointerToItemID detid . itUse . uaParams . apLinkedProjectile %~ deleteif
return $ pointerToItemID detid . itUse . uaParams . apProjectiles %~ delete pjid
deleteif (Just x) | x == pjid = Nothing
deleteif x = x
updatecontroller = fromMaybe id $ do