From 83f0606ea9dfd6b493097dc97330055dff4a2867 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 24 Jun 2011 21:50:32 +0200 Subject: Added Transformable class to simplify collision calculation --- src/HWiidPlayer.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/HWiidPlayer.hs') 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 -- cgit v1.2.3