summaryrefslogtreecommitdiffstats
path: root/src/HWiidPlayer.hs
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-24 21:50:32 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-24 21:50:32 +0200
commit83f0606ea9dfd6b493097dc97330055dff4a2867 (patch)
tree464d7f3ed2c02f48b6463d1528e3e0b5f50e79c6 /src/HWiidPlayer.hs
parentd7971385e844e24d9d851d3d142895b5cb89c91b (diff)
downloadhtanks-83f0606ea9dfd6b493097dc97330055dff4a2867.tar
htanks-83f0606ea9dfd6b493097dc97330055dff4a2867.zip
Added Transformable class to simplify collision calculation
Diffstat (limited to 'src/HWiidPlayer.hs')
-rw-r--r--src/HWiidPlayer.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/HWiidPlayer.hs b/src/HWiidPlayer.hs
index 04ea38e..d98b9c9 100644
--- a/src/HWiidPlayer.hs
+++ b/src/HWiidPlayer.hs
@@ -20,6 +20,8 @@ import Graphics.Rendering.OpenGL.GL.VertexSpec
import Player
import Tank
+import qualified Transformable as T
+import qualified Vector as V
data HWiidPlayer = HWiidPlayer Wiimote WiimoteAccCal [(Float, Float)]
@@ -51,15 +53,15 @@ instance Player HWiidPlayer where
then take irSkipSmooth newaims
else newaims
(aimx, aimy) = if null aims then (0, 0) else mulV (1/(fromIntegral $ length aims)) (foldr addV (0, 0) aims)
- ax = aimx - (fromRational . toRational . tankX $ tank)
- ay = aimy - (fromRational . toRational . tankY $ tank)
- aangle = if (ax /= 0 || ay /= 0) then Just $ fromRational $ round ((atan2 ay ax)*1000000*180/pi)%1000000 else Nothing
+ ax = realToFrac $ aimx - (fromRational . toRational . tankX $ tank)
+ ay = realToFrac $ aimy - (fromRational . toRational . tankY $ tank)
+ aim = if (ax /= 0 || ay /= 0) then Just $ V.Vector ax ay else Nothing
move = (mx /= 0 || my /= 0)
angle = atan2 my mx
- moveangle = if move then Just $ fromRational $ round ((angle - (sin $ 8*x)/8)*1000000*180/pi)%1000000 else Nothing
+ dir = if move then Just $ T.rotate (fromRational $ round ((angle - (sin $ 8*x)/8)*1000000*180/pi)%1000000) T.>< V.Vector 1 0 else Nothing
when foo $ print state
- return (HWiidPlayer wiimote cal aims, moveangle, move, aangle, shoot)
+ return (HWiidPlayer wiimote cal aims, dir, move, aim, shoot)
renderPlayer (HWiidPlayer _ _ []) = return ()
renderPlayer (HWiidPlayer _ _ aims) = unsafePreservingMatrix $ do