Use grid when creating block debris
This commit is contained in:
+1
-54
@@ -12,12 +12,11 @@ import Dodge.Data
|
||||
import Dodge.LevelGen.StaticWalls
|
||||
import Dodge.RoomLink
|
||||
import Geometry
|
||||
import Grid
|
||||
|
||||
import Data.Function (on)
|
||||
import Data.List
|
||||
import Data.Bifunctor
|
||||
import Data.Maybe
|
||||
import qualified Data.Tuple.Extra as Tup
|
||||
import qualified Control.Foldl as L
|
||||
import qualified Data.Set as S
|
||||
|
||||
@@ -57,56 +56,4 @@ pairInPolys
|
||||
-> Bool
|
||||
pairInPolys polys (a,b) = any (pointInPolygon a) polys && any (pointInPolygon b) polys
|
||||
|
||||
shiftedGrid
|
||||
:: Float -- ^ x min
|
||||
-> Float -- ^ x max
|
||||
-> Float -- ^ y min
|
||||
-> Float -- ^ y max
|
||||
-> [(Point2,Point2)]
|
||||
shiftedGrid xmin xmax ymin ymax = grid
|
||||
where
|
||||
xd = xmax - xmin
|
||||
yd = ymax - ymin
|
||||
xsteps = ceiling $ (xd - 40) / 60
|
||||
ysteps = ceiling $ (yd - 40) / 60
|
||||
shift p = bimap (p +.+) (p +.+)
|
||||
grid = map (shift (V2 (xmin + 20) (ymin+20))) $ makeGrid 60 xsteps 60 ysteps
|
||||
|
||||
-- creates a rectangular grid starting at (0,0) in the positive orthant
|
||||
-- needs fixing in degenerate (xstep or ystep == 0) cases
|
||||
makeGrid
|
||||
:: Float -- ^ horizontal step size
|
||||
-> Int -- ^ number of horizontal steps
|
||||
-> Float -- ^ vertical step size
|
||||
-> Int -- ^ number of vertical steps
|
||||
-> [(Point2,Point2)]
|
||||
makeGrid x nx y ny
|
||||
= nub
|
||||
. concatMap doublePair
|
||||
. concatMap (\p -> map (Tup.both (p +.+)) $ makeRect x y)
|
||||
$ gridPoints x nx y ny
|
||||
|
||||
--gridPoints :: Float -> Int -> Float -> Int -> [Point2]
|
||||
--gridPoints x nx y ny = [V2 a b | a <- take nx $ scanl (+) 0 $ repeat x
|
||||
-- , b <- take ny $ scanl (+) 0 $ repeat y
|
||||
-- ]
|
||||
gridPoints :: Float -> Int -> Float -> Int -> [Point2]
|
||||
gridPoints x nx y ny = map f $ gridPoints' nx ny
|
||||
where
|
||||
f (a,b) = V2 (fromIntegral a * x) (fromIntegral b * y)
|
||||
|
||||
gridPoints'' :: Float -> Int -> Float -> Int -> [(Point2,(Int,Int))]
|
||||
gridPoints'' x nx y ny = map f $ gridPoints' nx ny
|
||||
where
|
||||
f (a,b) = (V2 (fromIntegral a * x) (fromIntegral b * y), (a,b))
|
||||
|
||||
gridPoints' :: Int -> Int -> [(Int,Int)]
|
||||
gridPoints' nx ny = [(x,y) | x <- [0..nx-1], y <- [0..ny-1]]
|
||||
|
||||
makeRect :: Float -> Float -> [(Point2,Point2)]
|
||||
makeRect x y = map (bimap toV2 toV2) [((0,0),(x,0))
|
||||
,((0,0),(0,y))
|
||||
,((x,y),(x,0))
|
||||
,((x,y),(0,y))
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user