This commit is contained in:
2022-07-18 12:31:52 +01:00
parent 5495d33389
commit c14b3ff787
4 changed files with 50 additions and 29 deletions
+1 -3
View File
@@ -1,11 +1,9 @@
module Dodge.Bullet.Draw module Dodge.Bullet.Draw
( drawBul ( drawBul
) where ) where
import Dodge.Data import Dodge.Data.Bullet
import Picture import Picture
import Linear import Linear
drawBul :: Bullet -> Picture drawBul :: Bullet -> Picture
drawBul pt = setLayer BloomNoZWrite drawBul pt = setLayer BloomNoZWrite
. setDepth 20 . setDepth 20
+2 -1
View File
@@ -28,7 +28,8 @@ moveTeslaArc thearc w pt
where where
rcol = brightX 100 1.5 <$> takeOne [white,azure,blue,cyan] rcol = brightX 100 1.5 <$> takeOne [white,azure,blue,cyan]
rdir = state (randomR (-0.7,0.7)) <&> (+ ld) rdir = state (randomR (-0.7,0.7)) <&> (+ ld)
makeaspark = randColDirTimeSpark rcol rdir lp rspeed = state (randomR (3,6))
makeaspark = randSpark rspeed rcol rdir lp
makesparks = makeaspark . makeaspark . makeaspark makesparks = makeaspark . makeaspark . makeaspark
(lp,ld) = case last thearc of (lp,ld) = case last thearc of
ArcStep lp' ld' Nothing -> (lp',ld') ArcStep lp' ld' Nothing -> (lp',ld')
+46 -24
View File
@@ -3,7 +3,8 @@ module Dodge.Spark
, colSpark , colSpark
, colSparkRandDir , colSparkRandDir
, createBarrelSpark , createBarrelSpark
, randColDirTimeSpark , randColDirSpark
, randSpark
) where ) where
import Dodge.Data import Dodge.Data
import Dodge.WorldEvent.ThingsHit import Dodge.WorldEvent.ThingsHit
@@ -19,7 +20,8 @@ moveSpark w sk
| magV (_skVel sk) < 1 = (w,Nothing) | magV (_skVel sk) < 1 = (w,Nothing)
| otherwise = case thingHit sp ep w of | otherwise = case thingHit sp ep w of
Nothing -> (w, Just $ sk & skPos .~ ep & skVel .*.*~ 0.9 & skOldPos .~ sp) Nothing -> (w, Just $ sk & skPos .~ ep & skVel .*.*~ 0.9 & skOldPos .~ sp)
Just (hp,hthing) -> (sparkDam sp ep (hp,hthing) w, Just $ sk & skPos .~ hp & skOldPos .~ sp & skVel .~ 0) Just (hp,hthing) -> (sparkDam sp ep (hp,hthing) w
, Just $ sk & skPos .~ hp & skOldPos .~ sp & skVel .~ 0)
where where
sp = _skPos sk sp = _skPos sk
ep = sp +.+ _skVel sk ep = sp +.+ _skVel sk
@@ -36,26 +38,19 @@ sparkDam sp ep mayEiCrWl = case mayEiCrWl of
where where
thedam hitp = Damage SPARKING 1 sp hitp ep NoDamageEffect thedam hitp = Damage SPARKING 1 sp hitp ep NoDamageEffect
--import Control.Lens
-- TODO remove/simplify this function
createBarrelSpark :: Point2 -> Float -> Int -> World -> World createBarrelSpark :: Point2 -> Float -> Int -> World -> World
createBarrelSpark pos dir colid = sparks .:~ Spark createBarrelSpark pos dir colid = colSparkRandDir 0.1 (numColor colid) pos dir
{ _skVel = rotateV dir (V2 5 0)
, _skColor = numColor colid
, _skPos = pos
, _skOldPos = pos
, _skWidth = 1
}
colSpark :: Color -> Point2 -> Float -> World -> World colSpark :: Color -> Point2 -> Float -> World -> World
colSpark = colSparkRandDir 0.7 colSpark = colSparkRandDir 0.7
randColDirTimeSpark randColDirSpark
:: State StdGen Color :: State StdGen Color
-> State StdGen Float -> State StdGen Float
-> Point2 -> Point2
-> World -> World
-> World -> World
randColDirTimeSpark randcol randdir pos w = w randColDirSpark randcol randdir pos w = w
& sparks .:~ spark & sparks .:~ spark
& randGen .~ g & randGen .~ g
where where
@@ -71,17 +66,44 @@ randColDirTimeSpark randcol randdir pos w = w
, _skWidth = 1 , _skWidth = 1
} }
colSparkRandDir :: Float -> Color -> Point2 -> Float -> World -> World randSpark
colSparkRandDir randDir col pos baseDir w = w :: State StdGen Float
& sparks .:~ spark -> State StdGen Color
-> State StdGen Float
-> Point2
-> World
-> World
randSpark randspeed randcol randdir pos w = w
& randGen .~ g & randGen .~ g
where & sparks .:~ Spark
(a,g) = randomR (-randDir,randDir) $ _randGen w { _skVel = rotateV dir (V2 speed 0)
dir = a + baseDir , _skColor = col
spark = Spark , _skPos = pos
{ _skVel = rotateV dir (V2 5 0) , _skOldPos = pos
, _skColor = col
, _skPos = pos
, _skOldPos = pos
, _skWidth = 1 , _skWidth = 1
} }
where
((col,dir,speed),g) = (`runState` _randGen w) $ do
c <- randcol
d <- randdir
x <- randspeed
return (c,d,x)
colSparkRandDir :: Float -> Color -> Point2 -> Float -> World -> World
colSparkRandDir a col pos dir = randColDirSpark
(return col)
(state $ randomR (dir - a, dir + a))
pos
-- w
-- & sparks .:~ spark
-- & randGen .~ g
-- where
-- (a,g) = randomR (-randDir,randDir) $ _randGen w
-- dir = a + baseDir
-- spark = Spark
-- { _skVel = rotateV dir (V2 5 0)
-- , _skColor = col
-- , _skPos = pos
-- , _skOldPos = pos
-- , _skWidth = 1
-- }
+1 -1
View File
@@ -1,5 +1,5 @@
module Dodge.Spark.Draw where module Dodge.Spark.Draw where
import Dodge.Data import Dodge.Data.Spark
import Picture import Picture
drawSpark :: Spark -> Picture drawSpark :: Spark -> Picture