-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpygame_test.py
57 lines (45 loc) · 1.69 KB
/
pygame_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import time
import pygame
pygame.init()
size = [500, 700]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("My Game")
#Loop until the user clicks the close button.
done = False
# Define some colors
BLACK = ( 0, 0, 0)
WHITE = ( 255, 255, 255)
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
gamepad = pygame.joystick.Joystick(0)
gamepad.init()
print("Initialised? ", gamepad.get_name())
print("Axis are: ", gamepad.get_numaxes())
done = False
# -------- Main Program Loop -----------
while not done:
# EVENT PROCESSING STEP
pygame.event.pump()
for event in pygame.event.get(): # User did something
print(event)
if event.type == pygame.QUIT: # If user clicked close
done=True # Flag that we are done so we exit this loop
# Possible joystick actions: JOYAXISMOTION JOYBALLMOTION JOYBUTTONDOWN JOYBUTTONUP JOYHATMOTION
elif event.type == pygame.JOYAXISMOTION:
axis = [ 'X', 'Y' ]
print( "joystick: %d, movement: %4.2f in the %s-axis" % ( event.joy, event.value, axis[event.axis] ) )
elif event.type == pygame.JOYBUTTONDOWN and event.button == 7:
print( "Joystick button pressed." )
#pass
elif event.type == pygame.JOYBUTTONUP:
print( 'joystick: %d, button: %d' % ( event.joy, event.button ) )
# DRAWING STEP
# First, clear the screen to white. Don't put other drawing commands
# above this, or they will be erased with this command.
screen.fill( WHITE )
# Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# Limit to 20 frames per second
clock.tick( 20 )
# exit
pygame.quit()