diff --git a/game.py b/game.py index 9f36193..225a004 100644 --- a/game.py +++ b/game.py @@ -175,9 +175,15 @@ class Player: movement: pygame.Vector2 = direction * self.speed * dt - + self.pos.x += movement.x + if self.pos.x - self.width/2 < 0: + self.pos.x = self.width/2 + + + if self.pos.x + self.width/2 > SCREEN_WIDTH/2: + self.pos.x = SCREEN_WIDTH/2 - self.width/2 # self.pos += movement @@ -194,16 +200,16 @@ class Player: self.pos.x = self.rect.centerx - # if self.pos.x < self.player_rect.width/2 or self.pos.x + self.player_rect.width > SCREEN_WIDTH: - # self.pos.x = old_position_x - if self.pos.x - self.rect.width/2 < 0: - self.pos.x = self.rect.width/2 - if self.pos.x + self.width/2 > SCREEN_WIDTH/2: - self.pos.x = SCREEN_WIDTH/2 - self.width/2 self.pos.y += movement.y + if self.pos.y - self.height/2 < 0: + self.pos.y = self.height/2 + + if self.pos.y + self.height/2 > SCREEN_HEIGHT/2: + self.pos.y = SCREEN_HEIGHT/2 - self.height/2 + self.rect.centery = round(self.pos.y) for wall in walls: @@ -216,11 +222,8 @@ class Player: self.pos.y = self.rect.centery - if self.pos.y - self.rect.height/2 < 0: - self.pos.y = self.rect.height/2 - if self.pos.y + self.rect.height/2 > SCREEN_HEIGHT/2: - self.pos.y = SCREEN_HEIGHT/2 - self.rect.height/2 + def render(self, surface):