Skip to content

Commit 89bb90e

Browse files
committed
Minor Fix
1 parent 3618eea commit 89bb90e

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

8_Ball_Pool/8BallPool.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# 8 Ball Pool
44
# Language - Python
5-
# Modules - pygame, sys, random, math
5+
# Modules - pygame, sys, random, math
66
#
77
# Controls - Mouse, the length of Stick is propotional to Force applied
88
#
@@ -67,14 +67,14 @@ def draw(self, x, y):
6767
pygame.draw.ellipse(display, self.color, (x - radius, y - radius, radius*2, radius*2))
6868
if self.color == black or self.ballNum == "cue":
6969
ballNo = self.font.render(str(self.ballNum), True, white)
70+
display.blit(ballNo, (x - 5, y - 5))
7071
else:
7172
ballNo = self.font.render(str(self.ballNum), True, black)
73+
if self.ballNum > 9:
74+
display.blit(ballNo, (x - 6, y - 5))
75+
else:
76+
display.blit(ballNo, (x - 5, y - 5))
7277

73-
if self.ballNum > 9:
74-
display.blit(ballNo, (x - 6, y - 5))
75-
else:
76-
display.blit(ballNo, (x - 5, y - 5))
77-
7878
# Moves the Ball around the Screen
7979
def move(self):
8080
self.speed -= friction
@@ -168,7 +168,7 @@ def checkCueCollision(cueBall):
168168

169169
tangent = degrees((atan((balls[i].y - cueBall.y)/(balls[i].x - cueBall.x)))) + 90
170170
angle = tangent + 90
171-
171+
172172
balls[i].angle = (2*tangent - balls[i].angle)
173173
cueBall.angle = (2*tangent - cueBall.angle)
174174

@@ -194,7 +194,7 @@ def checkCollision():
194194

195195
tangent = degrees((atan((balls[i].y - balls[j].y)/(balls[i].x - balls[j].x)))) + 90
196196
angle = tangent + 90
197-
197+
198198
balls[i].angle = (2*tangent - balls[i].angle)
199199
balls[j].angle = (2*tangent - balls[j].angle)
200200

@@ -211,7 +211,7 @@ def border():
211211

212212
def score():
213213
font = pygame.font.SysFont("Agency FB", 30)
214-
214+
215215
pygame.draw.rect(display, (51, 51, 51), (0, height, width, outerHeight))
216216
for i in range(len(balls)):
217217
balls[i].draw((i + 1)*2*(radius + 1), height + radius + 10)
@@ -226,7 +226,7 @@ def reset():
226226
balls = []
227227

228228
s = 70
229-
229+
230230
b1 = Ball(s, height/2 - 4*radius, 0, colors[0], 0, 1)
231231
b2 = Ball(s + 2*radius, height/2 - 3*radius, 0, colors[1], 0, 2)
232232
b3 = Ball(s, height/2 - 2*radius, 0, colors[2], 0, 3)
@@ -242,7 +242,7 @@ def reset():
242242
b13 = Ball(s + 4*radius, height/2 + 2*radius, 0, colors[12], 0, 13)
243243
b14 = Ball(s + 2*radius, height/2 + 3*radius, 0, colors[13], 0, 14)
244244
b15 = Ball(s, height/2 + 4*radius, 0, colors[14], 0, 15)
245-
245+
246246
balls.append(b1)
247247
balls.append(b2)
248248
balls.append(b3)
@@ -258,9 +258,9 @@ def reset():
258258
balls.append(b13)
259259
balls.append(b14)
260260
balls.append(b15)
261-
262261

263-
262+
263+
264264
def gameOver():
265265
font = pygame.font.SysFont("Agency FB", 75)
266266
if len(balls) == 0:
@@ -292,7 +292,7 @@ def poolTable():
292292
loop = True
293293

294294
reset()
295-
295+
296296
noPockets = 6
297297
pockets = []
298298

@@ -302,7 +302,7 @@ def poolTable():
302302
p4 = Pockets(0, height - margin - 5 - p1.r, black)
303303
p5 = Pockets(width/2 - p1.r*2, height - margin - 5 - p1.r, black)
304304
p6 = Pockets(width - p1.r - margin - 5, height - margin - 5 - p1.r, black)
305-
305+
306306
pockets.append(p1)
307307
pockets.append(p2)
308308
pockets.append(p3)
@@ -312,11 +312,11 @@ def poolTable():
312312

313313
cueBall = Ball(width/2, height/2, 0, white, 0, "cue")
314314
cueStick = CueStick(0, 0, 100, stickColor)
315-
316-
315+
316+
317317
start = 0
318318
end = 0
319-
319+
320320
while loop:
321321
for event in pygame.event.get():
322322
if event.type == pygame.QUIT:
@@ -338,38 +338,38 @@ def poolTable():
338338
force = 10
339339

340340
cueStick.applyForce(cueBall, force)
341-
341+
342342

343343
display.fill(background)
344344

345345
cueBall.draw(cueBall.x, cueBall.y)
346346
cueBall.move()
347347

348348
if not (cueBall.speed > 0):
349-
349+
350350
cueStick.draw(cueBall.x, cueBall.y)
351-
351+
352352
for i in range(len(balls)):
353353
balls[i].draw(balls[i].x, balls[i].y)
354354

355355
for i in range(len(balls)):
356356
balls[i].move()
357-
357+
358358
checkCollision()
359359
checkCueCollision(cueBall)
360360
border()
361-
361+
362362
for i in range(noPockets):
363363
pockets[i].draw()
364-
364+
365365
for i in range(noPockets):
366366
pockets[i].checkPut()
367367

368368
if len(balls) == 1 and balls[0].ballNum == 8:
369369
gameOver()
370370

371-
score()
372-
371+
score()
372+
373373
pygame.display.update()
374374
clock.tick(60)
375375

0 commit comments

Comments
 (0)