Working implementation of light change when door opens

This commit is contained in:
2021-09-29 01:34:54 +01:00
parent 6b937b115e
commit f3437adef7
12 changed files with 87 additions and 66 deletions
+17 -17
View File
@@ -1,9 +1,9 @@
--{-# LANGUAGE BangPatterns #-}
module Dodge.LevelGen.TriggerDoor
( putDoor
, putDoubleDoor
, putSingleDoor
, addButtonDoor
, insertDoubleDoor
) where
import Dodge.Data
import Dodge.Base
@@ -25,13 +25,14 @@ import Control.Lens
import Data.Graph.Inductive hiding ((&))
-- probably don't have to rebuild the entire graph, oh well
addButtonDoor :: Color -> Point2 -> Float -> Point2 -> Point2 -> Float -> World -> World
addButtonDoor :: Color -> Point2 -> Float -> Point2 -> Point2 -> Float -> World -> (Int, World)
addButtonDoor c btp btr a b speed w
= over buttons (IM.insert bid bt)
= (,) 0
. over buttons (IM.insert bid bt)
$ set pathPoints (foldr insertPoint IM.empty (labNodes newGraph))
$ set pathGraph newGraph
$ set pathGraphP newGraphPairs
$ putDoubleDoor False c cond a b speed w
$ (snd $ putSingleDoor False c cond a b speed w)
where
bid = IM.newKey $ _buttons w
cond w' = BtNoLabel == _btState (_buttons w' IM.! bid)
@@ -50,9 +51,8 @@ putDoor
-> [(Point2,Point2)] -- ^ Door positions, closed to open.
-- Bumped out up and down by 9, not widened
-> World
-> World
putDoor col cond pss w = addWalls w
& doors %~ addDoor
-> (Int,World)
putDoor col cond pss w = (drid, addWalls w & doors %~ addDoor)
where
drid = IM.newKey $ _doors w
addDoor = IM.insert drid $ Door'
@@ -99,13 +99,6 @@ doorMechanismStepwise nsteps drid wlids pss dr w
-- it is not at all clear that the zoning selects the correct walls
putDoubleDoor :: Bool -> Color -> (World -> Bool) -> Point2 -> Point2 -> Float -> World -> World
putDoubleDoor isPathable col cond a b speed
= putSingleDoor isPathable col cond a c speed
. putSingleDoor isPathable col cond b c speed
where
c = 0.5 *.* (a +.+ b)
-- TODO think about wall zoning, simplify!
doorMechanism :: Int -> Float -> [(Int,(Point2,Point2),(Point2,Point2))] -> Door' -> World -> World
doorMechanism drid speed wlidOpCps dr w
@@ -129,9 +122,16 @@ doorMechanism drid speed wlidOpCps dr w
& walls . ix wlid %~ moveDoorToward speed p
& (\w'' -> foldr (changeZonedWall (moveDoorToward speed p) wlid) w'' (zoneps zp))
putSingleDoor :: Bool -> Color -> (World -> Bool) -> Point2 -> Point2 -> Float -> World -> World
putSingleDoor isPathable col cond a b speed w = addWalls w
& doors %~ addDoor
insertDoubleDoor :: Bool -> Color -> (World -> Bool) -> Point2 -> Point2 -> Float -> World
-> World
insertDoubleDoor isPathable col cond a b speed
= snd . putSingleDoor isPathable col cond a (0.5 *.* (a +.+ b)) speed
. snd . putSingleDoor isPathable col cond b (0.5 *.* (a +.+ b)) speed
putSingleDoor :: Bool -> Color -> (World -> Bool) -> Point2 -> Point2 -> Float -> World
-> (Int, World)
putSingleDoor isPathable col cond a b speed w = (drid, addWalls w
& doors %~ addDoor)
where
drid = IM.newKey $ _doors w
addDoor = IM.insert drid $ Door'