import pygame as pg
import time
pg.init()
WIDTH = 800
HEIGHT = 600
FPS = 60
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
screen = pg.display.set_mode((WIDTH, HEIGHT))
pg.display.set_caption('Interactive Miku Game')
class Miku(pg.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pg.image.load('Miku.jpg').convert()
        self.rect = self.image.get_rect()
        self.rect.center = (WIDTH // 2, HEIGHT // 2)
    def show_text_slow(self, text, pos):
        font = pg.font.SysFont('comicsans', 24)
        text_surface = font.render(text, True, (0, 0, 0))
        text_rect = text_surface.get_rect(center=pos)
        for i in range(len(text)):
            screen.blit(text_surface, text_rect)
            pg.display.flip()
            time.sleep(0.1)  # Adjust the delay here for slower text display
            text_rect.w += font.size(text[i])[0]
        screen.blit(text_surface, text_rect)
        pg.display.flip()
miku_sprite = Miku()
all_sprites = pg.sprite.Group(miku_sprite)
running = True
name = ""
selected_choice = False
get_name = True
go_walk = False
while running:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            running = False
    screen.fill(WHITE)
    all_sprites.draw(screen)
    if get_name:
        miku_sprite.show_text_slow("Привет. Я Мику! Как тебя зовут?", (WIDTH // 2, HEIGHT // 5))
        get_name = False
    elif not selected_choice:
        choice1_rect = pg.draw.rect(screen, GREEN, (WIDTH // 4, HEIGHT // 3, WIDTH // 2, HEIGHT // 6))
        pg.draw.rect(screen, GREEN, choice1_rect)
        miku_sprite.show_text_slow("Саня_читер777", (WIDTH // 2, HEIGHT // 3 + 30))
        choice2_rect = pg.draw.rect(screen, GREEN, (WIDTH // 4, HEIGHT // 2, WIDTH // 2, HEIGHT // 6))
        pg.draw.rect(screen, GREEN, choice2_rect)
        miku_sprite.show_text_slow("Олежа", (WIDTH // 2, HEIGHT // 2 + 30))
        for event in pg.event.get():
            if event.type == pg.MOUSEBUTTONUP:
                pos = pg.mouse.get_pos()
                if choice1_rect.collidepoint(pos):
                    selected_choice = True
                    miku_sprite.show_text_slow("Мику посчитала это имя странным, и убежала. концовка 1.", (WIDTH // 2, HEIGHT // 1.2))
                elif choice2_rect.collidepoint(pos):
                    selected_choice = True
                    miku_sprite.show_text_slow("Хорошее имя, Олежа...", (WIDTH // 2, HEIGHT // 1.2))
    elif selected_choice and not go_walk:
        miku_sprite.show_text_slow("Пойдём гулять?", (WIDTH // 2, HEIGHT // 1.2))
        choice_yes_rect = pg.draw.rect(screen, GREEN, (WIDTH // 4, HEIGHT // 2, WIDTH // 2, HEIGHT // 6))
        pg.draw.rect(screen, GREEN, choice_yes_rect)
        miku_sprite.show_text_slow("Да", (WIDTH // 2, HEIGHT // 2 + 30))
        choice_no_rect = pg.draw.rect(screen, GREEN, (WIDTH // 4, HEIGHT // 3, WIDTH // 2, HEIGHT // 6))
        pg.draw.rect(screen, GREEN, choice_no_rect)
        miku_sprite.show_text_slow("Нет", (WIDTH // 2, HEIGHT // 3 + 30))
        for event in pg.event.get():
            if event.type == pg.MOUSEBUTTONUP:
                pos = pg.mouse.get_pos()
                if choice_no_rect.collidepoint(pos):
                    miku_sprite.show_text_slow("Мику сильно расстроилась и ушла домой", (WIDTH // 2, HEIGHT // 1.1))
                    time.sleep(2)
                    running = False
                elif choice_yes_rect.collidepoint(pos):
                    go_walk = True
    pg.display.flip()
pg.quit()