]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
fixed pushing
authorSkullheadx <704277@pdsb.net>
Thu, 7 Jul 2022 19:03:08 +0000 (15:03 -0400)
committerSkullheadx <704277@pdsb.net>
Thu, 7 Jul 2022 19:03:08 +0000 (15:03 -0400)
Actors.py
Enemy.py
Game.py
PhysicsBody.py
Player.py
Setup.py
main.py

index bf4edb77b21046bb73882eec57dc2f1a7fb7c58d..dba2860a71ff115ab1e4923af6696186a5f3394b 100644 (file)
--- a/Actors.py
+++ b/Actors.py
@@ -1,5 +1,6 @@
 from Setup import *
 from PhysicsBody import PhysicsBody
+from Block import Block
 
 class Actor:
     width, height = 50, 100
@@ -88,14 +89,19 @@ class Actor:
                 if thing == self:
                     continue
                 if collision_rect.colliderect(thing.get_collision_rect()):
+                    print(self, vel, thing.velocity)
                     if thing.movable:
-                        thing.velocity.x = vel.x
-                    if vel.x > 0:
-                        pos.x = thing.position.x - self.width
-                        vel.x = min(vel.x, 0)
-                    elif vel.x < 0:
-                        pos.x = thing.position.x + thing.width
-                        vel.x = max(vel.x, 0)
+                        if vel.x > 0:
+                            thing.position.x = pos.x + self.width
+                        elif vel.x < 0:
+                            thing.position.x = pos.x - thing.width
+                    else:
+                        if vel.x > 0:
+                            pos.x = thing.position.x - self.width
+                            vel.x = min(vel.x, 0)
+                        elif vel.x < 0:
+                            pos.x = thing.position.x + thing.width
+                            vel.x = max(vel.x, 0)
                     collision_rect = self.get_collision_rect(pos)
 
         self.on_ground = False
@@ -109,16 +115,13 @@ class Actor:
                     if area.is_colliding(thing):
                         area.signal(thing)
                 if collision_rect.colliderect(thing.get_collision_rect()):
-                    if thing.movable:
-                        thing.velocity.y = vel.y
-
                     if vel.y > 0:
                         pos.y = thing.position.y - self.height
-                        vel.y = min(vel.y, 0)
+                        vel.y = min(vel.y + thing.velocity.y, 0)
                         self.on_ground = True
                     elif vel.y < 0:
                         pos.y = thing.position.y + thing.height
-                        vel.y = max(vel.y, 0)
+                        vel.y = max(vel.y + thing.velocity.y, 0)
                     collision_rect = self.get_collision_rect(pos)
 
         return pos, vel
index 1b253da311b5079e97c55fb058b76113064062b6..2c6122c9f90091c45ac584791bbe232a676de83a 100644 (file)
--- a/Enemy.py
+++ b/Enemy.py
@@ -32,7 +32,7 @@ class Enemy(Actor):
         self.dizzy_time = max(0,self.dizzy_time)
 
         # Deals with collision and applying velocity
-        self.position, self.velocity = self.move_and_collide(self.position, self.velocity, delta)
+        self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
 
         self.weapon.update(delta,self.position, math.copysign(1,self.velocity.x))
 
diff --git a/Game.py b/Game.py
index 6c80399596016a07df8c90250d1de3622d2ce9d1..f000c28ab34940ae8716256232393a879f26c3a9 100644 (file)
--- a/Game.py
+++ b/Game.py
@@ -21,6 +21,7 @@ class Game:
 
 
     def update(self, delta):
+        Setup.camera_offset += self.player.update(delta)
 
         for i,enemy in enumerate(self.enemies):
             enemy.update(delta, self.player)
@@ -32,7 +33,6 @@ class Game:
         for block in self.blocks:
             block.update(delta)
 
-        Setup.camera_offset += self.player.update(delta)
 
         # self.pet.update(delta, self.player, self.camera_pos)
 
index 6dbb26933a44fecf8dc24cfa28579dcbbc38929b..0d9555447b65cb581642039cbeab7426c2da006d 100644 (file)
@@ -45,10 +45,10 @@ class PhysicsBody:
                         thing.velocity.x = vel.x
                     if vel.x > 0:
                         pos.x = thing.position.x - self.width
-                        vel.x = min(vel.x, 0)
+                        vel.x = min(vel.x+ thing.velocity.x, 0)
                     elif vel.x < 0:
                         pos.x = thing.position.x + thing.width
-                        vel.x = max(vel.x, 0)
+                        vel.x = max(vel.x+ thing.velocity.x, 0)
                     collision_rect = self.get_collision_rect(pos)
         self.on_ground = False
         pos.y += vel.y * delta
@@ -63,11 +63,11 @@ class PhysicsBody:
 
                     if vel.y > 0:
                         pos.y = thing.position.y - self.height
-                        vel.y = min(vel.y, 0)
+                        vel.y = min(vel.y+ thing.velocity.y, 0)
                         self.on_ground = True
                     elif vel.y < 0:
                         pos.y = thing.position.y + thing.height
-                        vel.y = max(vel.y, 0)
+                        vel.y = max(vel.y+ thing.velocity.y, 0)
                     collision_rect = self.get_collision_rect(pos)
         return pos, vel
 
index 77785009415db2f4811c8e9ee418b3caba728c0b..fcac4086535d78c8a33500318122e6d7c65fe976 100644 (file)
--- a/Player.py
+++ b/Player.py
@@ -1,5 +1,6 @@
 import pygame.key
 
+import Setup
 from Setup import *
 from Actors import Actor
 
@@ -23,7 +24,7 @@ class Player(Actor):
         self.handle_input()
 
         # Deals with collision and applying velocity
-        self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity, delta)
+        self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
         return self.velocity * delta
 
     def handle_input(self):
@@ -37,6 +38,9 @@ class Player(Actor):
 
     def draw(self, surf):
         super().draw(surf)
+        # print(self.position, self.velocity, get_display_rect(self.get_collision_rect()).topleft, Setup.camera_offset)
+        # pg.draw.rect(surf, self.colour, get_display_rect(self.get_collision_rect()), border_radius=8)
+
         # pg.draw.rect(surf,self.colour,pg.Rect(center, (self.width, self.height)),border_radius=8)
 
         # Healthbar Stuff
index c3dfdcff53973ddcf2ed0682f2bb85d91af5f5b4..bce260cc83b25ae1785c96c3f19c4b9cd2d01458 100644 (file)
--- a/Setup.py
+++ b/Setup.py
@@ -33,3 +33,4 @@ def get_display_rect(collision_rect):
     pos = collision_rect.topleft
     width, height = collision_rect.w, collision_rect.h
     return pg.Rect(pos - camera_offset, (width, height))
+    # return pg.Rect(pos, (width, height))
diff --git a/main.py b/main.py
index 04b37f7bc2bc8ecf50b2b30faca8ace8537f654d..82950c41981d157cfcf9e34c72b3fabffc8d6ea6 100644 (file)
--- a/main.py
+++ b/main.py
@@ -10,7 +10,7 @@ scene = Menu()
 old_level = 0
 
 
-level = 0
+level = 1
 
 while is_running:
     if pg.event.peek(pg.QUIT):