/
game.py
190 lines (161 loc) · 6.14 KB
/
game.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import pygame, sys, random
import level
import score
import Pax
import Speedypax
#import menu
#import Spawnchance
from PhaseGhost import PhaseGhost
from HUD import Text
from HUD import Score
from Button import Button
from Pax import Pax
from Vision import Vision
from Wall import Wall
pygame.init()
clock= pygame.time.Clock()
width = 800
height = 800
size = width, height
bgColor = r,g,b = 0, 0, 0
screen = pygame.display.set_mode(size)
timer = Score([80, height - 25], "Time: ", 36)
timerWait = 0
timerWaitMax = 6000
run = False
options = False
playerType = "Pax"
mapImage = pygame.image.load("Resources/Maps/Maplv1.png").convert()
mapRect = mapImage.get_rect()
bgImage = pygame.image.load("Resources/Objects/download3 (2).png").convert()
bgRect = bgImage.get_rect()
ghosts = []
SpeedWalls = [Wall([267,373],[298,427]),
Wall([373,502],[427,524]),
Wall([502,373],[525,427]),
Wall([372,275],[427,298])]
walls = [Wall([0,0],[90,800]),
Wall([710,100],[800,800]),
Wall([0,0], [800,90]),
Wall([0,710],[800,800]),
Wall([127,126],[373,146]),
Wall([127,126],[146,373]),
Wall([127,427],[145,674]),
Wall([127,653],[373,674]),
Wall([427,654],[674,674]),
Wall([654,427],[674,674]),
Wall([654,126],[674,373]),
Wall([427,126],[674,143]),
Wall([177,176],[373,196]),
Wall([177,176],[197,373]),
Wall([177,427],[197,624]),
Wall([177,604],[373,624]),
Wall([427,604],[626,624]),
Wall([603,427],[626,624]),
Wall([427,175],[626,196]),
Wall([603,175],[626,373]),
Wall([227,227],[373,246]),
Wall([227,227],[247,373]),
Wall([227,427],[247,574]),
Wall([227,554],[373,574]),
Wall([427,554],[574,574]),
Wall([554,427],[574,574]),
Wall([554,227],[574,373]),
Wall([427,227],[574,246]),
Wall([427,502],[525,524]),
Wall([502,427],[525,524]),
Wall([427,275],[525,298]),
Wall([502,275],[525,373]),
Wall([276,275],[372,298]),
Wall([276,275],[298,373]),
Wall([276,427],[298,524]),
Wall([276,502],[373,524])]
startButton = Button([width/2, height-550],
"Resources/Objects/startButton.png",
"Resources/Objects/startButtonClicked.png")
while True:
while not run and not options:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
run = True
if event.type == pygame.MOUSEBUTTONDOWN:
startButton.click(event.pos)
if event.type == pygame.MOUSEBUTTONUP:
if startButton.release(event.pos):
run = True
bgColor = r,g,b
screen.fill(bgColor)
screen.blit(bgImage, bgRect)
screen.blit(startButton.image, startButton.rect)
pygame.display.flip()
clock.tick(60)
players = [Pax([width/2, height/2])]
visions = []
for player in players:
visions += [Vision("small", player)]
ghosts = []
while run and len(players)> 0:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_w or event.key == pygame.K_UP:
players[0].go("up")
if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
players[0].go("right")
if event.key == pygame.K_s or event.key == pygame.K_DOWN:
players[0].go("down")
if event.key == pygame.K_a or event.key == pygame.K_LEFT:
players[0].go("left")
#if event.key == pygame.K_SPACE:
# screen.blit(vision.image, vision.rect)
if event.type == pygame.KEYUP:
if event.key == pygame.K_w or event.key == pygame.K_UP:
players[0].go("stop up")
if event.key == pygame.K_d or event.key == pygame.K_RIGHT:
players[0].go("stop right")
if event.key == pygame.K_s or event.key == pygame.K_DOWN:
players[0].go("stop down")
if event.key == pygame.K_a or event.key == pygame.K_LEFT:
players[0].go("stop left")
#if event.key == pygame.K_SPACE:
#not screen.blit(vision.image, vision.rect)
if len(ghosts) < 10:
if random.randint(0, .25*100) == 0:
ghosts += [PhaseGhost("images/Ball/ball.png",
[random.randint(-2,2), random.randint(-2,2)],
[random.randint(100, width-100), random.randint(100, height-100)])
]
print ghosts[-1].rect.center
player.update(width, height)
for vision in visions:
vision.update()
for ghost in ghosts:
ghost.update(width, height)
for player in players:
for ghost in ghosts:
player.collideGhost(ghost)
ghost.collidePlayer(player)
for player in players:
if not player.living:
players.remove(player)
for wall in walls:
player.collideWall(wall)
for wall in SpeedWalls:
player.collideSpeed(wall)
for wall in SpeedWalls:
screen.blit(wall.image, wall.rect)
for wall in walls:
screen.blit(wall.image, wall.rect)
bgColor = r,g,b
screen.fill(bgColor)
screen.blit(mapImage, mapRect)
for ghost in ghosts:
screen.blit(ghost.image, ghost.rect)
for player in players:
screen.blit(player.image, player.rect)
screen.blit(vision.image, vision.rect)
pygame.display.flip()
clock.tick(60)
run = False