summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2010-04-08 16:00:01 +0200
committerMatthias Schiffer <matthias@gamezock.de>2010-04-08 16:00:01 +0200
commitf86af7816c3dc1e232e6e35f1c711ad2d0a713d2 (patch)
treed8f5dba2cdcd96cdbad545978aafacdb95b474a5 /src
parentd6b28723a26151d8ac6cb195d4e2135b05fdac5a (diff)
downloadhtanks-f86af7816c3dc1e232e6e35f1c711ad2d0a713d2.tar
htanks-f86af7816c3dc1e232e6e35f1c711ad2d0a713d2.zip
Added nunchuk support
Diffstat (limited to 'src')
-rw-r--r--src/HTanks.hs1
-rw-r--r--src/WiimotePlayer.hs23
2 files changed, 18 insertions, 6 deletions
diff --git a/src/HTanks.hs b/src/HTanks.hs
index 55d82ec..f018a8c 100644
--- a/src/HTanks.hs
+++ b/src/HTanks.hs
@@ -66,7 +66,6 @@ mainLoop = do
liftIO $ usleep gl $ truncate $ 1e6*(minFrameTime - drender)
currenttime <- liftIO getCurrentTime
- liftIO $ print $ diffUTCTime currenttime rtime
let d = round $ 1e2*(diffUTCTime currenttime t)
replicateM_ d simulationStep
diff --git a/src/WiimotePlayer.hs b/src/WiimotePlayer.hs
index 2487d17..3907615 100644
--- a/src/WiimotePlayer.hs
+++ b/src/WiimotePlayer.hs
@@ -18,18 +18,31 @@ data WiimotePlayer = WiimotePlayer Wiimote
instance Player WiimotePlayer where
playerUpdate (WiimotePlayer wiimote) tank = do
- buttons <- hwiidGetState wiimote >>= return . stateButtons
+ state <- hwiidGetState wiimote
messages <- hwiidGetMesg wiimote
- let shoot = any (\m -> (mesgType m == hwiidMesgTypeButton) && (test (mesgButtons m) hwiidButtonB)) $ messages
+ let buttons = stateButtons state
+ shoot = any (\m -> (mesgType m == hwiidMesgTypeButton) && (test (mesgButtons m) hwiidButtonB)) $ messages
+ foo = any (\m -> (mesgType m == hwiidMesgTypeButton) && (test (mesgButtons m) hwiidButtonA)) $ messages
x = (if (test buttons hwiidButtonLeft) then (-1) else 0) + (if (test buttons hwiidButtonRight) then 1 else 0)
y = (if (test buttons hwiidButtonDown) then (-1) else 0) + (if (test buttons hwiidButtonUp) then 1 else 0)
+ ext = stateExt state
+
+ (mx, my) <- if (extType ext) /= hwiidExtNunchuk
+ then return (x, y)
+ else do
+ let nx = ((fromIntegral . extNunchukStickX $ ext) - 0x80)/0x80
+ ny = ((fromIntegral . extNunchukStickY $ ext) - 0x80)/0x80
+ return $ if (nx*nx + ny*ny) < 0.4 then (x, y) else (x+nx, y+ny)
+
--ax = aimx - (fromRational . toRational . tankX $ tank)
--ay = aimy - (fromRational . toRational . tankY $ tank)
- move = (x /= 0 || y /= 0)
+ let move = (mx /= 0 || my /= 0)
+ angle = if move then Just $ fromRational $ round ((atan2 my mx)*1000000*180/pi)%1000000 else Nothing
+
- angle = if move then Just $ fromRational $ round ((atan2 y x)*1000000*180/pi)%1000000 else Nothing
--aangle = if (ax /= 0 || ay /= 0) then Just $ fromRational $ round ((atan2 ay ax)*1000000*180/pi)%1000000 else Nothing
+ when foo $ print state
return (WiimotePlayer wiimote, angle, move, Nothing, shoot)
@@ -37,7 +50,7 @@ newWiimotePlayer :: IO WiimotePlayer
newWiimotePlayer = do
wiimote <- hwiidOpen bdAddrAny (hwiidFlagMesgInterface .|. hwiidFlagNonblock)
when (wiimote == nullWiimote) $ fail "Wiimote error"
- hwiidSetReportMode wiimote hwiidReportButtons
+ hwiidSetReportMode wiimote (hwiidReportButtons .|. hwiidReportIR .|. hwiidReportNunchuk)
return $ WiimotePlayer wiimote
test :: (Bits a) => a -> a -> Bool