forked from HampshireCS/CS112-Spring2012
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmorenotes.py
More file actions
62 lines (50 loc) · 1.5 KB
/
morenotes.py
File metadata and controls
62 lines (50 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
import pygame
from pygame.locals import *
##Settings
BACKGROUND = 80,80,80
SCREEN_SIZE = 800,600
RECT_SIZE = 120,80
RED = 255,0,0
FPS = 30
pygame.init()
screen = pygame.display.set_mode(SCREEN_SIZE)
bounds = screen.get_rect()
rects = [pygame.Rect((0,0), RECT_SIZE),
pygame.Rect((0,0), RECT_SIZE),
pygame.Rect((680,0), RECT_SIZE),
pygame.Rect((680,500), RECT_SIZE),
pygame.Rect((0,500), RECT_SIZE)]
rects[0].center = bounds.center
rects[1].topleft = bounds.topleft
rects[2].topright = bounds.topright
rects[3].bottomleft = bounds.bottomleft
rects[4].bottomright = bounds.bottomright
clock = pygame.time.Clock()
done = False
grabbed = False
while not done:
for evt in pygame.event.get():
if evt.type == QUIT:
done = True
elif evt.type == KEYDOWN and evt.key == K_ESCAPE:
done = True
elif evt.type == MOUSEBUTTONDOWN:
for rect in rects:
if rect.collidepoint(pygame.mouse.get_pos()):
grabbed = rect
elif evt.type == MOUSEBUTTONUP:
grabbed = None
if grabbed:
grabbed.center = pygame.mouse.get_pos()
grabbed.clamp_ip(bounds)
screen.fill(BACKGROUND)
for rect in rects:
color = RED
if grabbed == True:
color = (255,255,255)
for rect in rects:
pygame.draw.rect(screen,(color),rect)
pygame.draw.rect(screen,(0,0,0),rect,5)
pygame.display.flip()
clock.tick(FPS)