From: Skullheadx <704277@pdsb.net> Date: Thu, 7 Jul 2022 19:03:08 +0000 (-0400) Subject: fixed pushing X-Git-Url: http://git.skullheadx.com/now.html?a=commitdiff_plain;h=75df8c3d56b9456fabac8bd6cc0b3dae1516f4f4;p=Pygame-Jam.git fixed pushing --- diff --git a/Actors.py b/Actors.py index bf4edb7..dba2860 100644 --- 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 diff --git a/Enemy.py b/Enemy.py index 1b253da..2c6122c 100644 --- 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 6c80399..f000c28 100644 --- 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) diff --git a/PhysicsBody.py b/PhysicsBody.py index 6dbb269..0d95554 100644 --- a/PhysicsBody.py +++ b/PhysicsBody.py @@ -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 diff --git a/Player.py b/Player.py index 7778500..fcac408 100644 --- 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 diff --git a/Setup.py b/Setup.py index c3dfdcf..bce260c 100644 --- 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 04b37f7..82950c4 100644 --- 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):