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
25 wm
.enable_accels(1) # turn on acceleration reporting
27 w
,h
= size
= (512,512)
28 screen
= pygame
.display
.set_mode(size
)
35 colors
= [ (255,0,0), (0,255,0), (0,0,255), (255,255,0), (255, 0, 255), (0,255,255) ]
38 for event
in pygame
.event
.get():
39 if event
.type == pygame
.QUIT
:
43 elif event
.type in [ pygame_wiimote
.WIIMOTE_BUTTON_PRESS
,
44 pygame_wiimote
.NUNCHUK_BUTTON_PRESS
]:
45 print event
.button
, 'pressed on', event
.id
46 elif event
.type in [ pygame_wiimote
.WIIMOTE_BUTTON_RELEASE
,
47 pygame_wiimote
.NUNCHUK_BUTTON_RELEASE
]:
48 print event
.button
, 'released on', event
.id
49 elif event
.type in [ pygame_wiimote
.WIIMOTE_ACCEL
, pygame_wiimote
.NUNCHUK_ACCEL
]:
50 if event
.type == pygame_wiimote
.WIIMOTE_ACCEL
:
55 s
= int((event
.accel
[c
] * h
/ maxA
+ h
)/2)
56 s
= max(0, min(h
-1, s
))
57 pygame
.draw
.line(screen
, colors
[b
+c
], (w
-3, old
[b
+c
]), (w
-2, s
))
59 screen
.blit(screen
, (-1, 0))
60 elif event
.type == pygame_wiimote
.WIIMOTE_STATUS
:
61 print 'status', event
.dict
62 elif event
.type == pygame_wiimote
.WIIMOTE_DISCONNECT
: