File size: 4,311 Bytes
78475cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import Phaser from 'phaser';
import { GAME_WIDTH, GAME_HEIGHT, BORDER_OFFSET } from '../constants.js';
import SoundGenerator from '../utils/SoundGenerator.js';

export default class ModeSelectScene extends Phaser.Scene {
  constructor() {
    super({ key: 'ModeSelectScene' });
  }

  create() {
    // Use the title backdrop
    const titleImage = this.add.image(BORDER_OFFSET, 0, 'title');
    titleImage.setOrigin(0, 0);
    titleImage.texture.setFilter(Phaser.Textures.FilterMode.NEAREST);

    // Dim the background by 50%
    const dimOverlay = this.add.rectangle(GAME_WIDTH / 2 + BORDER_OFFSET, GAME_HEIGHT / 2, GAME_WIDTH, GAME_HEIGHT, 0x000000, 0.5);
    dimOverlay.setDepth(5);

    // Title
    const titleText = this.add.bitmapText(GAME_WIDTH / 2 + BORDER_OFFSET, 60, 'pixel-font', 'MODE SELECT', 10).setOrigin(0.5);
    titleText.texture.setFilter(Phaser.Textures.FilterMode.NEAREST);
    titleText.setDepth(10);

    // Classic mode option
    this.classicText = this.add.bitmapText(GAME_WIDTH / 2 + BORDER_OFFSET, 100, 'pixel-font', '> CLASSIC', 10).setOrigin(0.5);
    this.classicText.texture.setFilter(Phaser.Textures.FilterMode.NEAREST);
    this.classicText.setDepth(10);
    this.classicText.setInteractive({ useHandCursor: true });

    const classicDesc = this.add.bitmapText(GAME_WIDTH / 2 + BORDER_OFFSET, 115, 'pixel-font', '7 STANDARD PIECES', 10).setOrigin(0.5);
    classicDesc.texture.setFilter(Phaser.Textures.FilterMode.NEAREST);
    classicDesc.setDepth(10);

    // Advanced mode option
    this.advancedText = this.add.bitmapText(GAME_WIDTH / 2 + BORDER_OFFSET, 145, 'pixel-font', '  ADVANCED', 10).setOrigin(0.5);
    this.advancedText.texture.setFilter(Phaser.Textures.FilterMode.NEAREST);
    this.advancedText.setDepth(10);
    this.advancedText.setInteractive({ useHandCursor: true });

    const advancedDesc = this.add.bitmapText(GAME_WIDTH / 2 + BORDER_OFFSET, 160, 'pixel-font', 'EXTRA UNIQUE PIECES', 10).setOrigin(0.5);
    advancedDesc.texture.setFilter(Phaser.Textures.FilterMode.NEAREST);
    advancedDesc.setDepth(10);

    // Track selected mode
    this.selectedMode = 'classic';

    // Hover effects
    this.classicText.on('pointerover', () => {
      if (this.selectedMode !== 'classic') {
        SoundGenerator.playMove();
        this.selectedMode = 'classic';
        this.updateSelection();
      }
    });

    this.advancedText.on('pointerover', () => {
      if (this.selectedMode !== 'advanced') {
        SoundGenerator.playMove();
        this.selectedMode = 'advanced';
        this.updateSelection();
      }
    });

    // Click handlers
    this.classicText.on('pointerdown', () => {
      SoundGenerator.playRotate();
      this.startGame('classic');
    });

    this.advancedText.on('pointerdown', () => {
      SoundGenerator.playRotate();
      this.startGame('advanced');
    });

    // Keyboard controls
    const upKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
    const downKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN);
    const spaceKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);
    const enterKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.ENTER);

    upKey.on('down', () => {
      if (this.selectedMode !== 'classic') {
        SoundGenerator.playMove();
        this.selectedMode = 'classic';
        this.updateSelection();
      }
    });

    downKey.on('down', () => {
      if (this.selectedMode !== 'advanced') {
        SoundGenerator.playMove();
        this.selectedMode = 'advanced';
        this.updateSelection();
      }
    });

    spaceKey.on('down', () => {
      SoundGenerator.playRotate();
      this.startGame(this.selectedMode);
    });

    enterKey.on('down', () => {
      SoundGenerator.playRotate();
      this.startGame(this.selectedMode);
    });
  }

  updateSelection() {
    if (this.selectedMode === 'classic') {
      this.classicText.setText('> CLASSIC');
      this.advancedText.setText('  ADVANCED');
    } else {
      this.classicText.setText('  CLASSIC');
      this.advancedText.setText('> ADVANCED');
    }
  }

  startGame(mode) {
    // Store the selected mode in the registry so GameScene can access it
    this.registry.set('gameMode', mode);
    this.scene.start('GameScene');
  }
}