feat: planet picker before solo play and in the lobby
Spelen opens a grid of all 12 worlds with numeric g/d/F/Power and color placeholders. Each lobby player picks their own field; the HUD and sprites follow that planet. Selection is kept in localStorage.
@@ -53,6 +53,10 @@ build_game:
53
53
- test -f build/.htaccess
54
54
- test -f build/lib/bootstrap.php
55
55
- test -f build/lib/Store.php
56
- test -f build/lib/Planets.php
57
- test -f build/lib/planets.json
58
- test -f build/images/block-terra-ember.png
59
- test -f build/images/block-cinder-magma.png
56
60
- test -f build/data/.htaccess
57
61
- test ! -f build/data/config.php
58
62
- test ! -e build/data/*.sqlite
@@ -84,6 +88,8 @@ build_game:
84
88
- build/.htaccess
85
89
- build/lib/bootstrap.php
86
90
- build/lib/Store.php
91
- build/lib/Planets.php
92
- build/lib/planets.json
87
93
- build/data/.htaccess
88
94
expire_in: 7d
89
95
@@ -53,6 +53,10 @@ build_game:53
- test -f build/.htaccess53
- test -f build/.htaccess54
- test -f build/lib/bootstrap.php54
- test -f build/lib/bootstrap.php55
- test -f build/lib/Store.php55
- test -f build/lib/Store.php56
- test -f build/lib/Planets.php57
- test -f build/lib/planets.json58
- test -f build/images/block-terra-ember.png59
- test -f build/images/block-cinder-magma.png56
- test -f build/data/.htaccess60
- test -f build/data/.htaccess57
- test ! -f build/data/config.php61
- test ! -f build/data/config.php58
- test ! -e build/data/*.sqlite62
- test ! -e build/data/*.sqlite@@ -84,6 +88,8 @@ build_game:84
- build/.htaccess88
- build/.htaccess85
- build/lib/bootstrap.php89
- build/lib/bootstrap.php86
- build/lib/Store.php90
- build/lib/Store.php91
- build/lib/Planets.php92
- build/lib/planets.json87
- build/data/.htaccess93
- build/data/.htaccess88
expire_in: 7d94
expire_in: 7d89
95
@@ -2,6 +2,191 @@
2
2
* AUTO-GENERATED FILE — DO NOT EDIT BY HAND.
3
3
* Built by src/build.sh from the sources in src/.
4
4
*/
5
var PLANET_CATALOG = {
6
"planets": [
7
{
8
"id": "terra",
9
"name": "Terra",
10
"people": "Terrans",
11
"jumpsToClear": 2,
12
"fallTime": 3,
13
"riseTime": 1.5,
14
"colors": [
15
{"id": 0, "name": "ember", "hex": "#e85d3a", "shape": "triangle", "image": "images/block-terra-ember.png"},
16
{"id": 1, "name": "aqua", "hex": "#3db8e8", "shape": "circle", "image": "images/block-terra-aqua.png"},
17
{"id": 2, "name": "leaf", "hex": "#4cbf4c", "shape": "square", "image": "images/block-terra-leaf.png"},
18
{"id": 3, "name": "sun", "hex": "#f0c53a", "shape": "diamond", "image": "images/block-terra-sun.png"},
19
{"id": 4, "name": "orchid", "hex": "#c45ad4", "shape": "star", "image": "images/block-terra-orchid.png"}
20
]
21
},
22
{
23
"id": "aurel",
24
"name": "Aurel",
25
"people": "Aurelians",
26
"jumpsToClear": 1,
27
"fallTime": 5,
28
"riseTime": 3,
29
"colors": [
30
{"id": 0, "name": "gold", "hex": "#f4c860", "shape": "hexagon", "image": "images/block-aurel-gold.png"},
31
{"id": 1, "name": "cream", "hex": "#f6e7c1", "shape": "circle", "image": "images/block-aurel-cream.png"},
32
{"id": 2, "name": "amber", "hex": "#e09a3e", "shape": "teardrop", "image": "images/block-aurel-amber.png"},
33
{"id": 3, "name": "sage", "hex": "#8fb86f", "shape": "plus", "image": "images/block-aurel-sage.png"},
34
{"id": 4, "name": "rose", "hex": "#e8a0a8", "shape": "pentagon", "image": "images/block-aurel-rose.png"}
35
]
36
},
37
{
38
"id": "cinder",
39
"name": "Cinder",
40
"people": "Cindari",
41
"jumpsToClear": 4,
42
"fallTime": 1,
43
"riseTime": 0.5,
44
"colors": [
45
{"id": 0, "name": "magma", "hex": "#ff3b1f", "shape": "triangle", "image": "images/block-cinder-magma.png"},
46
{"id": 1, "name": "coal", "hex": "#3a3232", "shape": "square", "image": "images/block-cinder-coal.png"},
47
{"id": 2, "name": "spark", "hex": "#ffb347", "shape": "diamond", "image": "images/block-cinder-spark.png"},
48
{"id": 3, "name": "ash", "hex": "#8a7a76", "shape": "circle", "image": "images/block-cinder-ash.png"},
49
{"id": 4, "name": "core", "hex": "#ff6a00", "shape": "star", "image": "images/block-cinder-core.png"}
50
]
51
},
52
{
53
"id": "lunara",
54
"name": "Lunara",
55
"people": "Lunarites",
56
"jumpsToClear": 1,
57
"fallTime": 2,
58
"riseTime": 1.2,
59
"colors": [
60
{"id": 0, "name": "silver", "hex": "#c5d0e0", "shape": "circle", "image": "images/block-lunara-silver.png"},
61
{"id": 1, "name": "dust", "hex": "#8b90a0", "shape": "diamond", "image": "images/block-lunara-dust.png"},
62
{"id": 2, "name": "pale", "hex": "#e8d9a8", "shape": "crescent", "image": "images/block-lunara-pale.png"},
63
{"id": 3, "name": "void", "hex": "#2c3348", "shape": "square", "image": "images/block-lunara-void.png"},
64
{"id": 4, "name": "lilac", "hex": "#b9a4d4", "shape": "star", "image": "images/block-lunara-lilac.png"}
65
]
66
},
67
{
68
"id": "mire",
69
"name": "Mire",
70
"people": "Mirians",
71
"jumpsToClear": 2,
72
"fallTime": 5,
73
"riseTime": 2.5,
74
"colors": [
75
{"id": 0, "name": "moss", "hex": "#3d7a45", "shape": "hexagon", "image": "images/block-mire-moss.png"},
76
{"id": 1, "name": "bog", "hex": "#1f4d3a", "shape": "teardrop", "image": "images/block-mire-bog.png"},
77
{"id": 2, "name": "rust", "hex": "#8b5a2b", "shape": "pentagon", "image": "images/block-mire-rust.png"},
78
{"id": 3, "name": "spore", "hex": "#9cbf5a", "shape": "circle", "image": "images/block-mire-spore.png"},
79
{"id": 4, "name": "murk", "hex": "#2e3b2f", "shape": "diamond", "image": "images/block-mire-murk.png"}
80
]
81
},
82
{
83
"id": "galeon",
84
"name": "Galeon",
85
"people": "Galeoni",
86
"jumpsToClear": 3,
87
"fallTime": 1,
88
"riseTime": 1.8,
89
"colors": [
90
{"id": 0, "name": "sky", "hex": "#4aa3ff", "shape": "arrow", "image": "images/block-galeon-sky.png"},
91
{"id": 1, "name": "cloud", "hex": "#e8eef6", "shape": "circle", "image": "images/block-galeon-cloud.png"},
92
{"id": 2, "name": "storm", "hex": "#3d4d6e", "shape": "square", "image": "images/block-galeon-storm.png"},
93
{"id": 3, "name": "sand", "hex": "#d4b483", "shape": "diamond","image": "images/block-galeon-sand.png"},
94
{"id": 4, "name": "kite", "hex": "#7fd0c0", "shape": "star", "image": "images/block-galeon-kite.png"}
95
]
96
},
97
{
98
"id": "obsid",
99
"name": "Obsid",
100
"people": "Obsidians",
101
"jumpsToClear": 4,
102
"fallTime": 3.5,
103
"riseTime": 2.2,
104
"colors": [
105
{"id": 0, "name": "glass", "hex": "#1a1a22", "shape": "gem", "image": "images/block-obsid-glass.png"},
106
{"id": 1, "name": "violet","hex": "#5a3d8a", "shape": "hexagon", "image": "images/block-obsid-violet.png"},
107
{"id": 2, "name": "shard", "hex": "#8a8aa0", "shape": "triangle", "image": "images/block-obsid-shard.png"},
108
{"id": 3, "name": "vein", "hex": "#c45a3a", "shape": "diamond", "image": "images/block-obsid-vein.png"},
109
{"id": 4, "name": "basalt","hex": "#3a3a42", "shape": "square", "image": "images/block-obsid-basalt.png"}
110
]
111
},
112
{
113
"id": "wisp",
114
"name": "Wisp",
115
"people": "Wisplings",
116
"jumpsToClear": 2,
117
"fallTime": 3.5,
118
"riseTime": 0.5,
119
"colors": [
120
{"id": 0, "name": "glow", "hex": "#c8ffe0", "shape": "circle", "image": "images/block-wisp-glow.png"},
121
{"id": 1, "name": "mist", "hex": "#a8d4e8", "shape": "diamond", "image": "images/block-wisp-mist.png"},
122
{"id": 2, "name": "sparkle", "hex": "#fff6a8", "shape": "star", "image": "images/block-wisp-sparkle.png"},
123
{"id": 3, "name": "veil", "hex": "#d0b8f0", "shape": "teardrop", "image": "images/block-wisp-veil.png"},
124
{"id": 4, "name": "gleam", "hex": "#f4f7ff", "shape": "plus", "image": "images/block-wisp-gleam.png"}
125
]
126
},
127
{
128
"id": "thorn",
129
"name": "Thorn",
130
"people": "Thornfolk",
131
"jumpsToClear": 3,
132
"fallTime": 2,
133
"riseTime": 1.0,
134
"colors": [
135
{"id": 0, "name": "briar", "hex": "#5a7a30", "shape": "triangle", "image": "images/block-thorn-briar.png"},
136
{"id": 1, "name": "berry", "hex": "#8b1a4a", "shape": "circle", "image": "images/block-thorn-berry.png"},
137
{"id": 2, "name": "bark", "hex": "#5a3a20", "shape": "square", "image": "images/block-thorn-bark.png"},
138
{"id": 3, "name": "petal", "hex": "#e89ab0", "shape": "diamond", "image": "images/block-thorn-petal.png"},
139
{"id": 4, "name": "gold", "hex": "#c8a030", "shape": "star", "image": "images/block-thorn-gold.png"}
140
]
141
},
142
{
143
"id": "zephyr",
144
"name": "Zephyr",
145
"people": "Zephyrites",
146
"jumpsToClear": 1,
147
"fallTime": 1.2,
148
"riseTime": 2.8,
149
"colors": [
150
{"id": 0, "name": "azure", "hex": "#6ec8ff", "shape": "crescent", "image": "images/block-zephyr-azure.png"},
151
{"id": 1, "name": "breeze","hex": "#b8e8ff", "shape": "circle", "image": "images/block-zephyr-breeze.png"},
152
{"id": 2, "name": "cirrus","hex": "#f0f7ff", "shape": "plus", "image": "images/block-zephyr-cirrus.png"},
153
{"id": 3, "name": "dusk", "hex": "#7a6ab0", "shape": "diamond", "image": "images/block-zephyr-dusk.png"},
154
{"id": 4, "name": "haze", "hex": "#ffe08a", "shape": "star", "image": "images/block-zephyr-haze.png"}
155
]
156
},
157
{
158
"id": "frore",
159
"name": "Frore",
160
"people": "Frorians",
161
"jumpsToClear": 3,
162
"fallTime": 4.5,
163
"riseTime": 0.8,
164
"colors": [
165
{"id": 0, "name": "ice", "hex": "#a8d8f0", "shape": "hexagon", "image": "images/block-frore-ice.png"},
166
{"id": 1, "name": "frost", "hex": "#eef7ff", "shape": "circle", "image": "images/block-frore-frost.png"},
167
{"id": 2, "name": "deep", "hex": "#3a6a8a", "shape": "diamond", "image": "images/block-frore-deep.png"},
168
{"id": 3, "name": "aurora", "hex": "#5ae8c0", "shape": "star", "image": "images/block-frore-aurora.png"},
169
{"id": 4, "name": "rime", "hex": "#d0e4f0", "shape": "triangle", "image": "images/block-frore-rime.png"}
170
]
171
},
172
{
173
"id": "forge",
174
"name": "Forge",
175
"people": "Forgelings",
176
"jumpsToClear": 4,
177
"fallTime": 2,
178
"riseTime": 1.5,
179
"colors": [
180
{"id": 0, "name": "iron", "hex": "#6a6a72", "shape": "square", "image": "images/block-forge-iron.png"},
181
{"id": 1, "name": "slag", "hex": "#3a3028", "shape": "hexagon", "image": "images/block-forge-slag.png"},
182
{"id": 2, "name": "spark", "hex": "#ff7a1a", "shape": "triangle", "image": "images/block-forge-spark.png"},
183
{"id": 3, "name": "brass", "hex": "#c8a048", "shape": "diamond", "image": "images/block-forge-brass.png"},
184
{"id": 4, "name": "soot", "hex": "#2a2a28", "shape": "circle", "image": "images/block-forge-soot.png"}
185
]
186
}
187
]
188
}
189
;
5
190
6
191
/*
7
192
* Start File:
@@ -114,6 +299,7 @@ function createPlanet (opts)
114
299
var riseTime = clamp(opts.riseTime == null ? 1.5 : opts.riseTime, 0.5, 3);
115
300
var colors = opts.colors || defaultColors();
116
301
var planet = {
302
id: opts.id || null,
117
303
name: opts.name || 'Terra',
118
304
people: opts.people || 'Terrans',
119
305
jumpsToClear: jumpsToClear,
@@ -133,15 +319,82 @@ function createPlanet (opts)
133
319
return planet;
134
320
}
135
321
136
function defaultPlanet ()
322
function loadCatalog ()
323
{
324
if (typeof PLANET_CATALOG !== 'undefined' && PLANET_CATALOG && PLANET_CATALOG.planets)
325
{ return PLANET_CATALOG; }
326
if (typeof require !== 'undefined')
327
{
328
try
329
{ return require('../server/lib/planets.json'); }
330
catch (e) {}
331
}
332
return { planets: [] };
333
}
334
335
function planetFromData (data)
137
336
{
138
return createPlanet({
139
name: 'Terra',
140
people: 'Terrans',
141
jumpsToClear: 2,
142
fallTime: 3,
143
riseTime: 1.5
337
var planet = createPlanet({
338
name: data.name,
339
people: data.people,
340
jumpsToClear: data.jumpsToClear,
341
fallTime: data.fallTime,
342
riseTime: data.riseTime,
343
colors: data.colors
144
344
});
345
planet.id = data.id;
346
return planet;
347
}
348
349
function allPlanets ()
350
{
351
var raw = loadCatalog().planets || [];
352
var out = [];
353
for (var i = 0; i < raw.length; i++)
354
{ out.push(planetFromData(raw[i])); }
355
if (out.length === 0)
356
{ out.push(createPlanet({ name: 'Terra', people: 'Terrans', jumpsToClear: 2, fallTime: 3, riseTime: 1.5 })); out[0].id = 'terra'; }
357
return out;
358
}
359
360
function planetById (id)
361
{
362
var all = allPlanets();
363
for (var i = 0; i < all.length; i++)
364
{
365
if (all[i].id === id)
366
{ return all[i]; }
367
}
368
return defaultPlanet();
369
}
370
371
function defaultPlanet ()
372
{
373
var all = allPlanets();
374
for (var i = 0; i < all.length; i++)
375
{
376
if (all[i].id === 'terra')
377
{ return all[i]; }
378
}
379
return all[0];
380
}
381
382
function formatStats (planet)
383
{
384
var d = displayValues(planet);
385
return 'g ' + d.gravity.toFixed(2)
386
+ ' d ' + d.density.toFixed(2)
387
+ ' F ' + Math.round(d.newtons) + ' N'
388
+ ' Power ' + d.power + '%';
389
}
390
391
function spriteKey (planet, colorIndex)
392
{
393
var colors = planet && planet.colors;
394
var c = colors && colors[colorIndex];
395
if (!c)
396
{ return 'gray'; }
397
return (planet.id || 'planet') + '-' + (c.name || String(colorIndex));
145
398
}
146
399
147
400
/**
@@ -221,6 +474,11 @@ var Planet = {
221
474
createPlanet: createPlanet,
222
475
defaultPlanet: defaultPlanet,
223
476
defaultColors: defaultColors,
477
allPlanets: allPlanets,
478
planetById: planetById,
479
planetFromData: planetFromData,
480
formatStats: formatStats,
481
spriteKey: spriteKey,
224
482
jumpHeight: jumpHeight,
225
483
launchVelocity: launchVelocity,
226
484
launchDeceleration: launchDeceleration,
@@ -453,6 +711,9 @@ function optsMissChance (args)
453
711
// GameCore(planet, rng, missChance) — third arg is optional.
454
712
if (args.length >= 3 && typeof args[2] === 'number' && isFinite(args[2]))
455
713
{ return Math.max(0, Math.min(1, args[2])); }
714
var planet = args[0];
715
if (planet && typeof PlanetMod.missChance === 'function')
716
{ return PlanetMod.missChance(planet); }
456
717
return GameCore.DEFAULT_MISS_CHANCE;
457
718
}
458
719
@@ -2400,14 +2661,25 @@ Online.testLogin = function (who)
2400
2661
return this.request('test_login', { user: who });
2401
2662
};
2402
2663
2403
Online.createLobby = function ()
2664
Online.createLobby = function (planetId)
2665
{
2666
return this.request('lobby_create', {
2667
miss_chance: this.DEFAULT_MISS_CHANCE,
2668
planet_id: planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')
2669
});
2670
};
2671
2672
Online.joinLobby = function (code, planetId)
2404
2673
{
2405
return this.request('lobby_create', { miss_chance: this.DEFAULT_MISS_CHANCE });
2674
return this.request('lobby_join', {
2675
code: code,
2676
planet_id: planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')
2677
});
2406
2678
};
2407
2679
2408
Online.joinLobby = function (code)
2680
Online.setPlanet = function (planetId)
2409
2681
{
2410
return this.request('lobby_join', { code: code });
2682
return this.request('lobby_set_planet', { planet_id: planetId });
2411
2683
};
2412
2684
2413
2685
Online.leaveLobby = function ()
@@ -2574,7 +2846,7 @@ Online.renderMinis = function (container)
2574
2846
el.querySelector('.mini-meta').textContent = p.eliminated
2575
2847
? ('Uit' + (p.place ? ' · ' + p.place + 'e' : ''))
2576
2848
: ('Punten ' + (p.score || 0));
2577
this._drawMini(el.querySelector('canvas'), p.snapshot);
2849
this._drawMini(el.querySelector('canvas'), p.snapshot, p.planet);
2578
2850
}
2579
2851
for (var id in existing)
2580
2852
{
@@ -2585,7 +2857,15 @@ Online.renderMinis = function (container)
2585
2857
2586
2858
var MINI_COLORS = ['#d4553a', '#3a9ad4', '#4caf6a', '#e6c04a', '#b86ad4'];
2587
2859
2588
Online._drawMini = function (canvas, snapshot)
2860
function miniColor (planet, color)
2861
{
2862
if (planet && planet.colors && planet.colors[color] && planet.colors[color].hex)
2863
{ return planet.colors[color].hex; }
2864
return MINI_COLORS[color] || '#888';
2865
}
2866
2867
2868
Online._drawMini = function (canvas, snapshot, planet)
2589
2869
{
2590
2870
if (!canvas)
2591
2871
{ return; }
@@ -2625,7 +2905,7 @@ Online._drawMini = function (canvas, snapshot)
2625
2905
else if (b.color < 0)
2626
2906
{ ctx.fillStyle = '#5a5d66'; }
2627
2907
else
2628
{ ctx.fillStyle = MINI_COLORS[b.color] || '#888'; }
2908
{ ctx.fillStyle = miniColor(planet, b.color); }
2629
2909
ctx.fillRect(x + 0.5, y + 0.5, tw - 1, th - 1);
2630
2910
}
2631
2911
};
@@ -2637,12 +2917,16 @@ Online.miniElement = function (playerId)
2637
2917
2638
2918
/* ---------- flight tweens ------------------------------------------ */
2639
2919
2640
function colorSpriteUrl (color)
2920
function colorSpriteUrl (color, planetId)
2641
2921
{
2642
2922
if (color < 0)
2643
2923
{ return 'images/block-gray.png'; }
2644
var names = ['ember', 'aqua', 'leaf', 'sun', 'orchid'];
2645
return 'images/block-' + (names[color] || 'gray') + '.png';
2924
var planet = null;
2925
if (typeof Planet !== 'undefined')
2926
{ planet = Planet.planetById(planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')); }
2927
if (planet && planet.colors && planet.colors[color] && planet.colors[color].image)
2928
{ return planet.colors[color].image; }
2929
return 'images/block-gray.png';
2646
2930
}
2647
2931
2648
2932
/**
@@ -2824,20 +3108,37 @@ if (typeof module !== 'undefined' && module.exports)
2824
3108
* through Online (src/online.js) and the same GameCore.
2825
3109
*/
2826
3110
2827
var IMAGES = [
2828
{ name: 'ember', url: 'images/block-ember.png' },
2829
{ name: 'aqua', url: 'images/block-aqua.png' },
2830
{ name: 'leaf', url: 'images/block-leaf.png' },
2831
{ name: 'sun', url: 'images/block-sun.png' },
2832
{ name: 'orchid', url: 'images/block-orchid.png' },
2833
{ name: 'gray', url: 'images/block-gray.png' },
2834
{ name: 'locked', url: 'images/block-locked.png' },
2835
{ name: 'flame', url: 'images/flame.png', subImgTotal: 4, perRow: 4 },
2836
{ name: 'cell', url: 'images/cell.png' },
2837
{ name: 'pixel', url: 'images/pixel.png' }
2838
];
2839
2840
var COLOR_SPRITES = ['ember', 'aqua', 'leaf', 'sun', 'orchid'];
3111
function planetImages ()
3112
{
3113
var list = [
3114
{ name: 'gray', url: 'images/block-gray.png' },
3115
{ name: 'locked', url: 'images/block-locked.png' },
3116
{ name: 'flame', url: 'images/flame.png', subImgTotal: 4, perRow: 4 },
3117
{ name: 'cell', url: 'images/cell.png' },
3118
{ name: 'pixel', url: 'images/pixel.png' },
3119
// Keep the original Terra placeholders as aliases (Tim may still have them).
3120
{ name: 'ember', url: 'images/block-ember.png' },
3121
{ name: 'aqua', url: 'images/block-aqua.png' },
3122
{ name: 'leaf', url: 'images/block-leaf.png' },
3123
{ name: 'sun', url: 'images/block-sun.png' },
3124
{ name: 'orchid', url: 'images/block-orchid.png' }
3125
];
3126
var planets = (typeof Planet !== 'undefined' ? Planet.allPlanets() : []);
3127
for (var i = 0; i < planets.length; i++)
3128
{
3129
var pl = planets[i];
3130
for (var c = 0; c < pl.colors.length; c++)
3131
{
3132
list.push({
3133
name: Planet.spriteKey(pl, c),
3134
url: pl.colors[c].image
3135
});
3136
}
3137
}
3138
return list;
3139
}
3140
3141
var IMAGES = planetImages();
2841
3142
var GAME_OVER_DELAY = 2;
2842
3143
2843
3144
var game = new Game();
@@ -2863,7 +3164,9 @@ var app = {
2863
3164
online: false,
2864
3165
eliminatedReported: false,
2865
3166
spectating: false,
2866
miniH: 0
3167
miniH: 0,
3168
selectedPlanetId: 'terra',
3169
planetSelectContext: 'solo'
2867
3170
};
2868
3171
2869
3172
window.onload = function ()
@@ -2888,13 +3191,15 @@ window.onload = function ()
2888
3191
});
2889
3192
2890
3193
bindOnlineUi();
3194
bindPlanetSelect();
3195
restoreSelectedPlanet();
2891
3196
};
2892
3197
2893
3198
function onPlay ()
2894
3199
{
2895
3200
if (app.mode === 'playing')
2896
3201
{ return; }
2897
startPlay();
3202
openPlanetSelect('solo');
2898
3203
}
2899
3204
2900
3205
function startPlay (opts)
@@ -2905,14 +3210,15 @@ function startPlay (opts)
2905
3210
hideEl('online-panel');
2906
3211
hideEl('spectator');
2907
3212
hideEl('podium');
3213
hideEl('planet-select');
2908
3214
showEl('hud');
2909
3215
2910
app.planet = (typeof Planet !== 'undefined' ? Planet.defaultPlanet() : PlanetMod.defaultPlanet());
3216
var planetMod = typeof Planet !== 'undefined' ? Planet : PlanetMod;
3217
app.planet = opts.planet || planetMod.planetById(selectedPlanetId());
2911
3218
var miss = opts.missChance;
2912
if (typeof miss === 'number' && isFinite(miss))
2913
{ app.core = new GameCore(app.planet, Math.random, miss); }
2914
else
2915
{ app.core = new GameCore(app.planet, Math.random); }
3219
if (typeof miss !== 'number' || !isFinite(miss))
3220
{ miss = planetMod.missChance(app.planet); }
3221
app.core = new GameCore(app.planet, Math.random, miss);
2916
3222
app.mode = 'playing';
2917
3223
app.online = !!opts.online;
2918
3224
app.gameOverShown = false;
@@ -2981,6 +3287,7 @@ function returnToMenu ()
2981
3287
teardownPlay();
2982
3288
app.mode = 'menu';
2983
3289
app.online = false;
3290
hideEl('planet-select');
2984
3291
showEl('menu');
2985
3292
var last = document.getElementById('last-score');
2986
3293
if (app.lastScore > 0)
@@ -3064,7 +3371,8 @@ function spriteFor (block)
3064
3371
{ return game.images.locked; }
3065
3372
if (block.color < 0)
3066
3373
{ return game.images.gray; }
3067
return game.images[COLOR_SPRITES[block.color]] || game.images.gray;
3374
var key = Planet.spriteKey(app.planet, block.color);
3375
return game.images[key] || game.images.gray;
3068
3376
}
3069
3377
3070
3378
function syncSprites ()
@@ -3223,10 +3531,7 @@ function refreshHud ()
3223
3531
document.getElementById('score').textContent = String(app.core.score);
3224
3532
var planet = app.planet;
3225
3533
document.getElementById('planet-name').textContent = planet.name + ' · ' + planet.people;
3226
var d = Planet.displayValues(planet);
3227
document.getElementById('planet-stats').textContent =
3228
'g ' + d.gravity.toFixed(2) + ' d ' + d.density.toFixed(2) +
3229
' F ' + Math.round(d.newtons) + ' N Power ' + d.power + '%';
3534
document.getElementById('planet-stats').textContent = Planet.formatStats(planet);
3230
3535
}
3231
3536
3232
3537
function makeManager ()
@@ -3504,10 +3809,11 @@ function startOnlineMatch ()
3504
3809
{
3505
3810
if (app.mode === 'playing' && app.online)
3506
3811
{ return; }
3507
var miss = (typeof Online !== 'undefined' && Online.lobby && Online.lobby.miss_chance != null)
3508
? Online.lobby.miss_chance
3509
: (typeof Online !== 'undefined' ? Online.DEFAULT_MISS_CHANCE : 0.30);
3510
startPlay({ online: true, missChance: miss });
3812
var planet = Planet.planetById(selectedPlanetId());
3813
var me = (typeof Online !== 'undefined' && Online.mePlayer) ? Online.mePlayer() : null;
3814
if (me && me.planet && me.planet.id)
3815
{ planet = Planet.planetById(me.planet.id); }
3816
startPlay({ online: true, planet: planet, missChance: Planet.missChance(planet) });
3511
3817
if (typeof Online !== 'undefined')
3512
3818
{ Online.startPolling(onlinePayload); }
3513
3819
}
@@ -3664,6 +3970,7 @@ function openOnlinePanel ()
3664
3970
hideEl('game-over');
3665
3971
hideEl('podium');
3666
3972
hideEl('spectator');
3973
hideEl('planet-select');
3667
3974
showEl('online-panel');
3668
3975
app.mode = 'online';
3669
3976
setOnlineStatus('Even kijken of online spelen beschikbaar is…');
@@ -3765,10 +4072,14 @@ function renderOnline ()
3765
4072
{ li.classList.add('you'); }
3766
4073
var label = p.name + (p.is_host ? ' (host)' : '') + (p.is_me ? ' (jij)' : '');
3767
4074
var state = p.ready ? 'Gereed' : 'Wacht…';
3768
li.innerHTML = '<span>' + escapeText(label) + '</span><span class="'
4075
var world = (p.planet && p.planet.name) ? (p.planet.name + ' · ' + p.planet.people) : '';
4076
li.innerHTML = '<span>' + escapeText(label)
4077
+ (world ? '<span class="planet-tag">' + escapeText(world) + '</span>' : '')
4078
+ '</span><span class="'
3769
4079
+ (p.ready ? 'ready' : 'waiting') + '">' + state + '</span>';
3770
4080
list.appendChild(li);
3771
4081
}
4082
renderPlanetGrid('lobby-planet-grid', true);
3772
4083
var me = Online.mePlayer();
3773
4084
document.getElementById('btn-ready').textContent = (me && me.ready) ? 'Niet gereed' : 'Gereed';
3774
4085
var start = document.getElementById('btn-start');
@@ -3802,6 +4113,150 @@ function escapeText (s)
3802
4113
.replace(/"/g, '"');
3803
4114
}
3804
4115
4116
4117
function selectedPlanetId ()
4118
{
4119
if (app.selectedPlanetId)
4120
{ return app.selectedPlanetId; }
4121
return 'terra';
4122
}
4123
4124
function restoreSelectedPlanet ()
4125
{
4126
var id = 'terra';
4127
try
4128
{ id = localStorage.getItem('meteors-planet') || 'terra'; }
4129
catch (e) {}
4130
setSelectedPlanet(id, true);
4131
}
4132
4133
function setSelectedPlanet (id, silent)
4134
{
4135
var all = Planet.allPlanets();
4136
var found = null;
4137
for (var i = 0; i < all.length; i++)
4138
{
4139
if (all[i].id === id)
4140
{ found = all[i]; break; }
4141
}
4142
if (!found)
4143
{ found = Planet.defaultPlanet(); }
4144
app.selectedPlanetId = found.id;
4145
try
4146
{ localStorage.setItem('meteors-planet', found.id); }
4147
catch (e) {}
4148
if (!silent)
4149
{
4150
var grid = document.getElementById('planet-grid');
4151
if (grid && !grid.hidden && grid.children.length)
4152
{ renderPlanetGrid('planet-grid', false); }
4153
var lobby = document.getElementById('lobby-planet-grid');
4154
if (lobby && lobby.children.length)
4155
{ renderPlanetGrid('lobby-planet-grid', true); }
4156
}
4157
return found;
4158
}
4159
4160
function openPlanetSelect (context)
4161
{
4162
if (app.mode === 'playing')
4163
{ return; }
4164
app.planetSelectContext = context || 'solo';
4165
app.mode = 'planet-select';
4166
hideEl('menu');
4167
hideEl('online-panel');
4168
hideEl('game-over');
4169
showEl('planet-select');
4170
renderPlanetGrid('planet-grid', false);
4171
var go = document.getElementById('btn-planet-go');
4172
if (go)
4173
{ go.textContent = 'Spelen'; }
4174
}
4175
4176
function renderPlanetGrid (containerId, compact)
4177
{
4178
var grid = document.getElementById(containerId);
4179
if (!grid)
4180
{ return; }
4181
var current = selectedPlanetId();
4182
var all = Planet.allPlanets();
4183
grid.innerHTML = '';
4184
if (compact)
4185
{ grid.classList.add('compact'); }
4186
for (var i = 0; i < all.length; i++)
4187
{
4188
var pl = all[i];
4189
var btn = document.createElement('button');
4190
btn.type = 'button';
4191
btn.className = 'planet-card' + (pl.id === current ? ' selected' : '');
4192
btn.setAttribute('role', 'listitem');
4193
btn.dataset.planet = pl.id;
4194
var swatches = '';
4195
for (var c = 0; c < pl.colors.length; c++)
4196
{
4197
swatches += '<img src="' + escapeText(pl.colors[c].image) + '" alt="'
4198
+ escapeText(pl.colors[c].name) + '" title="' + escapeText(pl.colors[c].name) + '">';
4199
}
4200
btn.innerHTML = '<div class="planet-title">' + escapeText(pl.name) + '</div>'
4201
+ '<div class="planet-people">' + escapeText(pl.people) + '</div>'
4202
+ '<div class="planet-nums">' + escapeText(Planet.formatStats(pl)) + '</div>'
4203
+ '<div class="planet-swatches">' + swatches + '</div>';
4204
btn.addEventListener('click', (function (id, isCompact)
4205
{
4206
return function ()
4207
{ onPlanetPicked(id, isCompact); };
4208
})(pl.id, !!compact));
4209
grid.appendChild(btn);
4210
}
4211
}
4212
4213
function onPlanetPicked (id, fromLobby)
4214
{
4215
setSelectedPlanet(id);
4216
if (fromLobby && typeof Online !== 'undefined' && Online.lobby)
4217
{
4218
Online.setPlanet(id).then(function ()
4219
{ renderOnline(); });
4220
}
4221
else
4222
{
4223
renderPlanetGrid('planet-grid', false);
4224
}
4225
}
4226
4227
function confirmPlanetSelect ()
4228
{
4229
var planet = setSelectedPlanet(selectedPlanetId());
4230
hideEl('planet-select');
4231
if (app.planetSelectContext === 'online')
4232
{
4233
openOnlinePanel();
4234
return;
4235
}
4236
startPlay({ planet: planet });
4237
}
4238
4239
function cancelPlanetSelect ()
4240
{
4241
hideEl('planet-select');
4242
app.mode = 'menu';
4243
showEl('menu');
4244
}
4245
4246
function bindPlanetSelect ()
4247
{
4248
var go = document.getElementById('btn-planet-go');
4249
var back = document.getElementById('btn-planet-back');
4250
if (go)
4251
{
4252
go.addEventListener('click', confirmPlanetSelect);
4253
}
4254
if (back)
4255
{
4256
back.addEventListener('click', cancelPlanetSelect);
4257
}
4258
}
4259
3805
4260
/*
3806
4261
* End File:
3807
4262
* /workspace/meteors/src/main.js
@@ -2,6 +2,191 @@2
* AUTO-GENERATED FILE — DO NOT EDIT BY HAND.2
* AUTO-GENERATED FILE — DO NOT EDIT BY HAND.3
* Built by src/build.sh from the sources in src/.3
* Built by src/build.sh from the sources in src/.4
*/4
*/5
var PLANET_CATALOG = {6
"planets": [7
{8
"id": "terra",9
"name": "Terra",10
"people": "Terrans",11
"jumpsToClear": 2,12
"fallTime": 3,13
"riseTime": 1.5,14
"colors": [15
{"id": 0, "name": "ember", "hex": "#e85d3a", "shape": "triangle", "image": "images/block-terra-ember.png"},16
{"id": 1, "name": "aqua", "hex": "#3db8e8", "shape": "circle", "image": "images/block-terra-aqua.png"},17
{"id": 2, "name": "leaf", "hex": "#4cbf4c", "shape": "square", "image": "images/block-terra-leaf.png"},18
{"id": 3, "name": "sun", "hex": "#f0c53a", "shape": "diamond", "image": "images/block-terra-sun.png"},19
{"id": 4, "name": "orchid", "hex": "#c45ad4", "shape": "star", "image": "images/block-terra-orchid.png"}20
]21
},22
{23
"id": "aurel",24
"name": "Aurel",25
"people": "Aurelians",26
"jumpsToClear": 1,27
"fallTime": 5,28
"riseTime": 3,29
"colors": [30
{"id": 0, "name": "gold", "hex": "#f4c860", "shape": "hexagon", "image": "images/block-aurel-gold.png"},31
{"id": 1, "name": "cream", "hex": "#f6e7c1", "shape": "circle", "image": "images/block-aurel-cream.png"},32
{"id": 2, "name": "amber", "hex": "#e09a3e", "shape": "teardrop", "image": "images/block-aurel-amber.png"},33
{"id": 3, "name": "sage", "hex": "#8fb86f", "shape": "plus", "image": "images/block-aurel-sage.png"},34
{"id": 4, "name": "rose", "hex": "#e8a0a8", "shape": "pentagon", "image": "images/block-aurel-rose.png"}35
]36
},37
{38
"id": "cinder",39
"name": "Cinder",40
"people": "Cindari",41
"jumpsToClear": 4,42
"fallTime": 1,43
"riseTime": 0.5,44
"colors": [45
{"id": 0, "name": "magma", "hex": "#ff3b1f", "shape": "triangle", "image": "images/block-cinder-magma.png"},46
{"id": 1, "name": "coal", "hex": "#3a3232", "shape": "square", "image": "images/block-cinder-coal.png"},47
{"id": 2, "name": "spark", "hex": "#ffb347", "shape": "diamond", "image": "images/block-cinder-spark.png"},48
{"id": 3, "name": "ash", "hex": "#8a7a76", "shape": "circle", "image": "images/block-cinder-ash.png"},49
{"id": 4, "name": "core", "hex": "#ff6a00", "shape": "star", "image": "images/block-cinder-core.png"}50
]51
},52
{53
"id": "lunara",54
"name": "Lunara",55
"people": "Lunarites",56
"jumpsToClear": 1,57
"fallTime": 2,58
"riseTime": 1.2,59
"colors": [60
{"id": 0, "name": "silver", "hex": "#c5d0e0", "shape": "circle", "image": "images/block-lunara-silver.png"},61
{"id": 1, "name": "dust", "hex": "#8b90a0", "shape": "diamond", "image": "images/block-lunara-dust.png"},62
{"id": 2, "name": "pale", "hex": "#e8d9a8", "shape": "crescent", "image": "images/block-lunara-pale.png"},63
{"id": 3, "name": "void", "hex": "#2c3348", "shape": "square", "image": "images/block-lunara-void.png"},64
{"id": 4, "name": "lilac", "hex": "#b9a4d4", "shape": "star", "image": "images/block-lunara-lilac.png"}65
]66
},67
{68
"id": "mire",69
"name": "Mire",70
"people": "Mirians",71
"jumpsToClear": 2,72
"fallTime": 5,73
"riseTime": 2.5,74
"colors": [75
{"id": 0, "name": "moss", "hex": "#3d7a45", "shape": "hexagon", "image": "images/block-mire-moss.png"},76
{"id": 1, "name": "bog", "hex": "#1f4d3a", "shape": "teardrop", "image": "images/block-mire-bog.png"},77
{"id": 2, "name": "rust", "hex": "#8b5a2b", "shape": "pentagon", "image": "images/block-mire-rust.png"},78
{"id": 3, "name": "spore", "hex": "#9cbf5a", "shape": "circle", "image": "images/block-mire-spore.png"},79
{"id": 4, "name": "murk", "hex": "#2e3b2f", "shape": "diamond", "image": "images/block-mire-murk.png"}80
]81
},82
{83
"id": "galeon",84
"name": "Galeon",85
"people": "Galeoni",86
"jumpsToClear": 3,87
"fallTime": 1,88
"riseTime": 1.8,89
"colors": [90
{"id": 0, "name": "sky", "hex": "#4aa3ff", "shape": "arrow", "image": "images/block-galeon-sky.png"},91
{"id": 1, "name": "cloud", "hex": "#e8eef6", "shape": "circle", "image": "images/block-galeon-cloud.png"},92
{"id": 2, "name": "storm", "hex": "#3d4d6e", "shape": "square", "image": "images/block-galeon-storm.png"},93
{"id": 3, "name": "sand", "hex": "#d4b483", "shape": "diamond","image": "images/block-galeon-sand.png"},94
{"id": 4, "name": "kite", "hex": "#7fd0c0", "shape": "star", "image": "images/block-galeon-kite.png"}95
]96
},97
{98
"id": "obsid",99
"name": "Obsid",100
"people": "Obsidians",101
"jumpsToClear": 4,102
"fallTime": 3.5,103
"riseTime": 2.2,104
"colors": [105
{"id": 0, "name": "glass", "hex": "#1a1a22", "shape": "gem", "image": "images/block-obsid-glass.png"},106
{"id": 1, "name": "violet","hex": "#5a3d8a", "shape": "hexagon", "image": "images/block-obsid-violet.png"},107
{"id": 2, "name": "shard", "hex": "#8a8aa0", "shape": "triangle", "image": "images/block-obsid-shard.png"},108
{"id": 3, "name": "vein", "hex": "#c45a3a", "shape": "diamond", "image": "images/block-obsid-vein.png"},109
{"id": 4, "name": "basalt","hex": "#3a3a42", "shape": "square", "image": "images/block-obsid-basalt.png"}110
]111
},112
{113
"id": "wisp",114
"name": "Wisp",115
"people": "Wisplings",116
"jumpsToClear": 2,117
"fallTime": 3.5,118
"riseTime": 0.5,119
"colors": [120
{"id": 0, "name": "glow", "hex": "#c8ffe0", "shape": "circle", "image": "images/block-wisp-glow.png"},121
{"id": 1, "name": "mist", "hex": "#a8d4e8", "shape": "diamond", "image": "images/block-wisp-mist.png"},122
{"id": 2, "name": "sparkle", "hex": "#fff6a8", "shape": "star", "image": "images/block-wisp-sparkle.png"},123
{"id": 3, "name": "veil", "hex": "#d0b8f0", "shape": "teardrop", "image": "images/block-wisp-veil.png"},124
{"id": 4, "name": "gleam", "hex": "#f4f7ff", "shape": "plus", "image": "images/block-wisp-gleam.png"}125
]126
},127
{128
"id": "thorn",129
"name": "Thorn",130
"people": "Thornfolk",131
"jumpsToClear": 3,132
"fallTime": 2,133
"riseTime": 1.0,134
"colors": [135
{"id": 0, "name": "briar", "hex": "#5a7a30", "shape": "triangle", "image": "images/block-thorn-briar.png"},136
{"id": 1, "name": "berry", "hex": "#8b1a4a", "shape": "circle", "image": "images/block-thorn-berry.png"},137
{"id": 2, "name": "bark", "hex": "#5a3a20", "shape": "square", "image": "images/block-thorn-bark.png"},138
{"id": 3, "name": "petal", "hex": "#e89ab0", "shape": "diamond", "image": "images/block-thorn-petal.png"},139
{"id": 4, "name": "gold", "hex": "#c8a030", "shape": "star", "image": "images/block-thorn-gold.png"}140
]141
},142
{143
"id": "zephyr",144
"name": "Zephyr",145
"people": "Zephyrites",146
"jumpsToClear": 1,147
"fallTime": 1.2,148
"riseTime": 2.8,149
"colors": [150
{"id": 0, "name": "azure", "hex": "#6ec8ff", "shape": "crescent", "image": "images/block-zephyr-azure.png"},151
{"id": 1, "name": "breeze","hex": "#b8e8ff", "shape": "circle", "image": "images/block-zephyr-breeze.png"},152
{"id": 2, "name": "cirrus","hex": "#f0f7ff", "shape": "plus", "image": "images/block-zephyr-cirrus.png"},153
{"id": 3, "name": "dusk", "hex": "#7a6ab0", "shape": "diamond", "image": "images/block-zephyr-dusk.png"},154
{"id": 4, "name": "haze", "hex": "#ffe08a", "shape": "star", "image": "images/block-zephyr-haze.png"}155
]156
},157
{158
"id": "frore",159
"name": "Frore",160
"people": "Frorians",161
"jumpsToClear": 3,162
"fallTime": 4.5,163
"riseTime": 0.8,164
"colors": [165
{"id": 0, "name": "ice", "hex": "#a8d8f0", "shape": "hexagon", "image": "images/block-frore-ice.png"},166
{"id": 1, "name": "frost", "hex": "#eef7ff", "shape": "circle", "image": "images/block-frore-frost.png"},167
{"id": 2, "name": "deep", "hex": "#3a6a8a", "shape": "diamond", "image": "images/block-frore-deep.png"},168
{"id": 3, "name": "aurora", "hex": "#5ae8c0", "shape": "star", "image": "images/block-frore-aurora.png"},169
{"id": 4, "name": "rime", "hex": "#d0e4f0", "shape": "triangle", "image": "images/block-frore-rime.png"}170
]171
},172
{173
"id": "forge",174
"name": "Forge",175
"people": "Forgelings",176
"jumpsToClear": 4,177
"fallTime": 2,178
"riseTime": 1.5,179
"colors": [180
{"id": 0, "name": "iron", "hex": "#6a6a72", "shape": "square", "image": "images/block-forge-iron.png"},181
{"id": 1, "name": "slag", "hex": "#3a3028", "shape": "hexagon", "image": "images/block-forge-slag.png"},182
{"id": 2, "name": "spark", "hex": "#ff7a1a", "shape": "triangle", "image": "images/block-forge-spark.png"},183
{"id": 3, "name": "brass", "hex": "#c8a048", "shape": "diamond", "image": "images/block-forge-brass.png"},184
{"id": 4, "name": "soot", "hex": "#2a2a28", "shape": "circle", "image": "images/block-forge-soot.png"}185
]186
}187
]188
}189
;5
190
6
/*191
/*7
* Start File:192
* Start File:@@ -114,6 +299,7 @@ function createPlanet (opts)114
var riseTime = clamp(opts.riseTime == null ? 1.5 : opts.riseTime, 0.5, 3);299
var riseTime = clamp(opts.riseTime == null ? 1.5 : opts.riseTime, 0.5, 3);115
var colors = opts.colors || defaultColors();300
var colors = opts.colors || defaultColors();116
var planet = {301
var planet = {302
id: opts.id || null,117
name: opts.name || 'Terra',303
name: opts.name || 'Terra',118
people: opts.people || 'Terrans',304
people: opts.people || 'Terrans',119
jumpsToClear: jumpsToClear,305
jumpsToClear: jumpsToClear,@@ -133,15 +319,82 @@ function createPlanet (opts)133
return planet;319
return planet;134
}320
}135
321
136
function defaultPlanet ()322
function loadCatalog ()323
{324
if (typeof PLANET_CATALOG !== 'undefined' && PLANET_CATALOG && PLANET_CATALOG.planets)325
{ return PLANET_CATALOG; }326
if (typeof require !== 'undefined')327
{328
try329
{ return require('../server/lib/planets.json'); }330
catch (e) {}331
}332
return { planets: [] };333
}334
335
function planetFromData (data)137
{336
{138
return createPlanet({337
var planet = createPlanet({139
name: 'Terra',338
name: data.name,140
people: 'Terrans',339
people: data.people,141
jumpsToClear: 2,340
jumpsToClear: data.jumpsToClear,142
fallTime: 3,341
fallTime: data.fallTime,143
riseTime: 1.5342
riseTime: data.riseTime,343
colors: data.colors144
});344
});345
planet.id = data.id;346
return planet;347
}348
349
function allPlanets ()350
{351
var raw = loadCatalog().planets || [];352
var out = [];353
for (var i = 0; i < raw.length; i++)354
{ out.push(planetFromData(raw[i])); }355
if (out.length === 0)356
{ out.push(createPlanet({ name: 'Terra', people: 'Terrans', jumpsToClear: 2, fallTime: 3, riseTime: 1.5 })); out[0].id = 'terra'; }357
return out;358
}359
360
function planetById (id)361
{362
var all = allPlanets();363
for (var i = 0; i < all.length; i++)364
{365
if (all[i].id === id)366
{ return all[i]; }367
}368
return defaultPlanet();369
}370
371
function defaultPlanet ()372
{373
var all = allPlanets();374
for (var i = 0; i < all.length; i++)375
{376
if (all[i].id === 'terra')377
{ return all[i]; }378
}379
return all[0];380
}381
382
function formatStats (planet)383
{384
var d = displayValues(planet);385
return 'g ' + d.gravity.toFixed(2)386
+ ' d ' + d.density.toFixed(2)387
+ ' F ' + Math.round(d.newtons) + ' N'388
+ ' Power ' + d.power + '%';389
}390
391
function spriteKey (planet, colorIndex)392
{393
var colors = planet && planet.colors;394
var c = colors && colors[colorIndex];395
if (!c)396
{ return 'gray'; }397
return (planet.id || 'planet') + '-' + (c.name || String(colorIndex));145
}398
}146
399
147
/**400
/**@@ -221,6 +474,11 @@ var Planet = {221
createPlanet: createPlanet,474
createPlanet: createPlanet,222
defaultPlanet: defaultPlanet,475
defaultPlanet: defaultPlanet,223
defaultColors: defaultColors,476
defaultColors: defaultColors,477
allPlanets: allPlanets,478
planetById: planetById,479
planetFromData: planetFromData,480
formatStats: formatStats,481
spriteKey: spriteKey,224
jumpHeight: jumpHeight,482
jumpHeight: jumpHeight,225
launchVelocity: launchVelocity,483
launchVelocity: launchVelocity,226
launchDeceleration: launchDeceleration,484
launchDeceleration: launchDeceleration,@@ -453,6 +711,9 @@ function optsMissChance (args)453
// GameCore(planet, rng, missChance) — third arg is optional.711
// GameCore(planet, rng, missChance) — third arg is optional.454
if (args.length >= 3 && typeof args[2] === 'number' && isFinite(args[2]))712
if (args.length >= 3 && typeof args[2] === 'number' && isFinite(args[2]))455
{ return Math.max(0, Math.min(1, args[2])); }713
{ return Math.max(0, Math.min(1, args[2])); }714
var planet = args[0];715
if (planet && typeof PlanetMod.missChance === 'function')716
{ return PlanetMod.missChance(planet); }456
return GameCore.DEFAULT_MISS_CHANCE;717
return GameCore.DEFAULT_MISS_CHANCE;457
}718
}458
719
@@ -2400,14 +2661,25 @@ Online.testLogin = function (who)2400
return this.request('test_login', { user: who });2661
return this.request('test_login', { user: who });2401
};2662
};2402
2663
2403
Online.createLobby = function ()2664
Online.createLobby = function (planetId)2665
{2666
return this.request('lobby_create', {2667
miss_chance: this.DEFAULT_MISS_CHANCE,2668
planet_id: planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')2669
});2670
};2671
2672
Online.joinLobby = function (code, planetId)2404
{2673
{2405
return this.request('lobby_create', { miss_chance: this.DEFAULT_MISS_CHANCE });2674
return this.request('lobby_join', {2675
code: code,2676
planet_id: planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')2677
});2406
};2678
};2407
2679
2408
Online.joinLobby = function (code)2680
Online.setPlanet = function (planetId)2409
{2681
{2410
return this.request('lobby_join', { code: code });2682
return this.request('lobby_set_planet', { planet_id: planetId });2411
};2683
};2412
2684
2413
Online.leaveLobby = function ()2685
Online.leaveLobby = function ()@@ -2574,7 +2846,7 @@ Online.renderMinis = function (container)2574
el.querySelector('.mini-meta').textContent = p.eliminated2846
el.querySelector('.mini-meta').textContent = p.eliminated2575
? ('Uit' + (p.place ? ' · ' + p.place + 'e' : ''))2847
? ('Uit' + (p.place ? ' · ' + p.place + 'e' : ''))2576
: ('Punten ' + (p.score || 0));2848
: ('Punten ' + (p.score || 0));2577
this._drawMini(el.querySelector('canvas'), p.snapshot);2849
this._drawMini(el.querySelector('canvas'), p.snapshot, p.planet);2578
}2850
}2579
for (var id in existing)2851
for (var id in existing)2580
{2852
{@@ -2585,7 +2857,15 @@ Online.renderMinis = function (container)2585
2857
2586
var MINI_COLORS = ['#d4553a', '#3a9ad4', '#4caf6a', '#e6c04a', '#b86ad4'];2858
var MINI_COLORS = ['#d4553a', '#3a9ad4', '#4caf6a', '#e6c04a', '#b86ad4'];2587
2859
2588
Online._drawMini = function (canvas, snapshot)2860
function miniColor (planet, color)2861
{2862
if (planet && planet.colors && planet.colors[color] && planet.colors[color].hex)2863
{ return planet.colors[color].hex; }2864
return MINI_COLORS[color] || '#888';2865
}2866
2867
2868
Online._drawMini = function (canvas, snapshot, planet)2589
{2869
{2590
if (!canvas)2870
if (!canvas)2591
{ return; }2871
{ return; }@@ -2625,7 +2905,7 @@ Online._drawMini = function (canvas, snapshot)2625
else if (b.color < 0)2905
else if (b.color < 0)2626
{ ctx.fillStyle = '#5a5d66'; }2906
{ ctx.fillStyle = '#5a5d66'; }2627
else2907
else2628
{ ctx.fillStyle = MINI_COLORS[b.color] || '#888'; }2908
{ ctx.fillStyle = miniColor(planet, b.color); }2629
ctx.fillRect(x + 0.5, y + 0.5, tw - 1, th - 1);2909
ctx.fillRect(x + 0.5, y + 0.5, tw - 1, th - 1);2630
}2910
}2631
};2911
};@@ -2637,12 +2917,16 @@ Online.miniElement = function (playerId)2637
2917
2638
/* ---------- flight tweens ------------------------------------------ */2918
/* ---------- flight tweens ------------------------------------------ */2639
2919
2640
function colorSpriteUrl (color)2920
function colorSpriteUrl (color, planetId)2641
{2921
{2642
if (color < 0)2922
if (color < 0)2643
{ return 'images/block-gray.png'; }2923
{ return 'images/block-gray.png'; }2644
var names = ['ember', 'aqua', 'leaf', 'sun', 'orchid'];2924
var planet = null;2645
return 'images/block-' + (names[color] || 'gray') + '.png';2925
if (typeof Planet !== 'undefined')2926
{ planet = Planet.planetById(planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')); }2927
if (planet && planet.colors && planet.colors[color] && planet.colors[color].image)2928
{ return planet.colors[color].image; }2929
return 'images/block-gray.png';2646
}2930
}2647
2931
2648
/**2932
/**@@ -2824,20 +3108,37 @@ if (typeof module !== 'undefined' && module.exports)2824
* through Online (src/online.js) and the same GameCore.3108
* through Online (src/online.js) and the same GameCore.2825
*/3109
*/2826
3110
2827
var IMAGES = [3111
function planetImages ()2828
{ name: 'ember', url: 'images/block-ember.png' },3112
{2829
{ name: 'aqua', url: 'images/block-aqua.png' },3113
var list = [2830
{ name: 'leaf', url: 'images/block-leaf.png' },3114
{ name: 'gray', url: 'images/block-gray.png' },2831
{ name: 'sun', url: 'images/block-sun.png' },3115
{ name: 'locked', url: 'images/block-locked.png' },2832
{ name: 'orchid', url: 'images/block-orchid.png' },3116
{ name: 'flame', url: 'images/flame.png', subImgTotal: 4, perRow: 4 },2833
{ name: 'gray', url: 'images/block-gray.png' },3117
{ name: 'cell', url: 'images/cell.png' },2834
{ name: 'locked', url: 'images/block-locked.png' },3118
{ name: 'pixel', url: 'images/pixel.png' },2835
{ name: 'flame', url: 'images/flame.png', subImgTotal: 4, perRow: 4 },3119
// Keep the original Terra placeholders as aliases (Tim may still have them).2836
{ name: 'cell', url: 'images/cell.png' },3120
{ name: 'ember', url: 'images/block-ember.png' },2837
{ name: 'pixel', url: 'images/pixel.png' }3121
{ name: 'aqua', url: 'images/block-aqua.png' },2838
];3122
{ name: 'leaf', url: 'images/block-leaf.png' },2839
3123
{ name: 'sun', url: 'images/block-sun.png' },2840
var COLOR_SPRITES = ['ember', 'aqua', 'leaf', 'sun', 'orchid'];3124
{ name: 'orchid', url: 'images/block-orchid.png' }3125
];3126
var planets = (typeof Planet !== 'undefined' ? Planet.allPlanets() : []);3127
for (var i = 0; i < planets.length; i++)3128
{3129
var pl = planets[i];3130
for (var c = 0; c < pl.colors.length; c++)3131
{3132
list.push({3133
name: Planet.spriteKey(pl, c),3134
url: pl.colors[c].image3135
});3136
}3137
}3138
return list;3139
}3140
3141
var IMAGES = planetImages();2841
var GAME_OVER_DELAY = 2;3142
var GAME_OVER_DELAY = 2;2842
3143
2843
var game = new Game();3144
var game = new Game();@@ -2863,7 +3164,9 @@ var app = {2863
online: false,3164
online: false,2864
eliminatedReported: false,3165
eliminatedReported: false,2865
spectating: false,3166
spectating: false,2866
miniH: 03167
miniH: 0,3168
selectedPlanetId: 'terra',3169
planetSelectContext: 'solo'2867
};3170
};2868
3171
2869
window.onload = function ()3172
window.onload = function ()@@ -2888,13 +3191,15 @@ window.onload = function ()2888
});3191
});2889
3192
2890
bindOnlineUi();3193
bindOnlineUi();3194
bindPlanetSelect();3195
restoreSelectedPlanet();2891
};3196
};2892
3197
2893
function onPlay ()3198
function onPlay ()2894
{3199
{2895
if (app.mode === 'playing')3200
if (app.mode === 'playing')2896
{ return; }3201
{ return; }2897
startPlay();3202
openPlanetSelect('solo');2898
}3203
}2899
3204
2900
function startPlay (opts)3205
function startPlay (opts)@@ -2905,14 +3210,15 @@ function startPlay (opts)2905
hideEl('online-panel');3210
hideEl('online-panel');2906
hideEl('spectator');3211
hideEl('spectator');2907
hideEl('podium');3212
hideEl('podium');3213
hideEl('planet-select');2908
showEl('hud');3214
showEl('hud');2909
3215
2910
app.planet = (typeof Planet !== 'undefined' ? Planet.defaultPlanet() : PlanetMod.defaultPlanet());3216
var planetMod = typeof Planet !== 'undefined' ? Planet : PlanetMod;3217
app.planet = opts.planet || planetMod.planetById(selectedPlanetId());2911
var miss = opts.missChance;3218
var miss = opts.missChance;2912
if (typeof miss === 'number' && isFinite(miss))3219
if (typeof miss !== 'number' || !isFinite(miss))2913
{ app.core = new GameCore(app.planet, Math.random, miss); }3220
{ miss = planetMod.missChance(app.planet); }2914
else3221
app.core = new GameCore(app.planet, Math.random, miss);2915
{ app.core = new GameCore(app.planet, Math.random); }2916
app.mode = 'playing';3222
app.mode = 'playing';2917
app.online = !!opts.online;3223
app.online = !!opts.online;2918
app.gameOverShown = false;3224
app.gameOverShown = false;@@ -2981,6 +3287,7 @@ function returnToMenu ()2981
teardownPlay();3287
teardownPlay();2982
app.mode = 'menu';3288
app.mode = 'menu';2983
app.online = false;3289
app.online = false;3290
hideEl('planet-select');2984
showEl('menu');3291
showEl('menu');2985
var last = document.getElementById('last-score');3292
var last = document.getElementById('last-score');2986
if (app.lastScore > 0)3293
if (app.lastScore > 0)@@ -3064,7 +3371,8 @@ function spriteFor (block)3064
{ return game.images.locked; }3371
{ return game.images.locked; }3065
if (block.color < 0)3372
if (block.color < 0)3066
{ return game.images.gray; }3373
{ return game.images.gray; }3067
return game.images[COLOR_SPRITES[block.color]] || game.images.gray;3374
var key = Planet.spriteKey(app.planet, block.color);3375
return game.images[key] || game.images.gray;3068
}3376
}3069
3377
3070
function syncSprites ()3378
function syncSprites ()@@ -3223,10 +3531,7 @@ function refreshHud ()3223
document.getElementById('score').textContent = String(app.core.score);3531
document.getElementById('score').textContent = String(app.core.score);3224
var planet = app.planet;3532
var planet = app.planet;3225
document.getElementById('planet-name').textContent = planet.name + ' · ' + planet.people;3533
document.getElementById('planet-name').textContent = planet.name + ' · ' + planet.people;3226
var d = Planet.displayValues(planet);3534
document.getElementById('planet-stats').textContent = Planet.formatStats(planet);3227
document.getElementById('planet-stats').textContent =3228
'g ' + d.gravity.toFixed(2) + ' d ' + d.density.toFixed(2) +3229
' F ' + Math.round(d.newtons) + ' N Power ' + d.power + '%';3230
}3535
}3231
3536
3232
function makeManager ()3537
function makeManager ()@@ -3504,10 +3809,11 @@ function startOnlineMatch ()3504
{3809
{3505
if (app.mode === 'playing' && app.online)3810
if (app.mode === 'playing' && app.online)3506
{ return; }3811
{ return; }3507
var miss = (typeof Online !== 'undefined' && Online.lobby && Online.lobby.miss_chance != null)3812
var planet = Planet.planetById(selectedPlanetId());3508
? Online.lobby.miss_chance3813
var me = (typeof Online !== 'undefined' && Online.mePlayer) ? Online.mePlayer() : null;3509
: (typeof Online !== 'undefined' ? Online.DEFAULT_MISS_CHANCE : 0.30);3814
if (me && me.planet && me.planet.id)3510
startPlay({ online: true, missChance: miss });3815
{ planet = Planet.planetById(me.planet.id); }3816
startPlay({ online: true, planet: planet, missChance: Planet.missChance(planet) });3511
if (typeof Online !== 'undefined')3817
if (typeof Online !== 'undefined')3512
{ Online.startPolling(onlinePayload); }3818
{ Online.startPolling(onlinePayload); }3513
}3819
}@@ -3664,6 +3970,7 @@ function openOnlinePanel ()3664
hideEl('game-over');3970
hideEl('game-over');3665
hideEl('podium');3971
hideEl('podium');3666
hideEl('spectator');3972
hideEl('spectator');3973
hideEl('planet-select');3667
showEl('online-panel');3974
showEl('online-panel');3668
app.mode = 'online';3975
app.mode = 'online';3669
setOnlineStatus('Even kijken of online spelen beschikbaar is…');3976
setOnlineStatus('Even kijken of online spelen beschikbaar is…');@@ -3765,10 +4072,14 @@ function renderOnline ()3765
{ li.classList.add('you'); }4072
{ li.classList.add('you'); }3766
var label = p.name + (p.is_host ? ' (host)' : '') + (p.is_me ? ' (jij)' : '');4073
var label = p.name + (p.is_host ? ' (host)' : '') + (p.is_me ? ' (jij)' : '');3767
var state = p.ready ? 'Gereed' : 'Wacht…';4074
var state = p.ready ? 'Gereed' : 'Wacht…';3768
li.innerHTML = '<span>' + escapeText(label) + '</span><span class="'4075
var world = (p.planet && p.planet.name) ? (p.planet.name + ' · ' + p.planet.people) : '';4076
li.innerHTML = '<span>' + escapeText(label)4077
+ (world ? '<span class="planet-tag">' + escapeText(world) + '</span>' : '')4078
+ '</span><span class="'3769
+ (p.ready ? 'ready' : 'waiting') + '">' + state + '</span>';4079
+ (p.ready ? 'ready' : 'waiting') + '">' + state + '</span>';3770
list.appendChild(li);4080
list.appendChild(li);3771
}4081
}4082
renderPlanetGrid('lobby-planet-grid', true);3772
var me = Online.mePlayer();4083
var me = Online.mePlayer();3773
document.getElementById('btn-ready').textContent = (me && me.ready) ? 'Niet gereed' : 'Gereed';4084
document.getElementById('btn-ready').textContent = (me && me.ready) ? 'Niet gereed' : 'Gereed';3774
var start = document.getElementById('btn-start');4085
var start = document.getElementById('btn-start');@@ -3802,6 +4113,150 @@ function escapeText (s)3802
.replace(/"/g, '"');4113
.replace(/"/g, '"');3803
}4114
}3804
4115
4116
4117
function selectedPlanetId ()4118
{4119
if (app.selectedPlanetId)4120
{ return app.selectedPlanetId; }4121
return 'terra';4122
}4123
4124
function restoreSelectedPlanet ()4125
{4126
var id = 'terra';4127
try4128
{ id = localStorage.getItem('meteors-planet') || 'terra'; }4129
catch (e) {}4130
setSelectedPlanet(id, true);4131
}4132
4133
function setSelectedPlanet (id, silent)4134
{4135
var all = Planet.allPlanets();4136
var found = null;4137
for (var i = 0; i < all.length; i++)4138
{4139
if (all[i].id === id)4140
{ found = all[i]; break; }4141
}4142
if (!found)4143
{ found = Planet.defaultPlanet(); }4144
app.selectedPlanetId = found.id;4145
try4146
{ localStorage.setItem('meteors-planet', found.id); }4147
catch (e) {}4148
if (!silent)4149
{4150
var grid = document.getElementById('planet-grid');4151
if (grid && !grid.hidden && grid.children.length)4152
{ renderPlanetGrid('planet-grid', false); }4153
var lobby = document.getElementById('lobby-planet-grid');4154
if (lobby && lobby.children.length)4155
{ renderPlanetGrid('lobby-planet-grid', true); }4156
}4157
return found;4158
}4159
4160
function openPlanetSelect (context)4161
{4162
if (app.mode === 'playing')4163
{ return; }4164
app.planetSelectContext = context || 'solo';4165
app.mode = 'planet-select';4166
hideEl('menu');4167
hideEl('online-panel');4168
hideEl('game-over');4169
showEl('planet-select');4170
renderPlanetGrid('planet-grid', false);4171
var go = document.getElementById('btn-planet-go');4172
if (go)4173
{ go.textContent = 'Spelen'; }4174
}4175
4176
function renderPlanetGrid (containerId, compact)4177
{4178
var grid = document.getElementById(containerId);4179
if (!grid)4180
{ return; }4181
var current = selectedPlanetId();4182
var all = Planet.allPlanets();4183
grid.innerHTML = '';4184
if (compact)4185
{ grid.classList.add('compact'); }4186
for (var i = 0; i < all.length; i++)4187
{4188
var pl = all[i];4189
var btn = document.createElement('button');4190
btn.type = 'button';4191
btn.className = 'planet-card' + (pl.id === current ? ' selected' : '');4192
btn.setAttribute('role', 'listitem');4193
btn.dataset.planet = pl.id;4194
var swatches = '';4195
for (var c = 0; c < pl.colors.length; c++)4196
{4197
swatches += '<img src="' + escapeText(pl.colors[c].image) + '" alt="'4198
+ escapeText(pl.colors[c].name) + '" title="' + escapeText(pl.colors[c].name) + '">';4199
}4200
btn.innerHTML = '<div class="planet-title">' + escapeText(pl.name) + '</div>'4201
+ '<div class="planet-people">' + escapeText(pl.people) + '</div>'4202
+ '<div class="planet-nums">' + escapeText(Planet.formatStats(pl)) + '</div>'4203
+ '<div class="planet-swatches">' + swatches + '</div>';4204
btn.addEventListener('click', (function (id, isCompact)4205
{4206
return function ()4207
{ onPlanetPicked(id, isCompact); };4208
})(pl.id, !!compact));4209
grid.appendChild(btn);4210
}4211
}4212
4213
function onPlanetPicked (id, fromLobby)4214
{4215
setSelectedPlanet(id);4216
if (fromLobby && typeof Online !== 'undefined' && Online.lobby)4217
{4218
Online.setPlanet(id).then(function ()4219
{ renderOnline(); });4220
}4221
else4222
{4223
renderPlanetGrid('planet-grid', false);4224
}4225
}4226
4227
function confirmPlanetSelect ()4228
{4229
var planet = setSelectedPlanet(selectedPlanetId());4230
hideEl('planet-select');4231
if (app.planetSelectContext === 'online')4232
{4233
openOnlinePanel();4234
return;4235
}4236
startPlay({ planet: planet });4237
}4238
4239
function cancelPlanetSelect ()4240
{4241
hideEl('planet-select');4242
app.mode = 'menu';4243
showEl('menu');4244
}4245
4246
function bindPlanetSelect ()4247
{4248
var go = document.getElementById('btn-planet-go');4249
var back = document.getElementById('btn-planet-back');4250
if (go)4251
{4252
go.addEventListener('click', confirmPlanetSelect);4253
}4254
if (back)4255
{4256
back.addEventListener('click', cancelPlanetSelect);4257
}4258
}4259
3805
/*4260
/*3806
* End File:4261
* End File:3807
* /workspace/meteors/src/main.js4262
* /workspace/meteors/src/main.js@@ -23,6 +23,16 @@
23
23
<p class="hint">Sleep blokjes verticaal om ze te wisselen. Trek een blokje boven zijn kolom om het omhoog te duwen. Blokjes die het veld verlaten, leveren punten op.</p>
24
24
</div>
25
25
26
<div id="planet-select" class="screen" hidden>
27
<h1>Kies een veld</h1>
28
<p class="tagline">Elk veld is een planeet, met een eigen volk, zwaartekracht, lucht en massa.</p>
29
<div id="planet-grid" class="planet-grid" role="list"></div>
30
<div class="planet-actions">
31
<button type="button" id="btn-planet-go">Spelen</button>
32
<button type="button" id="btn-planet-back" class="btn-secondary">Terug</button>
33
</div>
34
</div>
35
26
36
<div id="online-panel" class="screen" hidden>
27
37
<h1>Online</h1>
28
38
<p id="online-status" class="tagline">Even kijken of online spelen beschikbaar is…</p>
@@ -61,6 +71,8 @@
61
71
<div id="online-lobby" hidden>
62
72
<p class="who">Ingelogd als <strong id="lobby-me-name"></strong></p>
63
73
<p class="lobby-code">Code: <strong id="lobby-code"></strong> <button type="button" id="btn-copy-code" class="btn-tiny">Kopieer</button></p>
74
<p class="hint lobby-planet-label">Jouw veld</p>
75
<div id="lobby-planet-grid" class="planet-grid compact" role="list"></div>
64
76
<ul id="lobby-players" class="player-list"></ul>
65
77
<p id="lobby-hint" class="hint"></p>
66
78
<div class="lobby-actions">
@@ -23,6 +23,16 @@23
<p class="hint">Sleep blokjes verticaal om ze te wisselen. Trek een blokje boven zijn kolom om het omhoog te duwen. Blokjes die het veld verlaten, leveren punten op.</p>23
<p class="hint">Sleep blokjes verticaal om ze te wisselen. Trek een blokje boven zijn kolom om het omhoog te duwen. Blokjes die het veld verlaten, leveren punten op.</p>24
</div>24
</div>25
25
26
<div id="planet-select" class="screen" hidden>27
<h1>Kies een veld</h1>28
<p class="tagline">Elk veld is een planeet, met een eigen volk, zwaartekracht, lucht en massa.</p>29
<div id="planet-grid" class="planet-grid" role="list"></div>30
<div class="planet-actions">31
<button type="button" id="btn-planet-go">Spelen</button>32
<button type="button" id="btn-planet-back" class="btn-secondary">Terug</button>33
</div>34
</div>35
26
<div id="online-panel" class="screen" hidden>36
<div id="online-panel" class="screen" hidden>27
<h1>Online</h1>37
<h1>Online</h1>28
<p id="online-status" class="tagline">Even kijken of online spelen beschikbaar is…</p>38
<p id="online-status" class="tagline">Even kijken of online spelen beschikbaar is…</p>@@ -61,6 +71,8 @@61
<div id="online-lobby" hidden>71
<div id="online-lobby" hidden>62
<p class="who">Ingelogd als <strong id="lobby-me-name"></strong></p>72
<p class="who">Ingelogd als <strong id="lobby-me-name"></strong></p>63
<p class="lobby-code">Code: <strong id="lobby-code"></strong> <button type="button" id="btn-copy-code" class="btn-tiny">Kopieer</button></p>73
<p class="lobby-code">Code: <strong id="lobby-code"></strong> <button type="button" id="btn-copy-code" class="btn-tiny">Kopieer</button></p>74
<p class="hint lobby-planet-label">Jouw veld</p>75
<div id="lobby-planet-grid" class="planet-grid compact" role="list"></div>64
<ul id="lobby-players" class="player-list"></ul>76
<ul id="lobby-players" class="player-list"></ul>65
<p id="lobby-hint" class="hint"></p>77
<p id="lobby-hint" class="hint"></p>66
<div class="lobby-actions">78
<div class="lobby-actions">@@ -45,7 +45,7 @@ html, body {
45
45
text-align: center;
46
46
}
47
47
48
.screen[hidden], #hud[hidden], #game-over[hidden], #online-panel[hidden], #minis[hidden], #spectator[hidden], #podium[hidden], #flights[hidden] { display: none !important; }
48
.screen[hidden], #hud[hidden], #game-over[hidden], #online-panel[hidden], #minis[hidden], #spectator[hidden], #podium[hidden], #flights[hidden], #planet-select[hidden] { display: none !important; }
49
49
50
50
h1 {
51
51
font-size: clamp(48px, 14vw, 96px);
@@ -66,7 +66,7 @@ h1 {
66
66
max-width: 28em;
67
67
}
68
68
69
#btn-play {
69
#btn-play, #btn-planet-go {
70
70
appearance: none;
71
71
border: 0;
72
72
cursor: pointer;
@@ -87,14 +87,14 @@ h1 {
87
87
min-width: 200px;
88
88
}
89
89
90
#btn-play:is(:hover, :focus-visible) {
90
#btn-play:is(:hover, :focus-visible), #btn-planet-go:is(:hover, :focus-visible) {
91
91
transform: translateY(-1px);
92
92
box-shadow:
93
93
0 0 0 3px rgba(255, 220, 120, 0.4),
94
94
0 10px 28px rgba(240, 197, 58, 0.6);
95
95
}
96
96
97
#btn-play:active { transform: translateY(1px); }
97
#btn-play:active, #btn-planet-go:active { transform: translateY(1px); }
98
98
99
99
.last-score {
100
100
margin: 22px 0 0;
@@ -181,7 +181,7 @@ canvas {
181
181
@media (max-height: 520px) {
182
182
.hint { display: none; }
183
183
h1 { font-size: 42px; }
184
#btn-play { padding: 10px 36px; }
184
#btn-play, #btn-planet-go { padding: 10px 36px; }
185
185
}
186
186
187
187
@@ -207,7 +207,7 @@ a.button:is(:hover, :focus-visible) {
207
207
color: #fff6c8;
208
208
}
209
209
#btn-create, #btn-join, #btn-ready, #btn-start, #btn-spectate,
210
#btn-play {
210
#btn-play, #btn-planet-go {
211
211
/* play already styled */
212
212
}
213
213
@@ -227,16 +227,21 @@ a.button:is(:hover, :focus-visible) {
227
227
cursor: default;
228
228
}
229
229
230
#online-panel h1 {
231
font-size: clamp(36px, 9vw, 64px);
232
}
230
233
#online-panel {
231
234
z-index: 5;
232
235
overflow: auto;
233
236
text-align: center;
234
padding: 32px 16px 48px;
237
padding: 16px 16px 24px;
235
238
}
236
239
#online-panel .who {
237
240
color: #c5cae0;
238
margin: 0 0 16px;
241
margin: 0 0 8px;
239
242
}
243
#online-lobby .tagline { margin-bottom: 8px; }
244
#online-lobby .lobby-code { margin: 4px 0 6px; }
240
245
#online-panel .notice {
241
246
max-width: 36em;
242
247
margin: 0 auto 16px;
@@ -408,3 +413,129 @@ a.button:is(:hover, :focus-visible) {
408
413
#online-panel .hint, #online-panel .tagline { display: block; }
409
414
.mini-canvas { width: 56px; height: 73px; }
410
415
}
416
417
/* Stage 3: planet (field) selection */
418
#planet-select {
419
justify-content: flex-start;
420
overflow-y: auto;
421
touch-action: pan-y;
422
-webkit-overflow-scrolling: touch;
423
padding-top: 20px;
424
padding-bottom: 32px;
425
}
426
#planet-select h1 {
427
font-size: clamp(32px, 9vw, 64px);
428
margin-bottom: 4px;
429
}
430
#planet-select .tagline { margin-bottom: 16px; }
431
.planet-grid {
432
display: grid;
433
grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
434
gap: 12px;
435
width: min(1000px, 100%);
436
margin: 0 auto 16px;
437
text-align: left;
438
touch-action: pan-y;
439
}
440
.planet-card {
441
appearance: none;
442
display: block;
443
width: 100%;
444
margin: 0;
445
padding: 12px 14px 10px;
446
border: 1px solid rgba(200, 210, 240, 0.16);
447
border-radius: 14px;
448
background: rgba(16, 20, 40, 0.72);
449
color: inherit;
450
font: inherit;
451
text-align: left;
452
cursor: pointer;
453
touch-action: manipulation;
454
transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
455
}
456
.planet-card:hover, .planet-card:focus-visible {
457
border-color: rgba(255, 226, 122, 0.55);
458
outline: none;
459
}
460
.planet-card.selected {
461
border-color: #ffe27a;
462
box-shadow: 0 0 0 2px rgba(255, 226, 122, 0.35), 0 8px 24px rgba(0,0,0,0.35);
463
background: rgba(40, 32, 16, 0.78);
464
}
465
.planet-card .planet-title {
466
font-size: 1.15rem;
467
font-weight: 700;
468
letter-spacing: 0.03em;
469
color: #fff6c8;
470
}
471
.planet-card .planet-people {
472
font-size: 0.85rem;
473
color: #8e95b3;
474
margin: 0 0 6px;
475
}
476
.planet-card .planet-nums {
477
font-variant-numeric: tabular-nums;
478
font-size: 0.78rem;
479
color: #c5cae0;
480
letter-spacing: 0.01em;
481
line-height: 1.35;
482
margin: 0 0 8px;
483
}
484
.planet-card .planet-swatches {
485
display: flex;
486
gap: 6px;
487
align-items: center;
488
}
489
.planet-card .planet-swatches img {
490
width: 26px;
491
height: 26px;
492
image-rendering: auto;
493
flex: 0 0 auto;
494
}
495
.planet-actions {
496
display: flex;
497
gap: 12px;
498
flex-wrap: wrap;
499
justify-content: center;
500
margin-top: 8px;
501
flex-shrink: 0;
502
}
503
.planet-grid.compact {
504
grid-template-columns: repeat(4, minmax(0, 1fr));
505
gap: 8px;
506
width: min(920px, 92vw);
507
min-width: min(920px, 92vw);
508
max-height: none;
509
overflow: visible;
510
touch-action: pan-y;
511
margin-bottom: 10px;
512
align-self: center;
513
}
514
@media (max-width: 720px) {
515
.planet-grid.compact {
516
grid-template-columns: repeat(2, minmax(0, 1fr));
517
}
518
}
519
.planet-grid.compact .planet-card { padding: 6px 8px; }
520
.planet-grid.compact .planet-title { font-size: 1rem; }
521
.planet-grid.compact .planet-nums { font-size: 0.7rem; margin-bottom: 6px; }
522
.planet-grid.compact .planet-swatches img { width: 20px; height: 20px; }
523
.lobby-planet-label { margin: 8px 0 6px; }
524
.player-list .planet-tag {
525
display: block;
526
font-size: 0.78rem;
527
font-weight: 500;
528
color: #9aa3c4;
529
}
530
#online-lobby {
531
overflow-y: auto;
532
touch-action: pan-y;
533
-webkit-overflow-scrolling: touch;
534
justify-content: flex-start;
535
padding-top: 8px;
536
}
537
@media (max-width: 520px) {
538
.planet-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
539
.planet-card .planet-nums { font-size: 0.68rem; }
540
.planet-card { padding: 10px 8px 8px; }
541
}
@@ -45,7 +45,7 @@ html, body {45
text-align: center;45
text-align: center;46
}46
}47
47
48
.screen[hidden], #hud[hidden], #game-over[hidden], #online-panel[hidden], #minis[hidden], #spectator[hidden], #podium[hidden], #flights[hidden] { display: none !important; }48
.screen[hidden], #hud[hidden], #game-over[hidden], #online-panel[hidden], #minis[hidden], #spectator[hidden], #podium[hidden], #flights[hidden], #planet-select[hidden] { display: none !important; }49
49
50
h1 {50
h1 {51
font-size: clamp(48px, 14vw, 96px);51
font-size: clamp(48px, 14vw, 96px);@@ -66,7 +66,7 @@ h1 {66
max-width: 28em;66
max-width: 28em;67
}67
}68
68
69
#btn-play {69
#btn-play, #btn-planet-go {70
appearance: none;70
appearance: none;71
border: 0;71
border: 0;72
cursor: pointer;72
cursor: pointer;@@ -87,14 +87,14 @@ h1 {87
min-width: 200px;87
min-width: 200px;88
}88
}89
89
90
#btn-play:is(:hover, :focus-visible) {90
#btn-play:is(:hover, :focus-visible), #btn-planet-go:is(:hover, :focus-visible) {91
transform: translateY(-1px);91
transform: translateY(-1px);92
box-shadow:92
box-shadow:93
0 0 0 3px rgba(255, 220, 120, 0.4),93
0 0 0 3px rgba(255, 220, 120, 0.4),94
0 10px 28px rgba(240, 197, 58, 0.6);94
0 10px 28px rgba(240, 197, 58, 0.6);95
}95
}96
96
97
#btn-play:active { transform: translateY(1px); }97
#btn-play:active, #btn-planet-go:active { transform: translateY(1px); }98
98
99
.last-score {99
.last-score {100
margin: 22px 0 0;100
margin: 22px 0 0;@@ -181,7 +181,7 @@ canvas {181
@media (max-height: 520px) {181
@media (max-height: 520px) {182
.hint { display: none; }182
.hint { display: none; }183
h1 { font-size: 42px; }183
h1 { font-size: 42px; }184
#btn-play { padding: 10px 36px; }184
#btn-play, #btn-planet-go { padding: 10px 36px; }185
}185
}186
186
187
187
@@ -207,7 +207,7 @@ a.button:is(:hover, :focus-visible) {207
color: #fff6c8;207
color: #fff6c8;208
}208
}209
#btn-create, #btn-join, #btn-ready, #btn-start, #btn-spectate,209
#btn-create, #btn-join, #btn-ready, #btn-start, #btn-spectate,210
#btn-play {210
#btn-play, #btn-planet-go {211
/* play already styled */211
/* play already styled */212
}212
}213
213
@@ -227,16 +227,21 @@ a.button:is(:hover, :focus-visible) {227
cursor: default;227
cursor: default;228
}228
}229
229
230
#online-panel h1 {231
font-size: clamp(36px, 9vw, 64px);232
}230
#online-panel {233
#online-panel {231
z-index: 5;234
z-index: 5;232
overflow: auto;235
overflow: auto;233
text-align: center;236
text-align: center;234
padding: 32px 16px 48px;237
padding: 16px 16px 24px;235
}238
}236
#online-panel .who {239
#online-panel .who {237
color: #c5cae0;240
color: #c5cae0;238
margin: 0 0 16px;241
margin: 0 0 8px;239
}242
}243
#online-lobby .tagline { margin-bottom: 8px; }244
#online-lobby .lobby-code { margin: 4px 0 6px; }240
#online-panel .notice {245
#online-panel .notice {241
max-width: 36em;246
max-width: 36em;242
margin: 0 auto 16px;247
margin: 0 auto 16px;@@ -408,3 +413,129 @@ a.button:is(:hover, :focus-visible) {408
#online-panel .hint, #online-panel .tagline { display: block; }413
#online-panel .hint, #online-panel .tagline { display: block; }409
.mini-canvas { width: 56px; height: 73px; }414
.mini-canvas { width: 56px; height: 73px; }410
}415
}416
417
/* Stage 3: planet (field) selection */418
#planet-select {419
justify-content: flex-start;420
overflow-y: auto;421
touch-action: pan-y;422
-webkit-overflow-scrolling: touch;423
padding-top: 20px;424
padding-bottom: 32px;425
}426
#planet-select h1 {427
font-size: clamp(32px, 9vw, 64px);428
margin-bottom: 4px;429
}430
#planet-select .tagline { margin-bottom: 16px; }431
.planet-grid {432
display: grid;433
grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));434
gap: 12px;435
width: min(1000px, 100%);436
margin: 0 auto 16px;437
text-align: left;438
touch-action: pan-y;439
}440
.planet-card {441
appearance: none;442
display: block;443
width: 100%;444
margin: 0;445
padding: 12px 14px 10px;446
border: 1px solid rgba(200, 210, 240, 0.16);447
border-radius: 14px;448
background: rgba(16, 20, 40, 0.72);449
color: inherit;450
font: inherit;451
text-align: left;452
cursor: pointer;453
touch-action: manipulation;454
transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;455
}456
.planet-card:hover, .planet-card:focus-visible {457
border-color: rgba(255, 226, 122, 0.55);458
outline: none;459
}460
.planet-card.selected {461
border-color: #ffe27a;462
box-shadow: 0 0 0 2px rgba(255, 226, 122, 0.35), 0 8px 24px rgba(0,0,0,0.35);463
background: rgba(40, 32, 16, 0.78);464
}465
.planet-card .planet-title {466
font-size: 1.15rem;467
font-weight: 700;468
letter-spacing: 0.03em;469
color: #fff6c8;470
}471
.planet-card .planet-people {472
font-size: 0.85rem;473
color: #8e95b3;474
margin: 0 0 6px;475
}476
.planet-card .planet-nums {477
font-variant-numeric: tabular-nums;478
font-size: 0.78rem;479
color: #c5cae0;480
letter-spacing: 0.01em;481
line-height: 1.35;482
margin: 0 0 8px;483
}484
.planet-card .planet-swatches {485
display: flex;486
gap: 6px;487
align-items: center;488
}489
.planet-card .planet-swatches img {490
width: 26px;491
height: 26px;492
image-rendering: auto;493
flex: 0 0 auto;494
}495
.planet-actions {496
display: flex;497
gap: 12px;498
flex-wrap: wrap;499
justify-content: center;500
margin-top: 8px;501
flex-shrink: 0;502
}503
.planet-grid.compact {504
grid-template-columns: repeat(4, minmax(0, 1fr));505
gap: 8px;506
width: min(920px, 92vw);507
min-width: min(920px, 92vw);508
max-height: none;509
overflow: visible;510
touch-action: pan-y;511
margin-bottom: 10px;512
align-self: center;513
}514
@media (max-width: 720px) {515
.planet-grid.compact {516
grid-template-columns: repeat(2, minmax(0, 1fr));517
}518
}519
.planet-grid.compact .planet-card { padding: 6px 8px; }520
.planet-grid.compact .planet-title { font-size: 1rem; }521
.planet-grid.compact .planet-nums { font-size: 0.7rem; margin-bottom: 6px; }522
.planet-grid.compact .planet-swatches img { width: 20px; height: 20px; }523
.lobby-planet-label { margin: 8px 0 6px; }524
.player-list .planet-tag {525
display: block;526
font-size: 0.78rem;527
font-weight: 500;528
color: #9aa3c4;529
}530
#online-lobby {531
overflow-y: auto;532
touch-action: pan-y;533
-webkit-overflow-scrolling: touch;534
justify-content: flex-start;535
padding-top: 8px;536
}537
@media (max-width: 520px) {538
.planet-grid { grid-template-columns: 1fr 1fr; gap: 8px; }539
.planet-card .planet-nums { font-size: 0.68rem; }540
.planet-card { padding: 10px 8px 8px; }541
}@@ -7,20 +7,37 @@
7
7
* through Online (src/online.js) and the same GameCore.
8
8
*/
9
9
10
var IMAGES = [
11
{ name: 'ember', url: 'images/block-ember.png' },
12
{ name: 'aqua', url: 'images/block-aqua.png' },
13
{ name: 'leaf', url: 'images/block-leaf.png' },
14
{ name: 'sun', url: 'images/block-sun.png' },
15
{ name: 'orchid', url: 'images/block-orchid.png' },
16
{ name: 'gray', url: 'images/block-gray.png' },
17
{ name: 'locked', url: 'images/block-locked.png' },
18
{ name: 'flame', url: 'images/flame.png', subImgTotal: 4, perRow: 4 },
19
{ name: 'cell', url: 'images/cell.png' },
20
{ name: 'pixel', url: 'images/pixel.png' }
21
];
22
23
var COLOR_SPRITES = ['ember', 'aqua', 'leaf', 'sun', 'orchid'];
10
function planetImages ()
11
{
12
var list = [
13
{ name: 'gray', url: 'images/block-gray.png' },
14
{ name: 'locked', url: 'images/block-locked.png' },
15
{ name: 'flame', url: 'images/flame.png', subImgTotal: 4, perRow: 4 },
16
{ name: 'cell', url: 'images/cell.png' },
17
{ name: 'pixel', url: 'images/pixel.png' },
18
// Keep the original Terra placeholders as aliases (Tim may still have them).
19
{ name: 'ember', url: 'images/block-ember.png' },
20
{ name: 'aqua', url: 'images/block-aqua.png' },
21
{ name: 'leaf', url: 'images/block-leaf.png' },
22
{ name: 'sun', url: 'images/block-sun.png' },
23
{ name: 'orchid', url: 'images/block-orchid.png' }
24
];
25
var planets = (typeof Planet !== 'undefined' ? Planet.allPlanets() : []);
26
for (var i = 0; i < planets.length; i++)
27
{
28
var pl = planets[i];
29
for (var c = 0; c < pl.colors.length; c++)
30
{
31
list.push({
32
name: Planet.spriteKey(pl, c),
33
url: pl.colors[c].image
34
});
35
}
36
}
37
return list;
38
}
39
40
var IMAGES = planetImages();
24
41
var GAME_OVER_DELAY = 2;
25
42
26
43
var game = new Game();
@@ -46,7 +63,9 @@ var app = {
46
63
online: false,
47
64
eliminatedReported: false,
48
65
spectating: false,
49
miniH: 0
66
miniH: 0,
67
selectedPlanetId: 'terra',
68
planetSelectContext: 'solo'
50
69
};
51
70
52
71
window.onload = function ()
@@ -71,13 +90,15 @@ window.onload = function ()
71
90
});
72
91
73
92
bindOnlineUi();
93
bindPlanetSelect();
94
restoreSelectedPlanet();
74
95
};
75
96
76
97
function onPlay ()
77
98
{
78
99
if (app.mode === 'playing')
79
100
{ return; }
80
startPlay();
101
openPlanetSelect('solo');
81
102
}
82
103
83
104
function startPlay (opts)
@@ -88,14 +109,15 @@ function startPlay (opts)
88
109
hideEl('online-panel');
89
110
hideEl('spectator');
90
111
hideEl('podium');
112
hideEl('planet-select');
91
113
showEl('hud');
92
114
93
app.planet = (typeof Planet !== 'undefined' ? Planet.defaultPlanet() : PlanetMod.defaultPlanet());
115
var planetMod = typeof Planet !== 'undefined' ? Planet : PlanetMod;
116
app.planet = opts.planet || planetMod.planetById(selectedPlanetId());
94
117
var miss = opts.missChance;
95
if (typeof miss === 'number' && isFinite(miss))
96
{ app.core = new GameCore(app.planet, Math.random, miss); }
97
else
98
{ app.core = new GameCore(app.planet, Math.random); }
118
if (typeof miss !== 'number' || !isFinite(miss))
119
{ miss = planetMod.missChance(app.planet); }
120
app.core = new GameCore(app.planet, Math.random, miss);
99
121
app.mode = 'playing';
100
122
app.online = !!opts.online;
101
123
app.gameOverShown = false;
@@ -164,6 +186,7 @@ function returnToMenu ()
164
186
teardownPlay();
165
187
app.mode = 'menu';
166
188
app.online = false;
189
hideEl('planet-select');
167
190
showEl('menu');
168
191
var last = document.getElementById('last-score');
169
192
if (app.lastScore > 0)
@@ -247,7 +270,8 @@ function spriteFor (block)
247
270
{ return game.images.locked; }
248
271
if (block.color < 0)
249
272
{ return game.images.gray; }
250
return game.images[COLOR_SPRITES[block.color]] || game.images.gray;
273
var key = Planet.spriteKey(app.planet, block.color);
274
return game.images[key] || game.images.gray;
251
275
}
252
276
253
277
function syncSprites ()
@@ -406,10 +430,7 @@ function refreshHud ()
406
430
document.getElementById('score').textContent = String(app.core.score);
407
431
var planet = app.planet;
408
432
document.getElementById('planet-name').textContent = planet.name + ' · ' + planet.people;
409
var d = Planet.displayValues(planet);
410
document.getElementById('planet-stats').textContent =
411
'g ' + d.gravity.toFixed(2) + ' d ' + d.density.toFixed(2) +
412
' F ' + Math.round(d.newtons) + ' N Power ' + d.power + '%';
433
document.getElementById('planet-stats').textContent = Planet.formatStats(planet);
413
434
}
414
435
415
436
function makeManager ()
@@ -687,10 +708,11 @@ function startOnlineMatch ()
687
708
{
688
709
if (app.mode === 'playing' && app.online)
689
710
{ return; }
690
var miss = (typeof Online !== 'undefined' && Online.lobby && Online.lobby.miss_chance != null)
691
? Online.lobby.miss_chance
692
: (typeof Online !== 'undefined' ? Online.DEFAULT_MISS_CHANCE : 0.30);
693
startPlay({ online: true, missChance: miss });
711
var planet = Planet.planetById(selectedPlanetId());
712
var me = (typeof Online !== 'undefined' && Online.mePlayer) ? Online.mePlayer() : null;
713
if (me && me.planet && me.planet.id)
714
{ planet = Planet.planetById(me.planet.id); }
715
startPlay({ online: true, planet: planet, missChance: Planet.missChance(planet) });
694
716
if (typeof Online !== 'undefined')
695
717
{ Online.startPolling(onlinePayload); }
696
718
}
@@ -847,6 +869,7 @@ function openOnlinePanel ()
847
869
hideEl('game-over');
848
870
hideEl('podium');
849
871
hideEl('spectator');
872
hideEl('planet-select');
850
873
showEl('online-panel');
851
874
app.mode = 'online';
852
875
setOnlineStatus('Even kijken of online spelen beschikbaar is…');
@@ -948,10 +971,14 @@ function renderOnline ()
948
971
{ li.classList.add('you'); }
949
972
var label = p.name + (p.is_host ? ' (host)' : '') + (p.is_me ? ' (jij)' : '');
950
973
var state = p.ready ? 'Gereed' : 'Wacht…';
951
li.innerHTML = '<span>' + escapeText(label) + '</span><span class="'
974
var world = (p.planet && p.planet.name) ? (p.planet.name + ' · ' + p.planet.people) : '';
975
li.innerHTML = '<span>' + escapeText(label)
976
+ (world ? '<span class="planet-tag">' + escapeText(world) + '</span>' : '')
977
+ '</span><span class="'
952
978
+ (p.ready ? 'ready' : 'waiting') + '">' + state + '</span>';
953
979
list.appendChild(li);
954
980
}
981
renderPlanetGrid('lobby-planet-grid', true);
955
982
var me = Online.mePlayer();
956
983
document.getElementById('btn-ready').textContent = (me && me.ready) ? 'Niet gereed' : 'Gereed';
957
984
var start = document.getElementById('btn-start');
@@ -984,3 +1011,147 @@ function escapeText (s)
984
1011
.replace(/>/g, '>')
985
1012
.replace(/"/g, '"');
986
1013
}
1014
1015
1016
function selectedPlanetId ()
1017
{
1018
if (app.selectedPlanetId)
1019
{ return app.selectedPlanetId; }
1020
return 'terra';
1021
}
1022
1023
function restoreSelectedPlanet ()
1024
{
1025
var id = 'terra';
1026
try
1027
{ id = localStorage.getItem('meteors-planet') || 'terra'; }
1028
catch (e) {}
1029
setSelectedPlanet(id, true);
1030
}
1031
1032
function setSelectedPlanet (id, silent)
1033
{
1034
var all = Planet.allPlanets();
1035
var found = null;
1036
for (var i = 0; i < all.length; i++)
1037
{
1038
if (all[i].id === id)
1039
{ found = all[i]; break; }
1040
}
1041
if (!found)
1042
{ found = Planet.defaultPlanet(); }
1043
app.selectedPlanetId = found.id;
1044
try
1045
{ localStorage.setItem('meteors-planet', found.id); }
1046
catch (e) {}
1047
if (!silent)
1048
{
1049
var grid = document.getElementById('planet-grid');
1050
if (grid && !grid.hidden && grid.children.length)
1051
{ renderPlanetGrid('planet-grid', false); }
1052
var lobby = document.getElementById('lobby-planet-grid');
1053
if (lobby && lobby.children.length)
1054
{ renderPlanetGrid('lobby-planet-grid', true); }
1055
}
1056
return found;
1057
}
1058
1059
function openPlanetSelect (context)
1060
{
1061
if (app.mode === 'playing')
1062
{ return; }
1063
app.planetSelectContext = context || 'solo';
1064
app.mode = 'planet-select';
1065
hideEl('menu');
1066
hideEl('online-panel');
1067
hideEl('game-over');
1068
showEl('planet-select');
1069
renderPlanetGrid('planet-grid', false);
1070
var go = document.getElementById('btn-planet-go');
1071
if (go)
1072
{ go.textContent = 'Spelen'; }
1073
}
1074
1075
function renderPlanetGrid (containerId, compact)
1076
{
1077
var grid = document.getElementById(containerId);
1078
if (!grid)
1079
{ return; }
1080
var current = selectedPlanetId();
1081
var all = Planet.allPlanets();
1082
grid.innerHTML = '';
1083
if (compact)
1084
{ grid.classList.add('compact'); }
1085
for (var i = 0; i < all.length; i++)
1086
{
1087
var pl = all[i];
1088
var btn = document.createElement('button');
1089
btn.type = 'button';
1090
btn.className = 'planet-card' + (pl.id === current ? ' selected' : '');
1091
btn.setAttribute('role', 'listitem');
1092
btn.dataset.planet = pl.id;
1093
var swatches = '';
1094
for (var c = 0; c < pl.colors.length; c++)
1095
{
1096
swatches += '<img src="' + escapeText(pl.colors[c].image) + '" alt="'
1097
+ escapeText(pl.colors[c].name) + '" title="' + escapeText(pl.colors[c].name) + '">';
1098
}
1099
btn.innerHTML = '<div class="planet-title">' + escapeText(pl.name) + '</div>'
1100
+ '<div class="planet-people">' + escapeText(pl.people) + '</div>'
1101
+ '<div class="planet-nums">' + escapeText(Planet.formatStats(pl)) + '</div>'
1102
+ '<div class="planet-swatches">' + swatches + '</div>';
1103
btn.addEventListener('click', (function (id, isCompact)
1104
{
1105
return function ()
1106
{ onPlanetPicked(id, isCompact); };
1107
})(pl.id, !!compact));
1108
grid.appendChild(btn);
1109
}
1110
}
1111
1112
function onPlanetPicked (id, fromLobby)
1113
{
1114
setSelectedPlanet(id);
1115
if (fromLobby && typeof Online !== 'undefined' && Online.lobby)
1116
{
1117
Online.setPlanet(id).then(function ()
1118
{ renderOnline(); });
1119
}
1120
else
1121
{
1122
renderPlanetGrid('planet-grid', false);
1123
}
1124
}
1125
1126
function confirmPlanetSelect ()
1127
{
1128
var planet = setSelectedPlanet(selectedPlanetId());
1129
hideEl('planet-select');
1130
if (app.planetSelectContext === 'online')
1131
{
1132
openOnlinePanel();
1133
return;
1134
}
1135
startPlay({ planet: planet });
1136
}
1137
1138
function cancelPlanetSelect ()
1139
{
1140
hideEl('planet-select');
1141
app.mode = 'menu';
1142
showEl('menu');
1143
}
1144
1145
function bindPlanetSelect ()
1146
{
1147
var go = document.getElementById('btn-planet-go');
1148
var back = document.getElementById('btn-planet-back');
1149
if (go)
1150
{
1151
go.addEventListener('click', confirmPlanetSelect);
1152
}
1153
if (back)
1154
{
1155
back.addEventListener('click', cancelPlanetSelect);
1156
}
1157
}
@@ -7,20 +7,37 @@7
* through Online (src/online.js) and the same GameCore.7
* through Online (src/online.js) and the same GameCore.8
*/8
*/9
9
10
var IMAGES = [10
function planetImages ()11
{ name: 'ember', url: 'images/block-ember.png' },11
{12
{ name: 'aqua', url: 'images/block-aqua.png' },12
var list = [13
{ name: 'leaf', url: 'images/block-leaf.png' },13
{ name: 'gray', url: 'images/block-gray.png' },14
{ name: 'sun', url: 'images/block-sun.png' },14
{ name: 'locked', url: 'images/block-locked.png' },15
{ name: 'orchid', url: 'images/block-orchid.png' },15
{ name: 'flame', url: 'images/flame.png', subImgTotal: 4, perRow: 4 },16
{ name: 'gray', url: 'images/block-gray.png' },16
{ name: 'cell', url: 'images/cell.png' },17
{ name: 'locked', url: 'images/block-locked.png' },17
{ name: 'pixel', url: 'images/pixel.png' },18
{ name: 'flame', url: 'images/flame.png', subImgTotal: 4, perRow: 4 },18
// Keep the original Terra placeholders as aliases (Tim may still have them).19
{ name: 'cell', url: 'images/cell.png' },19
{ name: 'ember', url: 'images/block-ember.png' },20
{ name: 'pixel', url: 'images/pixel.png' }20
{ name: 'aqua', url: 'images/block-aqua.png' },21
];21
{ name: 'leaf', url: 'images/block-leaf.png' },22
22
{ name: 'sun', url: 'images/block-sun.png' },23
var COLOR_SPRITES = ['ember', 'aqua', 'leaf', 'sun', 'orchid'];23
{ name: 'orchid', url: 'images/block-orchid.png' }24
];25
var planets = (typeof Planet !== 'undefined' ? Planet.allPlanets() : []);26
for (var i = 0; i < planets.length; i++)27
{28
var pl = planets[i];29
for (var c = 0; c < pl.colors.length; c++)30
{31
list.push({32
name: Planet.spriteKey(pl, c),33
url: pl.colors[c].image34
});35
}36
}37
return list;38
}39
40
var IMAGES = planetImages();24
var GAME_OVER_DELAY = 2;41
var GAME_OVER_DELAY = 2;25
42
26
var game = new Game();43
var game = new Game();@@ -46,7 +63,9 @@ var app = {46
online: false,63
online: false,47
eliminatedReported: false,64
eliminatedReported: false,48
spectating: false,65
spectating: false,49
miniH: 066
miniH: 0,67
selectedPlanetId: 'terra',68
planetSelectContext: 'solo'50
};69
};51
70
52
window.onload = function ()71
window.onload = function ()@@ -71,13 +90,15 @@ window.onload = function ()71
});90
});72
91
73
bindOnlineUi();92
bindOnlineUi();93
bindPlanetSelect();94
restoreSelectedPlanet();74
};95
};75
96
76
function onPlay ()97
function onPlay ()77
{98
{78
if (app.mode === 'playing')99
if (app.mode === 'playing')79
{ return; }100
{ return; }80
startPlay();101
openPlanetSelect('solo');81
}102
}82
103
83
function startPlay (opts)104
function startPlay (opts)@@ -88,14 +109,15 @@ function startPlay (opts)88
hideEl('online-panel');109
hideEl('online-panel');89
hideEl('spectator');110
hideEl('spectator');90
hideEl('podium');111
hideEl('podium');112
hideEl('planet-select');91
showEl('hud');113
showEl('hud');92
114
93
app.planet = (typeof Planet !== 'undefined' ? Planet.defaultPlanet() : PlanetMod.defaultPlanet());115
var planetMod = typeof Planet !== 'undefined' ? Planet : PlanetMod;116
app.planet = opts.planet || planetMod.planetById(selectedPlanetId());94
var miss = opts.missChance;117
var miss = opts.missChance;95
if (typeof miss === 'number' && isFinite(miss))118
if (typeof miss !== 'number' || !isFinite(miss))96
{ app.core = new GameCore(app.planet, Math.random, miss); }119
{ miss = planetMod.missChance(app.planet); }97
else120
app.core = new GameCore(app.planet, Math.random, miss);98
{ app.core = new GameCore(app.planet, Math.random); }99
app.mode = 'playing';121
app.mode = 'playing';100
app.online = !!opts.online;122
app.online = !!opts.online;101
app.gameOverShown = false;123
app.gameOverShown = false;@@ -164,6 +186,7 @@ function returnToMenu ()164
teardownPlay();186
teardownPlay();165
app.mode = 'menu';187
app.mode = 'menu';166
app.online = false;188
app.online = false;189
hideEl('planet-select');167
showEl('menu');190
showEl('menu');168
var last = document.getElementById('last-score');191
var last = document.getElementById('last-score');169
if (app.lastScore > 0)192
if (app.lastScore > 0)@@ -247,7 +270,8 @@ function spriteFor (block)247
{ return game.images.locked; }270
{ return game.images.locked; }248
if (block.color < 0)271
if (block.color < 0)249
{ return game.images.gray; }272
{ return game.images.gray; }250
return game.images[COLOR_SPRITES[block.color]] || game.images.gray;273
var key = Planet.spriteKey(app.planet, block.color);274
return game.images[key] || game.images.gray;251
}275
}252
276
253
function syncSprites ()277
function syncSprites ()@@ -406,10 +430,7 @@ function refreshHud ()406
document.getElementById('score').textContent = String(app.core.score);430
document.getElementById('score').textContent = String(app.core.score);407
var planet = app.planet;431
var planet = app.planet;408
document.getElementById('planet-name').textContent = planet.name + ' · ' + planet.people;432
document.getElementById('planet-name').textContent = planet.name + ' · ' + planet.people;409
var d = Planet.displayValues(planet);433
document.getElementById('planet-stats').textContent = Planet.formatStats(planet);410
document.getElementById('planet-stats').textContent =411
'g ' + d.gravity.toFixed(2) + ' d ' + d.density.toFixed(2) +412
' F ' + Math.round(d.newtons) + ' N Power ' + d.power + '%';413
}434
}414
435
415
function makeManager ()436
function makeManager ()@@ -687,10 +708,11 @@ function startOnlineMatch ()687
{708
{688
if (app.mode === 'playing' && app.online)709
if (app.mode === 'playing' && app.online)689
{ return; }710
{ return; }690
var miss = (typeof Online !== 'undefined' && Online.lobby && Online.lobby.miss_chance != null)711
var planet = Planet.planetById(selectedPlanetId());691
? Online.lobby.miss_chance712
var me = (typeof Online !== 'undefined' && Online.mePlayer) ? Online.mePlayer() : null;692
: (typeof Online !== 'undefined' ? Online.DEFAULT_MISS_CHANCE : 0.30);713
if (me && me.planet && me.planet.id)693
startPlay({ online: true, missChance: miss });714
{ planet = Planet.planetById(me.planet.id); }715
startPlay({ online: true, planet: planet, missChance: Planet.missChance(planet) });694
if (typeof Online !== 'undefined')716
if (typeof Online !== 'undefined')695
{ Online.startPolling(onlinePayload); }717
{ Online.startPolling(onlinePayload); }696
}718
}@@ -847,6 +869,7 @@ function openOnlinePanel ()847
hideEl('game-over');869
hideEl('game-over');848
hideEl('podium');870
hideEl('podium');849
hideEl('spectator');871
hideEl('spectator');872
hideEl('planet-select');850
showEl('online-panel');873
showEl('online-panel');851
app.mode = 'online';874
app.mode = 'online';852
setOnlineStatus('Even kijken of online spelen beschikbaar is…');875
setOnlineStatus('Even kijken of online spelen beschikbaar is…');@@ -948,10 +971,14 @@ function renderOnline ()948
{ li.classList.add('you'); }971
{ li.classList.add('you'); }949
var label = p.name + (p.is_host ? ' (host)' : '') + (p.is_me ? ' (jij)' : '');972
var label = p.name + (p.is_host ? ' (host)' : '') + (p.is_me ? ' (jij)' : '');950
var state = p.ready ? 'Gereed' : 'Wacht…';973
var state = p.ready ? 'Gereed' : 'Wacht…';951
li.innerHTML = '<span>' + escapeText(label) + '</span><span class="'974
var world = (p.planet && p.planet.name) ? (p.planet.name + ' · ' + p.planet.people) : '';975
li.innerHTML = '<span>' + escapeText(label)976
+ (world ? '<span class="planet-tag">' + escapeText(world) + '</span>' : '')977
+ '</span><span class="'952
+ (p.ready ? 'ready' : 'waiting') + '">' + state + '</span>';978
+ (p.ready ? 'ready' : 'waiting') + '">' + state + '</span>';953
list.appendChild(li);979
list.appendChild(li);954
}980
}981
renderPlanetGrid('lobby-planet-grid', true);955
var me = Online.mePlayer();982
var me = Online.mePlayer();956
document.getElementById('btn-ready').textContent = (me && me.ready) ? 'Niet gereed' : 'Gereed';983
document.getElementById('btn-ready').textContent = (me && me.ready) ? 'Niet gereed' : 'Gereed';957
var start = document.getElementById('btn-start');984
var start = document.getElementById('btn-start');@@ -984,3 +1011,147 @@ function escapeText (s)984
.replace(/>/g, '>')1011
.replace(/>/g, '>')985
.replace(/"/g, '"');1012
.replace(/"/g, '"');986
}1013
}1014
1015
1016
function selectedPlanetId ()1017
{1018
if (app.selectedPlanetId)1019
{ return app.selectedPlanetId; }1020
return 'terra';1021
}1022
1023
function restoreSelectedPlanet ()1024
{1025
var id = 'terra';1026
try1027
{ id = localStorage.getItem('meteors-planet') || 'terra'; }1028
catch (e) {}1029
setSelectedPlanet(id, true);1030
}1031
1032
function setSelectedPlanet (id, silent)1033
{1034
var all = Planet.allPlanets();1035
var found = null;1036
for (var i = 0; i < all.length; i++)1037
{1038
if (all[i].id === id)1039
{ found = all[i]; break; }1040
}1041
if (!found)1042
{ found = Planet.defaultPlanet(); }1043
app.selectedPlanetId = found.id;1044
try1045
{ localStorage.setItem('meteors-planet', found.id); }1046
catch (e) {}1047
if (!silent)1048
{1049
var grid = document.getElementById('planet-grid');1050
if (grid && !grid.hidden && grid.children.length)1051
{ renderPlanetGrid('planet-grid', false); }1052
var lobby = document.getElementById('lobby-planet-grid');1053
if (lobby && lobby.children.length)1054
{ renderPlanetGrid('lobby-planet-grid', true); }1055
}1056
return found;1057
}1058
1059
function openPlanetSelect (context)1060
{1061
if (app.mode === 'playing')1062
{ return; }1063
app.planetSelectContext = context || 'solo';1064
app.mode = 'planet-select';1065
hideEl('menu');1066
hideEl('online-panel');1067
hideEl('game-over');1068
showEl('planet-select');1069
renderPlanetGrid('planet-grid', false);1070
var go = document.getElementById('btn-planet-go');1071
if (go)1072
{ go.textContent = 'Spelen'; }1073
}1074
1075
function renderPlanetGrid (containerId, compact)1076
{1077
var grid = document.getElementById(containerId);1078
if (!grid)1079
{ return; }1080
var current = selectedPlanetId();1081
var all = Planet.allPlanets();1082
grid.innerHTML = '';1083
if (compact)1084
{ grid.classList.add('compact'); }1085
for (var i = 0; i < all.length; i++)1086
{1087
var pl = all[i];1088
var btn = document.createElement('button');1089
btn.type = 'button';1090
btn.className = 'planet-card' + (pl.id === current ? ' selected' : '');1091
btn.setAttribute('role', 'listitem');1092
btn.dataset.planet = pl.id;1093
var swatches = '';1094
for (var c = 0; c < pl.colors.length; c++)1095
{1096
swatches += '<img src="' + escapeText(pl.colors[c].image) + '" alt="'1097
+ escapeText(pl.colors[c].name) + '" title="' + escapeText(pl.colors[c].name) + '">';1098
}1099
btn.innerHTML = '<div class="planet-title">' + escapeText(pl.name) + '</div>'1100
+ '<div class="planet-people">' + escapeText(pl.people) + '</div>'1101
+ '<div class="planet-nums">' + escapeText(Planet.formatStats(pl)) + '</div>'1102
+ '<div class="planet-swatches">' + swatches + '</div>';1103
btn.addEventListener('click', (function (id, isCompact)1104
{1105
return function ()1106
{ onPlanetPicked(id, isCompact); };1107
})(pl.id, !!compact));1108
grid.appendChild(btn);1109
}1110
}1111
1112
function onPlanetPicked (id, fromLobby)1113
{1114
setSelectedPlanet(id);1115
if (fromLobby && typeof Online !== 'undefined' && Online.lobby)1116
{1117
Online.setPlanet(id).then(function ()1118
{ renderOnline(); });1119
}1120
else1121
{1122
renderPlanetGrid('planet-grid', false);1123
}1124
}1125
1126
function confirmPlanetSelect ()1127
{1128
var planet = setSelectedPlanet(selectedPlanetId());1129
hideEl('planet-select');1130
if (app.planetSelectContext === 'online')1131
{1132
openOnlinePanel();1133
return;1134
}1135
startPlay({ planet: planet });1136
}1137
1138
function cancelPlanetSelect ()1139
{1140
hideEl('planet-select');1141
app.mode = 'menu';1142
showEl('menu');1143
}1144
1145
function bindPlanetSelect ()1146
{1147
var go = document.getElementById('btn-planet-go');1148
var back = document.getElementById('btn-planet-back');1149
if (go)1150
{1151
go.addEventListener('click', confirmPlanetSelect);1152
}1153
if (back)1154
{1155
back.addEventListener('click', cancelPlanetSelect);1156
}1157
}@@ -115,14 +115,25 @@ Online.testLogin = function (who)
115
115
return this.request('test_login', { user: who });
116
116
};
117
117
118
Online.createLobby = function ()
118
Online.createLobby = function (planetId)
119
119
{
120
return this.request('lobby_create', { miss_chance: this.DEFAULT_MISS_CHANCE });
120
return this.request('lobby_create', {
121
miss_chance: this.DEFAULT_MISS_CHANCE,
122
planet_id: planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')
123
});
124
};
125
126
Online.joinLobby = function (code, planetId)
127
{
128
return this.request('lobby_join', {
129
code: code,
130
planet_id: planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')
131
});
121
132
};
122
133
123
Online.joinLobby = function (code)
134
Online.setPlanet = function (planetId)
124
135
{
125
return this.request('lobby_join', { code: code });
136
return this.request('lobby_set_planet', { planet_id: planetId });
126
137
};
127
138
128
139
Online.leaveLobby = function ()
@@ -289,7 +300,7 @@ Online.renderMinis = function (container)
289
300
el.querySelector('.mini-meta').textContent = p.eliminated
290
301
? ('Uit' + (p.place ? ' · ' + p.place + 'e' : ''))
291
302
: ('Punten ' + (p.score || 0));
292
this._drawMini(el.querySelector('canvas'), p.snapshot);
303
this._drawMini(el.querySelector('canvas'), p.snapshot, p.planet);
293
304
}
294
305
for (var id in existing)
295
306
{
@@ -300,7 +311,15 @@ Online.renderMinis = function (container)
300
311
301
312
var MINI_COLORS = ['#d4553a', '#3a9ad4', '#4caf6a', '#e6c04a', '#b86ad4'];
302
313
303
Online._drawMini = function (canvas, snapshot)
314
function miniColor (planet, color)
315
{
316
if (planet && planet.colors && planet.colors[color] && planet.colors[color].hex)
317
{ return planet.colors[color].hex; }
318
return MINI_COLORS[color] || '#888';
319
}
320
321
322
Online._drawMini = function (canvas, snapshot, planet)
304
323
{
305
324
if (!canvas)
306
325
{ return; }
@@ -340,7 +359,7 @@ Online._drawMini = function (canvas, snapshot)
340
359
else if (b.color < 0)
341
360
{ ctx.fillStyle = '#5a5d66'; }
342
361
else
343
{ ctx.fillStyle = MINI_COLORS[b.color] || '#888'; }
362
{ ctx.fillStyle = miniColor(planet, b.color); }
344
363
ctx.fillRect(x + 0.5, y + 0.5, tw - 1, th - 1);
345
364
}
346
365
};
@@ -352,12 +371,16 @@ Online.miniElement = function (playerId)
352
371
353
372
/* ---------- flight tweens ------------------------------------------ */
354
373
355
function colorSpriteUrl (color)
374
function colorSpriteUrl (color, planetId)
356
375
{
357
376
if (color < 0)
358
377
{ return 'images/block-gray.png'; }
359
var names = ['ember', 'aqua', 'leaf', 'sun', 'orchid'];
360
return 'images/block-' + (names[color] || 'gray') + '.png';
378
var planet = null;
379
if (typeof Planet !== 'undefined')
380
{ planet = Planet.planetById(planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')); }
381
if (planet && planet.colors && planet.colors[color] && planet.colors[color].image)
382
{ return planet.colors[color].image; }
383
return 'images/block-gray.png';
361
384
}
362
385
363
386
/**
@@ -115,14 +115,25 @@ Online.testLogin = function (who)115
return this.request('test_login', { user: who });115
return this.request('test_login', { user: who });116
};116
};117
117
118
Online.createLobby = function ()118
Online.createLobby = function (planetId)119
{119
{120
return this.request('lobby_create', { miss_chance: this.DEFAULT_MISS_CHANCE });120
return this.request('lobby_create', {121
miss_chance: this.DEFAULT_MISS_CHANCE,122
planet_id: planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')123
});124
};125
126
Online.joinLobby = function (code, planetId)127
{128
return this.request('lobby_join', {129
code: code,130
planet_id: planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')131
});121
};132
};122
133
123
Online.joinLobby = function (code)134
Online.setPlanet = function (planetId)124
{135
{125
return this.request('lobby_join', { code: code });136
return this.request('lobby_set_planet', { planet_id: planetId });126
};137
};127
138
128
Online.leaveLobby = function ()139
Online.leaveLobby = function ()@@ -289,7 +300,7 @@ Online.renderMinis = function (container)289
el.querySelector('.mini-meta').textContent = p.eliminated300
el.querySelector('.mini-meta').textContent = p.eliminated290
? ('Uit' + (p.place ? ' · ' + p.place + 'e' : ''))301
? ('Uit' + (p.place ? ' · ' + p.place + 'e' : ''))291
: ('Punten ' + (p.score || 0));302
: ('Punten ' + (p.score || 0));292
this._drawMini(el.querySelector('canvas'), p.snapshot);303
this._drawMini(el.querySelector('canvas'), p.snapshot, p.planet);293
}304
}294
for (var id in existing)305
for (var id in existing)295
{306
{@@ -300,7 +311,15 @@ Online.renderMinis = function (container)300
311
301
var MINI_COLORS = ['#d4553a', '#3a9ad4', '#4caf6a', '#e6c04a', '#b86ad4'];312
var MINI_COLORS = ['#d4553a', '#3a9ad4', '#4caf6a', '#e6c04a', '#b86ad4'];302
313
303
Online._drawMini = function (canvas, snapshot)314
function miniColor (planet, color)315
{316
if (planet && planet.colors && planet.colors[color] && planet.colors[color].hex)317
{ return planet.colors[color].hex; }318
return MINI_COLORS[color] || '#888';319
}320
321
322
Online._drawMini = function (canvas, snapshot, planet)304
{323
{305
if (!canvas)324
if (!canvas)306
{ return; }325
{ return; }@@ -340,7 +359,7 @@ Online._drawMini = function (canvas, snapshot)340
else if (b.color < 0)359
else if (b.color < 0)341
{ ctx.fillStyle = '#5a5d66'; }360
{ ctx.fillStyle = '#5a5d66'; }342
else361
else343
{ ctx.fillStyle = MINI_COLORS[b.color] || '#888'; }362
{ ctx.fillStyle = miniColor(planet, b.color); }344
ctx.fillRect(x + 0.5, y + 0.5, tw - 1, th - 1);363
ctx.fillRect(x + 0.5, y + 0.5, tw - 1, th - 1);345
}364
}346
};365
};@@ -352,12 +371,16 @@ Online.miniElement = function (playerId)352
371
353
/* ---------- flight tweens ------------------------------------------ */372
/* ---------- flight tweens ------------------------------------------ */354
373
355
function colorSpriteUrl (color)374
function colorSpriteUrl (color, planetId)356
{375
{357
if (color < 0)376
if (color < 0)358
{ return 'images/block-gray.png'; }377
{ return 'images/block-gray.png'; }359
var names = ['ember', 'aqua', 'leaf', 'sun', 'orchid'];378
var planet = null;360
return 'images/block-' + (names[color] || 'gray') + '.png';379
if (typeof Planet !== 'undefined')380
{ planet = Planet.planetById(planetId || (typeof selectedPlanetId === 'function' ? selectedPlanetId() : 'terra')); }381
if (planet && planet.colors && planet.colors[color] && planet.colors[color].image)382
{ return planet.colors[color].image; }383
return 'images/block-gray.png';361
}384
}362
385
363
/**386
/**