Add blurring of lightmap (and refactoring)
This commit is contained in:
+5
-112
@@ -9,6 +9,7 @@ module Dodge.Item.Weapon
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Picture.Layer
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.Creature.Action
|
||||
import Dodge.RandomHelp
|
||||
@@ -22,6 +23,7 @@ import Dodge.Item.Weapon.TriggerType
|
||||
import Dodge.Item.Weapon.ExtraEffect
|
||||
import Dodge.Item.Weapon.UseEffect
|
||||
import Dodge.Item.Weapon.Laser
|
||||
import Dodge.Item.Weapon.Grenade
|
||||
import Dodge.Item.Attachment.Data
|
||||
import Dodge.Item.Attachment
|
||||
import Geometry
|
||||
@@ -761,33 +763,6 @@ aSelf = blinkAction
|
||||
reflect :: Float -> Float -> Float
|
||||
reflect a b = a + 2*(a-b)
|
||||
|
||||
moveGrenade
|
||||
:: Int -- ^ Timer
|
||||
-> Float -- ^ Direction
|
||||
-> Int -- ^ Projectile id
|
||||
-> World -> World
|
||||
moveGrenade 0 dir pID w = over projectiles (IM.delete pID)
|
||||
$ explosion (_pjPos (_projectiles w IM.! pID))
|
||||
w
|
||||
where
|
||||
pj = _projectiles w IM.! pID
|
||||
explosion = _pjPayload pj
|
||||
moveGrenade time dir pID w = case hitWl of
|
||||
Just _ -> soundOnce (fromIntegral tapQuiet) updatedWorld
|
||||
_ -> updatedWorld
|
||||
where
|
||||
updatedWorld = updateV $ set (projectiles . ix pID . pjPos) finalPos
|
||||
$ set (projectiles .ix pID.pjPict)
|
||||
(onLayer PtLayer $ uncurry translate newPos
|
||||
$ rotate dir $ grenadePic time)
|
||||
$ set (projectiles .ix pID.pjUpdate) (moveGrenade (time-1) dir pID) w
|
||||
pj = _projectiles w IM.! pID
|
||||
oldPos = _pjPos pj
|
||||
newPos = _pjVel pj +.+ oldPos
|
||||
hitWl = collideCircWalls' oldPos newPos 4 $ wallsNearPoint newPos w
|
||||
finalPos = maybe newPos fst hitWl
|
||||
setV v = set (projectiles .ix pID.pjVel) v
|
||||
updateV = maybe id (setV . snd) hitWl
|
||||
|
||||
pointToItem (InInv cid invid) = creatures . ix cid . crInv . ix invid
|
||||
pointToItem (OnFloor flid) = floorItems . ix flid . flIt
|
||||
@@ -882,7 +857,7 @@ grenade = Throwable
|
||||
, _itFloorPict = onLayer FlItLayer $ polygon [(-3,-3),(-3,3),(3,3),(3,-3)]
|
||||
, _twMaxRange = 150
|
||||
, _twAccuracy = 30
|
||||
, _twFire = useTimeCheck $ throwGrenade makeExplosionAt fuseTime
|
||||
, _twFire = useTimeCheck $ throwGrenade makeExplosionAt
|
||||
, _itAimingSpeed = 1
|
||||
, _itAimingRange = 0
|
||||
, _itZoom = defaultItZoom {_itAimZoomMax = f fuseTime, _itAimZoomMin = f fuseTime}
|
||||
@@ -905,7 +880,7 @@ grenade = Throwable
|
||||
flameGrenade :: Item
|
||||
flameGrenade = grenade {
|
||||
_itName = "FLMGREN " ++ show fuseTime
|
||||
, _twFire = throwGrenade makeFlameExplosionAt fuseTime
|
||||
, _twFire = throwGrenade makeFlameExplosionAt
|
||||
}
|
||||
where
|
||||
fuseTime = 50
|
||||
@@ -914,45 +889,12 @@ flameGrenade = grenade {
|
||||
teslaGrenade :: Item
|
||||
teslaGrenade = grenade {
|
||||
_itName = "TLSGREN " ++ show fuseTime
|
||||
, _twFire = throwGrenade makeTeslaExplosionAt fuseTime
|
||||
, _twFire = throwGrenade makeTeslaExplosionAt
|
||||
}
|
||||
where
|
||||
fuseTime = 50
|
||||
f x = 50 / fromIntegral x
|
||||
|
||||
increaseFuse
|
||||
:: Int -- ^ Old fuse time
|
||||
-> Int -- ^ Inventory item reference (I believe)
|
||||
-> World
|
||||
-> World
|
||||
increaseFuse fuse i w = w
|
||||
& creatures . ix 0 . crInv . ix itRef . itScrollUp .~ decreaseFuse newTime
|
||||
& creatures . ix 0 . crInv . ix itRef . itScrollDown .~ increaseFuse newTime
|
||||
& creatures . ix 0 . crInv . ix itRef . itName .~ "GRENADE " ++ show newTime
|
||||
& creatures . ix 0 . crInv . ix itRef . itAttachment ?~ ItFuse newTime
|
||||
& creatures . ix 0 . crInv . ix itRef . itZoom
|
||||
.~ (defaultItZoom {_itAimZoomMax = zm, _itAimZoomMin = zm})
|
||||
where
|
||||
itRef = fromMaybe (-2) $ w ^? creatures . ix 0 . crInvSel
|
||||
newTime = min (fuse + 5) 90
|
||||
zm = 50 / fromIntegral newTime
|
||||
|
||||
decreaseFuse
|
||||
:: Int -- ^ Old fuse time
|
||||
-> Int -- ^ Inventory item reference (I believe)
|
||||
-> World -> World
|
||||
decreaseFuse fuse i w = w
|
||||
& creatures . ix 0 . crInv . ix itRef . itScrollUp .~ decreaseFuse newTime
|
||||
& creatures . ix 0 . crInv . ix itRef . itScrollDown .~ increaseFuse newTime
|
||||
& creatures . ix 0 . crInv . ix itRef . itName .~ "GRENADE " ++ show newTime
|
||||
& creatures . ix 0 . crInv . ix itRef . itAttachment ?~ ItFuse newTime
|
||||
& creatures . ix 0 . crInv . ix itRef . itZoom
|
||||
.~ (defaultItZoom {_itAimZoomMax = zm, _itAimZoomMin = zm})
|
||||
where
|
||||
itRef = fromMaybe (-2) $ w ^? creatures . ix 0 . crInvSel
|
||||
newTime = max (fuse - 5) 20
|
||||
zm = 50 / fromIntegral newTime
|
||||
|
||||
defaultThrowable = grenade
|
||||
remoteBomb = defaultThrowable
|
||||
{ _itName = "REMOTEBOMB"
|
||||
@@ -967,56 +909,7 @@ remoteBomb = defaultThrowable
|
||||
, _itEquipPict = drawWeapon remoteBombUnarmedPic
|
||||
}
|
||||
|
||||
throwGrenade :: (Point2 -> World -> World) -> Int -> Int -> World -> World
|
||||
throwGrenade explosion fuseTime n w = setWp $ removePict $ over projectiles addG $ set randGen g w
|
||||
where
|
||||
addG = IM.insert i $ Shell
|
||||
{ _pjPos = p
|
||||
, _pjStartPos = p
|
||||
, _pjVel = v
|
||||
, _pjPict = onLayer PtLayer $ uncurry translate p $ grenadePic 0
|
||||
, _pjID = i
|
||||
, _pjUpdate = moveGrenade fuseTime dir i
|
||||
, _pjPayload = explosion
|
||||
}
|
||||
j = _crInvSel $ _creatures w IM.! n
|
||||
removePict = set (creatures . ix n . crInv . ix j . itEquipPict) $ \ _ _ -> blank
|
||||
i = newProjectileKey w
|
||||
(a, g) = randomR (-grenadeAccA,grenadeAccA::Float) (_randGen w)
|
||||
(l, _) = randomR (1 - 2*grenadeAccL,1+grenadeAccL::Float) g
|
||||
-- - v = 0.02 * l / _cameraZoom w *.* rotateV (a+_cameraRot w) (limitRange $ _mousePos w)
|
||||
v' = 1 / (fromIntegral fuseTime * _cameraZoom w) *.* rotateV (_cameraRot w) ( _mousePos w)
|
||||
v | magV v' > 6 = 6 *.* normalizeV v'
|
||||
| otherwise = v'
|
||||
cr = _creatures w IM.! n
|
||||
p' = _crPos cr +.+ rotateV (_crDir cr) (_crRad cr,0)
|
||||
p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (_crRad cr-4,0)
|
||||
| otherwise = p'
|
||||
dir = argV v
|
||||
setWp :: World -> World
|
||||
setWp w' = w' & creatures . ix n . crInv . ix j . itEffect .~ throwArmReset 20
|
||||
|
||||
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 .~ drawWeapon (grenadePic 50)
|
||||
| otherwise = it & itEffect . itEffectCounter -~ 1
|
||||
|
||||
(grenadeAccL, grenadeAccA) = (0.1, 0.1)
|
||||
|
||||
grenadePic :: Int -> Picture
|
||||
grenadePic x = pictures
|
||||
[ color (dark $ dark green) $ circleSolid 5
|
||||
, color green $ arc (degToRad $ (179 * fromIntegral x / 50) - 180 )
|
||||
(degToRad $ 180 - (179 * fromIntegral x / 50) )
|
||||
5
|
||||
, translate (-2) 2 $ rotate (pi*0.5)
|
||||
$ scale 0.05 0.05 $ color green $ text $ show $ 1 + quot x 20
|
||||
]
|
||||
|
||||
fireRemoteLauncher :: Int -> World -> World
|
||||
fireRemoteLauncher cid w = setLocation
|
||||
|
||||
Reference in New Issue
Block a user