【发布时间】:2021-05-11 13:45:24
【问题描述】:
我正在制作一个基于图块的 pygame 平台游戏
这是我的碰撞检查代码:
# check for collision
for tile in world.tile_list:
# check for collision in x direction
if tile[1].colliderect(self.rect.x + dx, self.rect.y, self.width, self.height):
dx = 0
# check for collision in y direction
if tile[1].colliderect(self.rect.x, self.rect.y + dy, self.width, self.height):
# check if below the ground i.e. jumping
if self.vel_y < 0:
dy = tile[1].bottom - self.rect.top
self.vel_y = 0
# check if above the ground i.e. falling
elif self.vel_y >= 0:
dy = tile[1].top - self.rect.bottom
self.vel_y = 0
当我运行游戏时,我遇到了一个奇怪的错误,即玩家可以在平台板块之外移动,而当玩家离开平台板块时应该跌倒
像这样:
1 = tile
0 = player
0
111111111
就像平台瓷砖的侧面有看不见的瓷砖。不知道为什么会这样
【问题讨论】:
标签: python python-3.x pygame