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
import Dodge.Default.Weapon import Dodge.Default.Weapon
import Dodge.Item.Weapon.InventoryDisplay import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Default.Shell
import Dodge.SoundLogic.LoadSound import Dodge.SoundLogic.LoadSound
import Dodge.WorldEvent.Explosion import Dodge.WorldEvent.Explosion
import Dodge.Item.Weapon.Shell import Dodge.Item.Weapon.Shell
@@ -20,7 +19,6 @@ import Dodge.SoundLogic
import Dodge.WorldEvent.SpawnParticle import Dodge.WorldEvent.SpawnParticle
import Dodge.WorldEvent.Cloud import Dodge.WorldEvent.Cloud
import Dodge.RandomHelp import Dodge.RandomHelp
import Dodge.Picture.Layer
import Geometry import Geometry
import Picture import Picture
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
@@ -41,10 +39,10 @@ launcher = defaultGun
{ _itName = "ROCKO" { _itName = "ROCKO"
, _itType = LAUNCHER , _itType = LAUNCHER
, _itConsumption = defaultAmmo , _itConsumption = defaultAmmo
{ _aoType = defaultShellAmmo { _aoType = ProjectileAmmo
{ _amPayload = makeExplosionAt { _amPayload = makeExplosionAt
, _amString = "EXPLOSIVE SHELL" , _amString = "EXPLOSIVE SHELL"
, _amPjDraw = shellPic , _amPjDraw = drawShell
} }
, _ammoBaseMax = 30 , _ammoBaseMax = 30
, _ammoLoaded = 30 , _ammoLoaded = 30
@@ -89,14 +87,6 @@ launcherPic _ =
, mempty , mempty
) )
defaultShellAmmo :: AmmoType
defaultShellAmmo = ProjectileAmmo
{ _amPayload = const id
, _amString = "Shell"
, _amPjDraw = const mempty
}
basicAmPjMoves :: IM.IntMap TweakParam basicAmPjMoves :: IM.IntMap TweakParam
basicAmPjMoves = IM.fromList . zip [0..] $ basicAmPjMoves = IM.fromList . zip [0..] $
[spinDrag [spinDrag
@@ -144,8 +134,6 @@ pjTrack itid i pj w = pjEffTimeRange (st,et) rotateToTarget pj w
pjpos = _pjPos pj pjpos = _pjPos pj
rotateToTarget _ = fromMaybe id $ do rotateToTarget _ = fromMaybe id $ do
tpos <- w ^? itPoint . itTargeting . tgPos . _Just 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)) return $ (props . ix (_pjID pj) . pjSpin .~ turnToAmount 0.15 pjpos tpos (argV $ _pjAcc pj))
itPoint = pointToItem $ _itemPositions w IM.! itid itPoint = pointToItem $ _itemPositions w IM.! itid
@@ -155,7 +143,7 @@ doThrust pj w = w
& props . ix i . pjVel %~ (\v -> accel +.+ frict *.* v) & props . ix i . pjVel %~ (\v -> accel +.+ frict *.* v)
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1) & soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& makeFlamelet (oldPos -.- vel) 0 (vel +.+ rotateV (pi+sparkD) accel) Nothing 3 10 & makeFlamelet (oldPos -.- vel) 0 (vel +.+ rotateV (pi+sparkD) accel) Nothing 3 10
& smokeGen & shellTrailCloud (addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)))
where where
accel = _pjAcc pj accel = _pjAcc pj
i = _pjID pj i = _pjID pj
@@ -165,41 +153,23 @@ doThrust pj w = w
(frict,g) = randomR (0.6,0.9) $ _randGen w (frict,g) = randomR (0.6,0.9) $ _randGen w
(sparkD,_) = randomR (-0.2,0.2) $ _randGen w (sparkD,_) = randomR (-0.2,0.2) $ _randGen w
r1 = randInCirc 10 & evalState $ _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 :: 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 where
am = _itConsumption it
i = IM.newKey $ _props w i = IM.newKey $ _props w
pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir)
dir = _crDir cr
params = _itParams it params = _itParams it
spindrag = _shellSpinDrag params spindrag = _shellSpinDrag params
spinamount = _shellSpinAmount params spinamount = _shellSpinAmount params
thrustdelay = _shellThrustDelay params thrustdelay = _shellThrustDelay params
theShell = defaultShell addShell = makeShell i it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
{ _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
. pjThrust thrustdelay pj . pjThrust thrustdelay pj
. reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj . reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj
. decTimMvVel pj . decTimMvVel pj
. moveShell pj . moveShell pj
, _pjPayload = _amPayload $ _aoType am
, _pjTimer = 50
}
moveShell moveShell :: Prop -- ^ Projectile id
:: Prop -- ^ Projectile id
-> World -> World
-> World -> World
moveShell pj w moveShell pj w
@@ -227,17 +197,30 @@ moveShell pj w
reduceSpinBy :: Float -> Prop -> World -> World reduceSpinBy :: Float -> Prop -> World -> World
reduceSpinBy x pj = props . ix (_pjID pj) . pjSpin *~ x reduceSpinBy x pj = props . ix (_pjID pj) . pjSpin *~ x
shellPic :: Prop -> SPic drawShell :: Prop -> SPic
shellPic pj = noPic $ translateSHz 18 . uncurryV translateSHf pos $ rotateSH (argV accel) basePic 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 where
basePic = colorSH black $ upperPrismPoly 4 $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)] col | t > (-99) = green
accel = _pjAcc pj | otherwise = red
pos = _pjPos pj t = _pjTimer pj
--shellPic pj = (,) mempty $ setDepth 20 . uncurryV translate pos $ rotate (argV accel) basePic doposition = translateSPz 18 . uncurryV translateSPf (_pjPos pj) . rotateSP (_pjDir pj)
-- where
-- basePic = color blackSH $ polygon $ map toV2 [(-6,4),(-6,-4),(6,-4),(8,0),(6,4)]
-- accel = _pjAcc pj
-- pos = _pjPos pj
pjEffTimeRange pjEffTimeRange
:: (Int,Int) :: (Int,Int)
@@ -283,58 +266,43 @@ trackingLauncher = launcher
, _itUse = ruseRate 10 fireTrackingLauncher upHammer , _itUse = ruseRate 10 fireTrackingLauncher upHammer
[ ammoCheckI [ ammoCheckI
, hammerCheckI , hammerCheckI
, useTimeCheck
, withSoundStart tap4S
, useAmmoAmount 1
] ]
& useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0.5
& useAim . aimStance .~ TwoHandTwist
} }
remoteLauncher :: Item remoteLauncher :: Item
remoteLauncher = launcher remoteLauncher = launcher
{ _itName = "ROCKO-REMOTE" { _itName = "ROCKO-REMOTE"
, _itType = REMOTELAUNCHER , _itType = REMOTELAUNCHER
, _itConsumption = defaultAmmo , _itUse = ruseRate 10 fireRemoteLauncher upHammer
{ _aoType = defaultShellAmmo
{ _amPayload = makeExplosionAt
, _amString = ""
, _amPjDraw = shellPic
}
, _ammoBaseMax = 30
, _ammoLoaded = 30
, _reloadTime = 80
}
, _itUse = ruseRate 10 (const fireRemoteLauncher) upHammer
[ ammoCheckI [ ammoCheckI
, hammerCheckI , hammerCheckI
, useTimeCheck
, withSoundStart tap4S
, useAmmoAmount 1
] ]
& useAim . aimSpeed .~ 0.2
& useAim . aimRange .~ 0.5
& useAim . aimStance .~ TwoHandTwist
, _itScope = RemoteScope (V2 0 0) 1 True , _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 :: Item -> Creature -> World -> World
fireRemoteLauncher cr w = setLocation fireRemoteLauncher it cr w = setLocation
$ resetFire $ resetFire
$ resetName $ resetName
$ soundStart (CrWeaponSound cid 0) pos tap4S Nothing
$ over props addRemRocket w $ over props addRemRocket w
where where
i = IM.newKey $ _props w i = IM.newKey $ _props w
cid = _crID cr cid = _crID cr
dir = _crDir cr addRemRocket = makeShell i it cr $ \pj ->
pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0) decTimMvVel pj . setRemoteScope itid pj . moveRemoteShell cid itid pj
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
}
j = _crInvSel cr j = _crInvSel cr
newitid = IM.newKey $ _itemPositions w newitid = IM.newKey $ _itemPositions w
maybeitid = cr ^? crInv . ix j . itID . _Just maybeitid = cr ^? crInv . ix j . itID . _Just
@@ -406,61 +374,21 @@ explodeRemoteRocket itid pjid w
resetName = set (itPoint . itName) "REMOTELAUNCHER" resetName = set (itPoint . itName) "REMOTELAUNCHER"
itPoint = pointToItem $ _itemPositions w IM.! itid 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 :: Int -> Int -> Int -> World -> World
retireRemoteRocket = retireRemoteProj $ const fireRemoteLauncher retireRemoteRocket = retireRemoteProj fireRemoteLauncher
fireTrackingLauncher :: Item -> Creature -> World -> World fireTrackingLauncher :: Item -> Creature -> World -> World
fireTrackingLauncher it cr w = setLocation fireTrackingLauncher it cr w = setLocation
$ soundStart (CrWeaponSound cid 0) pos tap4S Nothing
$ over props addTrackRocket w $ over props addTrackRocket w
where where
i = IM.newKey $ _props w i = IM.newKey $ _props w
am = _itConsumption it
cid = _crID cr cid = _crID cr
dir = _crDir cr addTrackRocket = makeShell i it cr $ \pj -> pjEffAtTime 35 (trySpinByCID (_crID cr) spinamount) pj
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
. pjThrust thrustdelay pj . pjThrust thrustdelay pj
. reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj . reduceSpinBy (1-fromIntegral spindrag*2 / 200) pj
. decTimMvVel pj . decTimMvVel pj
. pjTrack itid thrustdelay pj . pjTrack itid thrustdelay pj
. moveShell pj . moveShell pj
, _pjAcc = rotateV dir (V2 3 0)
, _pjDir = dir
, _pjSpin = 0
, _pjPayload = makeExplosionAt
, _pjTimer = 50
}
j = _crInvSel cr j = _crInvSel cr
newitid = IM.newKey $ _itemPositions w newitid = IM.newKey $ _itemPositions w
maybeitid = cr ^? crInv . ix j . itID . _Just maybeitid = cr ^? crInv . ix j . itID . _Just
@@ -474,3 +402,23 @@ fireTrackingLauncher it cr w = setLocation
thrustdelay = _shellThrustDelay params thrustdelay = _shellThrustDelay params
spindrag = _shellSpinDrag params spindrag = _shellSpinDrag params
params = _itParams it 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 module Dodge.Item.Weapon.Shell
( decTimMvVel ( decTimMvVel
) ) where
where
import Dodge.Data import Dodge.Data
import Geometry.Vector import Geometry.Vector
@@ -16,14 +15,3 @@ decTimMvVel pj = props . ix pjid %~
rot = _pjSpin pj rot = _pjSpin pj
vel = _pjVel pj vel = _pjVel pj
pjid = _pjID 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