152 lines
4.7 KiB
Haskell
152 lines
4.7 KiB
Haskell
module Dodge.Item.Weapon.Grenade
|
|
( grenade
|
|
) where
|
|
import Dodge.Data
|
|
import Dodge.Picture.Layer
|
|
import Dodge.WorldEvent.Explosion
|
|
import Dodge.Item.Weapon.TriggerType
|
|
import Dodge.Default
|
|
import Dodge.Base
|
|
import Dodge.Zone
|
|
import Dodge.SoundLogic
|
|
import Dodge.Item.Draw
|
|
import Dodge.Item.Weapon.InventoryDisplay
|
|
import Dodge.Item.Weapon.ExtraEffect
|
|
import Dodge.Item.Attachment
|
|
import Picture
|
|
import Geometry
|
|
import ShapePicture
|
|
import Shape
|
|
|
|
import Control.Lens
|
|
import qualified Data.IntMap.Strict as IM
|
|
|
|
grenade :: Item
|
|
grenade = Throwable
|
|
{ _itName = "GRENADE " ++ show fuseTime
|
|
, _itCurseStatus = Uncursed
|
|
, _itIdentity = Grenade
|
|
, _itMaxStack = 8
|
|
, _itAmount = 1
|
|
, _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
|
|
, _twMaxRange = 150
|
|
, _twAccuracy = 30
|
|
, _itUse = \_ -> throwGrenade makeExplosionAt
|
|
, _itUseModifiers =
|
|
[ useTimeCheckI
|
|
]
|
|
, _itAimingSpeed = 1
|
|
, _itAimingRange = 0
|
|
, _itZoom = defaultItZoom
|
|
, _itAimZoom = defaultItZoom {_itZoomMax = f fuseTime, _itZoomMin = f fuseTime}
|
|
, _itEquipPict = pictureWeaponOnAim' $ \_ -> grenadePic fuseTime
|
|
, _itID = Nothing
|
|
, _itUseRate = 25
|
|
, _itUseTime = 0
|
|
, _itAttachment = ItFuse fuseTime
|
|
, _itInvColor = white
|
|
, _itInvDisplay = basicWeaponDisplay
|
|
, _itEffect = wpRecock
|
|
, _itHammer = HammerUp
|
|
, _itScroll = changeFuse
|
|
, _itAimStance = OneHand
|
|
}
|
|
where
|
|
fuseTime = 50
|
|
f x = 50 / fromIntegral x
|
|
|
|
moveGrenade :: Prop -> World -> World
|
|
moveGrenade pj w
|
|
| _pjTimer pj <= 0 = w
|
|
& props %~ IM.delete pID
|
|
& _pjPayload pj (_pjPos (_props w IM.! pID))
|
|
| otherwise = case collideCircWalls oldPos newPos 4 $ wallsNearPoint newPos w of
|
|
Nothing -> w & props . ix pID %~ normalUpdate
|
|
Just (p,v) -> w
|
|
& soundStart (Tap 0) p tapQuietS Nothing
|
|
& props . ix pID %~ ( ( pjPos .~ p ) . ( pjTimer -~ 1 ) . (pjVel .~ v) )
|
|
where
|
|
pID = _pjID pj
|
|
normalUpdate = (pjTimer -~ 1)
|
|
. (pjZ %~ (max 0 . (+ _pjVelZ pj)))
|
|
. (pjVelZ -~ 0.1)
|
|
. ( pjPos .~ newPos )
|
|
oldPos = _pjPos pj
|
|
newPos = _pjVel pj +.+ oldPos
|
|
|
|
grenadePic :: Int -> SPic
|
|
grenadePic time =
|
|
( colorSH (dark $ dark green) $ upperPrismPolyHalf 5 $ polyCirc 3 5
|
|
, pictures
|
|
[ color green $ arc (degToRad $ (179 * fromIntegral time / 50) - 180 )
|
|
(degToRad $ 180 - (179 * fromIntegral time / 50) )
|
|
5
|
|
]
|
|
)
|
|
|
|
grenadeDraw :: Float -> Prop -> SPic
|
|
grenadeDraw dir prop = translateSPz z $ uncurryV translateSPf p $ rotateSP dir $ grenadePic time
|
|
where
|
|
p = _pjPos prop
|
|
time = _pjTimer prop
|
|
z = _pjZ prop
|
|
|
|
throwGrenade
|
|
:: (Point2 -> World -> World) -- ^ Payload
|
|
-> Creature
|
|
-> World
|
|
-> World
|
|
throwGrenade thePayload cr w = setWp $ removePict $ over props addG w
|
|
where
|
|
n = _crID cr
|
|
addG = IM.insert i $ Bomb
|
|
{ _pjPos = p
|
|
, _pjZ = 10
|
|
, _pjVelZ = 2
|
|
, _pjVel = v
|
|
, _prDraw = grenadeDraw dir
|
|
, _pjID = i
|
|
, _pjUpdate = moveGrenade
|
|
, _pjPayload = thePayload
|
|
, _pjTimer = fuseTime
|
|
}
|
|
j = _crInvSel cr
|
|
removePict = set (creatures . ix n . crInv . ix j . itEquipPict) $ \ _ _ -> (,) emptySH blank
|
|
i = newProjectileKey w
|
|
v' = 1 / (fromIntegral fuseTime * _cameraZoom w) *.* rotateV (_cameraRot w) ( _mousePos w)
|
|
v | magV v' > 6 = 6 *.* normalizeV v'
|
|
| otherwise = v'
|
|
p' = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr) 0)
|
|
p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr-4) 0)
|
|
| otherwise = p'
|
|
dir = argV v
|
|
setWp :: World -> World
|
|
setWp w' = w' & creatures . ix n . crInv . ix j . itEffect .~ throwArmReset 20
|
|
fuseTime = _itFuseTime $ _itAttachment $ _crInv cr IM.! j
|
|
|
|
throwArmReset :: Int -> ItEffect
|
|
throwArmReset x = ItInvEffect {_itInvEffect = f ,_itEffectCounter = x }
|
|
where
|
|
f _ cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i
|
|
counterDown it
|
|
| _itEffectCounter (_itEffect it) == 0 = it
|
|
& itHammer .~ HammerUp
|
|
& itEquipPict .~ pictureWeaponOnAim' (\_ -> grenadePic 50)
|
|
| otherwise = it & itEffect . itEffectCounter -~ 1
|
|
|
|
--flameGrenade :: Item
|
|
--flameGrenade = grenade {
|
|
-- _itName = "FLMGREN " ++ show fuseTime
|
|
-- , _itUse = \_ -> throwGrenade makeFlameExplosionAt
|
|
-- }
|
|
-- where
|
|
-- fuseTime = 50 :: Int
|
|
--
|
|
--teslaGrenade :: Item
|
|
--teslaGrenade = grenade {
|
|
-- _itName = "TLSGREN " ++ show fuseTime
|
|
-- , _itUse = \_ -> throwGrenade makeTeslaExplosionAt
|
|
-- }
|
|
-- where
|
|
-- fuseTime = 50 :: Int
|