Cleanup launcher code

This commit is contained in:
2022-03-01 20:16:41 +00:00
parent 910542a96a
commit a2ffeaa852
2 changed files with 73 additions and 137 deletions
+72 -124
View File
@@ -7,7 +7,6 @@ import Dodge.Data
import Dodge.Default
import Dodge.Default.Weapon
import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Default.Shell
import Dodge.SoundLogic.LoadSound
import Dodge.WorldEvent.Explosion
import Dodge.Item.Weapon.Shell
@@ -20,7 +19,6 @@ import Dodge.SoundLogic
import Dodge.WorldEvent.SpawnParticle
import Dodge.WorldEvent.Cloud
import Dodge.RandomHelp
import Dodge.Picture.Layer
import Geometry
import Picture
import qualified IntMapHelp as IM
@@ -41,10 +39,10 @@ launcher = defaultGun
{ _itName = "ROCKO"
, _itType = LAUNCHER
, _itConsumption = defaultAmmo
{ _aoType = defaultShellAmmo
{ _aoType = ProjectileAmmo
{ _amPayload = makeExplosionAt
, _amString = "EXPLOSIVE SHELL"
, _amPjDraw = shellPic
, _amPjDraw = drawShell
}
, _ammoBaseMax = 30
, _ammoLoaded = 30
@@ -89,14 +87,6 @@ launcherPic _ =
, mempty
)
defaultShellAmmo :: AmmoType
defaultShellAmmo = ProjectileAmmo
{ _amPayload = const id
, _amString = "Shell"
, _amPjDraw = const mempty
}
basicAmPjMoves :: IM.IntMap TweakParam
basicAmPjMoves = IM.fromList . zip [0..] $
[spinDrag
@@ -144,8 +134,6 @@ pjTrack itid i pj w = pjEffTimeRange (st,et) rotateToTarget pj w
pjpos = _pjPos pj
rotateToTarget _ = fromMaybe id $ do
tpos <- w ^? itPoint . itTargeting . tgPos . _Just
--let tdir = argV $ tpos -.- pjpos
--return $ props . ix (_pjID pj) . pjSpin .~ tdir - turnTo 0.1 pjpos tpos tdir
return $ (props . ix (_pjID pj) . pjSpin .~ turnToAmount 0.15 pjpos tpos (argV $ _pjAcc pj))
itPoint = pointToItem $ _itemPositions w IM.! itid
@@ -155,7 +143,7 @@ doThrust pj w = w
& props . ix i . pjVel %~ (\v -> accel +.+ frict *.* v)
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& makeFlamelet (oldPos -.- vel) 0 (vel +.+ rotateV (pi+sparkD) accel) Nothing 3 10
& smokeGen
& shellTrailCloud (addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)))
where
accel = _pjAcc pj
i = _pjID pj
@@ -165,41 +153,23 @@ doThrust pj w = w
(frict,g) = randomR (0.6,0.9) $ _randGen w
(sparkD,_) = randomR (-0.2,0.2) $ _randGen w
r1 = randInCirc 10 & evalState $ _randGen w
smokeGen = shellTrailCloud $ addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos))
--aPJtweakParams :: Prop -> Item -> Creature -> World -> World
--aPJtweakParams pr it cr w =
aRocketWithItemParams :: Item -> Creature -> World -> World
aRocketWithItemParams it cr w = over props (IM.insert i theShell) w
--aRocketWithItemParams it cr w = over props (IM.insert i theShell) w
aRocketWithItemParams it cr w = over props addShell w
where
am = _itConsumption it
i = IM.newKey $ _props w
pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir)
dir = _crDir cr
params = _itParams it
spindrag = _shellSpinDrag params
spinamount = _shellSpinAmount params
thrustdelay = _shellThrustDelay params
theShell = defaultShell
{ _pjPos = pos
, _pjStartPos = pos
, _pjVel = rotateV dir (V2 1 0)
, _pjAcc = rotateV dir (V2 3 0)
, _prDraw = _amPjDraw $ _aoType am
, _pjID = i
--, _pjUpdate = \pj -> ammoMvs pj . decTimMvVel pj . moveShell pj
, _pjUpdate = \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
addShell = makeShell i it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
. pjThrust thrustdelay pj
. reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj
. decTimMvVel pj
. moveShell pj
, _pjPayload = _amPayload $ _aoType am
, _pjTimer = 50
}
moveShell
:: Prop -- ^ Projectile id
moveShell :: Prop -- ^ Projectile id
-> World
-> World
moveShell pj w
@@ -227,17 +197,30 @@ moveShell pj w
reduceSpinBy :: Float -> Prop -> World -> World
reduceSpinBy x pj = props . ix (_pjID pj) . pjSpin *~ x
shellPic :: Prop -> SPic
shellPic pj = noPic $ translateSHz 18 . uncurryV translateSHf pos $ rotateSH (argV accel) basePic
drawShell :: Prop -> SPic
drawShell pj = noPic
. translateSHz 18
. uncurryV translateSHf (_pjPos pj)
$ rotateSH (argV $ _pjAcc pj) shellShape
shellShape :: Shape
shellShape = colorSH black $ upperPrismPoly 4 $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
remoteShellShape :: Color -> SPic
remoteShellShape col = (shellShape
, setLayer 1 . setDepth 4.5 . color col $ circleSolid 3
)
drawRemoteShell :: Prop -> SPic
drawRemoteShell pj
| rem (t+200) 20 < 9
= doposition $ noPic shellShape
| otherwise = doposition $ remoteShellShape col
where
basePic = colorSH black $ upperPrismPoly 4 $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
accel = _pjAcc pj
pos = _pjPos pj
--shellPic pj = (,) mempty $ setDepth 20 . uncurryV translate pos $ rotate (argV accel) basePic
-- where
-- basePic = color blackSH $ polygon $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
-- accel = _pjAcc pj
-- pos = _pjPos pj
col | t > (-99) = green
| otherwise = red
t = _pjTimer pj
doposition = translateSPz 18 . uncurryV translateSPf (_pjPos pj) . rotateSP (_pjDir pj)
pjEffTimeRange
:: (Int,Int)
@@ -283,58 +266,43 @@ trackingLauncher = launcher
, _itUse = ruseRate 10 fireTrackingLauncher upHammer
[ ammoCheckI
, hammerCheckI
, useTimeCheck
, withSoundStart tap4S
, useAmmoAmount 1
]
& useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0.5
& useAim . aimStance .~ TwoHandTwist
}
remoteLauncher :: Item
remoteLauncher = launcher
{ _itName = "ROCKO-REMOTE"
, _itType = REMOTELAUNCHER
, _itConsumption = defaultAmmo
{ _aoType = defaultShellAmmo
{ _amPayload = makeExplosionAt
, _amString = ""
, _amPjDraw = shellPic
}
, _ammoBaseMax = 30
, _ammoLoaded = 30
, _reloadTime = 80
}
, _itUse = ruseRate 10 (const fireRemoteLauncher) upHammer
, _itUse = ruseRate 10 fireRemoteLauncher upHammer
[ ammoCheckI
, hammerCheckI
, useTimeCheck
, withSoundStart tap4S
, useAmmoAmount 1
]
& useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0.5
& useAim . aimStance .~ TwoHandTwist
, _itScope = RemoteScope (V2 0 0) 1 True
-- , _itParams = ShellLauncher
-- { _tweakSel = 0
-- , _tweakParams = basicAmPjMoves -- TODO change to allow tweaking rocket speed
-- }
}
& itConsumption . aoType . amPjDraw .~ drawRemoteShell
-- TODO consider allowing tweaking rocket speed
fireRemoteLauncher :: Creature -> World -> World
fireRemoteLauncher cr w = setLocation
fireRemoteLauncher :: Item -> Creature -> World -> World
fireRemoteLauncher it cr w = setLocation
$ resetFire
$ resetName
$ soundStart (CrWeaponSound cid 0) pos tap4S Nothing
$ over props addRemRocket w
where
i = IM.newKey $ _props w
i = IM.newKey $ _props w
cid = _crID cr
dir = _crDir cr
pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0)
addRemRocket = IM.insert i $ Shell
{ _pjPos = pos
, _pjZ = 20
, _pjStartPos = pos
, _pjVel = rotateV dir (V2 1 0)
, _prDraw = remoteShellDraw
, _pjID = i
, _pjUpdate = \pj -> decTimMvVel pj . setRemoteScope itid pj . moveRemoteShell cid itid pj
, _pjAcc = V2 0 0
, _pjDir = dir
, _pjSpin = 0
, _pjPayload = makeExplosionAt
, _pjTimer = 50
}
addRemRocket = makeShell i it cr $ \pj ->
decTimMvVel pj . setRemoteScope itid pj . moveRemoteShell cid itid pj
j = _crInvSel cr
newitid = IM.newKey $ _itemPositions w
maybeitid = cr ^? crInv . ix j . itID . _Just
@@ -406,61 +374,21 @@ explodeRemoteRocket itid pjid w
resetName = set (itPoint . itName) "REMOTELAUNCHER"
itPoint = pointToItem $ _itemPositions w IM.! itid
remoteShellDraw :: Prop -> SPic
remoteShellDraw pj
| t > 40 = (,) mempty $ onLayerL [levLayer CrLayer - 2]
$ uncurryV translate pos $ rotate dir $ remoteShellPic t
| otherwise = (,) mempty $ uncurryV translate pos $ rotate dir $ remoteShellPic t
where
t = _pjTimer pj
pos = _pjPos pj
dir = _pjDir pj
remoteShellPic
:: Int -- ^ Timer
-> Picture
remoteShellPic t
| rem (t+200) 20 < 9 = setDepth 20 $ polygon $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
| otherwise = pictures
[ setDepth 20 $ polygon $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
, setLayer 1 . setDepth 20.5 . color col $ circleSolid 3
]
where
col | t > (-99) = green
| otherwise = red
retireRemoteRocket :: Int -> Int -> Int -> World -> World
retireRemoteRocket = retireRemoteProj $ const fireRemoteLauncher
retireRemoteRocket = retireRemoteProj fireRemoteLauncher
fireTrackingLauncher :: Item -> Creature -> World -> World
fireTrackingLauncher it cr w = setLocation
$ soundStart (CrWeaponSound cid 0) pos tap4S Nothing
$ over props addTrackRocket w
where
i = IM.newKey $ _props w
am = _itConsumption it
cid = _crID cr
dir = _crDir cr
pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0)
addTrackRocket = IM.insert i $ Shell
{ _pjPos = pos
, _pjZ = 20
, _pjStartPos = pos
, _pjVel = rotateV dir (V2 1 0)
, _prDraw = _amPjDraw $ _aoType am
, _pjID = i
, _pjUpdate = \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
addTrackRocket = makeShell i it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
. pjThrust thrustdelay pj
. reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj
. decTimMvVel pj
. pjTrack itid thrustdelay pj
. moveShell pj
, _pjAcc = rotateV dir (V2 3 0)
, _pjDir = dir
, _pjSpin = 0
, _pjPayload = makeExplosionAt
, _pjTimer = 50
}
j = _crInvSel cr
newitid = IM.newKey $ _itemPositions w
maybeitid = cr ^? crInv . ix j . itID . _Just
@@ -474,3 +402,23 @@ fireTrackingLauncher it cr w = setLocation
thrustdelay = _shellThrustDelay params
spindrag = _shellSpinDrag params
params = _itParams it
makeShell :: Int -> Item -> Creature -> (Prop -> World -> World) -> IM.IntMap Prop -> IM.IntMap Prop
makeShell i it cr theupdate = IM.insert i Shell
{ _pjPos = pos
, _pjZ = 20
, _pjStartPos = pos
, _pjVel = rotateV dir (V2 1 0)
, _prDraw = _amPjDraw $ _aoType am
, _pjID = i
, _pjUpdate = theupdate
, _pjAcc = rotateV dir (V2 3 0)
, _pjDir = dir
, _pjSpin = 0
, _pjPayload = _amPayload $ _aoType am
, _pjTimer = 50
}
where
dir = _crDir cr
pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0)
am = _itConsumption it
+1 -13
View File
@@ -1,7 +1,6 @@
module Dodge.Item.Weapon.Shell
( decTimMvVel
)
where
) where
import Dodge.Data
import Geometry.Vector
@@ -16,14 +15,3 @@ decTimMvVel pj = props . ix pjid %~
rot = _pjSpin pj
vel = _pjVel pj
pjid = _pjID pj
--pjAutoSpin :: Projectile -> World -> World
--pjAutoSpin pj = projectiles . ix pjid %~
-- ( (pjDir -~ 1)
-- . (pjPos %~ (+.+ vel) )
-- . (pjAcc %~ rotateV rot )
-- )
-- where
-- rot = _pjSpin pj
-- vel = _pjVel pj
-- pjid = _pjID pj