summaryrefslogtreecommitdiffstats
path: root/Player.hs
blob: f3303f8c6426d9632cc0e14feceb9ab62063801e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-}

module Player ( Player(..)
              , SomePlayer(..)
              ) where

import Data.Fixed
import Data.Typeable

import Tank
import GLDriver (SomeEvent)


class Player a where
    playerMovement :: a -> Tank -> (a, Maybe Micro, Bool)
    handleEvent :: a -> SomeEvent -> a
    
    handleEvent player _ = player


data SomePlayer = forall a. Player a => SomePlayer a

instance Player SomePlayer where
    playerMovement (SomePlayer player) tank = (\(p, angle, move) -> (SomePlayer p, angle, move)) $ playerMovement player tank
    handleEvent (SomePlayer player) event = SomePlayer $ handleEvent player event