]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
fixed bug where camera not working as intended
authorSkullheadx <704277@pdsb.net>
Thu, 7 Jul 2022 20:41:43 +0000 (16:41 -0400)
committerSkullheadx <704277@pdsb.net>
Thu, 7 Jul 2022 20:41:43 +0000 (16:41 -0400)
Actors.py
Game.py
Player.py

index dba2860a71ff115ab1e4923af6696186a5f3394b..5151bdad84fc967ce15d1b60e132c1e12e34d1e7 100644 (file)
--- 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 f000c28ab34940ae8716256232393a879f26c3a9..b76abae4c2d8c3d075fbdead9c20ae7f98164aed 100644 (file)
--- 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)
index fcac4086535d78c8a33500318122e6d7c65fe976..0af9e6e1ba2265f63ee272b679c5ec56037f9ea8 100644 (file)
--- 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()