27 lines
722 B
Haskell
27 lines
722 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 -> (a, Maybe Micro, Bool, Maybe Micro)
|
|
handleEvent :: a -> SomeEvent -> a
|
|
|
|
handleEvent player _ = player
|
|
|
|
|
|
data SomePlayer = forall a. Player a => SomePlayer a
|
|
|
|
instance Player SomePlayer where
|
|
playerUpdate (SomePlayer player) tank =
|
|
let (p, angle, move, aangle) = playerUpdate player tank
|
|
in (SomePlayer p, angle, move, aangle)
|
|
handleEvent (SomePlayer player) event = SomePlayer $ handleEvent player event
|