1 '''Test thw wiimote extension for pygame
3 I stole the graphing from wiiewer and then hacked it to work without Numeric
8 import pygame_wiimote
# ideally something like this would be part of pygame so the _ would become .
15 # initialze the wiimotes
16 if os
.name
!= 'nt': print 'press 1&2'
17 pygame_wiimote
.init(1, 5) # look for 1, wait 5 seconds
18 n
= pygame_wiimote
.get_count() # how many did we get?
21 print 'no wiimotes found'
24 wm
= pygame_wiimote
.Wiimote(0) # access the wiimote object
26 wm
.enable_accels(1) # turn on acceleration reporting
28 w
,h
= size
= (512,512)
29 screen
= pygame
.display
.set_mode(size
)
36 colors
= [ (255,0,0), (0,255,0), (0,0,255), (255,255,0), (255, 0, 255), (0,255,255) ]
39 for event
in pygame
.event
.get():
40 if event
.type == pygame
.QUIT
:
44 elif event
.type in [ pygame_wiimote
.WIIMOTE_BUTTON_PRESS
,
45 pygame_wiimote
.NUNCHUK_BUTTON_PRESS
]:
46 print event
.button
, 'pressed on', event
.id
47 elif event
.type in [ pygame_wiimote
.WIIMOTE_BUTTON_RELEASE
,
48 pygame_wiimote
.NUNCHUK_BUTTON_RELEASE
]:
49 print event
.button
, 'released on', event
.id
50 elif event
.type in [ pygame_wiimote
.WIIMOTE_ACCEL
, pygame_wiimote
.NUNCHUK_ACCEL
]:
51 if event
.type == pygame_wiimote
.WIIMOTE_ACCEL
:
56 s
= int((event
.accel
[c
] * h
/ maxA
+ h
)/2)
57 s
= max(0, min(h
-1, s
))
58 pygame
.draw
.line(screen
, colors
[b
+c
], (w
-3, old
[b
+c
]), (w
-2, s
))
60 screen
.blit(screen
, (-1, 0))
61 elif event
.type == pygame_wiimote
.WIIMOTE_STATUS
:
62 print 'status', event
.dict
63 elif event
.type == pygame_wiimote
.WIIMOTE_DISCONNECT
: