-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPixelReveal.html
More file actions
750 lines (661 loc) · 23.4 KB
/
Copy pathPixelReveal.html
File metadata and controls
750 lines (661 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pixel Reveal</title>
<script type="application/json" id="homeglow-manifest">
{
"manifestVersion": 1,
"id": "pixel-reveal",
"name": "Pixel Reveal",
"description": "A daily guessing game. A heavily pixelated emoji sharpens step by step, and the goal is to name it from four choices before it is fully revealed. One puzzle a day, with a streak for consecutive solves."
}
</script>
<link rel="stylesheet" href="/index.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Nunito:wght@500;600;700;800&display=swap');
* {
background: transparent !important;
background-color: transparent !important;
background-image: none !important;
box-sizing: border-box;
}
body {
background: transparent !important;
font-family: 'Nunito', sans-serif;
margin: 0;
padding: 0.75rem;
font-size: 0.85rem;
color: #2c2c2c;
}
[data-theme="dark"] body { color: #a6a6d1; }
.widget-container {
background: transparent !important;
border: none !important;
box-shadow: none !important;
backdrop-filter: none !important;
border-radius: 12px;
padding: 0.5rem;
width: 100%;
max-height: calc(100vh - 1.5rem);
overflow-y: auto;
}
/* ── Header ── */
.widget-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.75rem;
}
.widget-title {
font-family: 'Press Start 2P', monospace;
font-size: 0.75rem;
margin: 0;
color: inherit;
line-height: 1.4;
letter-spacing: 0.02em;
}
.date-badge {
font-size: 0.65rem;
font-weight: 700;
padding: 0.25rem 0.6rem;
border-radius: 20px;
border: 1px solid rgba(128,128,128,0.2);
opacity: 0.6;
white-space: nowrap;
}
/* ── Pixel canvas area ── */
.canvas-wrap {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 0.75rem;
position: relative;
}
#pixelCanvas {
border-radius: 8px;
image-rendering: pixelated;
image-rendering: crisp-edges;
display: block;
box-shadow: 0 4px 20px rgba(0,0,0,0.2);
border: 2px solid rgba(128,128,128,0.15);
}
/* Scanline overlay for retro feel */
.scanlines {
position: absolute;
inset: 0;
border-radius: 8px;
background: repeating-linear-gradient(
0deg,
transparent,
transparent 2px,
rgba(0,0,0,0.03) 2px,
rgba(0,0,0,0.03) 4px
) !important;
pointer-events: none;
}
/* ── Reveal progress ── */
.reveal-track {
display: flex;
justify-content: center;
gap: 0.4rem;
margin-bottom: 0.75rem;
}
.reveal-pip {
width: 10px;
height: 10px;
border-radius: 2px;
border: 1px solid rgba(128,128,128,0.3);
transition: all 0.3s;
background: rgba(128,128,128,0.15) !important;
}
.reveal-pip.wrong {
background: #ff6b6b !important;
border-color: #ff6b6b;
}
.reveal-pip.reveal {
background: #00ddeb !important;
border-color: #00ddeb;
animation: pipPop 0.3s cubic-bezier(0.175,0.885,0.32,1.275) both;
}
@keyframes pipPop {
0% { transform: scale(0); }
100% { transform: scale(1); }
}
/* ── Category chip ── */
.category-chip {
text-align: center;
font-size: 0.65rem;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
opacity: 0.4;
margin-bottom: 0.6rem;
font-family: 'Press Start 2P', monospace;
}
/* ── Multiple choice ── */
.choices {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.4rem;
margin-bottom: 0.75rem;
}
.choice-btn {
padding: 0.6rem 0.5rem;
border: 2px solid rgba(128,128,128,0.2);
border-radius: 10px;
cursor: pointer;
font-family: 'Nunito', sans-serif;
font-size: 0.82rem;
font-weight: 700;
text-align: center;
transition: all 0.2s;
background: rgba(255,255,255,0.05) !important;
color: inherit;
line-height: 1.3;
}
[data-theme="dark"] .choice-btn {
background: rgba(30,30,50,0.2) !important;
}
.choice-btn:hover:not(:disabled) {
transform: translateY(-2px);
border-color: #00ddeb;
background: rgba(0,221,235,0.08) !important;
}
.choice-btn:disabled { cursor: default; pointer-events: none; }
.choice-btn.correct {
background: rgba(6,214,160,0.2) !important;
border-color: #06d6a0;
color: #06d6a0;
}
.choice-btn.wrong-pick {
background: rgba(255,107,107,0.15) !important;
border-color: #ff6b6b;
color: #ff6b6b;
opacity: 0.7;
}
.choice-btn.reveal-correct {
background: rgba(6,214,160,0.1) !important;
border-color: rgba(6,214,160,0.4);
color: #06d6a0;
opacity: 0.6;
}
/* ── Status ── */
.status-msg {
text-align: center;
font-family: 'Press Start 2P', monospace;
font-size: 0.6rem;
line-height: 1.6;
margin-bottom: 0.6rem;
min-height: 1rem;
color: inherit;
}
.status-msg.win { color: #06d6a0; }
.status-msg.lose { color: #ff6b6b; }
/* ── Next round / come back tomorrow ── */
.next-btn {
display: block;
width: 100%;
background: linear-gradient(45deg, #00ddeb, #06d6a0) !important;
color: #fff !important;
border: none;
border-radius: 10px;
padding: 0.65rem;
font-family: 'Press Start 2P', monospace;
font-size: 0.6rem;
cursor: pointer;
transition: filter 0.2s, transform 0.2s;
margin-bottom: 0.5rem;
line-height: 1.6;
}
[data-theme="dark"] .next-btn {
background: linear-gradient(45deg, #2e2767, #014d39) !important;
color: #a6a6d1 !important;
}
.next-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.next-btn.hidden { display: none; }
/* ── Come back tomorrow ── */
.tomorrow-msg {
text-align: center;
font-family: 'Press Start 2P', monospace;
font-size: 0.55rem;
line-height: 1.8;
opacity: 0.5;
margin-top: 0.5rem;
}
/* ── Streak ── */
.streak-row {
display: flex;
justify-content: center;
align-items: center;
gap: 0.5rem;
font-size: 0.72rem;
font-weight: 700;
opacity: 0.6;
margin-top: 0.25rem;
}
/* ── Hidden offscreen emoji renderer ── */
#emojiRenderer {
position: fixed;
left: -9999px;
top: -9999px;
width: 200px;
height: 200px;
}
/* ── Confetti ── */
@keyframes confettiFall {
0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
100% { transform: translateY(140px) rotate(720deg); opacity: 0; }
}
.confetti-piece {
position: fixed;
width: 9px;
height: 9px;
pointer-events: none;
animation: confettiFall 1.3s ease-out forwards;
z-index: 999;
}
/* ── Loading ── */
.loading-msg {
text-align: center;
font-family: 'Press Start 2P', monospace;
font-size: 0.55rem;
opacity: 0.5;
padding: 2rem 0;
line-height: 2;
animation: blink 1.2s step-end infinite;
}
@keyframes blink {
0%,100% { opacity: 0.5; }
50% { opacity: 0.15; }
}
/* shake animation for wrong guess */
@keyframes shake {
0%,100% { transform: translateX(0); }
20% { transform: translateX(-6px); }
40% { transform: translateX(6px); }
60% { transform: translateX(-4px); }
80% { transform: translateX(4px); }
}
.shake { animation: shake 0.4s ease; }
</style>
</head>
<body>
<div class="widget-container">
<div class="widget-header">
<h1 class="widget-title">PIXEL<br>REVEAL</h1>
<div class="date-badge" id="dateBadge"></div>
</div>
<div id="mainContent">
<div class="loading-msg">LOADING...</div>
</div>
<!-- Hidden canvas for emoji rendering -->
<canvas id="emojiRenderer"></canvas>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// ── Theme ──
const params = new URLSearchParams(window.location.search);
const th = params.get('theme');
if (th === 'dark' || th === 'light') document.documentElement.setAttribute('data-theme', th);
const TODAY = new Date().toISOString().split('T')[0];
const dayNum = Math.floor((new Date(TODAY) - new Date('2024-01-01')) / 86400000);
document.getElementById('dateBadge').textContent = new Date().toLocaleDateString('en-US', {
month: 'short', day: 'numeric'
});
// ── Emoji bank ── organised by category
const EMOJI_BANK = {
Animals: [
{ emoji: '🦊', name: 'Fox' }, { emoji: '🐘', name: 'Elephant' },
{ emoji: '🦁', name: 'Lion' }, { emoji: '🐧', name: 'Penguin' },
{ emoji: '🦋', name: 'Butterfly' }, { emoji: '🐬', name: 'Dolphin' },
{ emoji: '🦒', name: 'Giraffe' }, { emoji: '🐙', name: 'Octopus' },
{ emoji: '🦅', name: 'Eagle' }, { emoji: '🐻', name: 'Bear' },
{ emoji: '🦈', name: 'Shark' }, { emoji: '🐊', name: 'Crocodile' },
{ emoji: '🦩', name: 'Flamingo' }, { emoji: '🐺', name: 'Wolf' },
{ emoji: '🦚', name: 'Peacock' }, { emoji: '🐸', name: 'Frog' },
{ emoji: '🦦', name: 'Otter' }, { emoji: '🐢', name: 'Turtle' },
{ emoji: '🦜', name: 'Parrot' }, { emoji: '🐳', name: 'Whale' },
{ emoji: '🦝', name: 'Raccoon' }, { emoji: '🐆', name: 'Leopard' },
{ emoji: '🦌', name: 'Deer' }, { emoji: '🐓', name: 'Rooster' },
],
Food: [
{ emoji: '🍕', name: 'Pizza' }, { emoji: '🍣', name: 'Sushi' },
{ emoji: '🌮', name: 'Taco' }, { emoji: '🍩', name: 'Doughnut' },
{ emoji: '🍦', name: 'Ice Cream' }, { emoji: '🥐', name: 'Croissant' },
{ emoji: '🍔', name: 'Burger' }, { emoji: '🍜', name: 'Noodles' },
{ emoji: '🥑', name: 'Avocado' }, { emoji: '🍓', name: 'Strawberry' },
{ emoji: '🥞', name: 'Pancakes' }, { emoji: '🍰', name: 'Cake' },
{ emoji: '🥨', name: 'Pretzel' }, { emoji: '🌯', name: 'Burrito' },
{ emoji: '🍍', name: 'Pineapple' }, { emoji: '🍇', name: 'Grapes' },
{ emoji: '🥝', name: 'Kiwi' }, { emoji: '🫐', name: 'Blueberries' },
{ emoji: '🍒', name: 'Cherries' }, { emoji: '🥭', name: 'Mango' },
],
Objects: [
{ emoji: '🎸', name: 'Guitar' }, { emoji: '🚀', name: 'Rocket' },
{ emoji: '⚓', name: 'Anchor' }, { emoji: '🎭', name: 'Theatre' },
{ emoji: '🔭', name: 'Telescope' }, { emoji: '🎺', name: 'Trumpet' },
{ emoji: '🏆', name: 'Trophy' }, { emoji: '🎪', name: 'Circus' },
{ emoji: '⛵', name: 'Sailboat' }, { emoji: '🎻', name: 'Violin' },
{ emoji: '🔬', name: 'Microscope' }, { emoji: '🗺️', name: 'Map' },
{ emoji: '🧲', name: 'Magnet' }, { emoji: '🎯', name: 'Dartboard' },
{ emoji: '🛸', name: 'UFO' }, { emoji: '⚗️', name: 'Flask' },
{ emoji: '🎠', name: 'Carousel' }, { emoji: '🗼', name: 'Tower' },
{ emoji: '🧩', name: 'Puzzle' }, { emoji: '🎡', name: 'Ferris Wheel' },
],
Nature: [
{ emoji: '🌋', name: 'Volcano' }, { emoji: '🌊', name: 'Wave' },
{ emoji: '🌈', name: 'Rainbow' }, { emoji: '❄️', name: 'Snowflake' },
{ emoji: '🌵', name: 'Cactus' }, { emoji: '🍄', name: 'Mushroom' },
{ emoji: '🌸', name: 'Cherry Blossom' }, { emoji: '⚡', name: 'Lightning' },
{ emoji: '🌍', name: 'Earth' }, { emoji: '🌙', name: 'Moon' },
{ emoji: '☄️', name: 'Comet' }, { emoji: '🌺', name: 'Hibiscus' },
{ emoji: '🍁', name: 'Maple Leaf' }, { emoji: '🌿', name: 'Herb' },
{ emoji: '🪸', name: 'Coral' }, { emoji: '🌾', name: 'Wheat' },
],
Places: [
{ emoji: '🏰', name: 'Castle' }, { emoji: '🗽', name: 'Statue of Liberty' },
{ emoji: '🏯', name: 'Japanese Castle' }, { emoji: '⛩️', name: 'Shrine' },
{ emoji: '🕌', name: 'Mosque' }, { emoji: '🎡', name: 'Amusement Park' },
{ emoji: '🏟️', name: 'Stadium' }, { emoji: '🗿', name: 'Moai' },
{ emoji: '⛪', name: 'Church' }, { emoji: '🏛️', name: 'Colosseum' },
{ emoji: '🎠', name: 'Merry-Go-Round' }, { emoji: '🌁', name: 'Foggy City' },
],
};
const CATEGORIES = Object.keys(EMOJI_BANK);
// ── Pixel levels: block sizes from most to least pixelated ──
// We render at 200x200 then display scaled, block size controls pixelation
const BLOCK_SIZES = [40, 28, 20, 14, 10, 1]; // index 0 = max pixelated, 5 = clear
const MAX_WRONG = 5; // wrong guesses before fully revealed + loss
// ── State ──
let todayEntry = null; // { emoji, name, category, choices }
let wrongCount = 0;
let gameOver = false;
let currentBlockIdx = 0; // starts at most pixelated
let gameResult = null; // 'win' | 'lose' | null
let emojiImageData = null; // cached ImageData of emoji at 200x200
// ── Persist state per day ──
function loadState() {
try {
const s = JSON.parse(localStorage.getItem('pixelReveal_state') || 'null');
if (s && s.date === TODAY) return s;
} catch(e) {}
return null;
}
function saveState() {
localStorage.setItem('pixelReveal_state', JSON.stringify({
date: TODAY,
wrongCount,
gameOver,
gameResult,
currentBlockIdx,
entryName: todayEntry.name,
entryEmoji: todayEntry.emoji,
entryCategory: todayEntry.category,
entryChoices: todayEntry.choices,
}));
}
function loadStreak() {
try { return JSON.parse(localStorage.getItem('pixelReveal_streak') || '{"count":0,"lastWin":""}'); }
catch(e) { return { count: 0, lastWin: '' }; }
}
function saveStreak(won) {
const streak = loadStreak();
const yesterday = new Date(TODAY);
yesterday.setDate(yesterday.getDate() - 1);
const yStr = yesterday.toISOString().split('T')[0];
if (won) {
streak.count = (streak.lastWin === yStr || streak.lastWin === TODAY) ? streak.count + (streak.lastWin === TODAY ? 0 : 1) : 1;
streak.lastWin = TODAY;
} else {
if (streak.lastWin !== TODAY) streak.count = 0;
}
localStorage.setItem('pixelReveal_streak', JSON.stringify(streak));
}
// ── Pick today's emoji deterministically ──
function pickTodayEntry() {
const catIndex = dayNum % CATEGORIES.length;
const category = CATEGORIES[catIndex];
const bank = EMOJI_BANK[category];
const emojiIndex = Math.floor(dayNum / CATEGORIES.length) % bank.length;
const correct = bank[emojiIndex];
// Build choices: 1 correct + 3 wrong from same + adjacent categories
const allWrong = [];
CATEGORIES.forEach(cat => {
EMOJI_BANK[cat].forEach(e => {
if (e.name !== correct.name) allWrong.push({ ...e, cat });
});
});
// Prefer same category for wrong answers (harder)
const sameCategory = allWrong.filter(e => e.cat === category);
const otherCategory = allWrong.filter(e => e.cat !== category);
// Seed-based shuffle for consistency
function seededShuffle(arr, seed) {
const a = [...arr];
for (let i = a.length - 1; i > 0; i--) {
seed = (seed * 1664525 + 1013904223) & 0xffffffff;
const j = Math.abs(seed) % (i + 1);
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
const shuffledSame = seededShuffle(sameCategory, dayNum + 1);
const shuffledOther = seededShuffle(otherCategory, dayNum + 2);
const wrongPool = [...shuffledSame, ...shuffledOther];
const wrongChoices = wrongPool.slice(0, 3).map(e => ({ emoji: e.emoji, name: e.name }));
// Build 4 choices and shuffle
const allChoices = [{ emoji: correct.emoji, name: correct.name, correct: true }, ...wrongChoices.map(c => ({ ...c, correct: false }))];
const shuffledChoices = seededShuffle(allChoices, dayNum + 3);
return {
emoji: correct.emoji,
name: correct.name,
category,
choices: shuffledChoices,
};
}
// ── Render emoji to canvas, get ImageData ──
function renderEmojiToImageData(emoji) {
return new Promise(resolve => {
const offscreen = document.getElementById('emojiRenderer');
offscreen.width = 200;
offscreen.height = 200;
const ctx = offscreen.getContext('2d');
ctx.clearRect(0, 0, 200, 200);
ctx.font = '160px serif';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(emoji, 100, 108);
resolve(ctx.getImageData(0, 0, 200, 200));
});
}
// ── Draw pixelated version onto display canvas ──
function drawPixelated(imageData, blockSize) {
const displaySize = 200;
const canvas = document.getElementById('pixelCanvas');
if (!canvas) return;
canvas.width = displaySize;
canvas.height = displaySize;
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, displaySize, displaySize);
if (blockSize <= 1) {
// Full quality — just draw original
ctx.putImageData(imageData, 0, 0);
return;
}
// Sample pixel colour at block centres, fill blocks
const src = imageData.data;
const srcW = imageData.width; // 200
for (let y = 0; y < displaySize; y += blockSize) {
for (let x = 0; x < displaySize; x += blockSize) {
// Sample from centre of block
const sx = Math.min(x + Math.floor(blockSize / 2), srcW - 1);
const sy = Math.min(y + Math.floor(blockSize / 2), srcW - 1);
const idx = (sy * srcW + sx) * 4;
const r = src[idx];
const g = src[idx + 1];
const b = src[idx + 2];
const a = src[idx + 3];
ctx.fillStyle = `rgba(${r},${g},${b},${a / 255})`;
ctx.fillRect(x, y, blockSize, blockSize);
}
}
}
// ── Full render ──
function renderGame() {
const mc = document.getElementById('mainContent');
mc.innerHTML = '';
// Reveal pips (5 slots)
const track = document.createElement('div');
track.className = 'reveal-track';
for (let i = 0; i < MAX_WRONG; i++) {
const pip = document.createElement('div');
pip.className = 'reveal-pip';
if (i < wrongCount) pip.classList.add('wrong');
track.appendChild(pip);
}
mc.appendChild(track);
// Category
const catChip = document.createElement('div');
catChip.className = 'category-chip';
catChip.textContent = todayEntry.category;
mc.appendChild(catChip);
// Canvas
const wrap = document.createElement('div');
wrap.className = 'canvas-wrap';
const canvas = document.createElement('canvas');
canvas.id = 'pixelCanvas';
canvas.width = 200;
canvas.height = 200;
canvas.style.width = '200px';
canvas.style.height = '200px';
wrap.appendChild(canvas);
const scanlines = document.createElement('div');
scanlines.className = 'scanlines';
wrap.appendChild(scanlines);
mc.appendChild(wrap);
// Draw pixelated image
if (emojiImageData) {
drawPixelated(emojiImageData, BLOCK_SIZES[currentBlockIdx]);
}
// Status
const status = document.createElement('div');
status.className = 'status-msg' + (gameResult === 'win' ? ' win' : gameResult === 'lose' ? ' lose' : '');
if (gameResult === 'win') status.textContent = 'YOU GOT IT!';
else if (gameResult === 'lose') status.textContent = `IT WAS ${todayEntry.name.toUpperCase()}`;
mc.appendChild(status);
// Choices
const choices = document.createElement('div');
choices.className = 'choices';
todayEntry.choices.forEach(choice => {
const btn = document.createElement('button');
btn.className = 'choice-btn';
btn.textContent = `${choice.emoji} ${choice.name}`;
if (gameOver) {
btn.disabled = true;
if (choice.correct) btn.classList.add(gameResult === 'win' ? 'correct' : 'reveal-correct');
}
btn.addEventListener('click', () => handleGuess(choice));
choices.appendChild(btn);
});
mc.appendChild(choices);
// Come back tomorrow / streak
if (gameOver) {
const streak = loadStreak();
if (streak.count > 1) {
const streakRow = document.createElement('div');
streakRow.className = 'streak-row';
streakRow.textContent = `🔥 ${streak.count} day streak`;
mc.appendChild(streakRow);
}
const tmrw = document.createElement('div');
tmrw.className = 'tomorrow-msg';
tmrw.textContent = 'Come back tomorrow\nfor a new image!';
mc.appendChild(tmrw);
}
}
// ── Handle guess ──
function handleGuess(choice) {
if (gameOver) return;
if (choice.correct) {
// WIN
gameOver = true;
gameResult = 'win';
currentBlockIdx = BLOCK_SIZES.length - 1; // fully reveal
saveStreak(true);
saveState();
renderGame();
spawnConfetti();
} else {
// WRONG — reveal more
wrongCount++;
currentBlockIdx = Math.min(currentBlockIdx + 1, BLOCK_SIZES.length - 2);
if (wrongCount >= MAX_WRONG) {
// LOSE — fully reveal
gameOver = true;
gameResult = 'lose';
currentBlockIdx = BLOCK_SIZES.length - 1;
saveStreak(false);
}
saveState();
renderGame();
// Shake the canvas
const wrap = document.querySelector('.canvas-wrap');
if (wrap) {
wrap.classList.add('shake');
setTimeout(() => wrap.classList.remove('shake'), 400);
}
// Update the wrong pip with animation
const pips = document.querySelectorAll('.reveal-pip');
if (pips[wrongCount - 1]) {
pips[wrongCount - 1].classList.add('wrong');
}
if (wrongCount >= MAX_WRONG && !gameOver) {
gameOver = true;
gameResult = 'lose';
currentBlockIdx = BLOCK_SIZES.length - 1;
saveState();
renderGame();
}
}
}
// ── Confetti ──
function spawnConfetti() {
const colors = ['#ff6b6b','#00ddeb','#ffd166','#06d6a0','#a29bfe','#fd79a8'];
for (let i = 0; i < 45; i++) {
const el = document.createElement('div');
el.className = 'confetti-piece';
el.style.cssText = `
left: ${5 + Math.random() * 90}%;
top: ${5 + Math.random() * 40}%;
background: ${colors[i % colors.length]} !important;
background-color: ${colors[i % colors.length]} !important;
animation-delay: ${Math.random() * 0.5}s;
animation-duration: ${1 + Math.random() * 0.6}s;
border-radius: ${Math.random() > 0.5 ? '50%' : '2px'};
`;
document.body.appendChild(el);
setTimeout(() => el.remove(), 2000);
}
}
// ── Init ──
async function init() {
todayEntry = pickTodayEntry();
// Restore saved state if same day
const saved = loadState();
if (saved && saved.entryEmoji === todayEntry.emoji) {
wrongCount = saved.wrongCount;
gameOver = saved.gameOver;
gameResult = saved.gameResult;
currentBlockIdx = saved.currentBlockIdx;
// Restore choices order from saved
todayEntry.choices = saved.entryChoices;
}
// Render emoji offscreen
emojiImageData = await renderEmojiToImageData(todayEntry.emoji);
renderGame();
}
init();
});
</script>
</body>
</html>