Cleanup. Add room-wise random placement spots
This commit is contained in:
@@ -33,6 +33,8 @@ data PlacementSpot
|
||||
| PSLnk { _psLinkTest :: (Point2,Float) -> Bool
|
||||
, _psLinkShift :: (Point2,Float) -> (Point2,Float)
|
||||
}
|
||||
| PSRoomRand
|
||||
{ _psRoomRandPointNum :: Int }
|
||||
data Placement = Placement
|
||||
{ _placementSpot :: PlacementSpot
|
||||
, _psType :: PSType
|
||||
@@ -68,6 +70,14 @@ jps0 pst = Just . Placement (PS (V2 0 0) 0) pst
|
||||
ps0j :: PSType -> Placement -> Placement
|
||||
ps0j pst plmnt = Placement (PS (V2 0 0) 0) pst (const $ Just plmnt)
|
||||
|
||||
addPlmnt :: Placement -> Placement -> Placement
|
||||
addPlmnt pl (PlacementUsingPos p f) = PlacementUsingPos p (fmap (addPlmnt pl) f)
|
||||
addPlmnt pl (RandomPlacement rp) = RandomPlacement $ fmap (addPlmnt pl) rp
|
||||
addPlmnt pl (Placement ps pt f) = Placement ps pt (fmap g f)
|
||||
where
|
||||
g Nothing = Just pl
|
||||
g (Just pl') = Just $ addPlmnt pl pl'
|
||||
|
||||
makeLenses ''PSType
|
||||
makeLenses ''PlacementSpot
|
||||
makeLenses ''Placement
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
{-# LANGUAGE BangPatterns #-}
|
||||
module Dodge.LevelGen.MoveDoor
|
||||
( zoneps
|
||||
, moveDoorToward
|
||||
, changeZonedWall
|
||||
, mvPs
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Zone
|
||||
import Geometry
|
||||
|
||||
import Control.Lens
|
||||
|
||||
mvP :: Float -> Point2 -> Point2 -> Point2
|
||||
{-# INLINE mvP #-}
|
||||
mvP !speed !ep !p = mvPointTowardAtSpeed speed ep p
|
||||
|
||||
mvPs :: Float -> (Point2,Point2) -> (Point2,Point2) -> (Point2,Point2)
|
||||
{-# INLINE mvPs #-}
|
||||
mvPs !speed (!ex,!ey) (!sx,!sy) = (mvP speed ex sx,mvP speed ey sy)
|
||||
|
||||
moveDoorToward :: Float -> (Point2,Point2) -> Wall -> Wall
|
||||
{-# INLINE moveDoorToward #-}
|
||||
moveDoorToward speed (ex,ey) = wlLine %~ mvPs speed (ex,ey)
|
||||
|
||||
zoneps :: (Point2, Point2) -> [(Int,Int)]
|
||||
{-# INLINE zoneps #-}
|
||||
zoneps (a,b)
|
||||
| dist a b <= 2 * zoneSize
|
||||
= [zoneOfPoint $ pHalf a b]
|
||||
| otherwise = map zoneOfPoint $ divideLine zoneSize a b
|
||||
|
||||
changeZonedWall
|
||||
:: (Wall -> Wall)
|
||||
-> Int
|
||||
-> (Int,Int)
|
||||
-> World
|
||||
-> World
|
||||
changeZonedWall eff n (x,y) = over (wallsZone . znObjects) $ adjustIMZone eff x y n
|
||||
@@ -2,17 +2,10 @@
|
||||
module Dodge.LevelGen.TriggerDoor
|
||||
( placeDoor
|
||||
, placeSlideDoor
|
||||
--, addButtonDoor
|
||||
) where
|
||||
import Dodge.Data
|
||||
--import Dodge.Base
|
||||
--import Dodge.Zone
|
||||
import Dodge.Default.Wall
|
||||
import Dodge.Wall.Move
|
||||
import Dodge.LevelGen.MoveDoor
|
||||
--import Dodge.LevelGen.Switch
|
||||
--import Dodge.LevelGen.Pathing
|
||||
import Dodge.LevelGen.MoveDoor
|
||||
import Dodge.LevelGen.DoorPane
|
||||
import Picture
|
||||
import Geometry
|
||||
@@ -22,7 +15,6 @@ import Dodge.SoundLogic.LoadSound
|
||||
import Dodge.Data.SoundOrigin
|
||||
|
||||
import Data.List
|
||||
--import Data.Maybe
|
||||
import Control.Lens
|
||||
--import Data.Graph.Inductive hiding ((&))
|
||||
import qualified Data.IntSet as IS
|
||||
@@ -42,7 +34,6 @@ placeDoor col cond pss w = (drid, addWalls w & doors %~ addDoor)
|
||||
, _drStatus = DoorInt 0
|
||||
, _drTrigger = cond
|
||||
, _drMech = doorMechanismStepwise nsteps drid wlids pss
|
||||
, _drCoord = 0
|
||||
}
|
||||
nsteps = length pss - 1
|
||||
wlids = take 4 [IM.newKey $ _walls w ..]
|
||||
@@ -77,7 +68,6 @@ doorMechanismStepwise nsteps drid wlids pss dr w
|
||||
newps = uncurry (rectanglePairs 9) (pss !! n)
|
||||
-- it is not at all clear that the zoning selects the correct walls
|
||||
|
||||
-- TODO think about wall zoning, simplify!
|
||||
doorMechanism :: Int -> Float -> [(Int,(Point2,Point2),(Point2,Point2))] -> Door -> World -> World
|
||||
doorMechanism drid speed wlidOpCps dr w
|
||||
| toOpen && dstatus /= DoorOpen = moveUpdate $ foldl' doOpen w wlidOpCps
|
||||
@@ -91,18 +81,11 @@ doorMechanism drid speed wlidOpCps dr w
|
||||
| dist (fst wlpos) (fst cpos) < 1 = doors . ix drid . drStatus .~ DoorClosed
|
||||
| otherwise = doors . ix drid . drStatus .~ DoorHalfway
|
||||
(wlid',opos,cpos) = head wlidOpCps
|
||||
wlpos = _wlLine $ _walls w IM.! wlid'
|
||||
wlpos = _wlLine $ _walls w IM.! wlid'
|
||||
toOpen = _drTrigger dr w
|
||||
dstatus = _drStatus dr
|
||||
doOpen w' (wlid,openpos,cp) = mvDoorWithZone w' wlid openpos cp
|
||||
doClose w' (wlid,_,cp) = mvDoorWithZone w' wlid cp cp
|
||||
mvDoorWithZone w' wlid p zp = moveWall wlid wl newwlline w'
|
||||
where
|
||||
wl = _walls w' IM.! wlid
|
||||
newwlline = mvPs speed p (_wlLine wl)
|
||||
-- w'
|
||||
-- & walls . ix wlid %~ moveDoorToward speed p
|
||||
-- & (\w'' -> foldr (changeZonedWall (moveDoorToward speed p) wlid) w'' (zoneps zp))
|
||||
doOpen w' (wlid,opp, _) = moveWallIDToward wlid speed opp w'
|
||||
doClose w' (wlid,_ ,clp) = moveWallIDToward wlid speed clp w'
|
||||
|
||||
-- TODO cut pathing if not pathable, reset when opened
|
||||
placeSlideDoor :: Bool -> Color -> (World -> Bool) -> Point2 -> Point2 -> Float -> World
|
||||
@@ -116,7 +99,6 @@ placeSlideDoor isPathable col cond a b speed w = (drid, addWalls w & doors %~ ad
|
||||
, _drStatus = DoorClosed
|
||||
, _drTrigger = cond
|
||||
, _drMech = doorMechanism drid speed (zip3 wlids shiftedPairs pairs)
|
||||
, _drCoord = 0
|
||||
}
|
||||
addWalls w' = foldl' addWall w' $ zip wlids pairs
|
||||
addWall w' (wlid, wlps) = w' & walls %~ IM.insert wlid defaultWall
|
||||
|
||||
Reference in New Issue
Block a user