aboutsummaryrefslogtreecommitdiff
path: root/Final.hs
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-12-03 01:03:52 -0700
committerJosh Rahm <joshuarahm@gmail.com>2022-12-03 01:03:52 -0700
commit11fca081b1241e1915f357fa40baa3e97aceb823 (patch)
treec0312c145d9133cef5e31b04a71bec050097f0f0 /Final.hs
parent7dd8c59353167e84dab9e7a1afc16e2290b249e3 (diff)
downloadterralloc-11fca081b1241e1915f357fa40baa3e97aceb823.tar.gz
terralloc-11fca081b1241e1915f357fa40baa3e97aceb823.tar.bz2
terralloc-11fca081b1241e1915f357fa40baa3e97aceb823.zip
Start reviving this ancient project. (It's pretty cool).
Got it to compile using Stack. Skybox works, but nothing else really does. I think this is a problem with how the program is interpreting the surface pixels when calculating the map terrain and elevation. I think some TLC is in order.
Diffstat (limited to 'Final.hs')
-rw-r--r--Final.hs31
1 files changed, 16 insertions, 15 deletions
diff --git a/Final.hs b/Final.hs
index 4fd50e0..951edce 100644
--- a/Final.hs
+++ b/Final.hs
@@ -5,8 +5,8 @@
module Main where
import Graphics.Rendering.OpenGL as GL
-import Graphics.UI.SDL.Image as SDLImg
-import Graphics.UI.SDL as SDL
+import SDL.Image as SDLImg
+import SDL
import Graphics.SDL.SDLHelp
import Graphics.Glyph.Util
import Control.Monad
@@ -27,6 +27,8 @@ import Resources
import System.Random
import System.Environment
+import qualified SDL
+import qualified SDL
{-
@@ -37,14 +39,12 @@ import System.Environment
- w is the minimum width of the two images and h is the minimum
- height.
-}
-buildArray :: SDL.Surface -> SDL.Surface -> Array (Int,Int) Tile
-buildArray terrain height =
+buildArray :: SDL.Surface -> SDL.Surface -> IO (Array (Int,Int) Tile)
+buildArray terrain height = do
+ (V2 (fromIntegral -> w) (fromIntegral -> h)) <- SDL.surfaceDimensions terrain
{- Pick the minimum width and height between the two images -}
- let w = min (SDL.surfaceGetWidth terrain) $ SDL.surfaceGetWidth height
- h = min (SDL.surfaceGetHeight terrain) $ SDL.surfaceGetHeight height
-
- {- Function that returns a Tile for an x y coordinate -}
- conv (x,y) =
+ let {- Function that returns a Tile for an x y coordinate -}
+ conv x y =
let terrainVal = fromIntegral $ getPixelUnsafe x y terrain
{- The height is encoded as the sum of the color channels, to make life a litte
- easier on the heightmap reader. -}
@@ -62,8 +62,8 @@ buildArray terrain height =
Tile terrainVal' heightVal
{- build the list of Tiles to jam into the array -}
- list = map conv [(x,y) | x <- [0..w-1], y <- [0..h-1]]
- in listArray ((0,0),(w-1,h-1)) list
+ list = [conv x y | x <- [0..w-1], y <- [0..h-1]]
+ in return $ listArray ((0,0),(w-1,h-1)) list
{- This function takes the array generated in the function from above and
- creates a new array that colors in the array with locations of bodies
@@ -202,7 +202,7 @@ printShowArray arr = do
forM_ [0..h] $ \y -> do
forM_ [0..w] $ \x -> do
lNext <- readArray arr (x,y)
- putStr $ show lNext
+ putStr $ show lNext ++ " "
putStrLn ""
{- The colors each tile type is mapped to
@@ -332,10 +332,10 @@ main = do
(m:_) -> doload m
_ -> sequence [SDLImg.load "maps/wonderland_terrain.png", SDLImg.load "maps/wonderland_height.png"]
- let arr = buildArray terrain height
+ arr <- buildArray terrain height
coloredArr <- colorArray arr
- surface <- simpleStartup "Terralloc" (1280,1024)
+ window <- simpleStartup "Terralloc" (1280,1024)
stgen <- newStdGen
stgen2 <- newStdGen
@@ -347,7 +347,8 @@ main = do
(mapping,water) <- getWaterQuads arr coloredArr
coloredArr2 <- mapArray (\idx -> if idx == 0 then -1 else Map.findWithDefault (-1) idx mapping) coloredArr
printShowArray coloredArr2
+ printArray arr
{- Kick off SDL with the callbacks defined in Resources -}
- makeResources surface (createBuilder arr) forestLocations jungleLocations water arr coloredArr2
+ makeResources window (createBuilder arr) forestLocations jungleLocations water arr coloredArr2
>>= startPipeline reshape eventHandle displayHandle updateHandle;