-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHole.py
40 lines (35 loc) · 1.73 KB
/
Hole.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
import pygame
class Hole:
def __init__(self, display, coord=None):
self.hole_img = pygame.image.load('pictures/Hole.png').convert_alpha()
self.coord = coord
self.display = display
self.make_colliders()
def make_colliders(self):
self.psuedo_holes = {}
self.psuedo_holes['right'] = pygame.Rect(self.coord[0] - 30,
self.coord[1],
30, 30)
self.psuedo_holes['left'] = pygame.Rect(self.coord[0] + 30,
self.coord[1],
30, 30)
self.psuedo_holes['down'] = pygame.Rect(self.coord[0],
self.coord[1] - 30,
30, 30)
self.psuedo_holes['up'] = pygame.Rect(self.coord[0],
self.coord[1] + 30,
30, 30)
self.psuedo_holes['exact'] = pygame.Rect(self.coord[0],
self.coord[1],
30, 30)
def collides(self, player_rect):
'''Return the direction of the hole with respect to the player when
(s)he is right in front of or exactly on it. Otherwise return None.'''
for direction in self.psuedo_holes:
# print "pseudo hole direction:", direction,
# print self.psuedo_holes[direction]
if self.psuedo_holes[direction].colliderect(player_rect):
return direction
return None
def draw(self):
self.display.blit(self.hole_img, self.coord)