MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / PongBall

Class PongBall

DemoPrograms/Demo_Pong_Multiple_Platforms.py:110–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108
109
110class PongBall():
111 def __init__(self, graph: sg.Graph, colour, x, width=BAT_SIZE[0], height=BAT_SIZE[1]):
112 self.graph = graph
113 self.id = graph.draw_rectangle(
114 (x - width / 2, 200), (x + width / 2, 200 + height), fill_color=colour)
115 self.y = 0
116 self.x = x
117 self.curx = x
118 self.cury = height/2
119
120 def up(self, amount):
121 self.y = -amount
122
123 def down(self, amount):
124 self.y = amount
125
126 @property
127 def curr_pos(self):
128 pos = self.cury
129 return pos
130
131 def draw(self):
132 self.graph.relocate_figure(self.id, self.curx, self.cury)
133 if self.cury + self.y + BAT_SIZE[1] <= GAMEPLAY_SIZE[1] and self.cury + self.y + BAT_SIZE[1] >= 0:
134 self.cury += self.y
135 if self.cury <= 0:
136 self.cury = 0
137 self.y = 0
138 if self.cury >= GAMEPLAY_SIZE[1]:
139 self.cury = GAMEPLAY_SIZE[1]
140 self.y = 0
141
142
143def pong():

Callers 1

pongFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected