Created
February 18, 2017 23:31
-
-
Save AlexLamson/d580423eebdd03c47be9a10411ee034c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, pygame | |
from pygame import Rect | |
from pygame.locals import * | |
size = width, height = 640, 480 | |
pos = (0, 0) #mouse position | |
inital_drag_pos = (0, 0) | |
dragging = False | |
(leftclick, middleclick, rightclick) = (False, False, False) | |
pygame.init() | |
screen = pygame.display.set_mode(size) | |
while True: | |
screen.fill((0, 0, 0)) | |
for event in pygame.event.get(): | |
# Close the window | |
if event.type == pygame.QUIT: | |
sys.exit() | |
# Keyboard input | |
elif event.type == pygame.KEYDOWN: | |
if event.key == pygame.K_q: | |
sys.exit() | |
# Mouse input | |
elif event.type == MOUSEBUTTONDOWN: | |
if not dragging: | |
inital_drag_pos = pygame.mouse.get_pos() | |
dragging = True | |
(leftclick, middleclick, rightclick) = pygame.mouse.get_pressed() | |
elif event.type == MOUSEBUTTONUP: | |
if leftclick: | |
pos = pygame.mouse.get_pos() | |
elif rightclick: | |
pos = pygame.mouse.get_pos() | |
(leftclick, middleclick, rightclick) = pygame.mouse.get_pressed() | |
dragging = False | |
if dragging: | |
# continuing to drag | |
pos = pygame.mouse.get_pos() | |
pygame.draw.line(screen, (0, 0, 255), inital_drag_pos, pos, 4) | |
pygame.display.flip() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment