MCPcopy Create free account
hub / github.com/geekcomputers/Python / update

Method update

PongPong_Game/pong/ball.py:14–41  ·  view source on GitHub ↗
(self, win_size: Tuple, border: Tuple, other_object, dt)

Source from the content-addressed store, hash-verified

12 self.velocity_x, self.velocity_y = 0.0, 0.0
13
14 def update(self, win_size: Tuple, border: Tuple, other_object, dt) -> None:
15 speed = [
16 2.37,
17 2.49,
18 2.54,
19 2.62,
20 2.71,
21 2.85,
22 2.96,
23 3.08,
24 3.17,
25 3.25,
26 ] # more choices more randomness
27 rn = random.choice(speed)
28 newx = self.x + self.velocity_x
29 newy = self.y + self.velocity_y
30
31 if newx < border + self.radius or newx > win_size[0] - border - self.radius:
32 self.velocity_x = -(self.velocity_x / abs(self.velocity_x)) * rn
33 elif newy > win_size[1] - border - self.radius:
34 self.velocity_y = -(self.velocity_y / abs(self.velocity_y)) * rn
35 elif (newy - self.radius < other_object.height) and (
36 other_object.x <= newx <= other_object.rightx
37 ):
38 self.velocity_y = -(self.velocity_y / abs(self.velocity_y)) * rn
39 else:
40 self.x = newx
41 self.y = newy

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected