export class Start extends Phaser.Scene {

    constructor() {
        super('Start');
    }

    preload() {
        this.load.image('background', 'assets/main_background.jpg');
        this.load.image('background_1', 'assets/background_1.jpg');
        this.load.image('background_3', 'assets/background_3.jpg');
        this.load.audio('backgroundMusic', 'assets/sounds/main_32_2.ogg');
        this.load.audio('backgroundMusic_Church', 'assets/sounds/Church_48_2.ogg');
        this.load.audio('backgroundMusic_Action1', 'assets/sounds/action1.ogg');
        this.load.audio('backgroundMusic_Final', 'assets/sounds/final.ogg');
    }

    create() {
        this.background = this.add.tileSprite(640, 360, 1280, 720, 'background');

        // Add a black background for the text
        const graphics = this.add.graphics();
        graphics.fillStyle(0x000000, 0.5);
        graphics.fillRect(0, 360, 1280, 360);

        // Define text style
        const textStyle = {
            fontFamily: 'monospace',
            fontSize: '32px',
            color: '#ffffff',
            align: 'left'
        };

        // Add text lines
        this.add.text(100, 400, '      <ДИКАЯ НОЧЬ>', textStyle);
        this.add.text(100, 450, '[1] начать', textStyle);
        this.add.text(100, 500, '[2] продолжить', textStyle);

        // Play background music
        this.sound.stopAll();
        this.sound.play('backgroundMusic', { loop: true });

        // Add keyboard listeners
        this.input.keyboard.on('keydown-ONE', () => {
            //this.scene.start('Pobeg');
            this.scene.start('Vstuplenie');
        });

        this.input.keyboard.on('keydown-TWO', () => {
            const savedScene = localStorage.getItem('Scene');
            if (savedScene) {
                this.scene.start(savedScene);
            }
        });
    }

    update() {
    }
    
}
