This repository has been archived on 2025-03-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
htanks/src/Player.hs
2010-04-07 13:28:38 +02:00

27 lines
790 B
Haskell

{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-}
module Player ( Player(..)
, SomePlayer(..)
) where
import Data.Fixed
import Data.Typeable
import Tank
import GLDriver (SomeEvent)
class Player a where
playerUpdate :: a -> Tank -> IO (a, Maybe Micro, Bool, Maybe Micro, Bool)
handleEvent :: a -> SomeEvent -> a
handleEvent player _ = player
data SomePlayer = forall a. Player a => SomePlayer a
instance Player SomePlayer where
playerUpdate (SomePlayer player) tank = do
(p, angle, move, aangle, shoot) <- playerUpdate player tank
return (SomePlayer p, angle, move, aangle, shoot)
handleEvent (SomePlayer player) event = SomePlayer $ handleEvent player event