From 1d41155f21acf1d7456d7149eabf0f223f798129 Mon Sep 17 00:00:00 2001 From: Kyrokx Date: Sat, 8 May 2021 17:53:02 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=AB=20-=20Collision=20system=20added?= =?UTF-8?q?=20(sheeeeeesh)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/house.tsx | 4 ++ game.py | 28 +++++++--- main_map.tmx | 132 ++++++++++++++++++++++++++++++++++++++++++----- src/Player.py | 9 ++++ 4 files changed, 154 insertions(+), 19 deletions(-) create mode 100644 Assets/house.tsx diff --git a/Assets/house.tsx b/Assets/house.tsx new file mode 100644 index 0000000..8b1b64c --- /dev/null +++ b/Assets/house.tsx @@ -0,0 +1,4 @@ + + + + diff --git a/game.py b/game.py index 1b4ccb2..f7f72b5 100644 --- a/game.py +++ b/game.py @@ -27,32 +27,46 @@ def __init__(self): # Player instence self.player = Player(self.player_spawn.x, self.player_spawn.y) # group with map - self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer, default_layer=4) + self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer, default_layer=3) self.group.add(self.player) + # Collision avec les mur + self.objects_in_map = [] + for obj in tmx_data.objects: + if obj.type == "collid": + self.objects_in_map.append(pygame.Rect(obj.x, obj.y, obj.width, obj.height)) + def handle(self): keys = pygame.key.get_pressed() - if keys[pygame.K_UP]: + if keys[pygame.K_UP] or keys[pygame.K_z]: self.player.move_up() self.player.change_image('up') - elif keys[pygame.K_DOWN]: + elif keys[pygame.K_DOWN] or keys[pygame.K_s]: self.player.move_down() self.player.change_image('down') - elif keys[pygame.K_LEFT]: + elif keys[pygame.K_LEFT] or keys[pygame.K_q]: self.player.move_left() self.player.change_image('left') - elif keys[pygame.K_RIGHT]: + elif keys[pygame.K_RIGHT] or keys[pygame.K_d]: self.player.move_right() self.player.change_image('right') + def update(self): + self.group.update() + + for sprite in self.group.sprites(): + if sprite.feet.collidelist(self.objects_in_map) > -1: + sprite.move_back() + def run(self): running = True clock = pygame.time.Clock() while running: + self.player.save_location() self.handle() - self.group.update() + self.update() self.group.draw(self.screen) self.group.center(self.player.rect.center) # Refresh window @@ -66,4 +80,4 @@ def run(self): sys.exit(0) running = False - clock.tick(60) \ No newline at end of file + clock.tick(60) diff --git a/main_map.tmx b/main_map.tmx index e7332b3..9998282 100644 --- a/main_map.tmx +++ b/main_map.tmx @@ -1,6 +1,8 @@ - + + + 324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324,324, @@ -135,18 +137,18 @@ 0,0,0,0,0,0,165,166,166,206,166,0,0,0,0,0,0,0,0,0,0,0,0,0,205,205,206,0,0,0,0,0,0,0,0,165,166,206,165,166,206,206,206,206,206,206,206,206,0,0,0,0,0,205,206,206,166,0,0,0,0,165,166,205,165,166,0,0,0,0, 0,0,0,0,0,165,166,166,206,205,206,0,0,0,0,0,0,0,0,0,0,0,165,166,205,206,165,166,166,0,0,0,0,0,165,165,165,165,165,166,165,165,165,165,165,165,205,206,0,0,0,0,0,0,0,205,206,166,0,0,0,165,166,165,166,166,0,0,0,0, 0,0,0,0,0,165,166,206,166,205,206,0,0,0,0,0,0,0,0,0,0,0,165,166,205,206,165,165,165,165,165,165,165,165,165,205,165,166,166,206,205,205,205,205,205,205,206,0,0,0,0,0,0,0,0,0,205,206,166,0,0,165,166,165,166,206,0,0,0,0, -0,0,0,0,0,165,166,166,165,205,206,0,0,0,0,0,0,0,0,0,0,0,165,166,166,166,166,205,205,205,205,205,205,205,165,165,166,166,206,205,206,206,206,205,205,206,0,0,0,0,0,0,0,0,0,0,205,206,206,166,0,165,165,165,166,0,0,0,0,0, -0,0,0,0,0,165,166,165,165,205,206,0,0,0,0,0,0,0,0,0,165,166,166,206,206,206,206,166,205,206,206,206,165,166,165,166,166,206,206,206,165,205,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,205,206,206,0,165,205,165,166,0,0,0,0,0, +0,0,0,0,0,165,166,166,165,205,206,0,0,0,0,0,0,0,0,0,0,0,165,166,166,166,166,205,205,205,205,205,205,205,165,165,166,166,206,205,206,206,206,205,205,206,0,0,0,0,0,0,0,0,0,0,205,206,206,166,165,165,165,165,166,0,0,0,0,0, +0,0,0,0,0,165,166,165,165,205,206,0,0,0,0,0,0,0,0,0,165,166,166,206,206,206,206,166,205,206,206,206,165,166,165,166,166,206,206,206,165,205,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,205,206,206,165,165,205,165,166,0,0,0,0,0, 0,0,0,0,0,165,165,166,166,166,166,0,0,0,0,0,0,165,166,166,166,206,165,165,165,165,165,165,165,165,165,165,165,166,166,206,206,205,205,205,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,205,206,166,205,165,166,166,0,0,0,0,0, -0,0,0,0,0,205,165,166,206,206,206,166,0,0,0,0,165,166,166,206,206,165,205,205,205,205,205,205,205,205,165,165,166,166,166,205,205,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,205,206,0,165,166,206,0,0,0,0,0, -0,0,0,0,165,165,165,166,166,205,206,206,166,0,0,165,166,166,166,166,166,205,205,206,206,206,206,165,166,165,166,166,206,206,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,205,206,166,166,206,0,0,0,0,0,0, -0,0,0,0,165,165,165,166,206,206,205,165,166,165,166,166,166,206,206,206,206,165,165,165,205,165,166,165,165,166,206,206,165,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,205,206,206,0,0,0,0,0,0,0, -0,0,0,0,165,165,165,165,165,165,165,205,206,165,165,165,165,165,165,165,165,205,205,165,165,165,165,205,205,206,205,205,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,165,205,205,205,205,205,205,205,206,166,205,205,165,165,205,205,205,165,165,205,205,205,205,206,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,205,205,205,205,205,205,205,206,206,206,165,165,205,205,206,206,206,205,205,206,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,205,205,205,205,205,205,206,205,205,205,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,205,165,166,206,206,206,166,0,0,0,0,165,166,166,206,206,165,205,205,205,205,205,205,205,205,165,165,166,166,166,205,205,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1660,1661,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,165,165,165,166,166,205,206,206,166,0,0,165,166,166,166,166,166,205,205,206,206,206,206,165,166,165,166,166,206,206,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1700,1701,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,165,165,165,166,206,206,205,165,166,165,166,166,166,206,206,206,206,165,165,165,205,165,166,165,165,166,206,206,165,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1660,1661,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,165,165,165,165,165,165,165,205,206,165,165,165,165,165,165,165,165,205,205,165,165,165,165,205,205,206,205,205,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1700,1701,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,165,205,205,205,205,205,205,205,206,166,205,205,165,165,205,205,205,165,165,205,205,205,205,206,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1660,1661,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,205,205,205,205,205,205,205,206,206,206,165,165,205,205,206,206,206,205,205,206,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1660,1661,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,205,205,205,205,205,205,206,205,205,205,205,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1700,1701,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1660,1660,1661,1660,1661,1660,1661,1660,1661,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1700,1700,1701,1700,1701,1700,1701,1700,1701,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 @@ -199,11 +201,117 @@ 111,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116, 151,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,156, 231,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,235,233,234,236 + + + + +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,87,87,87,87,87,87,87,87,87,87,87,87,87,87,88,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,87,88,88,0,0,0,127,127,127,127,127,87,88,127,127,127,127,127,127,127,128,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,87,87,88,0,0,0,0,0,0,0,0,0,1,2,0,0,1,2,87,88,0,0,87,88,128,128,2,0,87,88,88,88,88,88,88,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,127,127,128,1,2,0,0,0,0,0,0,0,41,42,0,0,41,42,87,87,88,0,127,128,0,41,42,0,127,128,128,128,128,128,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,41,42,0,0,0,0,0,0,0,81,82,0,0,81,82,127,87,88,0,0,0,0,81,82,0,0,0,0,85,86,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,87,88,0,81,82,0,0,0,0,0,0,0,121,122,0,0,121,122,0,127,128,0,0,0,0,121,122,0,0,0,0,125,126,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,127,128,0,121,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,87,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,42,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,87,87,88,0,0,85,86,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,81,82,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,127,87,88,0,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0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,42,0,0,0,0,127,128,0,0,0,87,88,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,42,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,81,82,0,0,0,0,0,0,0,87,88,127,128,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,81,82,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,0,0,121,122,0,0,0,0,0,87,88,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,121,122,0,0,0,0,0,0,0,0,0,0, +0,0,0,85,86,0,0,0,0,0,0,0,0,0,87,88,0,0,87,88,0,41,42,0,0,0,0,0,0,0,0,0,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,87,88,0,0,0,0,0,0,0,0,0, +0,0,0,125,126,0,0,0,0,0,0,0,87,88,127,128,1,2,127,128,0,81,82,0,0,0,0,0,0,0,0,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,128,0,0,0,0,0,0,0,0,0, +0,85,86,0,0,0,0,0,0,0,0,0,127,128,0,0,41,42,87,88,0,121,122,0,0,0,0,0,0,0,0,127,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,125,126,0,0,0,0,0,0,0,0,0,0,0,0,0,81,82,127,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Player.py b/src/Player.py index 7b39d16..c206f2d 100644 --- a/src/Player.py +++ b/src/Player.py @@ -9,6 +9,8 @@ def __init__(self, x, y): self.rect = self.image.get_rect() self.position = [x, y] self.speed = 2 + self.feet = pygame.Rect(0, 0, self.rect.width * 0.5, 12) + self.old_position = self.position.copy() self.images = { 'down': self.get_image(0, 0), 'up': self.get_image(0, 96), @@ -16,9 +18,16 @@ def __init__(self, x, y): 'right': self.get_image(0, 64) } + def save_location(self): self.old_position = self.position.copy() + def update(self): self.rect.topleft = self.position + self.feet.midbottom = self.rect.midbottom + def move_back(self): + self.position = self.old_position + self.rect.topleft = self.position + self.feet.midbottom = self.rect.midbottom def get_image(self, x, y): image = pygame.Surface([32, 32]) image.blit(self.sprite_sheet, (0, 0), (x, y, 32, 32))