Add blurring of lightmap (and refactoring)
This commit is contained in:
@@ -4,13 +4,12 @@ Particles and pictures that decorate weapons, such as laser scopes etc.
|
||||
module Dodge.Item.Weapon.Decoration
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Picture.Layer
|
||||
import Dodge.Picture
|
||||
import Geometry.Data
|
||||
import Picture
|
||||
|
||||
import Control.Lens
|
||||
|
||||
makeLaserScope
|
||||
:: Point2 -- ^ Start point
|
||||
-> Point2 -- ^ End point
|
||||
@@ -18,13 +17,13 @@ makeLaserScope
|
||||
-> Particle
|
||||
makeLaserScope p ep relFrac = Particle
|
||||
{_ptDraw = const $ onLayer PtLayer $ pictures
|
||||
[color (withAlpha 0.5 $ mixColors relFrac (1-relFrac) red green)
|
||||
$ lineOfThickness 0.5 [p,ep]
|
||||
,color (withAlpha 0.2 $ mixColors relFrac (1-relFrac) red green)
|
||||
$ lineOfThickness 1.5 [p,ep]
|
||||
,color (withAlpha 0.1 $ mixColors relFrac (1-relFrac) red green)
|
||||
$ lineOfThickness 2 [p,ep]
|
||||
]
|
||||
[lineAlphaThick 0.5 0.5
|
||||
,lineAlphaThick 0.2 1.5
|
||||
,lineAlphaThick 0.1 2
|
||||
]
|
||||
,_ptUpdate' = \w pt -> (w, Just $ pt & ptUpdate' .~ \w' _ -> (w',Nothing))
|
||||
}
|
||||
where
|
||||
lineAlphaThick a w =
|
||||
color (withAlpha a $ mixColors relFrac (1-relFrac) red green) $ lineOfThickness w [p,ep]
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
module Dodge.Item.Weapon.Grenade
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Picture.Layer
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.Item.Attachment.Data
|
||||
import Dodge.Item.Draw
|
||||
import Dodge.Default
|
||||
import Picture
|
||||
import Geometry
|
||||
|
||||
import Control.Lens
|
||||
import Data.Maybe (fromJust)
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import System.Random
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
]
|
||||
|
||||
throwGrenade
|
||||
:: (Point2 -> World -> World) -- ^ Payload
|
||||
-> Int -- ^ Creature id
|
||||
-> World
|
||||
-> World
|
||||
throwGrenade explosion 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
|
||||
}
|
||||
cr = _creatures w IM.! n
|
||||
j = _crInvSel cr
|
||||
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' = 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) (_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
|
||||
fuseTime = _itFuseTime $ fromJust $ _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 .~ drawWeapon (grenadePic 50)
|
||||
| otherwise = it & itEffect . itEffectCounter -~ 1
|
||||
|
||||
(grenadeAccL, grenadeAccA) = (0.1, 0.1)
|
||||
@@ -2,6 +2,7 @@ module Dodge.Item.Weapon.Laser
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Picture
|
||||
import Dodge.Picture.Layer
|
||||
import Dodge.Item.Attachment.Data
|
||||
import Dodge.Base
|
||||
import Dodge.SoundLogic
|
||||
|
||||
@@ -5,6 +5,7 @@ module Dodge.Item.Weapon.UseEffect
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Picture.Layer
|
||||
import Dodge.Item.Weapon.Decoration
|
||||
import Dodge.Item.Weapon.TriggerType
|
||||
import Dodge.WorldEvent.Flash
|
||||
|
||||
Reference in New Issue
Block a user