| 29 | |
| 30 | |
| 31 | class Opponent(Block): |
| 32 | def __init__(self, path, x_pos, y_pos, speed): |
| 33 | super().__init__(path, x_pos, y_pos) |
| 34 | self.speed = speed |
| 35 | self.x = x_pos |
| 36 | |
| 37 | def update(self, ball_group): |
| 38 | if game_state.state == "hard_game" or game_state.state == "med_game": |
| 39 | if self.rect.center[1] < ball_group.sprite.rect.y: |
| 40 | self.rect.y += self.speed |
| 41 | if self.rect.center[1] > ball_group.sprite.rect.y: |
| 42 | self.rect.y -= self.speed |
| 43 | self.constrain() |
| 44 | else: |
| 45 | if self.rect.top < ball_group.sprite.rect.y: |
| 46 | self.rect.y += self.speed |
| 47 | if self.rect.bottom > ball_group.sprite.rect.y: |
| 48 | self.rect.y -= self.speed |
| 49 | self.constrain() |
| 50 | |
| 51 | def constrain(self): |
| 52 | if self.rect.top <= 0: |
| 53 | self.rect.top = 0 |
| 54 | if self.rect.bottom > HEIGHT: |
| 55 | self.rect.bottom = HEIGHT |
| 56 | |
| 57 | |
| 58 | class Ball(Block): |