1 module Sim ( initSimSpace, testSim, physStep, validDirects ) where
3 import Data.Vector ((!), (//))
4 import qualified Data.Vector as V
6 -- Simulation simSpace simW simH
7 data Simulation = Simulation (V.Vector ChunkData) Int Int deriving (Show)
11 | Wall deriving (Show)
13 data ChunkData = ChunkData ChunkType deriving (Show)
16 simGet (Simulation s w _) x y = s ! (y*w+x)
17 simSet (Simulation s w h) c x y = Simulation (s // [(y*w+x,c)]) w h
19 initSimSpace x y = Simulation (V.replicate (y*x) (ChunkData Empty)) x y
21 testSim = simSet (initSimSpace 10 10) (ChunkData Water) 5 0
23 physStep sim@(Simulation _ w h) = _physStep [(x, y) | x <- [0..w-1], y <- [0..h-1]] (initSimSpace w h) sim
24 _physStep grid acc sim@(Simulation s w h) =
26 else _physStep (tail grid) next sim
27 where x = fst $ head grid
31 -- gets chunks around a given chunk that are inside grid
32 validDirects x y w h = filter
33 (\q -> 0 <= (fst q) && (fst q) < w && (snd q) <= 0 && (snd q) < h)
34 [(a,b) | a <- [x-1..x+1], b <- [y-1..y+1], not (a==x && b==y)]