Refactor, try to limit dependencies
This commit is contained in:
+49
-37
@@ -1,59 +1,71 @@
|
||||
module Dodge.Beam where
|
||||
import Dodge.Data
|
||||
|
||||
import Data.Maybe
|
||||
import Dodge.Data.World
|
||||
import Dodge.Flame
|
||||
import Dodge.Tesla.Arc
|
||||
import Dodge.Item.Location
|
||||
import Dodge.Tesla.Arc
|
||||
import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
import LensHelp
|
||||
import Picture
|
||||
|
||||
import Data.Maybe
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
doBeamCombine :: BeamCombineType
|
||||
-> (Point2,(Point2,Point2,Beam),(Point2,Point2,Beam))
|
||||
-> World
|
||||
-> World
|
||||
doBeamCombine ::
|
||||
BeamCombineType ->
|
||||
(Point2, (Point2, Point2, Beam), (Point2, Point2, Beam)) ->
|
||||
World ->
|
||||
World
|
||||
doBeamCombine bct = case bct of
|
||||
FlameBeamCombine -> flameBeamCombine
|
||||
LasBeamCombine -> lasBeamCombine
|
||||
LasBeamCombine -> lasBeamCombine
|
||||
TeslaBeamCombine -> teslaBeamCombine
|
||||
SplitBeamCombine -> splitBeamCombine
|
||||
NoBeamCombine -> const id
|
||||
flameBeamCombine :: (Point2,(Point2,Point2,Beam),(Point2,Point2,Beam))
|
||||
-> World -> World
|
||||
flameBeamCombine (p,(a,b,_),(x,y,_))
|
||||
= makeFlame p (2 *.* normalizeV (normalizeV (b-.-a)+.+normalizeV (y-.-x)))
|
||||
lasBeamCombine :: (Point2,(Point2,Point2,Beam),(Point2,Point2,Beam))
|
||||
-> World -> World
|
||||
lasBeamCombine (p,(a,b,_),(x,y,_))
|
||||
= cWorld . lasers .:~ lasRayAt yellow 11 1 p (argV (normalizeV (b-.-a)+.+normalizeV (y-.-x)))
|
||||
|
||||
splitBeamCombine :: (Point2,(Point2,Point2,Beam),(Point2,Point2,Beam))
|
||||
-> World -> World
|
||||
splitBeamCombine (p,(a,b,_),(x,y,_))
|
||||
= (cWorld . lasers .:~ lasRayAt yellow 11 1 p (dir+0.5*pi))
|
||||
. (cWorld . lasers .:~ lasRayAt yellow 11 1 p (dir-0.5*pi))
|
||||
flameBeamCombine ::
|
||||
(Point2, (Point2, Point2, Beam), (Point2, Point2, Beam)) ->
|
||||
World ->
|
||||
World
|
||||
flameBeamCombine (p, (a, b, _), (x, y, _)) =
|
||||
makeFlame p (2 *.* normalizeV (normalizeV (b -.- a) +.+ normalizeV (y -.- x)))
|
||||
|
||||
lasBeamCombine ::
|
||||
(Point2, (Point2, Point2, Beam), (Point2, Point2, Beam)) ->
|
||||
World ->
|
||||
World
|
||||
lasBeamCombine (p, (a, b, _), (x, y, _)) =
|
||||
cWorld . lasers .:~ lasRayAt yellow 11 1 p (argV (normalizeV (b -.- a) +.+ normalizeV (y -.- x)))
|
||||
|
||||
splitBeamCombine ::
|
||||
(Point2, (Point2, Point2, Beam), (Point2, Point2, Beam)) ->
|
||||
World ->
|
||||
World
|
||||
splitBeamCombine (p, (a, b, _), (x, y, _)) =
|
||||
(cWorld . lasers .:~ lasRayAt yellow 11 1 p (dir + 0.5 * pi))
|
||||
. (cWorld . lasers .:~ lasRayAt yellow 11 1 p (dir -0.5 * pi))
|
||||
where
|
||||
dir = argV (normalizeV (b-.-a)+.+normalizeV (y-.-x))
|
||||
dir = argV (normalizeV (b -.- a) +.+ normalizeV (y -.- x))
|
||||
|
||||
teslaBeamCombine :: (Point2,(Point2,Point2,Beam),(Point2,Point2,Beam))
|
||||
-> World -> World
|
||||
teslaBeamCombine (p,(a,b,bm),(x,y,_)) w
|
||||
= w' & pointerToItemLocation (_itemLocations (_cWorld w) IM.! itid) . itParams . subParams ?~ ip
|
||||
teslaBeamCombine ::
|
||||
(Point2, (Point2, Point2, Beam), (Point2, Point2, Beam)) ->
|
||||
World ->
|
||||
World
|
||||
teslaBeamCombine (p, (a, b, bm), (x, y, _)) w =
|
||||
w' & pointerToItemLocation (_itemLocations (_cWorld w) IM.! itid) . itParams . subParams ?~ ip
|
||||
where
|
||||
itid = fromJust $ _bmOrigin bm
|
||||
dir = argV (normalizeV (b-.-a)+.+normalizeV (y-.-x))
|
||||
(w',ip) = shootTeslaArc' (fromJust . _subParams $ _itParams it) p dir w
|
||||
dir = argV (normalizeV (b -.- a) +.+ normalizeV (y -.- x))
|
||||
(w', ip) = shootTeslaArc' (fromJust . _subParams $ _itParams it) p dir w
|
||||
it = case getItem itid w of
|
||||
Nothing -> error "tried to get item use teslaBeamCombine that doesn't exist"
|
||||
Just itm -> itm
|
||||
|
||||
lasRayAt :: Color -> Int -> Float -> Point2 -> Float -> LaserStart
|
||||
lasRayAt col dam phasev pos dir = LaserStart
|
||||
{ _lpType = DamageLaser dam
|
||||
, _lpPhaseV = phasev
|
||||
, _lpPos = pos
|
||||
, _lpDir = dir
|
||||
, _lpColor = col
|
||||
}
|
||||
lasRayAt col dam phasev pos dir =
|
||||
LaserStart
|
||||
{ _lpType = DamageLaser dam
|
||||
, _lpPhaseV = phasev
|
||||
, _lpPos = pos
|
||||
, _lpDir = dir
|
||||
, _lpColor = col
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user