In this section of code I test:
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:
This basically tests for a collision between two different objects (A player based object [x] and a falling object [o_x(1,2)]) if it detects a collision it will display a 'game over' picture and take the player back to the main menu, it also sets all the objects y axis to 0. Despite this when you hit GO (play) it returns you to the same situation and disregards my code that should reset the situation (moving the falling objects back to the top of the screen [global y_o, o_y = 0
])
I am new to python so an explanation is greatly appreciated
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()