diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 5143fee..f093015 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -34,19 +34,14 @@ class EventManager: # Key names are temporary # TODO: Load key bindings from JSON - if keys[pygame.K_w] and not self.collision(self.player.rect.x, self.player.rect.y - self.player.rect.w): + if keys[pygame.K_w] and not self.game.map.collision(self.player.rect.x, self.player.rect.y - self.player.rect.w): self.player.move(Rotations.NORTH) - if keys[pygame.K_s] and not self.collision(self.player.rect.x, self.player.rect.y + self.player.rect.w): + if keys[pygame.K_s] and not self.game.map.collision(self.player.rect.x, self.player.rect.y + self.player.rect.w): self.player.move(Rotations.SOUTH) - if keys[pygame.K_d] and not self.collision(self.player.rect.x + self.player.rect.w, self.player.rect.y): + if keys[pygame.K_d] and not self.game.map.collision(self.player.rect.x + self.player.rect.w, self.player.rect.y): self.player.move(Rotations.EAST) - if keys[pygame.K_a] and not self.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y): + if keys[pygame.K_a] and not self.game.map.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y): self.player.move(Rotations.WEST) - # add object to map.collidables list to be collidable - def collision(self, x, y): - for b in self.game.map.collidables: - if b.rect.x == x and b.rect.y == y: - return True - return False + diff --git a/src/game/Map.py b/src/game/Map.py index c072880..e5a1d27 100644 --- a/src/game/Map.py +++ b/src/game/Map.py @@ -39,3 +39,9 @@ class Map: self.entities.append(entity) self.screen.draw(entity, Locations.MAP, 0, 0) + # add object to map.collidables list to be collidable + def collision(self, x, y): + for b in self.collidables: + if b.rect.x == x and b.rect.y == y: + return True + return False