Advertisement
Guest User

drag.py

a guest
May 23rd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import pygame_sdl2
  2. pygame_sdl2.import_as_pygame()
  3. import sys
  4. import pygame
  5. from pygame.locals import *
  6.  
  7. pygame.init()
  8. # Resolution is ignored on Android
  9. surface = pygame.display.set_mode((640, 480))
  10. clock = pygame.time.Clock()
  11. surfrect = surface.get_rect()
  12. rect = pygame.Rect((0, 0), (64, 64))
  13. rect.center = (surfrect.w/2,surfrect.h/2)
  14. touched = False
  15. while True:
  16.     for ev in pygame.event.get():
  17.         if ev.type == QUIT:
  18.             pygame.quit()
  19.         elif ev.type == pygame.MOUSEBUTTONDOWN:
  20.             if rect.collidepoint(ev.pos):
  21.                 touched = True
  22.                 # This is the starting point
  23.                 pygame.mouse.get_rel()
  24.         elif ev.type == pygame.MOUSEBUTTONUP:
  25.             touched = False
  26.     clock.tick(60)
  27.     surface.fill((0, 0, 0))
  28.     if touched:
  29.         rect.move_ip(pygame.mouse.get_rel())
  30.         rect.clamp_ip(surfrect)
  31.     surface.fill((255, 255, 255), rect)
  32.     pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement