我正在创建我的第一个游戏,我在处理碰撞时遇到了一些问题。我有一个两人游戏,在同一个键盘上玩,awsd和上下左右控制。当两个玩家发生碰撞时,我希望他们不能互相移动。我很难弄明白
player_one_pos = [300,310]
player_two_pos = [600,310]
def detect_collision(player_one_pos, player_two_pos):
p1_x = player_one_pos[0]
p1_y = player_one_pos[1]
p2_x = player_two_pos[0]
p2_y = player_two_pos[1]
if (p1_x + player_width/2) == (p2_x - player_width/2):
return True
return False
if detect_collision(player_one_pos, player_two_pos):
## players collide, can't go through each other
我可以通过添加and语句来完成它。这个修复现在应该足够了
相关问题 更多 >
编程相关推荐