我是 pygame 的新手,需要了解如何与平台发生碰撞。到目前为止,我能够跳上平台,但是当我走下时,我的角色会移出屏幕。除此之外,当我跳到平台下时,我的角色会被卡在里面并且不会回来。
class User:
def __init__ (self,x,y,width,height):
self.x = x
self.y = y
self.width = width
self.height = height
self.vel_x = 8
self.vel_y = 8
self.gravity = 1
self.left = False
self.right = False
self.jumping = False
self.walkCount = 0
self.hitbox = (self.x + 17, self.y + 11, 29, 52)
self.visible = True
self.standingstill = True
self.health = 250
self.number_left = 0
这是我的播放器类的主要部分
if player.hitbox[1] < platform_img.hitbox[1] + platform_img.hitbox[3] and player.hitbox[1] + player.hitbox[3] > platform_img.hitbox[1]:
if player.hitbox[0] + player.hitbox[2] > platform_img.hitbox[0] and player.hitbox[0] < platform_img.hitbox[0] + platform_img.hitbox[2]:
player.collision()
这是我用于碰撞检测的内容,但我知道有一种内置的碰撞技术。如果这更容易,请您展示它如何与我的代码一起工作以及我将在哪里实现它。
答案 0 :(得分:0)
请显示所有代码以便我给出更好的答案,player.collision()
有什么作用? (我没有足够的代表来评论)