Add dust on bullet wall hit

This commit is contained in:
2021-09-13 12:23:51 +01:00
parent b27c174d93
commit 29f048cfdd
15 changed files with 93 additions and 68 deletions
+1 -1
View File
@@ -181,7 +181,7 @@ data TempLightSource = TLS
{ _tlsPos :: !Point3 { _tlsPos :: !Point3
, _tlsRad :: !Float , _tlsRad :: !Float
, _tlsIntensity :: !Point3 , _tlsIntensity :: !Point3
, _tlsUpdate :: World -> TempLightSource -> (World, Maybe TempLightSource) , _tlsUpdate :: World -> TempLightSource -> Maybe TempLightSource
, _tlsTime :: !Int , _tlsTime :: !Int
} }
data Creature = Creature data Creature = Creature
+3 -3
View File
@@ -247,7 +247,7 @@ defaultTLS = TLS
, _tlsTime = 1 , _tlsTime = 1
} }
where where
f w t f _ t
| _tlsTime t <= 0 | _tlsTime t <= 0
= (w, Nothing) = Nothing
| otherwise = (w, Just $ t & tlsTime -~ 1) | otherwise = Just $ t & tlsTime -~ 1
+1 -1
View File
@@ -98,7 +98,7 @@ youLight =
,_tlsRad = 300 ,_tlsRad = 300
,_tlsIntensity = 0.1 ,_tlsIntensity = 0.1
--,_tlsUpdate = \w _ -> (w, Nothing) --,_tlsUpdate = \w _ -> (w, Nothing)
,_tlsUpdate = \w _ -> (w, Just (youLight {_tlsPos = f $ _crPos (you w)})) ,_tlsUpdate = \w _ -> Just (youLight {_tlsPos = f $ _crPos (you w)})
,_tlsTime = 0 ,_tlsTime = 0
} }
where where
+3 -2
View File
@@ -328,7 +328,7 @@ ltAutoGun = defaultAutoGun
, withRandomDirI 0.1 , withRandomDirI 0.1
, torqueAfterI 0.2 , torqueAfterI 0.2
, withSidePushI 50 , withSidePushI 50
, withMuzFlareI , modClock 2 withMuzFlareI
] ]
, _wpSpread = 0.5 , _wpSpread = 0.5
, _wpRange = 20 , _wpRange = 20
@@ -388,6 +388,7 @@ miniGun = defaultAutoGun
, withRandomOffsetI 9 , withRandomOffsetI 9
, withMuzFlareI , withMuzFlareI
, withOldDir od3 , withOldDir od3
, withSmoke 1 black 20 200 5
] ]
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = onLayer FlItLayer miniGunPict , _itFloorPict = onLayer FlItLayer miniGunPict
@@ -948,7 +949,7 @@ moveRemoteShell cid itid pj w
hitWl = fst <$> collideCircWalls oldPos newPos 2 (wallsNearPoint newPos w) hitWl = fst <$> collideCircWalls oldPos newPos 2 (wallsNearPoint newPos w)
thingHit = hitCr <|> hitWl thingHit = hitCr <|> hitWl
r1 = _randGen w & evalState (randInCirc 10) r1 = _randGen w & evalState (randInCirc 10)
smokeGen = makeSmokeCloudAt $ addZ 20 $ oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos) smokeGen = shellTrailCloud $ addZ 20 $ oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)
doExplosion = explodeRemoteRocket itid i doExplosion = explodeRemoteRocket itid i
explodeRemoteRocket explodeRemoteRocket
+1
View File
@@ -44,6 +44,7 @@ autoGun = defaultAutoGun
, useAmmo 1 , useAmmo 1
, withRandomDirI (autogunSpread/2) , withRandomDirI (autogunSpread/2)
, withMuzFlareI , withMuzFlareI
, withSmoke 1 black 20 200 5
] ]
, _wpSpread = autogunSpread , _wpSpread = autogunSpread
, _wpRange = 20 , _wpRange = 20
+1 -1
View File
@@ -119,7 +119,7 @@ doThrust pj w = w
(frict,g) = randomR (0.6,0.9) $ _randGen w (frict,g) = randomR (0.6,0.9) $ _randGen w
(sparkD,_) = randomR (-0.2,0.2) $ _randGen w (sparkD,_) = randomR (-0.2,0.2) $ _randGen w
r1 = randInCirc 10 & evalState $ _randGen w r1 = randInCirc 10 & evalState $ _randGen w
smokeGen = makeSmokeCloudAt $ addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos)) smokeGen = shellTrailCloud $ addZ 20 (oldPos +.+ r1 +.+ 30 *.* normalizeV (oldPos -.- newPos))
flameLauncher :: Item flameLauncher :: Item
flameLauncher = launcher & wpAmmo . amPayload .~ makeFlameExplosionAt flameLauncher = launcher & wpAmmo . amPayload .~ makeFlameExplosionAt
+20 -3
View File
@@ -15,6 +15,7 @@ module Dodge.Item.Weapon.TriggerType
, withSoundStart , withSoundStart
, withSoundContinue , withSoundContinue
, withSoundForI , withSoundForI
, withSmoke
, withThickSmokeI , withThickSmokeI
, withThinSmokeI , withThinSmokeI
, withRandomOffsetI , withRandomOffsetI
@@ -33,14 +34,15 @@ module Dodge.Item.Weapon.TriggerType
, useTimeCheckI , useTimeCheckI
, ammoCheckI , ammoCheckI
, randSpreadDir , randSpreadDir
, modClock
) )
where where
import Dodge.Data import Dodge.Data
import Dodge.Data.SoundOrigin import Dodge.Data.SoundOrigin
import Dodge.SoundLogic import Dodge.SoundLogic
import Dodge.Creature.Action (startReloadingWeapon) import Dodge.Creature.Action (startReloadingWeapon)
import Dodge.WorldEvent (tempLightForAt) import Dodge.WorldEvent
import Dodge.WorldEvent.Cloud --import Dodge.WorldEvent.Cloud
import Dodge.RandomHelp import Dodge.RandomHelp
import Dodge.Item.Attachment.Data import Dodge.Item.Attachment.Data
import Dodge.Item.Data import Dodge.Item.Data
@@ -69,6 +71,15 @@ trigDoAlso
-> ChainEffect -> ChainEffect
trigDoAlso afterEff eff item cr = afterEff item cr . eff item cr trigDoAlso afterEff eff item cr = afterEff item cr . eff item cr
withSmoke :: Int -> Point4 -> Float -> Int -> Float -> ChainEffect
withSmoke num col rad t alt eff item cr w
= eff item cr
$ foldl' (flip $ smokeCloudAt col rad t alt . (+.+.+ pos) . (*8)) w ps
where
dir = _crDir cr
pos = addZ 0 $ _crPos cr +.+ (_crRad cr + 15) *.* unitVectorAtAngle dir
ps = replicateM num randOnUnitSphere & evalState $ _randGen w
withThinSmokeI :: ChainEffect withThinSmokeI :: ChainEffect
withThinSmokeI eff item cr w = eff item cr $ foldl' (flip $ makeThinSmokeAt . (+.+.+ pos) . (* 8)) w ps withThinSmokeI eff item cr w = eff item cr $ foldl' (flip $ makeThinSmokeAt . (+.+.+ pos) . (* 8)) w ps
where where
@@ -295,8 +306,14 @@ withTempLight time rad col eff item cr = eff item cr
} }
V2 x y = _crPos cr +.+ 15 *.* unitVectorAtAngle (_crDir cr) V2 x y = _crPos cr +.+ 15 *.* unitVectorAtAngle (_crDir cr)
modClock :: Int -> ChainEffect -> ChainEffect
modClock n chainEff eff it cr w
| _frameClock w `mod` n == 0 = (chainEff eff) it cr w
| otherwise = eff it cr w
withMuzFlareI :: ChainEffect withMuzFlareI :: ChainEffect
withMuzFlareI f it cr w = tempLightForAt 3 pos2 -- . muzzleFlashAt pos2 withMuzFlareI f it cr w =
makeTLight 3 100 (V3 1 1 0.5) pos2 -- . muzzleFlashAt pos2
$ f it cr w $ f it cr w
where where
--pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr) --pos = _crPos cr +.+ _crRad cr *.* unitVectorAtAngle (_crDir cr)
+30 -35
View File
@@ -1,12 +1,15 @@
module Dodge.LightSources where module Dodge.LightSources
( tLightTimedIntensity
, tLight
, lightAt
, colorLightAt
)
where
import Dodge.Data import Dodge.Data
--import Dodge.Base
--import Dodge.Picture.Layer
--import Dodge.LevelGen.Data
--import Geometry
--import Picture
import Geometry.Data import Geometry.Data
import Control.Lens
colorLightAt :: Point3 -> Point3 -> Int -> LightSource colorLightAt :: Point3 -> Point3 -> Int -> LightSource
colorLightAt col pos i = colorLightAt col pos i =
LS {_lsID = i LS {_lsID = i
@@ -19,46 +22,38 @@ colorLightAt col pos i =
lightAt :: Point3 -> Int -> LightSource lightAt :: Point3 -> Int -> LightSource
lightAt = colorLightAt 0.75 lightAt = colorLightAt 0.75
tLightFade :: Int -> Float -> (Int -> Float) -> Point2 -> TempLightSource tLightTimedIntensity :: Int -> Float -> (Int -> Float) -> Point2 -> TempLightSource
tLightFade 0 rmax intensityF (V2 x y) = TLS tLightTimedIntensity t rmax intensityF (V2 x y) = TLS
{ _tlsPos = V3 x y 0 { _tlsPos = V3 x y 0
, _tlsRad = rmax , _tlsRad = rmax
, _tlsIntensity = f $ intensityF 0 , _tlsIntensity = f $ intensityF t
, _tlsUpdate = \w _ -> (w, Nothing) , _tlsUpdate = upF
, _tlsTime = 0 , _tlsTime = t
}
where
f x' = V3 x' x' x'
tLightFade i rmax intensityF p@(V2 x y) = TLS
{ _tlsPos = V3 x y 0
, _tlsRad = rmax
, _tlsIntensity = f $ intensityF i
, _tlsUpdate = \w _ -> (w, Just $ tLightFade (i-1) rmax intensityF p)
, _tlsTime = 0
} }
where where
upF _ tls
| _tlsTime tls <= 0 = Nothing
| otherwise = Just $ tls
& tlsTime -~ 1
& tlsIntensity .~ f (intensityF (_tlsTime tls) )
f x' = V3 x' x' x' f x' = V3 x' x' x'
tLightRad tLight
:: Int :: Int
-> Float -- ^ maximal radius -> Float -- ^ maximal radius
-> Float -- ^ minimal radius (unused) -> Point3
-> Point2 -> Point2
-> TempLightSource -> TempLightSource
tLightRad 0 rmax _ (V2 x y) = TLS tLight t rmax col (V2 x y) = TLS
{ _tlsPos = V3 x y 1 { _tlsPos = V3 x y 1
, _tlsRad = rmax , _tlsRad = rmax
, _tlsIntensity = 0.5 , _tlsIntensity = col
, _tlsUpdate = \w _ -> (w, Nothing) , _tlsUpdate = upF
, _tlsTime = 0 , _tlsTime = t
}
tLightRad i rmax rmin p@(V2 x y) = TLS
{ _tlsPos = V3 x y 0
, _tlsRad = rmax
, _tlsIntensity = V3 0.5 0.5 0
, _tlsUpdate = \w _ -> (w, Just $ tLightRad (i-1) rmax rmin p)
, _tlsTime = 0
} }
where
upF _ tls
| _tlsTime tls <= 0 = Nothing
| otherwise = Just $ tls
& tlsTime -~ 1
tLightAt :: Int -> Point2 -> TempLightSource
tLightAt i = tLightRad i 100 0
+5 -2
View File
@@ -17,6 +17,7 @@ import Dodge.WorldEvent.Shockwave
import Dodge.Creature.State.Data import Dodge.Creature.State.Data
import Dodge.Creature.Property import Dodge.Creature.Property
import Geometry import Geometry
import Geometry.Vector3D
import Picture import Picture
import System.Random import System.Random
@@ -137,11 +138,13 @@ bulConCr' bt p cr w
mkwave = over worldEvents $ (.) (makeShockwaveAt [] p 15 4 1 white) mkwave = over worldEvents $ (.) (makeShockwaveAt [] p 15 4 1 white)
{- | Hitting wall effects: create a spark, damage blocks. -} {- | Hitting wall effects: create a spark, damage blocks. -}
bulHitWall' :: Particle -> Point2 -> Wall -> World -> World bulHitWall' :: Particle -> Point2 -> Wall -> World -> World
bulHitWall' bt p x w = damageBlocksBy 5 x bulHitWall' bt p wl w = damageBlocksBy 5 wl
$ createSparkCol 8 theCol pOut (reflectDir x) . smokeCloudAt dustcol 20 200 1 (addZ 20 pOut)
$ createSparkCol 8 theCol pOut (reflectDir wl)
$ set randGen g $ set randGen g
w w
where where
dustcol = _wlColor wl & _4 .~ 1
theCol = brightX 100 1.5 white theCol = brightX 100 1.5 white
sp = head $ _btTrail' bt sp = head $ _btTrail' bt
pOut = p +.+ safeNormalizeV (sp -.- p) pOut = p +.+ safeNormalizeV (sp -.- p)
+2 -2
View File
@@ -131,8 +131,8 @@ doDrawing pdata w = do
clearColor $= Color4 0.5 0.5 0.5 0 clearColor $= Color4 0.5 0.5 0.5 0
--blendFunc $= (SrcAlphaSaturate,One) --blendFunc $= (SrcAlphaSaturate,One)
--blendColor $= Color4 0.5 0.5 0.5 0.5 --blendColor $= Color4 0.5 0.5 0.5 0.5
blendFuncSeparate $= ((SrcAlphaSaturate,One) , (One,OneMinusSrcAlpha)) --blendFuncSeparate $= ((SrcAlphaSaturate,One) , (One,OneMinusSrcAlpha))
--blendFuncSeparate $= ((SrcAlpha,OneMinusSrcAlpha),(One,OneMinusSrcAlpha)) blendFuncSeparate $= ((SrcAlpha,OneMinusSrcAlpha),(One,OneMinusSrcAlpha))
drawBuffers $= [FBOColorAttachment 0,NoBuffers] drawBuffers $= [FBOColorAttachment 0,NoBuffers]
clear [ColorBuffer] clear [ColorBuffer]
renderLayer 2 shadV layerCounts renderLayer 2 shadV layerCounts
-2
View File
@@ -6,8 +6,6 @@ module Dodge.Render.MenuScreen
) )
where where
import Dodge.Data import Dodge.Data
--import Dodge.Config.Update
--import Dodge.Config.Data
import Dodge.Base.Window import Dodge.Base.Window
import Picture import Picture
import Dodge.Menu import Dodge.Menu
+2 -2
View File
@@ -124,9 +124,9 @@ updateSoundQueue :: World -> World
updateSoundQueue = set sounds M.empty updateSoundQueue = set sounds M.empty
updateLightSources :: World -> World updateLightSources :: World -> World
updateLightSources w = set tempLightSources (catMaybes tlss) w' updateLightSources w = set tempLightSources tlss w
where where
(w',tlss) = mapAccumR (\a b -> _tlsUpdate b a b) w $ _tempLightSources w tlss = mapMaybe (\b -> _tlsUpdate b w b) $ _tempLightSources w
updateProjectiles :: World -> World updateProjectiles :: World -> World
updateProjectiles w = IM.foldl' (flip $ dbArg _pjUpdate) w $ _projectiles w updateProjectiles w = IM.foldl' (flip $ dbArg _pjUpdate) w $ _projectiles w
+2 -2
View File
@@ -58,5 +58,5 @@ damCrsOnLine dam p1 p2 = over creatures (IM.map damIfOnLine)
= over crHP (\hp -> hp - dam) cr = over crHP (\hp -> hp - dam) cr
| otherwise = cr | otherwise = cr
tempLightForAt :: Int -> Point2 -> World -> World makeTLight :: Int -> Float -> Point3 -> Point2 -> World -> World
tempLightForAt i p w = w & tempLightSources %~ (tLightAt i p :) makeTLight i rad col p = tempLightSources %~ (tLight i rad col p :)
+21 -11
View File
@@ -10,14 +10,14 @@ import Picture
import Control.Lens import Control.Lens
makeCloudAt makeCloudAt
:: Float -- ^ radius :: (Cloud -> Picture) -- ^ draw function
-> Float -- ^ radius
-> Int -- ^ timer -> Int -- ^ timer
-> Float -- ^ resting altitude -> Float -- ^ resting altitude
-> (Cloud -> Picture) -- ^ draw function
-> Point3 -- start position -> Point3 -- start position
-> World -> World
-> World -> World
makeCloudAt rad t alt drawFunc p w = w & clouds %~ (theCloud :) makeCloudAt drawFunc rad t alt p w = w & clouds %~ (theCloud :)
where where
theCloud = Cloud theCloud = Cloud
{ _clPos = p { _clPos = p
@@ -30,6 +30,16 @@ makeCloudAt rad t alt drawFunc p w = w & clouds %~ (theCloud :)
, _clEffect = const id , _clEffect = const id
} }
smokeCloudAt
:: Color
-> Float -- ^ radius
-> Int -- ^ timer
-> Float -- ^ resting altitude
-> Point3 -- start position
-> World
-> World
smokeCloudAt col = makeCloudAt (drawCloudWith (4/3) 800 col)
drawCloudWith :: Float -> Float -> Color -> Cloud -> Picture drawCloudWith :: Float -> Float -> Color -> Cloud -> Picture
drawCloudWith radMult fadet col cl drawCloudWith radMult fadet col cl
= setLayer 2 = setLayer 2
@@ -39,23 +49,23 @@ drawCloudWith radMult fadet col cl
a = min 1 $ fromIntegral (_clTimer cl) / fadet a = min 1 $ fromIntegral (_clTimer cl) / fadet
makeThickSmokeAt :: Point3 -> World -> World makeThickSmokeAt :: Point3 -> World -> World
makeThickSmokeAt = makeCloudAt 3 50 30 (drawCloudWith 4 50 black) makeThickSmokeAt = makeCloudAt (drawCloudWith 4 50 black) 3 50 30
makeThinSmokeAt :: Point3 -> World -> World makeThinSmokeAt :: Point3 -> World -> World
makeThinSmokeAt = makeCloudAt 5 400 50 (drawCloudWith 4 400 (withAlpha 0.05 black)) makeThinSmokeAt = makeCloudAt (drawCloudWith 4 400 (withAlpha 0.05 black)) 5 400 50
makeStartCloudAt :: Point3 -> World -> World makeStartCloudAt :: Point3 -> World -> World
--makeSmokeCloudAt = makeCloudAt 10 200 (drawCloudWith 2 200 (greyN 0.5)) --makeSmokeCloudAt = makeCloudAt 10 200 (drawCloudWith 2 200 (greyN 0.5))
makeStartCloudAt = makeCloudAt 10 400 5 (drawCloudWith 2 800 white) makeStartCloudAt = makeCloudAt (drawCloudWith 2 800 white) 10 400 5
makeSmokeCloudAt :: Point3 -> World -> World shellTrailCloud :: Point3 -> World -> World
--makeSmokeCloudAt = makeCloudAt 10 200 (drawCloudWith 2 200 (greyN 0.5)) ----makeSmokeCloudAt = makeCloudAt 10 200 (drawCloudWith 2 200 (greyN 0.5))
makeSmokeCloudAt = makeCloudAt 15 400 40 (drawCloudWith (4/3) 800 (greyN 0.5)) shellTrailCloud = makeCloudAt (drawCloudWith (4/3) 800 (greyN 0.5)) 15 400 40
makeFlamerSmokeAt :: Float -> Point3 -> World -> World makeFlamerSmokeAt :: Float -> Point3 -> World -> World
makeFlamerSmokeAt x = makeCloudAt 6 200 40 (drawCloudWith 4 300 (greyN x)) makeFlamerSmokeAt x = makeCloudAt (drawCloudWith 4 300 (greyN x)) 6 200 40
spawnSmokeAtCursor :: World -> World spawnSmokeAtCursor :: World -> World
spawnSmokeAtCursor w = makeSmokeCloudAt (V3 x y 20) w spawnSmokeAtCursor w = shellTrailCloud (V3 x y 20) w
where where
V2 x y = mouseWorldPos w V2 x y = mouseWorldPos w
+1 -1
View File
@@ -85,7 +85,7 @@ flashFlareAt col alphax (V2 x y) = Particle
} }
explosionFlashAt :: Point2 -> World -> World explosionFlashAt :: Point2 -> World -> World
explosionFlashAt p = over tempLightSources ((:) $ tLightFade 20 150 intensityFunc p) explosionFlashAt p = over tempLightSources ((:) $ tLightTimedIntensity 20 150 intensityFunc p)
where where
intensityFunc x intensityFunc x
| x < 10 = 1 / (10 - fromIntegral x) | x < 10 = 1 / (10 - fromIntegral x)