about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2013-04-02 01:22:31 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2013-04-02 01:22:31 -0400
commit8cb868224840c734f38e9041aa1567cdecd17797 (patch)
tree505d26708603f12ddc7be321ef31a801ddb7d618
parent72479dcfc46a22ead22fc2ef639e5835b5a1840a (diff)
downloadfallen-hs-8cb868224840c734f38e9041aa1567cdecd17797.tar.gz
fallen-hs-8cb868224840c734f38e9041aa1567cdecd17797.tar.bz2
fallen-hs-8cb868224840c734f38e9041aa1567cdecd17797.zip
Cleaned up FunMap
-rw-r--r--Fallen/FunMap.hs10
1 files changed, 5 insertions, 5 deletions
diff --git a/Fallen/FunMap.hs b/Fallen/FunMap.hs index 809bd4c..07d4a77 100644 --- a/Fallen/FunMap.hs +++ b/Fallen/FunMap.hs
@@ -24,25 +24,25 @@ module Fallen.FunMap
24 } 24 }
25 25
26 -- emptyMap :: Int -> Int -> Tile -> Map 26 -- emptyMap :: Int -> Int -> Tile -> Map
27 emptyMap w h t = Map { dimension=(w,h), mapdata=(\p -> t), background=t } 27 emptyMap w h t = Map { dimension=(w,h), mapdata= const t, background=t }
28 28
29 -- inBounds :: Map -> Point -> Bool 29 -- inBounds :: Map -> Point -> Bool
30 inBounds m (x,y) = let (w,h) = dimension m in (x >= 0) && (x < w) && (y >= 0) && (y < h) 30 inBounds m (x,y) = let (w,h) = dimension m in (x >= 0) && (x < w) && (y >= 0) && (y < h)
31 31
32 -- getTileAtPos :: Map -> Point -> Tile 32 -- getTileAtPos :: Map -> Point -> Tile
33 getTileAtPos m p = if (inBounds m p) 33 getTileAtPos m p = if inBounds m p
34 then mapdata m p 34 then mapdata m p
35 else background m 35 else background m
36 36
37 -- findTileInMap :: Map -> Tile -> [Point] 37 -- findTileInMap :: Map -> Tile -> [Point]
38 -- REALLY inefficient 38 -- REALLY inefficient
39 findTileInMap m t = filter (\p -> t == mapdata m p) rawPoints where 39 findTileInMap m t = filter (==t) $ map (mapdata m) rawPoints where
40 (w,h) = dimension m 40 (w,h) = dimension m
41 rawPoints = [(x,y) | x <- [0..w-1], y <- [0..h-1]] 41 rawPoints = [(x,y) | x <- [0..w-1], y <- [0..h-1]]
42 42
43 -- updateMap :: Point -> Tile -> Map -> Map 43 -- updateMap :: Point -> Tile -> Map -> Map
44 updateMap p t (Map d xs bg) = Map d (redirect p t xs) bg where 44 updateMap p t (Map d xs bg) = Map d (redirect p t xs) bg where
45 redirect p t xs = (\p2 -> if p == p2 then t else xs p2) 45 redirect p t xs p2 = if p == p2 then t else xs p2
46 46
47 -- legalMoves :: Map -> Point -> [Tile] -> [Direction] 47 -- legalMoves :: Map -> Point -> [Tile] -> [Direction]
48 legalMoves m p ts = map fst $ filter legal $ map tileDir directions where 48 legalMoves m p ts = map fst $ filter legal $ map tileDir directions where
@@ -51,6 +51,6 @@ module Fallen.FunMap
51 51
52 -- fillMapRect :: Int -> Int -> Int -> Int -> Tile -> Map -> Map 52 -- fillMapRect :: Int -> Int -> Int -> Int -> Tile -> Map -> Map
53 fillMapRect x y w h t (Map d xs bg) = Map d redirectInBounds bg where 53 fillMapRect x y w h t (Map d xs bg) = Map d redirectInBounds bg where
54 redirectInBounds = (\p -> if (inBounds p) then t else xs p) 54 redirectInBounds p = if inBounds p then t else xs p
55 inBounds (px,py) = (px >= x) && (px < (x+w)) && (py >= y) && (py < (y+h)) 55 inBounds (px,py) = (px >= x) && (px < (x+w)) && (py >= y) && (py < (y+h))
56 \ No newline at end of file 56 \ No newline at end of file