Add support for left click actions
This commit is contained in:
@@ -25,6 +25,39 @@ boostPoint x cr w = case mayp2 of
|
||||
p1 = cpos +.+ x *.* safeNormalizeV (mouseWorldPos w -.- cpos)
|
||||
mayp2 = reflectPointWalls cpos p1 $ wallsAlongLine cpos p1 w
|
||||
|
||||
boostSelfL
|
||||
:: Float -- ^ boost amount
|
||||
-> Creature
|
||||
-> Int -- ^ item inventory id
|
||||
-> World
|
||||
-> World
|
||||
boostSelfL x cr invid w = case boostPoint x cr w of
|
||||
Left p -> wWithShock p
|
||||
& creatures . ix cid %~
|
||||
( (crPos .~ p)
|
||||
. (crInv . ix invid %~
|
||||
(wpLoadedAmmo .~ 0)
|
||||
. (itEffect . itEffectCounter .~ 1)
|
||||
. (itAttachment .~ Just (ItInt pid))
|
||||
)
|
||||
)
|
||||
Right p -> wWithShock p & creatures . ix cid . crPos .~ p
|
||||
& creatures . ix cid %~
|
||||
( (crPos .~ p)
|
||||
. (crInv . ix invid %~
|
||||
(wpLoadedAmmo -~ 1)
|
||||
. (itEffect . itEffectCounter .~ 1)
|
||||
. (itAttachment .~ Just (ItInt pid))
|
||||
)
|
||||
)
|
||||
where
|
||||
cid = _crID cr
|
||||
--cpos = _crPos cr
|
||||
r = _crRad cr
|
||||
pid = fromMaybe (IM.newKey $ _projectiles w)
|
||||
(cr ^? crInv . ix invid . itAttachment . _Just . itInt)
|
||||
wWithShock p' = addBoostShockwave pid p' (r *.* unitVectorAtAngle (_crDir cr)) w
|
||||
|
||||
boostSelf
|
||||
:: Float -- ^ boost amount
|
||||
-> Creature
|
||||
@@ -51,7 +84,6 @@ boostSelf x cr w = case boostPoint x cr w of
|
||||
)
|
||||
where
|
||||
cid = _crID cr
|
||||
--cpos = _crPos cr
|
||||
r = _crRad cr
|
||||
pid = fromMaybe (IM.newKey $ _projectiles w)
|
||||
(cr ^? crInv . ix (_crInvSel cr) . itAttachment . _Just . itInt)
|
||||
|
||||
@@ -78,8 +78,7 @@ itemLaserScopeEffect
|
||||
| _wpLoadedAmmo it == 0 = 1
|
||||
| otherwise = fromIntegral (_wpReloadState it) / fromIntegral (_wpReloadTime it)
|
||||
col = mixColors reloadFrac (1-reloadFrac) red green
|
||||
{- |
|
||||
Automatically send out radar pulses that detect walls. -}
|
||||
{- | Automatically send out radar pulses that detect walls. -}
|
||||
autoRadarEffect :: ItEffect
|
||||
autoRadarEffect = ItInvEffect {_itInvEffect = f 50 ,_itEffectCounter = 0 }
|
||||
where
|
||||
@@ -90,28 +89,27 @@ autoRadarEffect = ItInvEffect {_itInvEffect = f 50 ,_itEffectCounter = 0 }
|
||||
f t _ cr i w = w
|
||||
& creatures . ix (_crID cr) . crInv . ix i
|
||||
. itEffect . itInvEffect .~ f (t-1)
|
||||
{- |
|
||||
Automatically send out sonar pulses that detect creatures. -}
|
||||
{- | Automatically send out sonar pulses that detect creatures. -}
|
||||
autoSonarEffect :: ItEffect
|
||||
autoSonarEffect = ItInvEffect {_itInvEffect = f 50 ,_itEffectCounter = 0 }
|
||||
where
|
||||
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
|
||||
. itEffect . itInvEffect .~ f (t-1)
|
||||
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 . itEffect . itInvEffect .~ f (t-1)
|
||||
|
||||
bezierTargetEffect :: ItEffect
|
||||
bezierTargetEffect = ItInvEffect
|
||||
{_itInvEffect = setBezierTarget
|
||||
rbSetTarget :: ItEffect
|
||||
rbSetTarget = ItInvEffect
|
||||
{_itInvEffect = setTarg
|
||||
,_itEffectCounter = 0
|
||||
}
|
||||
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
|
||||
%~ maybe (Just $ ItTargetPos $ mouseWorldPos w) Just
|
||||
| otherwise = w & creatures . ix (_crID cr) . crInv . ix invid . itAttachment .~ Nothing
|
||||
where
|
||||
setTarg :: ItEffect -> Creature -> Int -> World -> World
|
||||
setTarg _ cr invid w
|
||||
| _crInvSel cr /= invid = w
|
||||
| SDL.ButtonRight `S.member` _mouseButtons w = w
|
||||
& creatures . ix (_crID cr) . crInv . ix invid . itAttachment
|
||||
%~ maybe (Just $ ItTargetPos $ mouseWorldPos w) Just
|
||||
| otherwise = w & creatures . ix (_crID cr) . crInv . ix invid . itAttachment .~ Nothing
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import Dodge.Picture.Layer
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.Item.Attachment.Data
|
||||
import Dodge.Item.Draw
|
||||
import Dodge.Default.Shell
|
||||
--import Dodge.Default
|
||||
import Picture
|
||||
import Geometry
|
||||
@@ -63,7 +64,7 @@ throwGrenade
|
||||
throwGrenade explosion cr w = setWp $ removePict $ over projectiles addG w
|
||||
where
|
||||
n = _crID cr
|
||||
addG = IM.insert i $ Shell
|
||||
addG = IM.insert i $ defaultShell
|
||||
{ _pjPos = p
|
||||
, _pjStartPos = p
|
||||
, _pjVel = v
|
||||
|
||||
@@ -193,8 +193,7 @@ useTimeCheck f cr w = case theItem ^? itUseTime of
|
||||
setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUseTime +~ useRate
|
||||
theItem = _crInv cr IM.! _crInvSel cr
|
||||
useRate = fromMaybe 0 $ theItem ^? itUseRate
|
||||
{- |
|
||||
Applies a world effect after a hammer position check. -}
|
||||
{- | Applies a world effect after a hammer position check. -}
|
||||
hammerCheck
|
||||
:: (Creature -> World -> World) -- ^ Underlying effect
|
||||
-> Creature
|
||||
@@ -206,8 +205,7 @@ hammerCheck f cr w = case (_crInv cr IM.! _crInvSel cr) ^? itHammer of
|
||||
where
|
||||
cid = _crID cr
|
||||
setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itHammer .~ HammerDown
|
||||
{- |
|
||||
Applies a world effect after an ammo check. -}
|
||||
{- | Applies a world effect after an ammo check. -}
|
||||
shoot
|
||||
:: (Creature -> World -> World)
|
||||
-- ^ Underlying effect
|
||||
@@ -228,6 +226,42 @@ shoot f cr w
|
||||
&& _itUseTime item == 0
|
||||
&& _wpLoadedAmmo item > 0
|
||||
reloadCondition = _wpLoadedAmmo item == 0
|
||||
{- | Applies a world effect after a hammer position check.
|
||||
Arbitrary inventory position. -}
|
||||
hammerCheckL
|
||||
:: (Creature -> Int -> World -> World) -- ^ Underlying effect
|
||||
-> Creature
|
||||
-> Int
|
||||
-> World
|
||||
-> World
|
||||
hammerCheckL f cr invid w = case (_crInv cr IM.! invid) ^? itHammer of
|
||||
Just HammerUp -> f cr invid $ setHammerDown w
|
||||
_ -> setHammerDown w
|
||||
where
|
||||
cid = _crID cr
|
||||
setHammerDown = creatures . ix cid . crInv . ix invid . itHammer .~ HammerDown
|
||||
{- | Applies a world effect after an ammo check.
|
||||
Arbitrary inventory position. -}
|
||||
shootL
|
||||
:: (Creature -> Int -> World -> World)
|
||||
-- ^ Underlying effect
|
||||
-> Creature
|
||||
-> Int -- ^ Inventory position
|
||||
-> World
|
||||
-> World
|
||||
shootL f cr invid w
|
||||
| fireCondition = f cr invid w & pointerToItem %~
|
||||
( (wpLoadedAmmo -~ 1) . (itUseTime .~ _itUseRate item) )
|
||||
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
|
||||
| otherwise = w
|
||||
where
|
||||
cid = _crID cr
|
||||
item = _crInv cr IM.! invid
|
||||
pointerToItem = creatures . ix cid . crInv . ix invid
|
||||
fireCondition = _wpReloadState item == 0
|
||||
&& _itUseTime item == 0
|
||||
&& _wpLoadedAmmo item > 0
|
||||
reloadCondition = _wpLoadedAmmo item == 0
|
||||
|
||||
withMuzFlare
|
||||
:: (Creature -> World -> World) -- ^ Underlying effect
|
||||
|
||||
Reference in New Issue
Block a user