-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hx
244 lines (187 loc) · 5.86 KB
/
Main.hx
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import luxe.Input;
import luxe.Scene;
import luxe.Vector;
import luxe.Color;
import luxe.Rectangle;
import luxe.Visual;
import luxe.Text;
class Main extends luxe.Game
{
var playing:Bool = false;
var score:Int;
var welcomeText:Text;
var scoreText:Text;
var playScene:Scene;
var menuScene:Scene;
var simonOne:SimonButton;
var simonTwo:SimonButton;
var simonThree:SimonButton;
var simonFour:SimonButton;
var simonColors:Array<Array<Color>>;
var background:Visual;
var turnColorYou:Color;
var turnColorSimon:Color;
var simon:Simon;
override function config(config:luxe.AppConfig):luxe.AppConfig
{
if(config.runtime.window != null) {
if(config.runtime.window.width != null) {
config.window.width = Std.int(config.runtime.window.width);
}
if(config.runtime.window.height != null) {
config.window.height = Std.int(config.runtime.window.height);
}
}
config.window.resizable = false;
if(config.runtime.colors != null) {
simonColors = new Array<Array<Color>>();
for(i in 0...4){
simonColors[i] = new Array<Color>();
for(j in 0...3){
simonColors[i][j] = new Color().rgb( Std.parseInt(config.runtime.colors[i][j]) );
}
}
}
if(config.runtime.turnColorYou != null) {
turnColorYou = new Color().rgb(config.runtime.turnColorYou);
}else{
turnColorYou = new Color().rgb(0xFFFFFF);
}
// Another way to write the same thing as above:
turnColorSimon = (config.runtime.turnColorSimon != null) ? new Color().rgb(config.runtime.turnColorSimon) : new Color().rgb(0x000000);
return config;
}
override function ready()
{
initGame();
} //ready
override function onkeyup( e:KeyEvent )
{
if(e.keycode == Key.escape)
{
Luxe.shutdown();
}
if(e.keycode == Key.enter && !playing)
{
playGame();
}
} //onkeyup
override function update(dt:Float)
{
} //update
function initGame():Void
{
playing = false;
playScene = new Scene('play');
menuScene = new Scene('menu');
addBackground();
addText();
addSimon();
}
// background changes as turns
function addBackground():Void
{
background = new Visual({
name: 'background',
geometry: Luxe.draw.box({
x:0,
y:0,
w: Luxe.screen.w,
h: Luxe.screen.h,
}),
color: turnColorSimon,
});
Luxe.events.listen('simon.finished', function(e){
background.color = turnColorYou;
});
Luxe.events.listen('simon.turn', function(e){
background.color = turnColorSimon;
});
}
function addText():Void
{
welcomeText = new Text({
bounds: new Rectangle(0,100,Luxe.screen.w, 100),
align: center,
point_size: 16,
text: 'Press [ENTER] to let Simon talk...',
batcher: Luxe.renderer.batcher
});
scoreText = new Text({
bounds: new Rectangle(10, 10, Luxe.screen.w-10, 30),
align: left,
point_size: 24,
text: 'SCORE: 0',
});
scoreText.visible = false;
score = 0;
}
// Adds clickable buttons of Simon
function addSimon():Void
{
var halfx:Float = Luxe.screen.w/2;
var halfy:Float = Luxe.screen.h/2;
var bsize:Float = SimonButton.SIZE;
var space:Int = 5;
simonOne = new SimonButton({
name: 'simonone',
number: 0,
color: simonColors[0][0],
colorOver: simonColors[0][1],
colorDown: simonColors[0][2],
start_angle: 0,
end_angle: 90,
bounds: new Rectangle(halfx + space, halfy-bsize - space, bsize, bsize),
pos: new Vector(halfx + space, halfy - space),
});
playScene.add( simonOne );
simonTwo = new SimonButton({
name: 'simontwo',
number: 1,
color: simonColors[1][0],
colorOver: simonColors[1][1],
colorDown: simonColors[1][2],
start_angle: 90,
end_angle: 180,
bounds: new Rectangle(halfx + space, halfy + space, bsize, bsize),
pos: new Vector(halfx + space, halfy + space),
});
playScene.add( simonTwo );
simonThree = new SimonButton({
name: 'simonthree',
number: 2,
color: simonColors[2][0],
colorOver: simonColors[2][1],
colorDown: simonColors[2][2],
start_angle: 180,
end_angle: 270,
bounds: new Rectangle(halfx-bsize - space, halfy + space, bsize, bsize),
pos: new Vector(halfx - space, halfy + space),
});
playScene.add( simonThree );
simonFour = new SimonButton({
name: 'simonfour',
number: 3,
color: simonColors[3][0],
colorOver: simonColors[3][1],
colorDown: simonColors[3][2],
start_angle: 270,
end_angle: 360,
bounds: new Rectangle(halfx-bsize - space, halfy-bsize - space, bsize, bsize),
pos: new Vector(halfx - space, halfy - space),
});
playScene.add( simonFour );
simon = new Simon({
name: 'simon'
});
}
function playGame():Void
{
playing = true;
welcomeText.visible = false;
Luxe.events.fire('simon.turn');
}
function restartGame():Void
{
}
} //Main