summaryrefslogtreecommitdiffstats
path: root/src/Player.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Player.hs')
-rw-r--r--src/Player.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Player.hs b/src/Player.hs
new file mode 100644
index 0000000..baf1cbe
--- /dev/null
+++ b/src/Player.hs
@@ -0,0 +1,27 @@
+{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-}
+
+module Player ( Player(..)
+ , SomePlayer(..)
+ ) where
+
+import Data.Fixed
+import Data.Typeable
+
+import Game (Tank(..))
+import GLDriver (SomeEvent)
+
+
+class Player a where
+ playerUpdate :: a -> Tank -> (a, Maybe Micro, Bool, Maybe Micro, Bool)
+ 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, shoot) = playerUpdate player tank
+ in (SomePlayer p, angle, move, aangle, shoot)
+ handleEvent (SomePlayer player) event = SomePlayer $ handleEvent player event