From: Skullheadx <704277@pdsb.net> Date: Thu, 7 Jul 2022 20:41:43 +0000 (-0400) Subject: fixed bug where camera not working as intended X-Git-Url: http://git.skullheadx.com/nixos/static/git-logo.png?a=commitdiff_plain;h=b27103da28692643ac9de03cb8931b52871d6e29;p=Pygame-Jam.git fixed bug where camera not working as intended --- diff --git a/Actors.py b/Actors.py index dba2860..5151bda 100644 --- a/Actors.py +++ b/Actors.py @@ -117,11 +117,11 @@ class Actor: if collision_rect.colliderect(thing.get_collision_rect()): if vel.y > 0: pos.y = thing.position.y - self.height - vel.y = min(vel.y + thing.velocity.y, 0) + vel.y = min(vel.y, 0) self.on_ground = True elif vel.y < 0: pos.y = thing.position.y + thing.height - vel.y = max(vel.y + thing.velocity.y, 0) + vel.y = max(vel.y, 0) collision_rect = self.get_collision_rect(pos) return pos, vel diff --git a/Game.py b/Game.py index f000c28..b76abae 100644 --- a/Game.py +++ b/Game.py @@ -21,7 +21,7 @@ class Game: def update(self, delta): - Setup.camera_offset += self.player.update(delta) + Setup.camera_offset = self.player.update(delta) for i,enemy in enumerate(self.enemies): enemy.update(delta, self.player) diff --git a/Player.py b/Player.py index fcac408..0af9e6e 100644 --- a/Player.py +++ b/Player.py @@ -15,6 +15,7 @@ class Player(Actor): def __init__(self, pos, collision_layer, collision_mask): super().__init__(pos, collision_layer, collision_mask) + self.initial_position = pg.Vector2(pos) # self.areas = {"body":Area(self.position, pg.Vector2(0, self.height/2),self.width, self.height/2,Actor)} def update(self, delta): @@ -25,7 +26,7 @@ class Player(Actor): # Deals with collision and applying velocity self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta) - return self.velocity * delta + return self.position - self.initial_position def handle_input(self): pressed = pygame.key.get_pressed()