我一直很难让你上班。我是新来的,不知道编码的来龙去脉,所以请你解释一下你的理由
下面是一些代码的简单示例:
def __init__(self, x, y, width, height, sprite):
self.x = player_x
self.y = player_y
self.width = player.width
self.height = player.height
self.col = pygame.sprite.collide_rect(self, sprite)
pygame.sprite.Sprite.__init__(self)
def velocity_player(self):
player_vertical_velocity = 0
player_horizontal_velocity = 0
player_y = player_y + player_vertical_velocity
player_x = player_x + player_horizontal_velocity
player_fr = 5
def render(self):
player_surface = pygame.image.load("Bunny.png")
player_surface.set_colorkey(TRANSPARENT_GREEN)
player_left = pygame.image.load("Bunny_left.png")
player_left.set_colorkey(TRANSPARENT_GREEN)
player_left = pygame.image.load("Bunny_left.png")
player_left.set_colorkey(TRANSPARENT_GREEN)
player_fall = pygame.image.load("Bunny_Fall.png")
player_fall.set_colorkey(TRANSPARENT_GREEN)
player_jump = pygame.image.load("Bunny_r_Jump.png")
screen.blit(player_surface, [player_x, player_y])
首先,从学习Classes的概念开始(另见Python - Classes and OOP Basics)。必须在每一帧中检测碰撞。通常你不想在课堂上做这件事。见How do I detect collision in pygame?
当使用^{}s 和^{}s 时,冲突由^{} 和^{} 等函数检测。但是,碰撞检测通常不会在Sprite类中执行。这是在管理精灵和精灵之间交互的外部代码中完成的
最简单的例子:
相关问题 更多 >
编程相关推荐