-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgravity.metajs
638 lines (577 loc) · 19.2 KB
/
gravity.metajs
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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
"use strict";
try { // debug
var log = function() { // debug
var args = []; // debug
for (var i=0; i<arguments.length; i++) args.push(arguments[i]); // debug
/Android/.test(navigator.userAgent) ? // debug
0: //alert(args.join(' - ')) : // debug
console.log.apply(console,args); // debug
}; // debug
var abs = Math.abs,
sin = Math.sin,
cos = Math.cos,
pi = Math.PI,
completeRad = 2 * pi, // complete revolution
turn3 = completeRad/3,
biteLimit = function(val) {
return val>255 ? 255 : ( val<0 ? 0 : val );
},
rand = function(num) { return (Math.random()-0.5) * (num||1) },
music, playAudio;
// include audio
var randColor = function(mr,vr,mg,vg,mb,vb) {
var r1 = Math.round( mr + rand(vr) ),
g1 = Math.round( mg + rand(vg) ),
b1 = Math.round( mb + rand(vb) ),
r2 = Math.round( r1*2.8 ),
g2 = Math.round( g1*2.8 ),
b2 = Math.round( b1*2.8 ),
r3 = Math.round( r1*3.6 ),
g3 = Math.round( g1*3.6 ),
b3 = Math.round( b1*3.6 );
biteLimit(r2);
biteLimit(g2);
biteLimit(b2);
biteLimit(r3);
biteLimit(g3);
biteLimit(b3);
return [ [r1,g1,b1].join(','), [r2,g2,b2].join(','), [r3,g3,b3].join(',') ];
};
var distP2P = function(p1, p2) {
var dx = p1.x - p2.x,
dy = p1.y - p2.y,
d = Math.sqrt( dx*dx + dy*dy ),
x = dx / d,
y = dy / d;
return { x:x, y:y, d:d }
};
var ctx = c.getContext('2d'),
ctxBg = bg.getContext('2d'),
starX=0, starY=0,
ctxMap = map.getContext('2d'),
d = document,
de = d.documentElement,
b = d.body,
touchable = false,
qualityLevel = 1,
showStars = true,
allowSound = true,
pause = true,
pressDialogBt = sin, // initialize with a harmless function
encEntryUrl = encodeURIComponent('http://js13kgames.com/entries/gravity'),
twittHref = 'https://twitter.com/intent/tweet?original_referer='+ encEntryUrl +
'&url='+ encEntryUrl +'&text=',
secs = function(num) { return num*1000 },
//macro orbDist1: 500
//macro orbDist2: 900
//macro orbDist3: 1400
//macro orbDist4: 1900
//macro orbVel1: .0020
//macro orbVel2: .0010
//macro orbVel3: .0005
//macro orbVel4: .0002
planets = {
sun:{ m:200, c:['255,180,0','255,255,10','255,255,80'], r:150+rand(10) },
// Orbit 1
p1a: { m:40, c:randColor(100,60,80,80,0,120),
r:35+rand(10), d:orbDist1+rand(20), v:orbVel1, a:rand() },
p1b: { m:40, c:randColor(100,60,80,80,0,120),
r:35+rand(10), d:orbDist1+rand(20), v:orbVel1, a:2+rand() },
p1c: { m:40, c:randColor(100,60,80,80,0,120),
r:35+rand(10), d:orbDist1+rand(20), v:orbVel1, a:4+rand() },
// Orbit 2
p2a: { m:30, c:['0,100,180','0,180,220','50,220,255'],
r:40, d:orbDist2+rand(50), v:orbVel2, a:0.0+rand()*.8 },
m2a1: { m:20, c:['100,100,100','200,200,200','250,250,250'],
r:25, d:130+rand(10), v:orbVel1*3, a:rand(7), p:'p2a' },
p2b: { m:30, c:randColor(100,60,80,80,0,120),
r:35+rand(10), d:orbDist2+rand(50), v:orbVel2, a:1.5+rand()*.8 },
p2c: { m:30, c:randColor(100,60,80,80,0,120),
r:45+rand(10), d:orbDist2+rand(50), v:orbVel2, a:3.0+rand()*.8 },
p2d: { m:30, c:randColor(100,60,80,80,0,120),
r:35+rand(10), d:orbDist2+rand(50), v:orbVel2, a:4.5+rand()*.8 },
// Orbit 3
p3a: { m:50, c:randColor(100,60,80,80,0,120),
r:70+rand(15), d:orbDist3+rand(20), v:orbVel3, a:2+rand() },
p3b: { m:50, c:randColor(100,60,80,80,0,120),
r:80+rand(15), d:orbDist3+rand(20), v:orbVel3, a:4+rand() },
m3b1: { m:20, c:randColor(100,60,80,80,0,120),
r:20+rand(2), d:160+rand(10), v:orbVel3*6, a:rand(7), p:'p3b' },
m3b2: { m:20, c:randColor(100,60,80,80,0,120),
r:18+rand(3), d:230+rand(10), v:orbVel3*3, a:rand(), p:'p3b' },
m3b3: { m:20, c:randColor(100,60,80,80,0,120),
r:18+rand(3), d:230+rand(10), v:orbVel3*3, a:3+rand(), p:'p3b' },
p3c: { m:50, c:randColor(100,60,80,80,0,120),
r:70+rand(15), d:orbDist3+rand(20), v:orbVel3, a:0+rand() },
// Orbit 4
p4a: { m:50, c:randColor(100,60,80,80,0,120),
r:50+rand(20), d:orbDist4+rand(50), v:orbVel4, a:0.0+rand()*.8 },
p4b: { m:50, c:randColor(100,60,80,80,0,120),
r:50+rand(20), d:orbDist4+rand(50), v:orbVel4, a:1.5+rand()*.8 },
p4c: { m:50, c:randColor(100,60,80,80,0,120),
r:50+rand(20), d:orbDist4+rand(50), v:orbVel4, a:3.0+rand()*.8 },
p4d: { m:50, c:randColor(100,60,80,80,0,120),
r:50+rand(20), d:orbDist4+rand(50), v:orbVel4, a:4.5+rand()*.8 }
},
biggerPlanetD = orbDist4,
boids = [], // see "Initialize Boids"
missiles = [],
cannons = [],
sun = planets.sun,
// zoom: the wanted zoom.
// z: the current zoom.
// scrC*: the center of the screen, calculated on start and each resize.
// viewC*: the related wanted position to put on the center of the screen.
// vC*: the current related position to put on the center of the screen.
vCX = null,
vCY = null,
viewCX = 0,
viewCY = 0,
scrCX = 0,
scrCY = 0,
w = 0,
h = 0,
z = 0.1,
zoom = 1,
ship = null, // see "Initialize Ship"
shipAlive = false,
usrInput = {},
explosions = [],
focus = ship,
gConst = 0.01, //6.674e-11
pixelRatio = window.devicePixelRatio,
now = Date.now,
start = now();
viewport.setAttribute('content',
'width=device-width, user-scalable=no, initial-scale=' + ((1/pixelRatio)+1)/2
);
if ( pixelRatio >= 2 ) b.className += ' pix20';
else if ( pixelRatio > 1 ) b.className += ' pix15';
try {
if (document.createEvent("TouchEvent")) {
b.className += ' touchable';
touchable = true;
}
} catch(e) { }
var shipDamage = function(points, dieMsg, aliveFunc) {
ship.life -= points;
if (ship.life <= 0) {
ship.life = 0;
newExplosion(ship, true, 20);
shipDie(dieMsg);
return false;
}
if (aliveFunc) aliveFunc();
};
var shipDie = function(txt, showNow) {
if (!shipAlive && !showNow) return;
playAudio('nearExplosion');
shipAlive = false;
if (!showNow) return setTimeout( function(){ shipDie(txt,true) }, 500 );
//TODO: playAudio('death');
focus = sun;
zoom = (h/biggerPlanetD)/2;
if (!txt) txt = 'You die.'
var timeStr = time2str( now() - start );
deadMsg.innerHTML += txt + '<p/> Notify your allies:' +
' <a href="'+ twittHref + encodeURIComponent(
'Check out Gravity, at @js13kGames compo! '+
'I died in '+timeStr+' trying to purge the reddish threat.'
)+'" target="_blank">Twitt</a>, ' + winFB.outerHTML +
' <a class="bt" onclick="document.location.reload()">Restart</a>';
pressDialogBt = function(){ document.location.reload() };
deadMsg.style.display = 'block';
};
ctrl.onclick = function() {
pause = true;
pressDialogBt = function(){ ctrlClose.click(); };
ctrlBox.style.display = 'block';
};
ctrlClose.onclick = function() {
pause = false;
ctrlBox.style.display = 'none';
};
//var bgZFactor = 1.8; // star field based on browser width
var bgZ = 900; // star field fixed width
var bgW = Math.round(bgZ*2.9); // star field fixed width
var bgH = bgZ*2; // star field fixed width
//include stars
(window.onresize = function() {
if (vCX==null) { // set initial view center near to the home planet.
vCX = planets.p2a.d/2;
vCY = planets.p2a.d/2;
}
// Read the screen size, set canvas size equal to screen, and set its center.
scrCX = (c.width = w = de.clientWidth) / 2;
scrCY = (c.height = h = de.clientHeight) / 2;
// Set the same map properties
map.cx = (map.width = mapBox.clientWidth - 10) / 2;
map.cy = (map.height = mapBox.clientHeight - 10) / 2;
})();
var boidsOnPlanet = function(p) {
if (!p) return [];
var list = [];
boids.forEach(function(b){ if(b.planet==p) list.push(b) });
return list;
};
var ownerOfPlanet = function(p) {
var boids = boidsOnPlanet(p);
if (boids.length==0) return -1;
var owner = boids[0].o;
boids.forEach(function(b){ owner = (owner+b.o)/2 });
return owner;
};
var planetGroups = function() {
var p, groups = { greens:[], reddish:[], conflict:[], total:0 };
for ( var id in planets ) {
p = planets[id];
if (p!=sun) {
groups.total++;
if (ownerOfPlanet(p)==0) groups.greens.push(p);
else if (ownerOfPlanet(p)==1) groups.reddish.push(p);
else groups.conflict.push(p);
}
}
return groups;
}
Array.prototype.remove = function(item) {
var newList = [];
this.forEach(function(i){
if(i!=item) newList.push(i);
});
return newList;
};
/*Array.prototype.rand = function() {
var index = Math.round( Math.random() * this.length );
if (index == this.length) index = 0;
return this[index];
};*/
var landingPos = function(obj, p) {
return {
x: p.x + cos(obj.rotate)*(p.r+obj.r),
y: p.y + sin(obj.rotate)*(p.r+obj.r)
}
};
var updatePosition = function(obj, inPlanet, planetProximation) {
var p = obj.planet;
if (p) { // in a planet
obj.vx = obj.vy = 0;
obj.rotateV = (obj.rotateV||0) * 0.99;
obj.rotate = (obj.rotate||0) + obj.rotateV;
obj.x = p.x + cos(obj.rotate||0)*(p.r+obj.r);
obj.y = p.y + sin(obj.rotate||0)*(p.r+obj.r);
if (inPlanet) inPlanet(p);
}
else { // Object is fling
for ( var id in planets ) {
var p = planets[id];
var dist = distP2P( p, obj );
// Normal gravity lower to distance. Here never is so far.
var f = dist.d<999 ? (gConst*p.m)/dist.d : (gConst*p.m)/999;
obj.vx = (obj.vx||0) + f * dist.x;
obj.vy = (obj.vy||0) + f * dist.y;
var proximity = dist.d - p.r - obj.r;
if (planetProximation) for ( var limitDist in planetProximation ) {
// Near to the planet
if (proximity <= parseInt(limitDist))
planetProximation[limitDist](p, proximity);
}
}
}
obj.rotate %= completeRad;
if (obj.rotate<0) obj.rotate += completeRad;
obj.x += obj.vx;
obj.y += obj.vy;
};
var getAngleToPlanet = function(obj, planet) {
var dist = distP2P(obj, planet);
var acos = Math.acos(dist.x);
var asin = Math.asin(dist.y);
var angleToPlanet = (asin > 0 ? acos : completeRad - acos);
return angleToPlanet % completeRad;
};
var addCrew = function(b) {
ship.crew.push(b);
boids = boids.remove(b);
b.shipIO = now();
if (b.planet) onUpdateBoidsOnPlanet('addToShip', b.planet);
b.planet = null;
};
var shipLastExitCrew=0, shipLastJet=0;
var releaseCrew = function() {
var b = ship.crew[0];
// Has boid AND 1sec no user up AND 1sec last boid leave the ship
if ( b && (now()-shipLastJet)>secs(1) &&
shipLastJet>b.shipIO &&
(now()-shipLastExitCrew)>secs(.5)
) {
shipLastExitCrew = now();
b.shipIO = now();
b.planet = ship.planet;
b.rotate = ship.rotate + rand(.5);
boids.push(b);
ship.crew = ship.crew.remove(b);
onUpdateBoidsOnPlanet('playerLanding', b.planet);
}
};
var newCannon = function(planet, rotate) {
var c = {
o:1, planet:planet, rotate:rotate||rand(completeRad), r:10, build:0, lastShot:0
};
cannons.push(c);
return c;
};
var getCannonFromPlanet = function(planet) {
for ( var c,i=0; c=cannons[i]; i++ )
if (c.planet==planet) return c;
return false;
};
var buildCannonIfCan = function(planet) {
var minBoids = 7, groups = planetGroups();
if ( groups.greens.length > groups.total*.5 ) minBoids = 5;
if ( groups.greens.length > groups.total*.8 ) minBoids = 3;
if ( ownerOfPlanet(planet)==1 // This is a reddish planet
&& boidsOnPlanet(planet).length > minBoids // Has enough boids
&& !getCannonFromPlanet(planet) // Dont has a cannon
) {
newCannon(planet);
}
}
var destroyCannon = function(cannon) {
if (!cannon) return false;
newExplosion(cannon, true, 20);
if ( ownerOfPlanet(cannon.planet) == 1 ) cannon.build = -5;
else cannons = cannons.remove(cannon);
return true;
};
var newMissile = function(o, x,y, vx,vy) {
var m = {o:o, x:x, y:y, r:4, vx:vx, vy:vy };
missiles.push(m);
return m;
};
var newBoid = function(o, r, x,y, vx,vy, rotate, planet, pushToList) {
var c1 = 40, c2 = -40;
if (rand()<0) c1*=-1, c2*=-1;
var b = {
o: o, r: (r||1+rand()),
x: (x||0), y: (y||0),
vx: (vx||0), vy: (vy||0),
planet: planet,
rotate: (rotate||rand(completeRad)),
rotateV: rand(.01),
shipIO: now()-secs(5),
color: (o == 0) ?
randColor(c1/2,40, 90,50, c2,50) :
randColor(110,50, 40,50, 0,10)
};
if (pushToList!==false) boids.push(b);
if (planet) onUpdateBoidsOnPlanet('born', planet);
return b;
};
var boidDie = function(b) {
boids = boids.remove(b);
if (b.planet) onUpdateBoidsOnPlanet('die', b.planet);
};
var newExplosion = function(sourceObj, withSound, r, inc) {
if ( sourceObj instanceof Array ) {
var mover = sourceObj[1].planet ? sourceObj[1].planet : sourceObj[1];
sourceObj = sourceObj[0];
} else {
var mover = sourceObj.planet ? sourceObj.planet : sourceObj;
}
explosions.push({
x: sourceObj.x, y: sourceObj.y,
vx: mover.vx, vy: mover.vy,
r: r||10, inc: inc||1
});
if (withSound) {
if ( distP2P(ship, sourceObj).d < (w/z)/3 ) playAudio('nearExplosion');
else playAudio('distantExplosion');
}
};
var lastMsgToUsr = now();
var msgToUsr = function() {
lastMsgToUsr = now();
var index = Math.round( Math.random() * arguments.length );
if (index == arguments.length) index = 0;
msgBox.innerHTML = arguments[index];
msgBox.className = 'visible';
setTimeout( function(){ msgBox.className='' }, secs(1) );
};
var onUpdateBoidsOnPlanet = function(eventType, planet) {
var owner = ownerOfPlanet(planet);
if ( owner==0 ) destroyCannon( getCannonFromPlanet(planet) );
else buildCannonIfCan(planet);
switch (eventType) {
case 'born': /* noting more to say */ break;
case 'die': /* noting more to say */ break;
case 'conflict':
msgToUsr(
'A green died with honor.',
'A green died, but he took a reddish with him.'
);
break;
case 'addToShip':
if ( lastMsgToUsr < now()-secs(6) )
msgToUsr( '',
'A green enlistment to the crew.', '',
'A new green enter in the ship.', '',
'Today is a good day to die.', ''
);
break;
case 'playerLanding':
if ( lastMsgToUsr < now()-secs(6) )
msgToUsr( '',
"It's always a great day when a green lands a planet.", '',
'A new green land the planet.', '',
'We will rule this planet!', ''
);
break;
case 'enemyLanding':
if ( owner == 1 ) {
if ( lastMsgToUsr < now()-secs(6) )
msgToUsr( '',
'Our radar detects a reddish has landed a planet.', '',
'Reddish reinforcements was landed on a <b>non green</b> planet.', ''
);
} else {
if ( lastMsgToUsr < now()-secs(2) )
msgToUsr(
'Our radar detects a reddish has landed a green planet!',
'Reddish reinforcements was landed on a conflicting planet.',
'WARNING! WARNING! Reddish landing on one of our planets!'
);
}
break;
}
var pg = planetGroups();
if ( pg.greens.length == pg.total ) {
music.pause();
setTimeout(youWin, secs(.5));
}
if ( pg.greens.length == 0 && pg.conflict.length == 0 )
shipDie('You lose all your planets');
};
var time2str = function(milliseconds) {
var time = new Date(milliseconds),
h = time.getUTCHours(),
m = time.getUTCMinutes(),
timeStr = '';
if ( h == 1 ) timeStr += 'one hour';
else if ( h > 0 ) timeStr += h+' hours';
if ( h>0 && m>0 ) timeStr += ' and ';
if ( m == 1 ) timeStr += 'one minute';
else if ( m > 0 ) timeStr += m+' minutes';
if ( timeStr == '' ) timeStr = time.getUTCSeconds()+' seconds';
return timeStr;
};
var youWin = function() {
playAudio('win');
pause = true; //TODO: set "win", not "pause".
var timeStr = time2str( now() - start );
finishTime.innerHTML = timeStr;
playerWin.style.display = 'block';
winTwitt.href = twittHref + encodeURIComponent(
'Check out Gravity, at @js13kGames compo! '+
'I purged the reddish threat from my star system in '+timeStr+'.'
);
winFB.onclick =
winTwitt.onclick =
winBMGoogle.onclick = function() {
breakingNewsBt.style.display = 'inline-block';
};
};
var ticCounter = 0, framesPerSec = 30, lastFrame = now(), frameRate, lastFrameRate;
setInterval(function() {
frameRate = Math.round( 1000/(now()-lastFrame) );
if (frameRate<20 && lastFrameRate<20 && ticCounter>framesPerSec*10 &&
(qualityLevel<3 || showStars) && shipAlive && !pause) msgToUsr(
'Your framerate is too low!<br>' +
'You may try tho disble some graphic features at the config dialog.'
);
lastFrameRate = frameRate;
lastFrame = now();
//include objects-update
//include draw
}, 1000/framesPerSec);
d.onclick = function (ev) {
if (d.fullScreenEnabled) b.requestFullscreen();
if (d.mozFullScreenEnabled) b.mozRequestFullScreen();
if (d.webkitFullscreenEnabled) de.webkitRequestFullScreen();
};
var pressBt = function(bt, on) {
shipLastJet = now();
usrInput[bt] = on;
window[bt].className = on ? 'pressed' : ''
};
var fireWeapon = function () {
if ( ship.weapon ) {
btW.className = 'empty';
ship.weapon = false;
newMissile(0, ship.x, ship.y,
(ship.planet ? ship.planet.vx : ship.vx) + cos(ship.rotate) * 4,
(ship.planet ? ship.planet.vy : ship.vy) + sin(ship.rotate) * 4
);
playAudio('gun');
setTimeout(function(){
btW.className = '';
ship.weapon = true;
}, secs(4));
}
};
var introStep = 0;
window.introNext = function () {
if(introStep>3) return;
window['introTxt'+introStep++].style.display = 'none';
if (introStep<=3) window['introTxt'+introStep].style.display = 'block';
if (introStep==3) introNextBt.innerHTML = 'Close';
if (introStep==4) {
intro.style.display = 'none';
pause = false;
}
};
d.onkeydown = function (ev) {
switch (ev.keyCode) {
case 38: pressBt('btU', true); break;
case 37: pressBt('btL', true); break;
case 39: pressBt('btR', true); break;
case 32: fireWeapon(); break;
case 80: pause = !pause;
if (pause) msgToUsr('Paused');
else msgToUsr('Playing');
break;
}
};
d.onkeyup = function (ev) {
switch (ev.keyCode) {
case 38: pressBt('btU', false); break;
case 37: pressBt('btL', false); break;
case 39: pressBt('btR', false); break;
case 13: pressDialogBt(); break;
}
};
var touch = function(bt) {
window[bt].addEventListener("touchstart", function(){ pressBt(bt, true) });
window[bt].addEventListener("touchend", function(){ pressBt(bt, false) });
};
touch('btL');
touch('btR');
touch('btU');
btW.addEventListener("touchstart", function(){ fireWeapon() });
ctrlQ1.onclick = function(){ qualityLevel = 1 };
ctrlQ2.onclick = function(){ qualityLevel = 2 };
ctrlQ3.onclick = function(){ qualityLevel = 3 };
toggleStars.onclick = function(){
showStars = !showStars;
bg.style.display = showStars ? 'block' : 'none';
};
ctrlM.onclick = function(){ this.checked ? music.play() : music.pause() };
ctrlS.onclick = function(){ allowSound = this.checked };
ctrlQ1.click();
toggleStars.checked = true;
ctrlM.checked = true;
ctrlS.checked = true;
} catch (e) { // debug
alert(e) // debug
throw e; // debug
} // debug