Guest User

Untitled

a guest
Jul 12th, 2020
3,728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #!/usr/bin/python3.4
  2. # YOU MUST PROVIDE YOUR OWN pic.png
  3. # Setup Python ----------------------------------------------- #
  4. import pygame, sys
  5.  
  6. # Setup pygame/window ---------------------------------------- #
  7. mainClock = pygame.time.Clock()
  8. from pygame.locals import *
  9. pygame.init()
  10. pygame.display.set_caption('game base')
  11. screen = pygame.display.set_mode((500, 500),0,32)
  12.  
  13. img = pygame.image.load('pic.png').convert()
  14.  
  15. offset = [0, 0]
  16.  
  17. clicking = False
  18. right_clicking = False
  19. middle_click = False
  20.  
  21. # Loop ------------------------------------------------------- #
  22. while True:
  23.  
  24. # Background --------------------------------------------- #
  25. screen.fill((0,0,0))
  26.  
  27. mx, my = pygame.mouse.get_pos()
  28.  
  29. rot = 0
  30. loc = [mx, my]
  31. if clicking:
  32. rot -= 90
  33. if right_clicking:
  34. rot += 180
  35. if middle_click:
  36. rot += 90
  37. screen.blit(pygame.transform.rotate(img, rot), (loc[0] + offset[0], loc[1] + offset[1]))
  38.  
  39. # Buttons ------------------------------------------------ #
  40. right_clicking = False
  41. for event in pygame.event.get():
  42. if event.type == QUIT:
  43. pygame.quit()
  44. sys.exit()
  45. if event.type == KEYDOWN:
  46. if event.key == K_ESCAPE:
  47. pygame.quit()
  48. sys.exit()
  49. if event.type == MOUSEBUTTONDOWN:
  50. if event.button == 1:
  51. clicking = True
  52. if event.button == 3:
  53. right_clicking = True
  54. if event.button == 2:
  55. middle_click = not middle_click
  56. if event.button == 4:
  57. offset[1] -= 10
  58. if event.button == 5:
  59. offset[1] += 10
  60. if event.type == MOUSEBUTTONUP:
  61. if event.button == 1:
  62. clicking = False
  63.  
  64.  
  65. # Update ------------------------------------------------- #
  66. pygame.display.update()
  67. mainClock.tick(60)
Advertisement
Add Comment
Please, Sign In to add comment