summaryrefslogtreecommitdiffstats
path: root/src/Player.hs
blob: 923944366279964237001bbf41864bcfdab7a183 (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 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