diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2010-02-22 18:27:18 +0100 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2010-02-22 18:27:18 +0100 |
commit | 465bf683453c869e9b81c87661540c5e28438b1c (patch) | |
tree | fdb837f5790ebebc9ca601684acaadeab742a9e3 /HTanks.hs | |
parent | 62fe58cb55a279c285980a313d4355d91e93601c (diff) | |
download | htanks-465bf683453c869e9b81c87661540c5e28438b1c.tar htanks-465bf683453c869e9b81c87661540c5e28438b1c.zip |
Added simple main loop
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 |