-
Notifications
You must be signed in to change notification settings - Fork 26
/
blank pygame project.py
62 lines (47 loc) · 1.83 KB
/
blank pygame project.py
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
#Credit the Invent With Python book (http://inventwithpython.com)
#for doRectsOverlap and isPointInsideRect functions
#used to detect collisions in our game
def doRectsOverlap(rect1, rect2):
for a, b in [(rect1, rect2), (rect2, rect1)]:
# Check if a's corners are inside b
if ((isPointInsideRect(a.left, a.top, b)) or
(isPointInsideRect(a.left, a.bottom, b)) or
(isPointInsideRect(a.right, a.top, b)) or
(isPointInsideRect(a.right, a.bottom, b))):
return True
return False
#used the by the doRectsOverlap function (won't be called directly from game code)
def isPointInsideRect(x, y, rect):
if (x > rect.left) and (x < rect.right) and (y > rect.top) and (y < rect.bottom):
return True
else:
return False
import pygame, sys, random
pygame.init()
screen = pygame.display.set_mode([640,480])
black = [0, 0, 0]
#the game's variables
#SECTION 1 - YOUR CODE HERE FOR CREATING VARIABLES AND FUNCTIONS
running = True
#game loop
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEMOTION:
print "mouse moved"
#SECTION 2 - YOUR CODE HERE FOR WHEN THE MOUSE IS MOVED
if event.type == pygame.KEYDOWN:
print "key pressed"
#SECTION 3 - YOUR CODE HERE FOR WHEN A KEY IS PRESSED
#pause for 20 milliseconds
pygame.time.delay(20)
#make the screen completely black
screen.fill(black)
#logic for moving everything in the game and checking collisions
#SECTION 4 - YOUR CODE HERE FOR CHANGING VARIABLES AND CHECKING FOR COLLISIONS
#draw everything on the screen
#SECTION 5 - YOUR CODE HERE FOR DRAWING EVERYTHING
#update the entire display
pygame.display.update()
pygame.quit()