MCPcopy Index your code
hub / github.com/geekcomputers/Python / Ball

Class Ball

PingPong/Ball.py:6–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5
6class Ball:
7 def __init__(self, pos, vel, win, rad, minCoord, maxCoord):
8 self.pos = pos
9 self.vel = vel
10 self.win = win
11 self.rad = rad
12 self.minCoord = minCoord
13 self.maxCoord = maxCoord
14
15 def drawBall(self):
16 pygame.draw.circle(self.win, (255,) * 3, self.pos, self.rad, 0)
17
18 def doHorizontalFlip(self):
19 self.vel[0] *= -1
20 print("Github")
21
22 def doVerticalFlip(self):
23 self.vel[1] *= -1
24
25 def borderCollisionCheck(self):
26 if (self.pos[0] <= self.minCoord[0]) or (self.pos[0] >= self.maxCoord[0]):
27 self.doHorizontalFlip()
28
29 if (self.pos[1] <= self.minCoord[1]) or (self.pos[1] >= self.maxCoord[1]):
30 self.doVerticalFlip()
31
32 def updatePos(self):
33 self.pos = [self.pos[0] + self.vel[0], self.pos[1] + self.vel[1]]
34
35 def checkSlabCollision(self, slabPos): # slab pos = [xmin, ymin, xmax, ymax]
36 if (
37 self.pos[0] + self.rad > slabPos[0]
38 and self.pos[0] - self.rad < slabPos[2]
39 and self.pos[1] + self.rad > slabPos[1]
40 and self.pos[1] - self.rad < slabPos[3]
41 ):
42 # Handle collision here (e.g., reverse ball's direction)
43 if self.pos[0] < slabPos[0] or self.pos[0] > slabPos[2]:
44 self.vel[0] *= -1
45 if self.pos[1] < slabPos[1] or self.pos[1] > slabPos[3]:
46 self.vel[1] *= -1

Callers 1

main.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected