Add ItEffect data as parameter to the effect itself
This commit is contained in:
@@ -3,7 +3,10 @@ module Dodge.Item.Weapon.Booster
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Geometry
|
||||
import IntMapHelp
|
||||
import qualified IntMapHelp as IM
|
||||
import Dodge.Picture.Layer
|
||||
import Picture
|
||||
import Dodge.Item.Attachment.Data
|
||||
|
||||
import Data.Maybe
|
||||
import Control.Lens
|
||||
@@ -22,13 +25,12 @@ boostPoint x cr w = case mayp2 of
|
||||
p1 = cpos +.+ x *.* normalizeV (mouseWorldPos w -.- cpos)
|
||||
mayp2 = reflectPointWalls cpos p1 $ wallsAlongLine cpos p1 w
|
||||
|
||||
boostSelf
|
||||
:: Maybe Int -- ^ shockwave projectile id
|
||||
-> Float -- ^ boost amount
|
||||
boostSelf
|
||||
:: Float -- ^ boost amount
|
||||
-> Creature
|
||||
-> World
|
||||
-> World
|
||||
boostSelf mpid x cr w = case boostPoint x cr w of
|
||||
boostSelf x cr w = case boostPoint x cr w of
|
||||
Left p -> wWithShock
|
||||
& creatures . ix cid %~ ( (crPos .~ p) . (crInv . ix (_crInvSel cr) . wpLoadedAmmo .~ 1))
|
||||
Right p -> wWithShock & creatures . ix cid . crPos .~ p
|
||||
@@ -36,8 +38,8 @@ boostSelf mpid x cr w = case boostPoint x cr w of
|
||||
cid = _crID cr
|
||||
cpos = _crPos cr
|
||||
r = _crRad cr
|
||||
pid = fromMaybe (newKey $ _projectiles w) mpid
|
||||
wWithShock = addBoostShockwave pid cpos (vNormal $ r *.* unitVectorAtAngle (_crDir cr)) w
|
||||
pid = fromMaybe (IM.newKey $ _projectiles w) (cr ^? crInv . ix (_crInvSel cr) . itAttachment . _Just . itInt)
|
||||
wWithShock = addBoostShockwave pid cpos (r *.* unitVectorAtAngle (_crDir cr)) w
|
||||
|
||||
addBoostShockwave
|
||||
:: Int
|
||||
@@ -45,5 +47,42 @@ addBoostShockwave
|
||||
-> Point2
|
||||
-> World
|
||||
-> World
|
||||
addBoostShockwave _ _ _ w = w
|
||||
addBoostShockwave pjid p v w = w & projectiles %~
|
||||
IM.insertWith f pjid thePJ
|
||||
where
|
||||
thePJ = LinearShockwave
|
||||
{ _pjDraw = drawBoostShockwave
|
||||
, _pjID = pjid
|
||||
, _pjUpdate = updateLinearShockwave
|
||||
, _pjPoints = [(p,v)]
|
||||
, _pjTimer = 10
|
||||
}
|
||||
f newVal oldVal = newVal & pjPoints %~ (++ _pjPoints oldVal)
|
||||
|
||||
updateLinearShockwave :: Projectile -> World -> World
|
||||
updateLinearShockwave pj w
|
||||
| t < 1 = w & projectiles %~ IM.delete pjid
|
||||
| otherwise = w & projectiles . ix (_pjID pj) . pjTimer -~ 1
|
||||
where
|
||||
pjid = _pjID pj
|
||||
t = _pjTimer pj
|
||||
|
||||
drawBoostShockwave :: Projectile -> Picture
|
||||
drawBoostShockwave pj = setLayer 1 $ onLayer UPtLayer $ color red $ pictures $
|
||||
[ line (map fst pvs)
|
||||
, line [(0,0),(0,200)]
|
||||
, uncurry translate (fst $ head pvs) $ circle 20
|
||||
]
|
||||
where
|
||||
pvs = _pjPoints pj
|
||||
t = _pjTimer pj
|
||||
xs = drop (10 - t) [1,1.2..]
|
||||
lps = zipWith f pvs xs
|
||||
rps = zipWith g pvs xs
|
||||
f (p,v) x = p -- +.+ x *.* vNormal v
|
||||
g (p,v) x = p -- -.- x *.* vNormal v
|
||||
|
||||
resetAttachmentID :: ItEffect
|
||||
resetAttachmentID = ItInvEffect f 0
|
||||
where
|
||||
f _ cr invid w = w
|
||||
|
||||
@@ -27,7 +27,7 @@ wpRecock = ItInvEffect
|
||||
,_itEffectCounter = 0
|
||||
}
|
||||
where
|
||||
f cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust fOnIt i
|
||||
f _ cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust fOnIt i
|
||||
moveHammerUp HammerDown = HammerReleased
|
||||
moveHammerUp HammerReleased = HammerUp
|
||||
moveHammerUp HammerUp = HammerUp
|
||||
@@ -42,7 +42,7 @@ bezierRecock = ItInvEffect
|
||||
,_itEffectCounter = 0
|
||||
}
|
||||
where
|
||||
f cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust fOnIt i
|
||||
f _ cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust fOnIt i
|
||||
fOnIt it = case _itHammer it of
|
||||
HammerDown -> it & itHammer .~ HammerUp
|
||||
_ -> it & itAttachment .~ Nothing
|
||||
@@ -55,7 +55,7 @@ itemLaserScopeEffect
|
||||
where
|
||||
moveHammerUp !HammerDown = HammerReleased
|
||||
moveHammerUp !_ = HammerUp
|
||||
f cr invid w
|
||||
f _ cr invid w
|
||||
| invid == _crInvSel cr = w
|
||||
& particles %~ (:) (makeLaserScope sp ep reloadFrac)
|
||||
& creatures . ix (_crID cr) . crInv . ix invid . itHammer %~ moveHammerUp
|
||||
@@ -83,11 +83,11 @@ Automatically send out radar pulses that detect walls. -}
|
||||
autoRadarEffect :: ItEffect
|
||||
autoRadarEffect = ItInvEffect {_itInvEffect = f 50 ,_itEffectCounter = 0 }
|
||||
where
|
||||
f :: Int -> Creature -> Int -> World -> World
|
||||
f 0 cr i w = aRadarPulse cr w
|
||||
f :: Int -> ItEffect -> Creature -> Int -> World -> World
|
||||
f 0 _ cr i w = aRadarPulse cr w
|
||||
& creatures . ix (_crID cr) . crInv . ix i
|
||||
. itEffect . itInvEffect .~ f 100
|
||||
f t cr i w = w
|
||||
f t _ cr i w = w
|
||||
& creatures . ix (_crID cr) . crInv . ix i
|
||||
. itEffect . itInvEffect .~ f (t-1)
|
||||
{- |
|
||||
@@ -95,11 +95,11 @@ Automatically send out sonar pulses that detect creatures. -}
|
||||
autoSonarEffect :: ItEffect
|
||||
autoSonarEffect = ItInvEffect {_itInvEffect = f 50 ,_itEffectCounter = 0 }
|
||||
where
|
||||
f :: Int -> Creature -> Int -> World -> World
|
||||
f 0 cr i w = aSonarPulse cr
|
||||
f :: Int -> ItEffect -> Creature -> Int -> World -> World
|
||||
f 0 _ cr i w = aSonarPulse cr
|
||||
w & creatures . ix (_crID cr) . crInv . ix i
|
||||
. itEffect . itInvEffect .~ f 140
|
||||
f t cr i w = w & creatures . ix (_crID cr) . crInv . ix i
|
||||
f t _ cr i w = w & creatures . ix (_crID cr) . crInv . ix i
|
||||
. itEffect . itInvEffect .~ f (t-1)
|
||||
|
||||
bezierTargetEffect :: ItEffect
|
||||
@@ -107,8 +107,8 @@ bezierTargetEffect = ItInvEffect
|
||||
{_itInvEffect = setBezierTarget
|
||||
,_itEffectCounter = 0
|
||||
}
|
||||
setBezierTarget :: Creature -> Int -> World -> World
|
||||
setBezierTarget cr invid w
|
||||
setBezierTarget :: ItEffect -> Creature -> Int -> World -> World
|
||||
setBezierTarget _ cr invid w
|
||||
| _crInvSel cr /= invid = w
|
||||
| SDL.ButtonRight `S.member` _mouseButtons w = w
|
||||
& creatures . ix (_crID cr) . crInv . ix invid . itAttachment
|
||||
|
||||
@@ -35,7 +35,7 @@ moveGrenade time dir pID w = case hitWl of
|
||||
$ set (projectiles .ix pID. pjDraw)
|
||||
(\ _ -> onLayer PtLayer $ uncurry translate newPos
|
||||
$ rotate dir $ grenadePic time)
|
||||
$ set (projectiles .ix pID.pjUpdate) (moveGrenade (time-1) dir pID) w
|
||||
$ set (projectiles .ix pID.pjUpdate) (\_ -> moveGrenade (time-1) dir pID) w
|
||||
pj = _projectiles w IM.! pID
|
||||
oldPos = _pjPos pj
|
||||
newPos = _pjVel pj +.+ oldPos
|
||||
@@ -69,7 +69,7 @@ throwGrenade explosion cr w = setWp $ removePict $ over projectiles addG w
|
||||
, _pjVel = v
|
||||
, _pjDraw = \_ -> onLayer PtLayer $ uncurry translate p $ grenadePic 0
|
||||
, _pjID = i
|
||||
, _pjUpdate = moveGrenade fuseTime dir i
|
||||
, _pjUpdate = \_ -> moveGrenade fuseTime dir i
|
||||
, _pjPayload = explosion
|
||||
}
|
||||
j = _crInvSel cr
|
||||
@@ -91,7 +91,7 @@ throwGrenade explosion cr w = setWp $ removePict $ over projectiles addG w
|
||||
throwArmReset :: Int -> ItEffect
|
||||
throwArmReset x = ItInvEffect {_itInvEffect = f ,_itEffectCounter = x }
|
||||
where
|
||||
f cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i
|
||||
f _ cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i
|
||||
counterDown it
|
||||
| _itEffectCounter (_itEffect it) == 0 = it
|
||||
& itHammer .~ HammerUp
|
||||
|
||||
@@ -128,7 +128,7 @@ tractorBeamAt colID i pos dir = Projectile
|
||||
, _pjVel = d
|
||||
, _pjDraw = \_ -> blank
|
||||
, _pjID = i
|
||||
, _pjUpdate = updateTractor colID 10 i
|
||||
, _pjUpdate = \_ -> updateTractor colID 10 i
|
||||
}
|
||||
where
|
||||
d = unitVectorAtAngle dir
|
||||
@@ -138,7 +138,7 @@ tractorBeamAt colID i pos dir = Projectile
|
||||
The interaction of this with objects, walls etc needs more thought. -}
|
||||
updateTractor :: Int -> Int -> Int -> World -> World
|
||||
updateTractor colID time i w
|
||||
| time > 0 = set (projectiles . ix i . pjUpdate) (updateTractor colID (time-1) i)
|
||||
| time > 0 = set (projectiles . ix i . pjUpdate) (\_ -> updateTractor colID (time-1) i)
|
||||
$ set (projectiles . ix i . pjDraw) (\_ -> pic)
|
||||
$ over creatures (IM.map tractCr)
|
||||
$ over floorItems (IM.map tractFlIt)
|
||||
|
||||
Reference in New Issue
Block a user