Advertisement
cookertron

Kostik Iln XBOX Controller Stick Demo

Feb 11th, 2022
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import pygame
  2. from pygame import Rect, Vector2
  3. from pygame.locals import *
  4.  
  5. class square:
  6.     def __init__(s, pos):
  7.         s.anchor = Vector2(pos)
  8.         s.pos = Vector2(pos)
  9.        
  10.    
  11.     def draw(s):
  12.         global PDS
  13.         pygame.draw.rect(PDS, WHITE, (s.pos - (50, 50), (100, 100)))
  14.  
  15.     def update(s, axis1, axis2):
  16.         s.pos = s.anchor + Vector2(axis1 * 300, axis2 * 300)
  17.  
  18.    
  19. BLACK = (0, 0, 0)
  20. WHITE = (255, 255, 255)
  21.  
  22. pygame.init()
  23. PDR = Rect(0, 0, 1280, 720)
  24. PDS = pygame.display.set_mode(PDR.size)
  25.  
  26. joystick = pygame.joystick.Joystick(0)
  27.  
  28. stick1 = square(Vector2(PDR.center) - (PDR.center[0] // 2, 0))
  29. stick2 = square(Vector2(PDR.center) + (PDR.center[0] // 2, 0))
  30.  
  31. exit_demo = False
  32. while not exit_demo:
  33.     events = pygame.event.get()
  34.     for e in events:
  35.         if e.type == KEYUP and e.key == K_ESCAPE:
  36.             exit_demo = True
  37.  
  38.     PDS.fill(BLACK)
  39.  
  40.     stick1.draw()
  41.     stick2.draw()
  42.     stick1.update(joystick.get_axis(0), joystick.get_axis(1))
  43.     stick2.update(joystick.get_axis(2), joystick.get_axis(3))
  44.     pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement