diff options
Diffstat (limited to 'HTanks.hs')
-rw-r--r-- | HTanks.hs | 34 |
1 files changed, 24 insertions, 10 deletions
@@ -1,24 +1,38 @@ import Game import Level import Tank -import Control.Monad.State import GLDriver import GLX +import Control.Concurrent (threadDelay) +import Control.Monad.State +import Data.Maybe + + main :: IO () main = do - glxContext <- initGL glxDriver + gl <- initGL glxDriver let gameState = GameState {level = testLevel, tanks = [Tank 0.5 0.5 0]} - (_, gameState) <- runGame gameState mainLoop + (_, gameState) <- runGame gameState $ mainLoop gl print $ tanks gameState -mainLoop :: Game () -mainLoop = do - (tank:_) <- gets tanks - let newtank = tank {posx = 1 + posx tank} - modify $ \game -> game {tanks = newtank:(tail $ tanks game)} - gets tanks >>= \t -> liftIO $ print t - when (posx newtank < 10) mainLoop +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 = return True
\ No newline at end of file |