The menu page I made in my game does not work correctly. I'm trying to make a menu using pygame
. My menu has 2 buttons start
and exit
. When I press the start
button, it should go to the game screen, but it works incorrectly, why?
This is my code:
run = True
while run:
clock.tick(FPS)
for etkinlik in pygame.event.get():
if etkinlik.type == pygame.QUIT:
run = False
screen.fill((202, 228, 241))
if start_button.draw(screen):
start_button.clicked==True
print('Play')
if exit_button.draw(screen):
run = False
print('EXIT')
if start_button.clicked==True:
# arka planı çizmek için kullandığım fonksiyoumu çağırdım
draw_bg()
# Savaşcıların canlarını göster.
draw_health_bar(fighter_1.health, 20, 20)
draw_health_bar(fighter_2.health, 580, 20)
# Savaşcıların skorlarını göster.
draw_text("P1: " + str(score[0]), score_font, WHITE, 20, 60)
draw_text("P2: " + str(score[1]), score_font, WHITE, 580, 60)
# geri sayımı güncelle
if intro_count <= 0:
# karakterleri taşı
fighter_1.move(SCREEN_WIDTH, SCREEN_HEIGHT, screen, fighter_2, round_over)
fighter_2.move(SCREEN_WIDTH, SCREEN_HEIGHT, screen, fighter_1, round_over)
else:
# Yazıyı görüntüle.
draw_text(str(intro_count), count_font, WHITE, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3)
if (pygame.time.get_ticks() - last_count_update) >= 1000:
intro_count -= 1
last_count_update = pygame.time.get_ticks()
# Karakterleri güncelle
fighter_1.update()
fighter_2.update()
# döcüşcü çizimleri
fighter_1.draw(screen)
fighter_2.draw(screen)
# Oyuncu kazandı mi kontrol et
if round_over == False:
if fighter_1.alive == False:
score[1] += 1
round_over = True
round_over_time = pygame.time.get_ticks()
elif fighter_2.alive == False:
score[0] += 1
round_over = True
round_over_time = pygame.time.get_ticks()
else:
# kazandın yazısını yazdır.
screen.blit(victory_img, (360, 150))
if pygame.time.get_ticks() - round_over_time > ROUND_OVER_COOLDOWN:
round_over = False
intro_count = 3
fighter_1 = Fighter(1, 200, 310, False, WARRIOR_DATA, warrior_sheet, WARRIOR_ANIMATION_STEPS,
sword_fx)
fighter_2 = Fighter(2, 700, 310, True, WIZARD_DATA, wizard_sheet, WIZARD_ANIMATION_STEPS, magic_fx)
pygame.display.flip()
# Görüntüyü güncelleme komutu
pygame.display.update()
# çıkış komutu
pygame.quit()