Я использовал случайный диапазон для своих горшков, и я не знаю, как сделать столкновение между горшками и птицей. Я не могу использовать коды каналов, потому что это проект, и я должен создать его с помощью горшков. Я написал простой cra sh def, чтобы знать, что произошло столкновение. Не знаю, как брать диапазон банка
pygame.init()
#displayset
display_width = 600
display_height = 300
high_pot = display_height * 0.80
low_pot = display_height * 0.20
half_pot_gap = 50
#object
birdImg = pygame.image.load('bird.png')
bird_height = 80
bird_width = 80
x = 50
y = (display_height * 0.5) - (bird_height/2)
#colors
black = (0,0,0)
white = (255,255,255)
yellow = (255,255,0)
red = (255,0,0)
skyblue = (135,206,235)
orange = (255,69,0)
#deeeeeef
def bird(x,y):
gameDisplay.blit(birdImg,(x,y))
def pot(pot1X,pot1Y,pot1H,pot2X,pot2Y,pot2H,potW,potColor):
pygame.draw.rect(gameDisplay,potColor,(pot1X,pot1Y,potW,pot1H))
pygame.draw.rect(gameDisplay,black,(pot1X,pot1Y,potW,pot1H),2)
pygame.draw.rect(gameDisplay,potColor,(pot2X,pot2Y,potW,pot2H))
pygame.draw.rect(gameDisplay,black,(pot2X,pot2Y,potW,pot2H),2)
pot_head_1X = pot1X - 10
pot_head_1Y = pot1H
pot_head_2X = pot2X - 10
pot_head_2Y = pot2Y
pot_head_width = 50
pot_head_height = 20
pygame.draw.rect(gameDisplay,orange,(pot_head_1X,pot_head_1Y,pot_head_width,pot_head_height))
pygame.draw.rect(gameDisplay,black,(pot_head_1X,pot_head_1Y,pot_head_width,pot_head_height),2)
pygame.draw.rect(gameDisplay,orange,(pot_head_2X,pot_head_2Y,pot_head_width,pot_head_height))
pygame.draw.rect(gameDisplay,black,(pot_head_2X,pot_head_2Y,pot_head_width,pot_head_height),2)
def new_pot(factor):
new_random = random.randrange(low_pot,high_pot)
pot1H = new_random - half_pot_gap
pot1X = display_width + 100 * factor
pot1Y = 0
pot2H = display_height - (new_random + half_pot_gap)
pot2X = display_width + 100 * factor
pot2Y = new_random + half_pot_gap
return pot1X,pot1Y,pot1H,pot2X,pot2Y,pot2H
#scoredef
def display_message(textMessage, tColor, position_X, position_Y):
textMessage = str(textMessage)
font_and_size = pygame.font.Font("freesansbold.ttf",22)
text_surface = font_and_size.render(textMessage, True, tColor)
text_rect = text_surface.get_rect()
text_rect.center = ((position_X),(position_Y))
gameDisplay.blit(text_surface,text_rect)
#pot
potW = 30
potColor = yellow
gameSpeed = 3
pot1X = [0,0,0,0]
pot1Y = [0,0,0,0]
pot1H = [0,0,0,0]
pot2X = [0,0,0,0]
pot2Y = [0,0,0,0]
pot2H = [0,0,0,0]
pot1X[0],pot1Y[0],pot1H[0],pot2X[0],pot2Y[0],pot2H[0] = new_pot(1)
pot1X[1],pot1Y[1],pot1H[1],pot2X[1],pot2Y[1],pot2H[1] = new_pot(3)
pot1X[2],pot1Y[2],pot1H[2],pot2X[2],pot2Y[2],pot2H[2] = new_pot(5)
pot1X[3],pot1Y[3],pot1H[3],pot2X[3],pot2Y[3],pot2H[3] = new_pot(6.5)
score = 0
score_counter = 0
def crash():
display_message("YOU CRASHED" ,red,50, 50)
#window
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption("Racey")
clock = pygame.time.Clock()
tasadof = False
y_change = 0
space_flag = 0
down = True
while not tasadof:
for event in pygame.event.get():
if event.type == pygame.QUIT:
tasadof = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
y_change = -9
space_flag = 0
down = False
if not down:
if y_change<0:
if y-1 > - 10:
y -= 1
else:
y= -10
y_change+=1
space_flag = 0
else:
down = True
space_flag = 0
else:
y += 2
if y> (display_height-(bird_height-20)):
y = display_height-(bird_height-20)
y += y_change
gameDisplay.fill(skyblue)
bird(x,y)
for i in range(4):
pot(pot1X[i],pot1Y[i],pot1H[i],pot2X[i],pot2Y[i],pot2H[i],potW,potColor)
pot1X[i] -= gameSpeed
pot2X[i] -= gameSpeed
if pot1X[i] < -50 :
pot1X[i],pot1Y[i],pot1H[i],pot2X[i],pot2Y[i],pot2H[i] = new_pot(1)
score += 5
pygame.display.update()
clock.tick(100)
pygame.quit()
quit()