在我测试的这部分代码中:
if y <= o_y + 160:
if x >= o_x and x <= o_x + 80 or x + 60 > o_x and x + 60 < o_x + 80:
这基本上测试了两个不同对象(基于玩家的对象[x]和下降对象[o_x(1,2)])之间的碰撞,如果它检测到碰撞,它将显示&#39;游戏结束&# 39;图片并将播放器带回主菜单,它还将所有对象y轴设置为0.尽管如此,当你点击GO(播放)时,它会返回到相同的情况并忽略我应该重置情况的代码(移动将对象放回屏幕顶部[global y_o, o_y = 0
])
我是python的新手,所以非常感谢解释
def fallingObject():
global car
car = a
global car1
car1 = c
global car2
car2 = e
objectSpawn = True
while objectSpawn:
if o_y < height:
global o_y
o_y += +1
global o_y1
o_y1 += +1
global o_y2
o_y2 += +1
objectSpawn = False
blit_screen()
if o_y >= height:
global o_x1
o_x1 = random.randrange(220, 450)
global o_y1
o_y1 = 0
global o_x2
o_x2 = random.randrange(450, 680)
global o_y2
o_y2 = 0
global o_x
o_x = random.randrange(-10, 220)
global o_y
o_y = 0
global car_s
car_s = random.randrange(1,6)
global car_s1
car_s1 = random.randrange(1,6)
global car_s2
car_s2 = random.randrange(1,6)
objectSpawn = False
blit_screen()
if y + 120 < o_y:
print("y cross over")
if y <= o_y + 160:
if x >= o_x and x <= o_x + 80 or x + 60 > o_x and x + 60 < o_x + 80:
screen.blit(crash, (0,0))
pygame.display.flip()
pygame.time.delay(3000)
game_intro()
global o_y
o_y = 0
global o_y1
o_y1 = 0
global o_y2
o_y2 = 0
blit_screen()
if y + 120 < o_y1:
print("y cross over")
if y <= o_y1 + 160:
if x >= o_x1 and x <= o_x1 + 80 or x + 60 > o_x1 and x + 60 < o_x1 + 80:
screen.blit(crash, (0,0))
pygame.display.flip()
pygame.time.delay(3000)
game_intro()
global o_y
o_y = 0
global o_y1
o_y1 = 0
global o_y2
o_y2 = 0
blit_screen()
if y + 120 < o_y2:
print("y cross over")
if y <= o_y2 + 160:
if x >= o_x2 and x <= o_x2 + 80 or x + 60 > o_x2 and x + 60 < o_x2 + 80:
screen.blit(crash, (0,0))
pygame.display.flip()
pygame.time.delay(3000)
game_intro()
global o_y
o_y = 0
global o_y1
o_y1 = 0
global o_y2
o_y2 = 0
blit_screen()
def blit_screen():
if car_s == 1:
car = a
else:
if car_s == 2:
car = b
else:
if car_s == 3:
car = c
else:
if car_s == 4:
car = d
else:
if car_s == 5:
car = e
else:
print(" ")
if car_s1 == 1:
car1 = a
else:
if car_s1 == 2:
car1 = b
else:
if car_s1 == 3:
car1 = c
else:
if car_s1 == 4:
car1 = d
else:
if car_s1 == 5:
car1 = e
else:
print(" ")
if car_s2 == 1:
car2 = a
else:
if car_s2 == 2:
car2 = b
else:
if car_s2 == 3:
car2 = c
else:
if car_s2 == 4:
car2 = d
else:
if car_s2 == 5:
car2 = e
else:
print(" ")
screen.fill(blue)
screen.blit(road, (0,0))
screen.blit(car, (o_x,o_y))
screen.blit(car1, (o_x1,o_y1))
screen.blit(car2, (o_x2,o_y2))
screen.blit(carImg, (x,y))
pygame.display.flip()
clock.tick(60)
game_intro()