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

Method update

brickout-game/brickout-game.py:65–102  ·  view source on GitHub ↗

moves the ball at the screen. contains some collision detection.

(self, paddle, brickwall)

Source from the content-addressed store, hash-verified

63 pygame.draw.circle(screen, (255, 0, 0), (self._xLoc, self._yLoc), self._radius)
64
65 def update(self, paddle, brickwall):
66 """
67 moves the ball at the screen.
68 contains some collision detection.
69 """
70 self._xLoc += self.__xVel
71 self._yLoc += self.__yVel
72 # left screen wall bounce
73 if self._xLoc <= self._radius:
74 self.__xVel *= -1
75 # right screen wall bounce
76 elif self._xLoc >= self.__width - self._radius:
77 self.__xVel *= -1
78 # top wall bounce
79 if self._yLoc <= self._radius:
80 self.__yVel *= -1
81 # bottom drop out
82 elif self._yLoc >= self.__width - self._radius:
83 return True
84
85 # for bouncing off the bricks.
86 if brickwall.collide(self):
87 self.__yVel *= -1
88
89 # collision detection between ball and paddle
90 paddleY = paddle._yLoc
91 paddleW = paddle._width
92 paddleH = paddle._height
93 paddleX = paddle._xLoc
94 ballX = self._xLoc
95 ballY = self._yLoc
96
97 if ((ballX + self._radius) >= paddleX and ballX <= (paddleX + paddleW)) and (
98 (ballY + self._radius) >= paddleY and ballY <= (paddleY + paddleH)
99 ):
100 self.__yVel *= -1
101
102 return False
103
104
105"""

Callers 1

brickout-game.pyFile · 0.45

Calls 1

collideMethod · 0.45

Tested by

no test coverage detected