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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
###
#
# TetraCity
# Copyright (C) 2010, 2011 Levi D. Smith
#
# TetraCity is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TetraCity is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with TetraCity. If not, see <http://www.gnu.org/licenses/gpl.txt>.
#
###
MAX_OPTIONS = 8
class Options
GEN_BAG = 0
GEN_RANDOM = 1
def initialize(i1, i2)
@musicVolume = i1
@soundEffectsVolume = i2
@useLighting = true
@mode = "BASIC"
@ghostPieceOn = true
@pieceGeneration = GEN_BAG
@colorScheme = 0
@piecePreviewCount = 5
end
def soundEffectsVolume
@soundEffectsVolume
end
def musicVolume
@musicVolume
end
def useLighting
@useLighting
end
def mode
@mode
end
def ghostPieceOn
@ghostPieceOn
end
def setMode(str)
@mode = str
end
attr_accessor :soundEffectsVolume
attr_accessor :musicVolume
attr_accessor :useLighting
attr_accessor :mode
attr_accessor :ghostPieceOn
attr_accessor :pieceGeneration
attr_accessor :colorScheme
attr_accessor :piecePreviewCount
end
def optionsLoop
keepLooping = true
$selected_option = 0
init_throttle()
while keepLooping
throttle()
optionsDraw
while event = SDL::Event2.poll
case event
when SDL::Event::Quit
exit
when SDL::Event::KeyDown
case event.sym
when SDL::Key::UP
$selected_option -= 1
if ($selected_option < 0)
$selected_option = 0
end
when SDL::Key::DOWN
$selected_option += 1
if ($selected_option > MAX_OPTIONS - 1)
$selected_option = MAX_OPTIONS - 1
end
when SDL::Key::LEFT
if ($selected_option == 0)
decreaseMusicVolume
elsif ($selected_option == 1)
decreaseSoundEffectsVolume
elsif ($selected_option == 2)
setUseLighting(false)
elsif ($selected_option == 3)
$theOptions.ghostPieceOn = false
elsif ($selected_option == 4)
$theOptions.pieceGeneration = Options::GEN_BAG
elsif ($selected_option == 5)
$theOptions.colorScheme -= 1
if ($theOptions.colorScheme < 0)
$theOptions.colorScheme = 0
end
elsif ($selected_option == 6)
$theOptions.piecePreviewCount -= 1
if ($theOptions.piecePreviewCount < 0)
$theOptions.piecePreviewCount = 0
end
end
when SDL::Key::RIGHT
if ($selected_option == 0)
increaseMusicVolume
elsif ($selected_option == 1)
increaseSoundEffectsVolume
elsif ($selected_option == 2)
setUseLighting(true)
elsif ($selected_option == 3)
$theOptions.ghostPieceOn = true
elsif ($selected_option == 4)
$theOptions.pieceGeneration = Options::GEN_RANDOM
elsif ($selected_option == 5)
$theOptions.colorScheme += 1
if ($theOptions.colorScheme > 6)
$theOptions.colorScheme = 6
end
elsif ($selected_option == 6)
$theOptions.piecePreviewCount += 1
if ($theOptions.piecePreviewCount > 5)
$theOptions.piecePreviewCount = 5
end
end
when SDL::Key::SPACE
if ($selected_option == 7)
keepLooping = false
end
when SDL::Key::Q, SDL::Key::ESCAPE
keepLooping = false
end
end
end
end
end
def optionsDraw
glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
colorHighlight = [1.0, 1.0, 1.0]
colorNormal = [0.5, 0.5, 0.5]
colorFg=[1.0, 1.0, 1.0]
glPushMatrix
glLoadIdentity
glOrtho(0, 1024, 768, 0, -1, 1)
glColor(1.0, 1.0, 1.0)
x_offset = 32
y_offset = 128
width = 800
height = 400
iCol1 = x_offset + 32
iCol2 = x_offset + 400
glBegin(GL_QUADS)
glColor(0, 0, 0)
z = 0.0
glVertex(x_offset, y_offset, z)
glVertex(x_offset + width, y_offset, z)
glVertex(x_offset + width, y_offset + height, z)
glVertex(x_offset, y_offset + height, z)
glEnd
glBegin(GL_LINES)
glColor(1.0, 0.0, 0.0)
glVertex(x_offset, y_offset, z)
glVertex(x_offset + width, y_offset, z)
glColor(0.0, 0.0, 1.0)
glVertex(x_offset + width, y_offset, z)
glVertex(x_offset + width, y_offset + height, z)
glVertex(x_offset + width, y_offset + height, z)
glVertex(x_offset, y_offset + height, z)
glColor(1.0, 0.0, 0.0)
glVertex(x_offset, y_offset + height, z)
glVertex(x_offset, y_offset, z)
glEnd()
drawMenuText("OPTIONS", 200, 150, 128, 16, colorHighlight)
x = iCol1
y = 200
iSpacing = 32
y += iSpacing
if ($selected_option == 0)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("Music Volume", x, y, 128, 16, colorFg)
drawRectangle(iCol2, y, iCol2 + 128, y + 16, 0.0, 0.5, 0.5, 0.5)
drawRectangle(iCol2, y, iCol2 + $theOptions.musicVolume, y + 16, 0.0, 1, 1, 1)
y += iSpacing
if ($selected_option == 1)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("Sound Effects Vol", x, y, 128, 16, colorFg)
drawRectangle(iCol2, y, iCol2 + 128, y + 16, 0.0, 0.5, 0.5, 0.5)
drawRectangle(iCol2, y, iCol2 + $theOptions.soundEffectsVolume, y + 16, 0.0, 1, 1, 1)
### USE LIGHTING ###
y += iSpacing
if ($selected_option == 2)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("Use Lighting", iCol1, y, 128, 16, colorFg)
if (! $theOptions.useLighting)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("OFF", iCol2, y, 128, 16, colorFg)
if ($theOptions.useLighting)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("ON", iCol2 + 128, y, 128, 16, colorFg)
### GHOST PIECE ###
y += iSpacing
if ($selected_option == 3)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("Ghost Piece", iCol1, y, 128, 16, colorFg)
if (! $theOptions.ghostPieceOn)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("OFF", iCol2, y, 128, 16, colorFg)
if ($theOptions.ghostPieceOn)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("ON", iCol2 + 128, y, 128, 16, colorFg)
### PIECE GENERATION ###
y += iSpacing
if ($selected_option == 4)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("Piece Generation", iCol1, y, 128, 16, colorFg)
if ($theOptions.pieceGeneration == Options::GEN_BAG)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("BAG", iCol2, y, 128, 16, colorFg)
if ($theOptions.pieceGeneration == Options::GEN_RANDOM)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("RANDOM", iCol2 + 128, y, 128, 16, colorFg)
### COLOR SCHEME ###
y += iSpacing
if ($selected_option == 5)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("Color Scheme", iCol1, y, 128, 16, colorFg)
iColorSchemeChoice = 0
if ($theOptions.colorScheme == iColorSchemeChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
iColorSchemeChoice = 1
if ($theOptions.colorScheme == iColorSchemeChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
iColorSchemeChoice = 2
if ($theOptions.colorScheme == iColorSchemeChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
iColorSchemeChoice = 3
if ($theOptions.colorScheme == iColorSchemeChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
iColorSchemeChoice = 4
if ($theOptions.colorScheme == iColorSchemeChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
iColorSchemeChoice = 5
if ($theOptions.colorScheme == iColorSchemeChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
iColorSchemeChoice = 6
if ($theOptions.colorScheme == iColorSchemeChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
### PIECE PREVIEW ###
y += iSpacing
if ($selected_option == 6)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("iPiecePreview", iCol1, y, 128, 16, colorFg)
iPiecePreviewChoice = 0
if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("OFF", iCol2 + (iPiecePreviewChoice * 32), y, 32, 16, colorFg)
iPiecePreviewChoice = 1
if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iPiecePreviewChoice}", iCol2 + (iPiecePreviewChoice * 32) + 64, y, 32, 16, colorFg)
iPiecePreviewChoice = 2
if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iPiecePreviewChoice}", iCol2 + (iPiecePreviewChoice * 32) + 64, y, 32, 16, colorFg)
iPiecePreviewChoice = 3
if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iPiecePreviewChoice}", iCol2 + (iPiecePreviewChoice * 32) + 64, y, 32, 16, colorFg)
iPiecePreviewChoice = 4
if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iPiecePreviewChoice}", iCol2 + (iPiecePreviewChoice * 32) + 64, y, 32, 16, colorFg)
iPiecePreviewChoice = 5
if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("#{iPiecePreviewChoice}", iCol2 + (iPiecePreviewChoice * 32) + 64, y, 32, 16, colorFg)
### BACK TO MENU ###
y += iSpacing
y += iSpacing
if ($selected_option == 7)
colorFg = colorHighlight
else
colorFg = colorNormal
end
drawMenuText("Back to Menu", iCol1, y, 128, 16, colorFg)
glPopMatrix
SDL::GL.swap_buffers
end
def drawRectangle(x1, y1, x2, y2, z, r, g, b)
glColor(r, g, b)
glBegin(GL_QUADS)
glVertex(x1, y1, z)
glVertex(x1, y2, z)
glVertex(x2, y2, z)
glVertex(x2, y1, z)
glEnd
end
|