| 159 | |
| 160 | |
| 161 | class Gamer: |
| 162 | def __init__(self, top_x: int, |
| 163 | top_y: int, |
| 164 | width: int, |
| 165 | high: int, |
| 166 | color: tuple, |
| 167 | player_name : str, |
| 168 | display_width: int, |
| 169 | display_high: int) -> None: |
| 170 | self.init_top_x = top_x |
| 171 | self.init_top_y = top_y |
| 172 | self.width = width |
| 173 | self.high = high |
| 174 | self.color = color |
| 175 | self.rect = pygame.Rect(top_x, top_y, width, high) |
| 176 | self.speed_y = 0 |
| 177 | self.disp_w = display_width |
| 178 | self.disp_h = display_high |
| 179 | self.name = player_name |
| 180 | |
| 181 | def draw(self, display: pygame.Surface) -> None: |
| 182 | pygame.draw.rect(display, self.color, self.rect) |
| 183 | |
| 184 | def update_pos(self) -> None: |
| 185 | if self.speed_y != 0: |
| 186 | self.rect.y += self.speed_y |
| 187 | if self.rect.top <= 0: |
| 188 | self.rect.top = 0 |
| 189 | if self.rect.bottom >= self.disp_h: |
| 190 | self.rect.bottom = self.disp_h |
| 191 | |
| 192 | def set_speed(self, speed_y: int | float) -> None: |
| 193 | if speed_y == 0: |
| 194 | self.speed_y = 0 |
| 195 | else: |
| 196 | self.speed_y += speed_y |
| 197 | |
| 198 | def get_speed(self): |
| 199 | return self.speed_y |
| 200 | |
| 201 | def reset(self) -> None: |
| 202 | self.rect.x = self.init_top_x |
| 203 | self.rect.y = self.init_top_y |
| 204 | |
| 205 | def get_borders(self) -> dict: |
| 206 | return { |
| 207 | 'top': self.rect.top, |
| 208 | 'right': self.rect.right, |
| 209 | 'bott': self.rect.bottom, |
| 210 | 'left': self.rect.left, |
| 211 | 'center_x': self.rect.centerx, |
| 212 | 'center_y': self.rect.centery |
| 213 | } |
| 214 | |
| 215 | |
| 216 | class GameField: |