31 lines
918 B
Haskell
31 lines
918 B
Haskell
{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-}
|
|
|
|
module Player ( Player(..)
|
|
, SomePlayer(..)
|
|
) where
|
|
|
|
import Vector
|
|
import Data.Typeable
|
|
|
|
import Tank
|
|
import GLDriver (SomeEvent)
|
|
|
|
|
|
class Player a where
|
|
playerUpdate :: a -> Tank -> IO (a, Maybe Rotation, Bool, Maybe Rotation, Bool)
|
|
|
|
handleEvent :: a -> SomeEvent -> a
|
|
handleEvent player _ = player
|
|
|
|
renderPlayer :: a -> IO ()
|
|
renderPlayer _ = return ()
|
|
|
|
|
|
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
|
|
renderPlayer (SomePlayer player) = renderPlayer player
|