summaryrefslogtreecommitdiffstats
path: root/src/Player.hs
blob: 4784b8ba55f4d0869efbd13e792220e5116e42c7 (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
26
27
28
29
30
31
{-# 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
    
    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