Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from pygame import Rect, Vector2
- from pygame.locals import *
- class square:
- def __init__(s, pos):
- s.anchor = Vector2(pos)
- s.pos = Vector2(pos)
- def draw(s):
- global PDS
- pygame.draw.rect(PDS, WHITE, (s.pos - (50, 50), (100, 100)))
- def update(s, axis1, axis2):
- s.pos = s.anchor + Vector2(axis1 * 300, axis2 * 300)
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- pygame.init()
- PDR = Rect(0, 0, 1280, 720)
- PDS = pygame.display.set_mode(PDR.size)
- joystick = pygame.joystick.Joystick(0)
- stick1 = square(Vector2(PDR.center) - (PDR.center[0] // 2, 0))
- stick2 = square(Vector2(PDR.center) + (PDR.center[0] // 2, 0))
- exit_demo = False
- while not exit_demo:
- events = pygame.event.get()
- for e in events:
- if e.type == KEYUP and e.key == K_ESCAPE:
- exit_demo = True
- PDS.fill(BLACK)
- stick1.draw()
- stick2.draw()
- stick1.update(joystick.get_axis(0), joystick.get_axis(1))
- stick2.update(joystick.get_axis(2), joystick.get_axis(3))
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement