3 import Prelude
hiding (lookup)
4 import Data
.IntMap
(IntMap
)
5 import qualified Data
.IntMap
as IM
6 import qualified Data
.Set
as Set
9 import Control
.Monad
.State
24 worldSpace
:: Spatial
,
26 images
:: IntMap Image
29 runWorld
:: [Input
] -> World
-> (World
, [Output
])
30 runWorld ins
(World s cam img
) = (World s
' cam
' img
', outs
) where
33 (over
,diver
,s1
) = internalInteractions s
36 wakeUps
(allPieces s
),
38 map (\(a
,b
) -> (a
, Overlap
(self b
) b
)) over
,
39 map (\(b
,a
) -> (a
, Overlap
(self b
) b
)) over
,
40 map (\(a
,b
) -> (a
, Diverge
(self b
) b
)) diver
,
41 map (\(b
,a
) -> (a
, Diverge
(self b
) b
)) diver
43 f
(sv
,rvs
) (p
,c
) = let (sv
',r
) = pokePiece p c sv
in (sv
',r
:rvs
)
44 (s2
,rvs
) = foldl f
(s1
,[]) cols
45 --(outs,spawns) = separateReactions (concat rvs)
46 (outs
,spawns
) = ([],[])
47 s3
= spawnPieces spawns s2
48 s
' = moveEverything s3
52 wprint
:: (Show a
) => a
-> b
53 wprint x
= trace
(show x
) undefined
55 wakeUps
:: [Piece
] -> [(Piece
, Collision
)]
60 renderWorld
:: Video
-> World
-> IO ()
61 renderWorld video w
= seeBelow
where
62 draws
= snapShotPieces
(worldSpace w
)
66 forM_ draws
(\(img
,xy
) -> imgApply img
(xy
+cxy
))
71 loadWorld
:: Video
-> IO World
73 img
<- loadImage video
"image.bmp"
76 (7, testPiece img
(100:+0) (0:+10) 2 7),
77 (5, testPiece img
(100:+200) (0:+(-10)) 1 5)
80 worldSpace
= Spatial pm
(Set
.empty),
82 images
= IM
.fromList
[(3,img
)]