Better collision checking

master
GreenXenith 2020-04-24 14:38:16 -07:00
parent a408c30553
commit 9a5ca4b0de
4 changed files with 3 additions and 5 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -32,7 +32,7 @@ map.generate()
# Player
player = Player()
player.sprite.texture = spritesheet.SpriteSheet(assets.get("character.png"), 16, 24)
player.sprite.set_rect((0, 16, 16, 24))
player.sprite.set_rect((0, 8, 16, 24))
# TODO: Scale character up x2 (1.5m)
# TODO: Use asset loader for spritesheets
player.sprite.texture.set_animation(0, 0, 0)
@ -42,7 +42,6 @@ player.set_pos(map.generator.rooms[0].x + 2, map.generator.rooms[0].y + 2)
CENTER = [winsize[0] / 2, winsize[1] / 2]
BGCOLOR = pygame.Color("#3e1202")
arial = pygame.font.SysFont("Arial", 10)
# Mainloop

View File

@ -20,7 +20,6 @@ class Map:
# self.placer = loot.Placer()
# self.map = self.placer.populate(self.map)
# TODO: Dont use rect h/w, use corners x/y
def collides(self, pos, rect):
px = int(math.floor(pos.x))
py = int(math.floor(pos.y))
@ -29,8 +28,8 @@ class Map:
if y >= 0 and y < len(self.map[1]) and x >=0 and x < len(self.map[1][y]):
tile = self.map[1][y][x]
if tile and tile.is_solid():
if pos.x + (rect.width / self.METER) >= x and pos.x <= (x + 1) and \
pos.y + (rect.height / self.METER) >= y and pos.y <= (y + 1):
if pos.x + (rect[2] / self.METER) >= x and pos.x + (rect[0] / self.METER) <= (x + 1) and \
pos.y + (rect[3] / self.METER) >= y and pos.y + (rect[1] / self.METER) <= (y + 1):
return True
return False