我很难使足球相撞。如何让球员移动球?我不知道怎么做。我附上了我用来和足球碰撞的代码。到目前为止,当球员跑进球里时,球只会进入斜线,而不会进入网窝。谁能帮忙吗?在
# collision scenario for what happenes when second soccer player collides with ball
blocks_hit_list_soccer2 = pygame.sprite.spritecollide(soccer_Avatar2, block_list, False)
for i in blocks_hit_list_soccer2:
soccer_Avatar2.rect.x -= soccer2_x_speed
soccer_Avatar2.rect.y -= soccer2_y_speed
soccer2_x_speed = 0
soccer2_y_speed = 0
# collision scenario for what happens when ball collides with wall
blocks_hit_list_ball = pygame.sprite.spritecollide(soccer_Ball, block_list, False)
for i in blocks_hit_list_ball:
soccer_Ball.rect.x == ball_x_speed
soccer_Ball.rect.y == ball_y_speed
ball_x_speed = 0
ball_y_speed = 0
# collision scenario for what happens when ball collides with first soccer player
blocks_hit_list_ball = pygame.sprite.spritecollide(soccer_Ball, player1_list, False)
for i in blocks_hit_list_ball:
soccer_Ball.rect.x += ball_x_speed
soccer_Ball.rect.y += ball_y_speed
ball_x_speed = 5
ball_y_speed = 5
# collision scenario for what happens when ball collides with second soccer player
blocks_hit_list_ball2 = pygame.sprite.spritecollide(soccer_Ball, player2_list, False)
for i in blocks_hit_list_ball2:
soccer_Ball.rect.x -= ball_x_speed
soccer_Ball.rect.y -= ball_y_speed
ball_x_speed = 5
ball_y_speed = 5
再试试这个。。。。。在
如果你使用的是足球图像,那么这个代码就可以工作了!当用户触摸设备屏幕的左侧或右侧时,以下操作将使足球(或图像)移动。。。。。在
相关问题 更多 >
编程相关推荐