-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
59 lines (50 loc) · 1.58 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module Main (main) where
import GameState
import Paddle
import Brick
import Breaker
import MAGPoint
import MAGColor
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
import Data.IORef
import GameObjects (Drawable(..))
main = do
(progname, _) <- getArgsAndInitialize
storedState <- newIORef level1
initialDisplayMode $= [DoubleBuffered]
initialWindowSize $= (Size 800 800)
createWindow "Brick Attack"
displayCallback $= (display storedState)
idleCallback $= Just (idleFn storedState)
-- reshapeCallback $= Just reshape
keyboardMouseCallback $= Just (manageInput storedState)
initFn
mainLoop
initFn :: IO ()
initFn = do
matrixMode $= Projection
ortho 0.0 80.0 0.0 80.0 0.0 1.0
manageInput :: IORef GameState -> Key -> KeyState -> Modifiers -> Position -> IO ()
manageInput storedState key keystate modifiers pos = do
keyAct storedState key keystate
postRedisplay Nothing
keyAct :: IORef GameState -> Key -> KeyState -> IO ()
keyAct storedState (SpecialKey KeyLeft) Down = do
state <- get storedState
writeIORef storedState state{paddle = movePaddle (paddle state) (-2)}
keyAct storedState (SpecialKey KeyRight) Down = do
state <- get storedState
writeIORef storedState state{paddle = movePaddle (paddle state) 2}
keyAct _ _ _ = return ()
idleFn :: IORef GameState -> IO ()
idleFn state = do
gameState <- readIORef state
writeIORef state (updateState (determineUpdate gameState) gameState)
postRedisplay Nothing
display :: IORef GameState -> DisplayCallback
display state = do
gameState <- readIORef state
clear [ColorBuffer]
drawGame gameState
swapBuffers