Refactor, try to limit dependencies
This commit is contained in:
+55
-44
@@ -1,63 +1,74 @@
|
||||
module Dodge.EnergyBall where
|
||||
import Dodge.Data
|
||||
|
||||
import Dodge.DamageCircle
|
||||
import Dodge.Data.World
|
||||
import Dodge.LightSource
|
||||
import Geometry
|
||||
import Picture
|
||||
import LensHelp
|
||||
import Picture
|
||||
import RandomHelp
|
||||
|
||||
makeFlamelet
|
||||
:: Point2 -- ^ Position
|
||||
-> Float -- ^ z position
|
||||
-> Point2 -- ^ Velocity
|
||||
-> Float -- ^ Size
|
||||
-> Int -- ^ Timer
|
||||
-> World
|
||||
-> World
|
||||
makeFlamelet (V2 x y) z vel size time w = w
|
||||
& randGen .~ g
|
||||
& cWorld . energyBalls .:~ EnergyBall
|
||||
{ _ebVel = vel
|
||||
, _ebColor = red
|
||||
, _ebPos = V2 x y
|
||||
, _ebWidth = size
|
||||
, _ebTimer = time
|
||||
, _ebEff = (FLAMING,1)
|
||||
, _ebZ = z
|
||||
, _ebRot = rot
|
||||
}
|
||||
makeFlamelet ::
|
||||
-- | Position
|
||||
Point2 ->
|
||||
-- | z position
|
||||
Float ->
|
||||
-- | Velocity
|
||||
Point2 ->
|
||||
-- | Size
|
||||
Float ->
|
||||
-- | Timer
|
||||
Int ->
|
||||
World ->
|
||||
World
|
||||
makeFlamelet (V2 x y) z vel size time w =
|
||||
w
|
||||
& randGen .~ g
|
||||
& cWorld . energyBalls
|
||||
.:~ EnergyBall
|
||||
{ _ebVel = vel
|
||||
, _ebColor = red
|
||||
, _ebPos = V2 x y
|
||||
, _ebWidth = size
|
||||
, _ebTimer = time
|
||||
, _ebEff = (FLAMING, 1)
|
||||
, _ebZ = z
|
||||
, _ebRot = rot
|
||||
}
|
||||
where
|
||||
(rot ,g) = randomR (0,3) $ _randGen w
|
||||
(rot, g) = randomR (0, 3) $ _randGen w
|
||||
|
||||
moveEnergyBall :: World -> EnergyBall -> (World, Maybe EnergyBall)
|
||||
moveEnergyBall w eb
|
||||
| _ebTimer eb <= 0 = ( w, Nothing)
|
||||
| otherwise =
|
||||
moveEnergyBall w eb
|
||||
| _ebTimer eb <= 0 = (w, Nothing)
|
||||
| otherwise =
|
||||
( ebFlicker eb $ uncurry (damageCircle 5 (_ebPos eb)) (_ebEff eb) w
|
||||
, Just $ eb & ebTimer -~ 1 & ebPos .+.+~ _ebVel eb & ebVel .*.*~ 0.9
|
||||
)
|
||||
|
||||
|
||||
incBallAt :: Point2 -> World -> World
|
||||
incBallAt p w = w & cWorld . energyBalls .:~ theincball
|
||||
& randGen .~ g
|
||||
incBallAt p w =
|
||||
w & cWorld . energyBalls .:~ theincball
|
||||
& randGen .~ g
|
||||
where
|
||||
(theincball,g) = runState thestate (_randGen w)
|
||||
(theincball, g) = runState thestate (_randGen w)
|
||||
thestate = do
|
||||
rot <- state $ randomR (0,3)
|
||||
return EnergyBall
|
||||
{ _ebVel = 0
|
||||
, _ebColor = red
|
||||
, _ebPos = p
|
||||
, _ebWidth = 3
|
||||
, _ebTimer = 20
|
||||
, _ebEff = (FLAMING,1)
|
||||
, _ebZ = 20
|
||||
, _ebRot = rot
|
||||
}
|
||||
rot <- state $ randomR (0, 3)
|
||||
return
|
||||
EnergyBall
|
||||
{ _ebVel = 0
|
||||
, _ebColor = red
|
||||
, _ebPos = p
|
||||
, _ebWidth = 3
|
||||
, _ebTimer = 20
|
||||
, _ebEff = (FLAMING, 1)
|
||||
, _ebZ = 20
|
||||
, _ebRot = rot
|
||||
}
|
||||
|
||||
ebFlicker :: EnergyBall -> World -> World
|
||||
ebFlicker pt
|
||||
| _ebTimer pt `mod` 7 == 0 = cWorld . tempLightSources
|
||||
.:~ tlsTimeRadColPos 1 70 (0.5 *.*.* xyzV4 (_ebColor pt)) (addZ 20 $ _ebPos pt)
|
||||
ebFlicker pt
|
||||
| _ebTimer pt `mod` 7 == 0 =
|
||||
cWorld . tempLightSources
|
||||
.:~ tlsTimeRadColPos 1 70 (0.5 *.*.* xyzV4 (_ebColor pt)) (addZ 20 $ _ebPos pt)
|
||||
| otherwise = id
|
||||
|
||||
Reference in New Issue
Block a user