Skip to content

Commit

Permalink
Now the score is also an entity.
Browse files Browse the repository at this point in the history
  • Loading branch information
sixohsix committed Mar 12, 2012
1 parent 951bd32 commit 7deeca1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/HsSdlTest.hs
Expand Up @@ -112,6 +112,20 @@ guy tile randomGen loc = Entity nextState isAlive blit where
T.blitTile tile surf (x loc) (y loc)
return ()

makeScore :: GameEnvM Entity
makeScore = do
t <- eGet textTiles
let blitText = T.drawTileLookup t
in return $ score blitText 0

score :: (SDL.Surface -> String -> Co2 -> IO ()) -> Int -> Entity
score blitText s = Entity nextState isAlive blit where
unchanged = score blitText s
nextState = \state -> score blitText (s + 1)
isAlive = True
blit = \surf -> blitText surf (show s) (Co2 45 60)


initGame :: IO (GameEnv, GameState)
initGame = do
SDL.setVideoMode 640 480 32 []
Expand Down Expand Up @@ -150,7 +164,6 @@ drawScreen = do
fc <- sGet frameCount
liftIO $ SDL.blitSurface back Nothing screen Nothing
drawEntities
blitText (show fc) (Co2 45 60)
liftIO $ SDL.flip screen

drawEntities :: GameEnvM ()
Expand Down Expand Up @@ -179,7 +192,8 @@ loop = do
ents <- sGet liveEntities
when (null ents) $ do
guy <- makeGuy
modify $ \s -> s { liveEntities = [guy] }
score <- makeScore
modify $ \s -> s { liveEntities = [guy, score] }
handleEvents
updateGame
drawScreen
Expand Down

0 comments on commit 7deeca1

Please sign in to comment.