-
Notifications
You must be signed in to change notification settings - Fork 10
/
StartGameLevelNode.js
138 lines (123 loc) · 4.62 KB
/
StartGameLevelNode.js
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
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2013-2020, University of Colorado Boulder
/**
* a Scenery Node that allows the user to select which game level to play
*
* @author John Blanco
*/
import ResetAllButton from '../../../../scenery-phet/js/buttons/ResetAllButton.js';
import TimerToggleButton from '../../../../scenery-phet/js/buttons/TimerToggleButton.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import HBox from '../../../../scenery/js/nodes/HBox.js';
import Image from '../../../../scenery/js/nodes/Image.js';
import Node from '../../../../scenery/js/nodes/Node.js';
import Text from '../../../../scenery/js/nodes/Text.js';
import ShredConstants from '../../../../shred/js/ShredConstants.js';
import LevelSelectionButton from '../../../../vegas/js/LevelSelectionButton.js';
import massChargeIcon from '../../../images/mass_charge_icon_png.js';
import periodicTableIcon from '../../../images/periodic_table_icon_png.js';
import questionMarkIcon from '../../../images/question_mark_icon_png.js';
import symbolQuestionIcon from '../../../images/symbol_question_icon_png.js';
import buildAnAtom from '../../buildAnAtom.js';
import buildAnAtomStrings from '../../buildAnAtomStrings.js';
import BAASharedConstants from '../../common/BAASharedConstants.js';
import GameModel from '../model/GameModel.js';
const chooseYourGameString = buildAnAtomStrings.chooseYourGame;
// constants
const CONTROLS_INSET = 10;
const BASE_COLOR = '#D4AAD4';
class StartGameLevelNode extends Node {
/**
* @param {GameModel} gameModel
* @param {Bounds2} layoutBounds
* @param {Tandem} tandem
*/
constructor( gameModel, layoutBounds, tandem ) {
super();
// title
const title = new Text( chooseYourGameString, {
font: new PhetFont( 30 ),
maxWidth: layoutBounds.width,
centerX: layoutBounds.centerX
} );
this.addChild( title );
// buttons for starting a game level
const periodicTableGameButton = createLevelSelectionButton(
gameModel,
periodicTableIcon,
'periodic-table-game',
'periodicTableGame',
tandem
);
const massAndChargeGameButton = createLevelSelectionButton(
gameModel,
massChargeIcon,
'mass-and-charge-game',
'massAndChargeGame',
tandem
);
const symbolGameButton = createLevelSelectionButton(
gameModel,
symbolQuestionIcon,
'symbol-game',
'symbolGame',
tandem
);
const advancedSymbolGameButton = createLevelSelectionButton(
gameModel,
questionMarkIcon,
'advanced-symbol-game',
'advancedSymbolGame',
tandem
);
const buttonHBox = new HBox( {
children: [ periodicTableGameButton, massAndChargeGameButton, symbolGameButton, advancedSymbolGameButton ],
spacing: 30,
centerY: layoutBounds.centerY,
centerX: layoutBounds.centerX
} );
this.addChild( buttonHBox );
// timer control
const timerToggleButton = new TimerToggleButton( gameModel.timerEnabledProperty, {
stroke: 'gray',
tandem: tandem.createTandem( 'timerToggleButton' ),
left: CONTROLS_INSET,
bottom: layoutBounds.height - CONTROLS_INSET
} );
this.addChild( timerToggleButton );
// reset all button
const resetAllButton = new ResetAllButton( {
listener: () => {
gameModel.reset();
},
radius: BAASharedConstants.RESET_BUTTON_RADIUS,
tandem: tandem.createTandem( 'resetAllButton' ),
right: layoutBounds.width - CONTROLS_INSET,
bottom: layoutBounds.height - CONTROLS_INSET
} );
this.addChild( resetAllButton );
// additional layout
title.centerY = ( layoutBounds.minY + buttonHBox.top ) / 2;
}
}
// helper function to create level selection buttons, helps to avoid code duplication
function createLevelSelectionButton( gameModel, icon, levelName, gameLevelTandemName, tandem ) {
return new LevelSelectionButton(
new Image( icon ),
gameModel.scores[ ShredConstants.MAP_LEVEL_NAME_TO_NUMBER( levelName ) ],
{
listener: () => {
gameModel.startGameLevel( levelName, tandem.createTandem( gameLevelTandemName ) );
},
baseColor: BASE_COLOR,
bestTimeProperty: gameModel.bestTimes[ ShredConstants.MAP_LEVEL_NAME_TO_NUMBER( levelName ) ],
bestTimeVisibleProperty: gameModel.bestTimeVisible[ ShredConstants.MAP_LEVEL_NAME_TO_NUMBER( levelName ) ],
tandem: tandem.createTandem( gameLevelTandemName + 'Button' ),
scoreDisplayOptions: {
numberOfStars: GameModel.CHALLENGES_PER_LEVEL,
perfectScore: GameModel.MAX_POINTS_PER_GAME_LEVEL
}
}
);
}
buildAnAtom.register( 'StartGameLevelNode', StartGameLevelNode );
export default StartGameLevelNode;