-
Notifications
You must be signed in to change notification settings - Fork 0
/
Environment
135 lines (98 loc) · 3.4 KB
/
Environment
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
class Pacman(pygame.sprite.sprite):
def __init__(self, x, y):
self.image = pygame.Surface([1200, 600])
self.image.fill(WHITE)
# Make our top-left corner the passed-in location.
self.rect = self.image.get_rect()
self.rect.y = ypos
self.rect.x = xpos
def detectWalls(self, walls):
#left and right
self.rect.x += self.velocityx
# hit a wall?
barrier_hit_list = pygame.sprite.spritecollide(self, walls, False)
for block in block_hit_list:
# moving right, set right side to left side of wall
if self.velocityx > 0:
self.rect.right = block.rect.left
else:
# moving left, vice versa.
self.rect.left = block.rect.right
#up and down
self.rect.y += self.velocityy
# hit a wall?
barrier_hit_list = pygame.sprite.spritecollide(self, walls, False)
for block in block_hit_list:
# Reset our position based on the top/bottom of the object.
if self.velocityy > 0:
self.rect.bottom = block.rect.top
else:
self.rect.top = block.rect.bottom
class Wall(pygame.sprite.Sprite):
def __init__(self, wallx, wally, width, height):
self.image = pygame.Surface([width, height])
self.image.fill(50, 50, 255) #blue
# top-left corner is passed-in location.
#self.rect = self.image.get_rect()
#self.rect.y = ypos
#self.rect.x = xpos
class Room(object):
wallList = None
enemySprites = None
def __init__(self):
self.wallList = pygame.sprite.Group()
self.enemySprites = pygame.sprite.Group()
class Room1(Room):
def __init__(self):
# Will Make the walls once decided.
# a list of uncreated walls. Each is in the form [x, y, width, height]
#walls = [[],
# [],
# [],
# [],
# [],
# [],
# []
# ]
# Loop through the list.
#wall = Wall( , , , , , , , ,)
#self.wallList.add(wall)
class Room2(Room):
def __init__(self):
# Will Make the walls once decided.
# a list of uncreated walls. Each is in the form [x, y, width, height]
#walls = [[],
# [],
# [],
# [],
# [],
# [],
# []
# ]
# Loop through the list.
#wall = Wall( , , , , , , , ,)
#self.wallList.add(wall)
def main():
pygame.init()
screen = pygame.display.set_mode([1200, 600])
pygame.display.set_caption('Hackspace Pacman')
player = Player(50, 50)
movingsprites = pygame.sprite.Group()
movingsprites.add(player)
rooms = []
room = Room1()
rooms.append(room)
room = Room2()
rooms.append(room)
current_room_number = 0
current_room = rooms[current_room_number]
clock = pygame.time.Clock()
##stop = False
while stop==False:
##movement stuff
screen.fill(0,0,0)
movingsprites.draw(screen)
current_room.wallList.draw(screen)
pygame.display.flip() ##updates the entire Surface on the display regardless if any argument is passed
clock.tick(50)
pygame.quit()