43 lines
855 B
Haskell
43 lines
855 B
Haskell
{-# LANGUAGE PatternGuards #-}
|
|
|
|
import Game
|
|
import Level
|
|
import Tank
|
|
|
|
import GLDriver
|
|
import GLX
|
|
|
|
import Control.Concurrent (threadDelay)
|
|
import Control.Monad.State
|
|
import Data.Maybe
|
|
|
|
|
|
main :: IO ()
|
|
main = do
|
|
gl <- initGL glxDriver
|
|
|
|
let gameState = GameState {level = testLevel, tanks = [Tank 0.5 0.5 0]}
|
|
|
|
runGame gameState $ mainLoop gl
|
|
|
|
deinitGL gl
|
|
|
|
mainLoop :: Driver a => a -> Game ()
|
|
mainLoop gl = do
|
|
run <- liftIO $ handleEvents gl
|
|
liftIO $ threadDelay 10000
|
|
when run $ mainLoop gl
|
|
|
|
handleEvents :: Driver a => a -> IO Bool
|
|
handleEvents gl = do
|
|
event <- nextEvent gl
|
|
if (isJust event)
|
|
then
|
|
handleEvent $ fromJust event
|
|
else
|
|
return True
|
|
|
|
handleEvent :: SomeEvent -> IO Bool
|
|
handleEvent ev
|
|
| Just QuitEvent <- fromEvent ev = return False
|
|
| otherwise = return True
|