MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / Game_Manager

Class Game_Manager

projects/PONG/main.py:129–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127
128
129class Game_Manager:
130 def __init__(self, ball_group, paddle_group) -> None:
131 self.player_score = 0
132 self.opponent_score = 0
133 self.ball_group = ball_group
134 self.paddle_group = paddle_group
135
136 def run_game(self):
137 # Drawing Game Objects
138 self.paddle_group.draw(WIN)
139 self.ball_group.draw(WIN)
140
141 # Updating the game objects
142 self.paddle_group.update(self.ball_group)
143 self.ball_group.update()
144 self.reset_ball()
145 self.draw_score()
146
147 def reset_ball(self):
148 if self.ball_group.sprite.rect.left >= WIDTH:
149 self.opponent_score += 1
150 self.ball_group.sprite.reset_ball()
151 if self.ball_group.sprite.rect.right <= 0:
152 self.player_score += 1
153 self.ball_group.sprite.reset_ball()
154
155 def draw_score(self):
156 player_score = game_font.render(str(self.player_score), True, accent_color)
157 opponent_score = game_font.render(str(self.opponent_score), True, accent_color)
158
159 player_score_rect = player_score.get_rect(midleft=(WIDTH / 2 + 40, HEIGHT / 2))
160 opponent_score_rect = opponent_score.get_rect(
161 midright=(WIDTH / 2 - 40, HEIGHT / 2)
162 )
163
164 WIN.blit(player_score, player_score_rect)
165 WIN.blit(opponent_score, opponent_score_rect)
166
167
168class Cursor(pygame.sprite.Sprite):

Callers 1

create_ballFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected