Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import os
  2. import pygame
  3.  
  4. size = width, height = 400, 300
  5. screen = pygame.display.set_mode(size)
  6.  
  7.  
  8. def load_image(name, color_key=None):
  9. fullname = os.path.join('data', name)
  10. try:
  11. image = pygame.image.load(fullname).convert()
  12. except pygame.error as message:
  13. print('Cannot load image:', name)
  14. raise SystemExit(message)
  15.  
  16. if color_key is not None:
  17. if color_key == -1:
  18. color_key = image.get_at((0, 0))
  19. image.set_colorkey(color_key)
  20. else:
  21. image = image.convert_alpha()
  22. return image
  23.  
  24.  
  25. clock = pygame.time.Clock()
  26.  
  27. # группа, содержащая все спрайты
  28. all_sprites = pygame.sprite.Group()
  29.  
  30. # изображение должно лежать в папке data
  31. cursor_image = load_image("arrow.png")
  32. cursor = pygame.sprite.Sprite(all_sprites)
  33. cursor.image = cursor_image
  34. cursor.rect = cursor.image.get_rect()
  35.  
  36. # скрываем системный курсор
  37. pygame.mouse.set_visible(False)
  38.  
  39. running = True
  40. while running:
  41. for event in pygame.event.get():
  42. if event.type == pygame.QUIT:
  43. running = False
  44. if event.type == pygame.MOUSEMOTION:
  45. # изменяем положение спрайта-стрелки
  46. cursor.rect.topleft = event.pos
  47. screen.fill(pygame.Color("black"))
  48. # рисуем курсор только если он в пределах окна
  49. if pygame.mouse.get_focused():
  50. all_sprites.draw(screen)
  51. pygame.display.flip()
  52.  
  53. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement