move collision to Map class
This commit is contained in:
parent
853a3b1601
commit
c121519605
@ -34,19 +34,14 @@ class EventManager:
|
|||||||
# Key names are temporary
|
# Key names are temporary
|
||||||
# TODO: Load key bindings from JSON
|
# 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)
|
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)
|
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)
|
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)
|
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
|
|
||||||
|
|
||||||
|
@ -39,3 +39,9 @@ class Map:
|
|||||||
self.entities.append(entity)
|
self.entities.append(entity)
|
||||||
self.screen.draw(entity, Locations.MAP, 0, 0)
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user