| Total Complexity | 10 |
| Total Lines | 68 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from random import randrange |
||
| 2 | |||
| 3 | from src.utils import load |
||
| 4 | |||
| 5 | |||
| 6 | class Platform: |
||
| 7 | _texture = None |
||
| 8 | |||
| 9 | def __init__(self, x, y): |
||
| 10 | self.rect = self.texture.get_rect() |
||
| 11 | |||
| 12 | self.rect.x = x |
||
| 13 | self.rect.y = y |
||
| 14 | |||
| 15 | self.initial_y = self.rect.y |
||
| 16 | |||
| 17 | @property |
||
| 18 | def texture(self): |
||
| 19 | if self._texture is None: |
||
| 20 | self._texture = load("src/assets/images/platform.png") |
||
| 21 | return self._texture |
||
| 22 | |||
| 23 | def move(self, game): |
||
| 24 | if self.rect.x < -500: |
||
| 25 | self.rect.x = self.rect.x = max( |
||
| 26 | platform.rect.x for platform in game.platforms |
||
| 27 | ) + randrange(600, 1000) |
||
| 28 | |||
| 29 | self.rect.y = randrange(400, 620) |
||
| 30 | self.initial_y = self.rect.y |
||
| 31 | |||
| 32 | else: |
||
| 33 | self.rect.x -= int(game.player.ax) |
||
| 34 | |||
| 35 | def check_hit_box(self, game): |
||
| 36 | if any( |
||
| 37 | [ |
||
| 38 | self.rect.collidepoint( |
||
| 39 | game.player.rect.x, game.player.rect.y + 68 |
||
| 40 | ), |
||
| 41 | self.rect.collidepoint( |
||
| 42 | game.player.rect.x + 50, game.player.rect.y + 68 |
||
| 43 | ) |
||
| 44 | ] |
||
| 45 | ): |
||
| 46 | |||
| 47 | game.player.rect.y = self.rect.y - 68 + 1 |
||
| 48 | game.player.jump_count = 1 |
||
| 49 | self.rect.x += randrange(0, 2) - 1 |
||
| 50 | self.rect.y += 2 |
||
| 51 | |||
| 52 | elif self.rect.y > self.initial_y: |
||
| 53 | self.rect.y -= 1 |
||
| 54 | |||
| 55 | if any( |
||
| 56 | [ |
||
| 57 | self.rect.collidepoint( |
||
| 58 | game.player.rect.x + 50, game.player.rect.y |
||
| 59 | ), |
||
| 60 | self.rect.collidepoint( |
||
| 61 | game.player.rect.x + 50, game.player.rect.y + 66 |
||
| 62 | ) |
||
| 63 | ] |
||
| 64 | ): |
||
| 65 | game.player.rect.x = self.rect.x - 51 |
||
| 66 | if game.player.rect.x < 0: |
||
| 67 | game.over = True |
||
| 68 |