Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import pygame
- W, H = 1366, 768
- HW, HH = int(W / 2), int(H / 2)
- BRICK_SIZE = 80
- BRICK_SIZE_HALF = int(BRICK_SIZE / 2)
- BRICK_COLOR = (255, 0, 0)
- BLACK = (0, 0, 0)
- pygame.init()
- DS = pygame.display.set_mode((W, H), pygame.FULLSCREEN)
- CLOCK = pygame.time.Clock()
- FPS = 60
- pygame.joystick.init()
- joysticks = [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())]
- if not joysticks:
- print "NO JOYSTICKS DETECTED"
- sys.exit()
- joysticks[0].init()
- bx = HW
- by = HH
- while True:
- pygame.event.get()
- k = pygame.key.get_pressed()
- if k[pygame.K_ESCAPE]: break
- DS.fill(BLACK)
- pygame.draw.rect(DS, BRICK_COLOR, (bx - BRICK_SIZE_HALF, by - BRICK_SIZE_HALF, BRICK_SIZE, BRICK_SIZE), 0)
- # code here
- bx += round(joysticks[0].get_axis(0), 1) * 3
- by += round(joysticks[0].get_axis(1), 1) * 3
- if bx < 0: bx = W
- if bx > W: bx = 0
- if by < 0: by = H
- if by > H: by = 0
- pygame.display.update()
- CLOCK.tick(FPS)
- pygame.joystick.quit()
- pygame.quit()
- sys.exit()
Add Comment
Please, Sign In to add comment