/* Kidopia: The Magical Game Shop. Original idea: a young player. A child runs a magic video game shop: customers walk in with game ideas, the owner makes each game on a magic phone, the game flies to the big TV, and everyone plays on the couch. One script, no libraries, no image or sound files: the shop and the people are drawn on a canvas, the game art uses the device's emoji, and every sound is made with the Web Audio API. Rule from the brief: no cats anywhere. */ (function(){'use strict'; /* ================= iPhone sound fix: Web Audio plays even when the phone is on silent ================= */ let AC=null,silentEl=null,master=null,musGain=null,sfxGain=null,noiseBuf=null; function iosUnlock(){ try{if(navigator.audioSession&&navigator.audioSession.type!=='playback')navigator.audioSession.type='playback';}catch(e){} if(!('audioSession' in navigator)){ try{ if(!silentEl){silentEl=new Audio('audio/silence.mp3');silentEl.loop=true;silentEl.setAttribute('playsinline','');} const p=silentEl.play();if(p&&p.catch)p.catch(()=>{}); }catch(e){} } } function wake(){ iosUnlock(); if(AC&&AC.state!=='running'){try{const p=AC.resume();if(p&&p.catch)p.catch(()=>{});}catch(e){}} } ['pointerdown','touchend','click','keydown'].forEach(ev=>document.addEventListener(ev,wake,{passive:true,capture:true})); document.addEventListener('visibilitychange',()=>{if(!document.hidden)wake();}); function initAudio(){ iosUnlock(); if(AC){wake();return;} try{AC=new (window.AudioContext||window.webkitAudioContext)();try{AC.resume();}catch(e){}}catch(e){AC=null;return;} master=AC.createGain();master.gain.value=SAVE.mute?0:0.85;master.connect(AC.destination); musGain=AC.createGain();musGain.gain.value=0.2;musGain.connect(master); sfxGain=AC.createGain();sfxGain.gain.value=0.5;sfxGain.connect(master); noiseBuf=AC.createBuffer(1,Math.floor(AC.sampleRate*0.5),AC.sampleRate); const d=noiseBuf.getChannelData(0);for(let i=0;inote(t+i*.06,f,.12,'triangle',.25));}, door(){if(!live())return;const t=AC.currentTime;note(t,988,.5,'sine',.3);note(t+.22,784,.7,'sine',.3);}, blip(){if(!live())return;const t=AC.currentTime;for(let i=0;i<3;i++)note(t+i*.07,380+Math.random()*260,.06,'square',.06);}, create(){if(!live())return;const t=AC.currentTime;note(t,180,2,'sawtooth',.08,0,1400);note(t,240,2,'triangle',.12,0,1800);for(let i=0;i<12;i++)note(t+i*.16,1200+Math.random()*1400,.12,'sine',.08);}, whoosh(){if(!live())return;const t=AC.currentTime;noise(t,.9,.35,300,1.2,0,4000);for(let i=0;i<8;i++)note(t+i*.1,1500+i*180,.1,'sine',.06);}, tvon(){if(!live())return;const t=AC.currentTime;note(t,90,.35,'sawtooth',.12,0,1600);noise(t+.1,.25,.15,2500,2);}, coin(){if(!live())return;const t=AC.currentTime;note(t,988,.08,'square',.12);note(t+.07,1319,.25,'square',.12);}, collect(){if(!live())return;const t=AC.currentTime;note(t,660,.12,'triangle',.22,0,1320);}, friend(){if(!live())return;const t=AC.currentTime;[784,988,1175,1568].forEach((f,i)=>note(t+i*.06,f,.15,'triangle',.2));}, hit(){if(!live())return;const t=AC.currentTime;note(t,220,.3,'sawtooth',.18,0,70);noise(t,.18,.2,800,1);}, bonk(){if(!live())return;const t=AC.currentTime;note(t,500,.14,'square',.14,0,160);}, jump(){if(!live())return;const t=AC.currentTime;note(t,330,.16,'square',.1,0,700);}, boost(){if(!live())return;const t=AC.currentTime;noise(t,.5,.25,600,1,0,3000);note(t,200,.5,'sawtooth',.08,0,800);}, beep(hi){if(!live())return;note(AC.currentTime,hi?880:440,hi?.4:.15,'square',.14);}, win(){if(!live())return;const t=AC.currentTime;[523,659,784,1047,784,1047].forEach((f,i)=>note(t+i*.11,f,i===5?.6:.16,'triangle',.25));}, star(){if(!live())return;const t=AC.currentTime;[1319,1568,2093].forEach((f,i)=>note(t+i*.09,f,.35,'sine',.18));}, unlock(){if(!live())return;const t=AC.currentTime;[523,659,784,988,1175,1319,1568].forEach((f,i)=>note(t+i*.07,f,.25,'triangle',.18));}, party(){if(!live())return;const t=AC.currentTime;for(let i=0;i<14;i++){noise(t+i*.07,.12,.15,2000+Math.random()*3000,3);note(t+i*.07,600+Math.random()*900,.1,'square',.05);}} }; /* ---- cheerful music, made note by note ---- */ const STY={ shop:{bpm:112,root:60,sc:[0,2,4,5,7,9,11],minor:0,lead:'triangle',drums:1,prog:[0,4,5,3],rest:.4}, happy:{bpm:126,root:62,sc:[0,2,4,5,7,9,11],minor:0,lead:'square',drums:1,prog:[0,3,4,0],rest:.3}, adventure:{bpm:138,root:57,sc:[0,2,3,5,7,8,10],minor:1,lead:'square',drums:1,prog:[0,5,3,4],rest:.25}, space:{bpm:94,root:55,sc:[0,2,4,7,9],minor:0,lead:'sine',drums:0,prog:[0,3,5,4],rest:.45}, calm:{bpm:84,root:65,sc:[0,2,4,7,9],minor:0,lead:'sine',drums:0,prog:[0,3,0,4],rest:.55}, party:{bpm:142,root:60,sc:[0,2,4,7,9],minor:0,lead:'square',drums:2,prog:[0,4,5,3],rest:.2} }; const MAJ=[0,2,4,5,7,9,11],MIN=[0,2,3,5,7,8,10]; const MUS={style:'shop',next:0,step:0,pat:[]}; function mf(m){return 440*Math.pow(2,(m-69)/12);} function setMusic(id){ if(!STY[id])id='shop'; if(MUS.style===id&&MUS.pat.length)return; MUS.style=id;MUS.step=0;const s=STY[id];let d=4;MUS.pat=[]; for(let i=0;i<32;i++){ if(Math.random()9)d=8;MUS.pat.push(d); } if(AC)MUS.next=Math.max(MUS.next,AC.currentTime+0.05); } function musicTick(){ if(!AC||AC.state!=='running')return; if(MUS.next=7?12:0); if(st===0||st===4)note(t,mf(cr-24),sd*1.8,'triangle',.32,musGain); if(st===0)[0,2,4].forEach(k=>{const dd=deg+k;note(t,mf(s.root+cs[dd%7]+12*Math.floor(dd/7)),sd*7,'sine',.05,musGain);}); const p=MUS.pat[i%32]; if(p!=null){const L=s.sc.length;note(t,mf(s.root+12+s.sc[p%L]+12*Math.floor(p/L)),sd*.9,s.lead,s.lead==='square'?.045:.09,musGain);} if(s.drums){ if(st===0||st===4)note(t,150,.14,'sine',.45,musGain,40); if(st===2||st===6)noise(t,.12,.18,1800,.8,musGain); if(s.drums===2||st%2===1)noise(t,.04,.06,7000,1,musGain); } } MUS.next+=sd;MUS.step++; } } /* ================= small helpers ================= */ const rnd=(a,b)=>a+Math.random()*(b-a); const ri=(a,b)=>Math.floor(rnd(a,b+1)); const pick=a=>a[Math.floor(Math.random()*a.length)]; const clamp=(v,a,b)=>vb?b:v; const lerp=(a,b,t)=>a+(b-a)*t; const shuffle=a=>{for(let i=a.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[a[i],a[j]]=[a[j],a[i]];}return a;}; const esc=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); const an=w=>/^[aeiou]/i.test(w)?'an':'a'; const FONT='Fredoka,"Trebuchet MS",sans-serif'; const EMOF='"Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif'; /* ================= what can go into a game ================= */ const HEROES=[ {id:'unicorn',n:'Unicorn',e:'๐Ÿฆ„'},{id:'dragon',n:'Dragon',e:'๐Ÿ‰'},{id:'mermaid',n:'Mermaid',e:'๐Ÿงœโ€โ™€๏ธ'}, {id:'astronaut',n:'Astronaut',e:'๐Ÿง‘โ€๐Ÿš€'},{id:'princess',n:'Princess',e:'๐Ÿ‘ธ'},{id:'superhero',n:'Superhero',e:'๐Ÿฆธ'}, {id:'robot',n:'Robot',e:'๐Ÿค–'},{id:'puppy',n:'Puppy',e:'๐Ÿถ'},{id:'bunny',n:'Bunny',e:'๐Ÿฐ'}, {id:'penguin',n:'Penguin',e:'๐Ÿง'},{id:'parrot',n:'Pirate Parrot',e:'๐Ÿฆœ'},{id:'dino',n:'Dino',e:'๐Ÿฆ•'}, {id:'bear',n:'Bear',e:'๐Ÿป'}, {id:'panda',n:'Panda',e:'๐Ÿผ',u:1},{id:'octopus',n:'Octopus',e:'๐Ÿ™',u:1},{id:'owl',n:'Owl',e:'๐Ÿฆ‰',u:1},{id:'frog',n:'Frog',e:'๐Ÿธ',u:1} ]; const WORLDS=[ {id:'rainbow',n:'Rainbow Land',s:'Rainbow',e:'๐ŸŒˆ',sky:['#7fd8ff','#ffd6f5'],gr:'#8be08b',gr2:'#ff9ad5',deco:['๐ŸŒˆ','โ˜๏ธ','๐ŸŒธ'],items:['โญ','๐Ÿ’Ž','๐Ÿ“'],haz:'โ›ˆ๏ธ',marks:['๐ŸŽ ','๐Ÿฐ','๐ŸŽก','๐ŸŒป','๐ŸŽช'],mus:'happy'}, {id:'candy',n:'Candy Kingdom',s:'Candy',e:'๐Ÿญ',sky:['#ffb3e6','#fff0b3'],gr:'#ff8fc8',gr2:'#fff4fb',deco:['๐Ÿญ','๐Ÿฌ'],items:['๐Ÿฌ','๐Ÿญ','๐Ÿซ'],haz:'๐ŸŒถ๏ธ',marks:['๐Ÿฐ','๐Ÿญ','๐ŸŽ‚','๐Ÿช','๐Ÿฉ'],mus:'party'}, {id:'ocean',n:'Under the Sea',s:'Ocean',e:'๐Ÿ ',sky:['#1ec8e8','#0a4f9e'],gr:'#f2d98c',gr2:'#e0bf62',deco:['๐Ÿก','๐Ÿ ','๐ŸŸ'],items:['๐Ÿš','๐Ÿ’Ž','๐Ÿช™'],haz:'๐Ÿฆ€',marks:['๐Ÿ™','๐Ÿณ','๐Ÿข','๐Ÿฆญ','๐Ÿฌ'],mus:'calm'}, {id:'space',n:'Outer Space',s:'Space',e:'๐Ÿš€',sky:['#0b0630','#3a1a7a'],gr:'#5b4b9a',gr2:'#8a7bd0',deco:['โœจ','๐Ÿช','๐ŸŒ™'],items:['โญ','๐Ÿ’ซ','๐ŸŒŸ'],haz:'โ˜„๏ธ',marks:['๐Ÿช','๐Ÿ›ธ','๐ŸŒ™','๐Ÿ›ฐ๏ธ','๐ŸŒ'],mus:'space'}, {id:'icecream',n:'Ice Cream Factory',s:'Ice Cream',e:'๐Ÿฆ',sky:['#bff0ff','#ffe4f2'],gr:'#ffe9c7',gr2:'#ffc2e0',deco:['๐Ÿฆ','๐Ÿจ'],items:['๐Ÿฆ','๐Ÿจ','๐Ÿง'],haz:'๐Ÿ”ฅ',marks:['๐Ÿฆ','๐Ÿญ','๐Ÿจ','๐Ÿง','๐Ÿ’'],mus:'happy'}, {id:'sky',n:'Dragon Sky',s:'Sky',e:'โ˜๏ธ',sky:['#ff9f5a','#ffe1a8'],gr:'#7dc46b',gr2:'#5aa84a',deco:['โ˜๏ธ','๐Ÿ”๏ธ'],items:['๐Ÿ’Ž','โญ','๐Ÿช™'],haz:'๐ŸŒฉ๏ธ',marks:['๐Ÿ”๏ธ','๐Ÿฏ','๐Ÿ—ป','๐ŸŒ‹','๐Ÿ•๏ธ'],mus:'adventure'}, {id:'castle',n:'Princess Castle',s:'Castle',e:'๐Ÿฐ',sky:['#c9a7ff','#ffe1f0'],gr:'#9ad48a',gr2:'#f7c6ff',deco:['๐Ÿฐ','๐ŸŒท'],items:['๐Ÿ‘‘','๐Ÿ’Ž','๐Ÿ—๏ธ'],haz:'๐Ÿฆ‡',marks:['๐Ÿฐ','๐Ÿ‘‘','โ›ฒ','๐ŸŒท','๐ŸŽ '],mus:'calm'}, {id:'city',n:'Superhero City',s:'City',e:'๐Ÿ™๏ธ',sky:['#3fa8ff','#b8e6ff'],gr:'#9aa3b5',gr2:'#c5ccda',deco:['๐Ÿข','๐Ÿš'],items:['โญ','๐Ÿช™','๐Ÿ’ก'],haz:'๐Ÿšง',marks:['๐Ÿ—ฝ','๐Ÿš’','๐Ÿฅ','๐ŸŽก','๐ŸŸ๏ธ'],mus:'adventure'}, {id:'donut',n:'Donut World',s:'Donut',e:'๐Ÿฉ',sky:['#ffd6a5','#ffadad'],gr:'#c98a5a',gr2:'#ff8fc8',deco:['๐Ÿฉ','๐Ÿช'],items:['๐Ÿฉ','๐Ÿช','๐Ÿฅจ'],haz:'๐Ÿ',marks:['๐Ÿฉ','๐Ÿฅ','๐Ÿช','๐Ÿง‡','๐Ÿฅž'],mus:'party'}, {id:'pirate',n:'Pirate Island',s:'Pirate',e:'๐Ÿ๏ธ',sky:['#5ad1ff','#c8f4ff'],gr:'#f2d98c',gr2:'#4fc3e8',deco:['๐ŸŒด','โ›ต'],items:['๐Ÿช™','๐Ÿ’ฐ','๐Ÿ’Ž'],haz:'๐Ÿฆ€',marks:['โ›ต','๐ŸŒด','โš“','๐Ÿ๏ธ','๐Ÿ—ฟ'],mus:'adventure'}, {id:'robot',n:'Robot Factory',s:'Robot',e:'โš™๏ธ',sky:['#2b3a55','#6f86b0'],gr:'#7d8aa8',gr2:'#a8b4cc',deco:['โš™๏ธ','๐Ÿ’ก'],items:['๐Ÿ”ฉ','โš™๏ธ','๐Ÿ”‹'],haz:'โšก',marks:['๐Ÿค–','๐Ÿ›ธ','๐Ÿ”ญ','๐Ÿญ','๐Ÿ“ก'],mus:'space'}, {id:'jungle',n:'Jungle Park',s:'Jungle',e:'๐ŸŒด',sky:['#7fe0a0','#e8ffcc'],gr:'#5aa84a',gr2:'#3f8a3a',deco:['๐ŸŒด','๐ŸŒบ'],items:['๐ŸŒ','๐Ÿ“','๐Ÿ‰'],haz:'๐Ÿชจ',marks:['๐Ÿ˜','๐Ÿฆ’','๐Ÿฆœ','๐Ÿต','๐Ÿฆ›'],mus:'adventure'}, {id:'volcano',n:'Volcano Island',s:'Volcano',e:'๐ŸŒ‹',sky:['#ff7b54','#ffd23f'],gr:'#6b3a2a',gr2:'#a0522d',deco:['๐ŸŒ‹','๐Ÿ”ฅ'],items:['๐Ÿ’Ž','โญ','๐Ÿช™'],haz:'๐Ÿ”ฅ',marks:['๐ŸŒ‹','๐Ÿฆ–','๐Ÿ’Ž','๐Ÿชจ','๐Ÿ•๏ธ'],mus:'adventure',u:1}, {id:'snow',n:'Snow Land',s:'Snow',e:'โ„๏ธ',sky:['#a8e0ff','#ffffff'],gr:'#f0f8ff',gr2:'#cfe8ff',deco:['โ„๏ธ','โ›„'],items:['โ„๏ธ','๐ŸงŠ','โญ'],haz:'๐ŸŒจ๏ธ',marks:['โ›„','๐Ÿ”๏ธ','๐Ÿง','๐ŸŽฟ','๐Ÿ›ท'],mus:'calm',u:1} ]; const MODES=[ {id:'race',n:'Racing',e:'๐ŸŽ๏ธ',w:'racing',noun:'Race'}, {id:'fly',n:'Flying',e:'โœˆ๏ธ',w:'flying',noun:'Flight'}, {id:'platform',n:'Jumping',e:'๐Ÿฆ˜',w:'jumping',noun:'Jump'}, {id:'treasure',n:'Treasure hunt',e:'๐Ÿ—บ๏ธ',w:'treasure hunt',noun:'Treasure Hunt'}, {id:'explore',n:'Exploring',e:'๐Ÿ”ญ',w:'exploring',noun:'Quest'}, {id:'collect',n:'Collecting',e:'๐Ÿงบ',w:'collecting',noun:'Catch'}, {id:'dodge',n:'Dodging',e:'๐Ÿ’จ',w:'dodging',noun:'Dash'}, {id:'puzzle',n:'Puzzle',e:'๐Ÿงฉ',w:'puzzle',noun:'Puzzle'}, {id:'rescue',n:'Rescue',e:'๐Ÿ›Ÿ',w:'rescue',noun:'Rescue'} ]; const POWERS=[ {id:'speed',n:'Super speed',e:'โšก'},{id:'shield',n:'Shield bubble',e:'๐Ÿ›ก๏ธ'},{id:'magnet',n:'Magnet',e:'๐Ÿงฒ'}, {id:'jump',n:'Super jump',e:'๐Ÿš€'},{id:'slow',n:'Slow motion',e:'โณ'},{id:'double',n:'Double points',e:'โœจ'} ]; const GOALS=[ {id:'finish',n:'Reach the end',e:'๐Ÿ'},{id:'collect',n:'Collect treasure',e:'๐Ÿ’Ž'}, {id:'friends',n:'Save friends',e:'๐Ÿฃ'},{id:'score',n:'Beat the high score',e:'๐Ÿ†'} ]; const OBST=[ {id:'world',n:'World surprise',e:'๐ŸŒ'},{id:'rocks',n:'Rolling rocks',e:'๐Ÿชจ'},{id:'bees',n:'Buzzy bees',e:'๐Ÿ'}, {id:'clouds',n:'Storm clouds',e:'โ›ˆ๏ธ'},{id:'crabs',n:'Grumpy crabs',e:'๐Ÿฆ€'},{id:'ghosts',n:'Silly ghosts',e:'๐Ÿ‘ป'},{id:'meteors',n:'Meteors',e:'โ˜„๏ธ'} ]; const MUSICS=[ {id:'happy',n:'Happy',e:'๐ŸŽต'},{id:'adventure',n:'Adventure',e:'๐Ÿฅ'},{id:'space',n:'Space',e:'๐ŸŒŒ'}, {id:'calm',n:'Calm',e:'๐ŸŒ™'},{id:'party',n:'Party',e:'๐ŸŽ‰'} ]; const LEVELS=[{id:'easy',n:'Easy',e:'๐Ÿข'},{id:'medium',n:'Medium',e:'๐Ÿ‡'},{id:'hard',n:'Hard',e:'๐Ÿš€'}]; const FRIENDS=['๐Ÿฃ','๐Ÿฅ','๐Ÿน','๐Ÿจ','๐Ÿผ','๐Ÿฐ','๐Ÿถ','๐Ÿง']; const IDEAS=[ {n:'Unicorn Rainbow Racing',t:'a unicorn racing on a rainbow and grabbing stars',hero:'unicorn',world:'rainbow',mode:'race',c:['#ff7eb3','#7f7fff']}, {n:'Candy Kingdom Adventure',t:'a bunny hopping over chilli peppers in a candy kingdom',hero:'bunny',world:'candy',mode:'platform',c:['#ff4fa3','#ffb86b']}, {n:'Underwater Treasure Hunt',t:'a mermaid hunting for treasure under the sea and avoiding crabs',hero:'mermaid',world:'ocean',mode:'treasure',c:['#1ec8e8','#2b6fd6']}, {n:'Space Explorer',t:'an astronaut exploring outer space at night',hero:'astronaut',world:'space',mode:'explore',c:['#3a1a7a','#7b5cff']}, {n:'Magical Ice Cream Factory',t:'a penguin catching ice cream in an ice cream factory',hero:'penguin',world:'icecream',mode:'collect',c:['#ff9ad5','#6fd6ff']}, {n:'Flying Dragon Adventure',t:'a dragon flying in the clouds and collecting gems',hero:'dragon',world:'sky',mode:'fly',c:['#ff8a3d','#ffcf3f']}, {n:'Princess Castle Adventure',t:'a princess saving lost puppies in a castle',hero:'princess',world:'castle',mode:'rescue',c:['#b36bff','#ff8fd0']}, {n:'Superhero City',t:'a superhero saving lost chicks from storms in a big city',hero:'superhero',world:'city',mode:'rescue',c:['#2b6fd6','#ff4f6d']}, {n:'Donut World',t:'a puppy dodging bees in donut world and eating donuts',hero:'puppy',world:'donut',mode:'dodge',c:['#c98a5a','#ff8fc8']}, {n:'Pirate Island',t:'a pirate parrot hunting for treasure on pirate island',hero:'parrot',world:'pirate',mode:'treasure',c:['#19a7c3','#e0bf62']}, {n:'Robot Adventure',t:'a memory puzzle with a robot in a robot factory',hero:'robot',world:'robot',mode:'puzzle',c:['#4b5d82','#22d3ee']}, {n:'Rainbow Obstacle Course',t:'a dino jumping over an obstacle course on a rainbow',hero:'dino',world:'rainbow',mode:'platform',c:['#19c37d','#ffd23f']} ]; const SECRETS=[ {h:'dragon',w:'icecream',n:'Frosty Dragon Freeze'},{h:'unicorn',w:'space',n:'Galaxy Unicorn'}, {h:'robot',w:'ocean',n:'Submarine Robot'},{h:'parrot',w:'space',n:'Space Pirates'}, {h:'penguin',w:'volcano',n:'Toasty Penguin'},{h:'puppy',w:'donut',n:'Donut Doggo'}, {h:'mermaid',w:'candy',n:'Candy Sea Mermaid'},{h:'superhero',w:'castle',n:'Castle Hero'}, {h:'dino',w:'jungle',n:'Dino Jungle Party'},{h:'octopus',w:'pirate',n:'Eight-Arm Pirate'} ]; const UNLOCKS=[ {c:25,k:'hero',id:'panda',t:'New character: Panda',e:'๐Ÿผ'}, {c:55,k:'world',id:'volcano',t:'New world: Volcano Island',e:'๐ŸŒ‹'}, {c:85,k:'ctrl',id:'gold',t:'Special gold controllers',e:'๐ŸŽฎ'}, {c:120,k:'deco',id:'balloons',t:'Shop decoration: balloons',e:'๐ŸŽˆ'}, {c:160,k:'phone',id:'rainbow',t:'Phone upgrade: Rainbow phone, faster making',e:'๐Ÿ“ฑ'}, {c:200,k:'tv',id:'tv2',t:'A second TV for the shop',e:'๐Ÿ“บ'}, {c:250,k:'hero',id:'octopus',t:'New character: Octopus',e:'๐Ÿ™'}, {c:310,k:'world',id:'snow',t:'New world: Snow Land',e:'โ„๏ธ'}, {c:370,k:'deco',id:'disco',t:'Shop decoration: disco ball',e:'๐Ÿชฉ'}, {c:440,k:'hero',id:'owl',t:'New character: Owl',e:'๐Ÿฆ‰'}, {c:520,k:'phone',id:'gold',t:'Phone upgrade: Golden phone',e:'โœจ'}, {c:600,k:'ctrl',id:'rainbow',t:'Special rainbow controllers',e:'๐ŸŒˆ'}, {c:700,k:'hero',id:'frog',t:'New character: Frog',e:'๐Ÿธ'} ]; const DEF_POWER={race:'speed',fly:'jump',platform:'jump',treasure:'magnet',explore:'speed',collect:'magnet',dodge:'shield',puzzle:'slow',rescue:'shield'}; const OBST_E={rocks:'๐Ÿชจ',bees:'๐Ÿ',clouds:'โ›ˆ๏ธ',crabs:'๐Ÿฆ€',ghosts:'๐Ÿ‘ป',meteors:'โ˜„๏ธ'}; const byId=(a,id)=>a.find(x=>x.id===id)||a[0]; /* ================= saved progress (this browser only, no personal data) ================= */ const SKEY='kidopia-v1'; let SAVE={coins:0,stars:0,games:0,unl:[],secrets:[],best:0,mute:false,made:[]}; try{const s=JSON.parse(localStorage.getItem(SKEY)||'null');if(s&&typeof s==='object')Object.assign(SAVE,s);}catch(e){} function save(){try{localStorage.setItem(SKEY,JSON.stringify(SAVE));}catch(e){}} const has=(k,id)=>SAVE.unl.indexOf(k+':'+id)>=0; const okHero=h=>!h.u||has('hero',h.id); const okWorld=w=>!w.u||has('world',w.id); /* ================= canvas ================= */ const cv=document.getElementById('cv'),ctx=cv.getContext('2d'); let W=0,H=0,DPR=1; const TOUCH=('ontouchstart' in window)||navigator.maxTouchPoints>0; function resize(){ W=window.innerWidth;H=window.innerHeight; DPR=Math.min(window.devicePixelRatio||1,W*H>900000?1.5:2); cv.width=Math.round(W*DPR);cv.height=Math.round(H*DPR); } window.addEventListener('resize',resize);resize(); const EC={}; function emo(c,e,x,y,size,rot,alpha){ let k=EC[e]; if(!k){ k=document.createElement('canvas');k.width=k.height=128;const g=k.getContext('2d'); if(!(window.KidArt&&KidArt.draw(g,e))){g.font='96px '+EMOF;g.textAlign='center';g.textBaseline='middle';g.fillText(e,64,72);}EC[e]=k; } if(rot||alpha!=null){c.save();c.translate(x,y);if(rot)c.rotate(rot);if(alpha!=null)c.globalAlpha*=alpha;c.drawImage(k,-size/2,-size/2,size,size);c.restore();} else c.drawImage(k,x-size/2,y-size/2,size,size); } function rr(c,x,y,w,h,r){r=Math.min(r,w/2,h/2);c.beginPath();c.moveTo(x+r,y);c.arcTo(x+w,y,x+w,y+h,r);c.arcTo(x+w,y+h,x,y+h,r);c.arcTo(x,y+h,x,y,r);c.arcTo(x,y,x+w,y,r);c.closePath();} function ell(c,x,y,rx,ry){c.beginPath();c.ellipse(x,y,rx,ry,0,0,Math.PI*2);} function txt(c,s,x,y,size,col,align,stroke){ c.font='700 '+size+'px '+FONT;c.textAlign=align||'center';c.textBaseline='middle'; if(stroke){c.lineWidth=size/5;c.strokeStyle=stroke;c.lineJoin='round';c.strokeText(s,x,y);} c.fillStyle=col;c.fillText(s,x,y); } function wrap(c,s,maxW,size){ c.font='700 '+size+'px '+FONT;const words=String(s).split(' '),lines=[];let cur=''; for(const w of words){const t=cur?cur+' '+w:w;if(c.measureText(t).width>maxW&&cur){lines.push(cur);cur=w;}else cur=t;} if(cur)lines.push(cur);return lines; } /* ================= people ================= */ const NAMES=['Mia','Leo','Zara','Omar','Ava','Kai','Lily','Noah','Sofia','Ravi','Emma','Yuki','Nora','Sam','Ella','Theo','Maya','Ben','Aria','Finn','Lena','Jay','Ivy','Max','Rosa','Ali','Hana','Luca']; const SKIN=['#ffdbb4','#f1c27d','#e0ac69','#c68642','#8d5524','#ffe0c4','#b97a4a']; const HAIR=['#2b1a10','#5a3214','#a0522d','#f4c542','#e8743b','#1a1a1a','#7b4fd6','#ff6fb5','#3fa8ff']; const SHIRT=['#ff4f6d','#3fa8ff','#19c37d','#ffd23f','#ff8a3d','#9b5cff','#ff6fb5','#22d3ee','#ffffff']; const PANTS=['#2d3a8c','#3b2f2f','#5b6b8a','#7b3fa0','#1f6f5f','#c0392b']; const PERS=[ {id:'excited',hi:'Hi hi hi! I LOVE video games!',know:'I already know what I want!',dunno:'So many games... I can\'t pick!',wait:'I can\'t wait!',couch:'Let\'s play together!'}, {id:'shy',hi:'Um... hello. Can you make me a game?',know:'I have an idea... is that okay?',dunno:'I don\'t know what I like yet.',wait:'Ooh...',couch:'Will you play with me?'}, {id:'silly',hi:'Knock knock! It\'s me, your best customer!',know:'My idea is SUPER silly!',dunno:'Bloop! My brain is empty!',wait:'Wiggle wiggle!',couch:'Couch power, go!'}, {id:'curious',hi:'Wow! Can you really make any game?',know:'I thought of a game on the way here!',dunno:'What kinds of games can you make?',wait:'How does the magic phone work?',couch:'Look, it\'s on the TV!'}, {id:'dreamy',hi:'I dreamed about a magic game last night...',know:'I remember my dream game!',dunno:'My dream was a bit fuzzy...',wait:'So sparkly!',couch:'Just like my dream!'} ]; let seedN=1; function mkLook(){ const robot=Math.random()<.12; return {skin:pick(SKIN),hair:pick(HAIR),hs:ri(0,5),shirt:pick(SHIRT),pants:pick(PANTS),hat:Math.random()<.45?ri(1,5):0, glasses:Math.random()<.2,robot,metal:pick(['#9fb6d6','#c7a0ff','#7fe0c8','#ffb36b']),print:ri(0,3)}; } function mkPerson(o){return Object.assign({x:-160,y:800,tx:-160,facing:1,walk:0,moving:false,sit:false,happy:0,talk:0,wave:0,ctrl:false, seed:(seedN++)*1.7,bubble:null,speed:250,arrive:null,scale:1},o);} const OWNER=mkPerson({x:720,y:760,tx:720,facing:-1,owner:true,look:{skin:'#f1c27d',hair:'#3b1d0e',hs:3,shirt:'#ffd23f',pants:'#47208f',hat:5,glasses:false,robot:false,print:0}}); function say(p,text,dur){p.bubble={text,t:dur||3.2,age:0};p.talk=Math.min(2.2,.5+text.length*.03);SFX.blip();} function drawPerson(c,p,T){ const L=p.look,s=p.scale||1,sd=p.seed; c.save();c.translate(p.x,p.y);c.scale(s*p.facing,s); const ph=p.walk; let bob=p.moving?-Math.abs(Math.sin(ph))*7:Math.sin(T*2.2+sd)*1.5; if(p.happy>0)bob=-Math.abs(Math.sin(T*9+sd))*22; c.fillStyle='rgba(30,0,60,.18)';ell(c,0,2,46,10);c.fill(); const sitY=p.sit?-62:0; // legs c.fillStyle=L.pants; if(p.sit){ rr(c,-22,-84,70,22,10);c.fill();rr(c,30,-80,20,78,9);c.fill(); rr(c,-6,-84,60,22,10);c.fill(); c.fillStyle='#fff';rr(c,26,-8,34,12,6);c.fill(); } else { const a=p.moving?Math.sin(ph)*.55:0; for(const sg of [-1,1]){ c.save();c.translate(sg*11,-72+bob*.4);c.rotate(a*sg);c.fillStyle=L.pants;rr(c,-9,0,18,68,9);c.fill(); c.fillStyle=L.robot?'#556':'#fff';rr(c,-11,58,26,12,6);c.fill();c.restore(); } } c.translate(0,bob+sitY); // body if(L.robot){c.fillStyle=L.metal;rr(c,-34,-152,68,84,14);c.fill();c.fillStyle='#fff8';rr(c,-18,-136,36,22,6);c.fill(); c.fillStyle=Math.sin(T*6+sd)>0?'#ff4f6d':'#4cf2a0';ell(c,0,-92,6,6);c.fill();} else{c.fillStyle=L.shirt;rr(c,-31,-150,62,84,24);c.fill(); c.fillStyle='rgba(255,255,255,.35)'; if(L.print===1){ell(c,0,-112,12,12);c.fill();} else if(L.print===2){c.fillRect(-31,-122,62,10);} else if(L.print===3){emo(c,'โญ',0,-112,26);} } if(p.apron){c.fillStyle='#9b5cff';rr(c,-24,-130,48,64,10);c.fill();txt(c,'K',0,-104,30,'#ffd23f');} // arms c.lineCap='round';c.lineWidth=15;c.strokeStyle=L.robot?L.metal:L.shirt; const armA=p.moving?Math.sin(ph)*.6:0; const arm=(sg,ang,len)=>{c.save();c.translate(sg*30,-140);c.rotate(ang);c.beginPath();c.moveTo(0,0);c.lineTo(0,len);c.stroke(); c.fillStyle=L.robot?'#ccd':L.skin;ell(c,0,len+4,9,9);c.fill();c.restore();}; if(p.ctrl){arm(-1,-1.0,44);arm(1,-1.25,48); const cc=has('ctrl','rainbow')?'#ff4fa3':has('ctrl','gold')?'#ffc21a':'#2b2b3a'; c.fillStyle=cc;rr(c,10,-128,52,26,12);c.fill();c.fillStyle='#4cf2a0';ell(c,48,-118,4,4);c.fill();c.fillStyle='#ff4f6d';ell(c,40,-112,4,4);c.fill();} else if(p.wave>0){arm(-1,.1-armA,50);arm(1,Math.PI*0.85+Math.sin(T*12)*.35,50);} else if(p.happy>0){arm(-1,Math.PI*0.8,50);arm(1,Math.PI*0.8,50);} else if(p.holdPhone){arm(-1,-.9,44);arm(1,-1.2,46); c.fillStyle='#111';rr(c,22,-158,30,50,7);c.fill();const gl=.5+.5*Math.sin(T*8); c.fillStyle='rgba(255,'+(150+gl*100|0)+',255,1)';rr(c,25,-154,24,42,5);c.fill();} else{arm(-1,.15+armA,52);arm(1,-.15-armA,52);} // head const hy=-196; if(L.robot){ c.strokeStyle='#889';c.lineWidth=5;c.beginPath();c.moveTo(0,hy-44);c.lineTo(0,hy-66);c.stroke(); c.fillStyle=Math.sin(T*4+sd)>0?'#ffd23f':'#ff4fa3';ell(c,0,hy-70,8,8);c.fill(); c.fillStyle=L.metal;rr(c,-44,hy-44,88,84,20);c.fill(); c.fillStyle='#223';rr(c,-32,hy-24,64,34,12);c.fill(); const bl=((T+sd)%3.5)<.12;c.fillStyle='#4cf2ff'; if(bl){c.fillRect(-22,hy-8,14,4);c.fillRect(8,hy-8,14,4);}else{rr(c,-22,hy-16,14,18,4);c.fill();rr(c,8,hy-16,14,18,4);c.fill();} c.strokeStyle='#4cf2ff';c.lineWidth=4;c.beginPath(); if(p.talk>0){ell(c,0,hy+24,9,3+Math.abs(Math.sin(T*18))*5);c.stroke();}else{c.arc(0,hy+18,10,.2,Math.PI-.2);c.stroke();} c.restore();return; } c.fillStyle=L.hair; if(L.hs===1||L.hs===3&&p.owner){rr(c,-48,hy-40,96,p.owner?120:104,40);c.fill();} c.fillStyle=L.skin;ell(c,0,hy,44,44);c.fill(); ell(c,-43,hy+4,8,10);c.fill();ell(c,43,hy+4,8,10);c.fill(); // hair front c.fillStyle=L.hair; c.beginPath();c.arc(0,hy-4,46,Math.PI*1.03,Math.PI*1.97);c.quadraticCurveTo(20,hy-22,-10,hy-20);c.quadraticCurveTo(-34,hy-18,-45,hy-4);c.fill(); if(L.hs===2){for(let i=0;i<7;i++){const a=Math.PI*(1.05+i*.15);ell(c,Math.cos(a)*44,hy+Math.sin(a)*44,15,15);c.fill();}} if(L.hs===3){ell(c,-52,hy-4,15,15);c.fill();ell(c,52,hy-4,15,15);c.fill();} if(L.hs===4){ell(c,0,hy-50,20,18);c.fill();} if(L.hs===5){c.beginPath();for(let i=0;i<5;i++){const x=-36+i*18;c.moveTo(x-10,hy-34);c.lineTo(x,hy-62);c.lineTo(x+10,hy-34);}c.fill();} // face const bl=((T+sd)%4)<.13; for(const ex of [-15,15]){ if(bl){c.strokeStyle='#2a1460';c.lineWidth=3;c.beginPath();c.moveTo(ex-7,hy-4);c.lineTo(ex+7,hy-4);c.stroke();} else{c.fillStyle='#fff';ell(c,ex,hy-4,9,11);c.fill();c.fillStyle='#2a1460';ell(c,ex+3,hy-2,5,6.5);c.fill();c.fillStyle='#fff';ell(c,ex+5,hy-5,2,2);c.fill();} } c.fillStyle='rgba(255,90,120,.35)';ell(c,-26,hy+12,8,5);c.fill();ell(c,26,hy+12,8,5);c.fill(); c.fillStyle='#8a2040'; if(p.talk>0){ell(c,3,hy+20,8,3+Math.abs(Math.sin(T*16))*6);c.fill();} else if(p.happy>0||p.ctrl){c.beginPath();c.arc(3,hy+14,13,0,Math.PI);c.fill();c.fillStyle='#ff8fa8';ell(c,3,hy+22,6,3);c.fill();} else{c.strokeStyle='#8a2040';c.lineWidth=3.5;c.beginPath();c.arc(3,hy+12,10,.25,Math.PI-.25);c.stroke();} if(L.glasses){c.strokeStyle='#2a1460';c.lineWidth=3;ell(c,-15,hy-4,13,12);c.stroke();ell(c,15,hy-4,13,12);c.stroke();c.beginPath();c.moveTo(-2,hy-4);c.lineTo(2,hy-4);c.stroke();} // hats if(L.hat===1){c.fillStyle=L.shirt==='#ffffff'?'#ff4f6d':L.shirt;c.beginPath();c.arc(0,hy-18,44,Math.PI,0);c.fill();rr(c,0,hy-24,64,12,6);c.fill();} if(L.hat===2){c.fillStyle='#3fa8ff';c.beginPath();c.arc(0,hy-14,46,Math.PI,0);c.fill();c.fillStyle='#fff';rr(c,-47,hy-22,94,14,7);c.fill();ell(c,0,hy-62,10,10);c.fill();} if(L.hat===3){c.fillStyle='#ff4fa3';c.beginPath();c.moveTo(18,hy-40);c.lineTo(46,hy-58);c.lineTo(46,hy-22);c.closePath();c.moveTo(18,hy-40);c.lineTo(-8,hy-60);c.lineTo(-8,hy-22);c.closePath();c.fill();ell(c,18,hy-40,8,8);c.fill();} if(L.hat===4){c.strokeStyle='#ffd23f';c.lineWidth=8;c.beginPath();c.arc(0,hy,44,Math.PI*1.12,Math.PI*1.88);c.stroke();} if(L.hat===5){c.fillStyle='#ffc21a';c.beginPath();c.moveTo(-26,hy-36);c.lineTo(-26,hy-62);c.lineTo(-13,hy-48);c.lineTo(0,hy-68);c.lineTo(13,hy-48);c.lineTo(26,hy-62);c.lineTo(26,hy-36);c.closePath();c.fill();c.fillStyle='#ff4fa3';ell(c,0,hy-46,4,4);c.fill();} c.restore(); } /* ================= the shop scene ================= */ const SHOP={door:0,lights:0,tvOn:0,tvGame:null,tv2:0}; const BOXES=[];for(let i=0;i<18;i++)BOXES.push({c:pick(['#ff4f6d','#3fa8ff','#19c37d','#ffd23f','#9b5cff','#ff8a3d','#22d3ee']),e:pick(['๐Ÿฆ„','๐Ÿš€','๐Ÿฉ','๐Ÿ‰','๐Ÿฐ','๐Ÿค–','๐Ÿ๏ธ','๐Ÿฆ','๐Ÿญ','๐Ÿฆธ','๐ŸŒˆ','๐Ÿ '])}); const CAM={x:800,sc:1,oy:0,vw:1600,cx:null}; const TV={x:1150,y:190,w:340,h:220}; const SEATS=[1265,1395];const WAITS=[940,1030]; function uiReserve(){ let bottom=0,right=0; for(const el of ui.children){ if(el.classList.contains('hide'))continue; const r=el.getBoundingClientRect();if(!r.height)continue; if(el.classList.contains('sheet')||(el.classList.contains('phone')&&r.width>W*.8))bottom=Math.max(bottom,H-r.top+6); else if(el.classList.contains('phone'))right=Math.max(right,W-r.left+6); } return {bottom,right}; } function camSetup(focus,dt){ const R=uiReserve(),aw=W-R.right,port=aw/H<1.25,area=Math.max(H*.32,H-R.bottom); let sc,oy; if(!port&&R.bottom=1600?800:clamp(focus,vw/2,1600-vw/2); CAM.x=dt?lerp(CAM.x,tx,Math.min(1,dt*2.2)):tx;CAM.vw=vw; } function w2s(x,y){return [(x-CAM.x)*CAM.sc+CAM.cx,y*CAM.sc+CAM.oy];} function drawShop(c,T,people){ c.setTransform(DPR*CAM.sc,0,0,DPR*CAM.sc,DPR*(CAM.cx-CAM.x*CAM.sc),DPR*CAM.oy); const Lt=SHOP.lights; const x0=CAM.x-CAM.cx/CAM.sc-20,x1=CAM.x+(W-CAM.cx)/CAM.sc+20; // wall let g=c.createLinearGradient(0,-400,0,700);g.addColorStop(0,'#3a1580');g.addColorStop(1,Lt>.5?'#8a3fc8':'#4a2080'); c.fillStyle=g;c.fillRect(x0,-600,x1-x0,1300); c.fillStyle='rgba(255,255,255,.05)';for(let x=Math.floor(x0/80)*80;x((k%7+7)%7)/7&&((Math.floor(T*2)+k)%5!==0);const y=44+Math.sin(x*.05)*10; c.fillStyle=on?BC[((k%5)+5)%5]:'#553';ell(c,x,y,8,11);c.fill(); if(on){c.globalAlpha=.25;ell(c,x,y,20,20);c.fill();c.globalAlpha=1;} } // big sign c.save();c.translate(800,128); c.fillStyle='#2a1460';rr(c,-260,-70,520,140,36);c.fill(); c.strokeStyle=Lt>.3?'#ff4fa3':'#553';c.lineWidth=8;rr(c,-252,-62,504,124,30);c.stroke(); const word='KIDOPIA',cols=['#ff4f6d','#ffd23f','#4cf2a0','#3fa8ff','#ff8fd0','#ff8a3d','#c79bff']; c.font='700 84px '+FONT;c.textBaseline='middle';c.textAlign='center'; for(let i=0;i<7;i++){ const x=-195+i*65,y=-14+Math.sin(T*3+i*.7)*4;const on=Lt>(i+1)/8; if(on){c.globalAlpha=.35;c.fillStyle=cols[i];c.fillText(word[i],x,y+3);c.globalAlpha=1;} c.fillStyle=on?cols[i]:'#4a3a6a';c.fillText(word[i],x,y); } txt(c,'The Magical Game Shop',0,42,26,Lt>.9?'#ffd23f':'#6a5a8a'); c.restore(); // door const dx=80,dw=190,dy=330,dh=370; c.fillStyle='#ff8a3d';rr(c,dx-18,dy-20,dw+36,dh+20,14);c.fill(); g=c.createLinearGradient(0,dy,0,dy+dh);g.addColorStop(0,'#8fd8ff');g.addColorStop(.7,'#d8f4ff');g.addColorStop(.71,'#b8b8c8');g.addColorStop(1,'#9a9aac'); c.fillStyle=g;c.fillRect(dx,dy,dw,dh); emo(c,'๐ŸŒณ',dx+40,dy+200,80);emo(c,'โ˜€๏ธ',dx+150,dy+60,50); const op=SHOP.door*88; c.fillStyle='rgba(180,230,255,.45)';c.strokeStyle='#ddd';c.lineWidth=6; c.fillRect(dx-op,dy,dw/2,dh);c.strokeRect(dx-op,dy,dw/2,dh);c.fillRect(dx+dw/2+op,dy,dw/2,dh);c.strokeRect(dx+dw/2+op,dy,dw/2,dh); c.fillStyle='#ff8a3d';c.fillRect(dx-40,dy-20,22,dh+20);c.fillRect(dx+dw+18,dy-20,22,dh+20); c.fillStyle='#2a1460';rr(c,dx+30,dy-90,130,50,14);c.fill();txt(c,'OPEN',dx+95,dy-64,34,Lt>.2?(Math.sin(T*4)>-.6?'#ff4f6d':'#ff9ab0'):'#553'); c.fillStyle='#19c37d';rr(c,dx-10,dy+dh-6,dw+20,14,6);c.fill(); // shelves for(let r=0;r<3;r++){ const sy=300+r*110;c.fillStyle='#ffb86b';c.fillRect(310,sy+76,240,12); for(let i=0;i<6;i++){const b=BOXES[r*6+i];c.fillStyle=b.c;rr(c,318+i*38,sy+(i%2?12:4),32,72-(i%2?8:0),5);c.fill();emo(c,b.e,334+i*38,sy+40,24);} } emo(c,'๐Ÿชด',1095,640,110); // poster or second TV if(has('tv','tv2')){ c.fillStyle='#111';rr(c,880,215,200,130,12);c.fill(); const sg=c.createLinearGradient(890,0,1070,0);const hh=(T*60)%360; sg.addColorStop(0,'hsl('+hh+',90%,60%)');sg.addColorStop(1,'hsl('+((hh+120)%360)+',90%,60%)'); c.fillStyle=sg;c.fillRect(890,225,180,110); const last=SAVE.made.length?SAVE.made[SAVE.made.length-1]:null; txt(c,last?'NEW GAME!':'KIDOPIA TV',980,250,20,'#fff',0,'#2a1460'); emo(c,last?last.e:'๐ŸŽฎ',980,295,46+Math.sin(T*4)*4); c.fillStyle='#333';c.fillRect(970,345,20,30); } else { c.fillStyle='#fff';rr(c,890,215,180,150,10);c.fill();c.fillStyle='#ff4fa3';rr(c,898,223,164,134,8);c.fill(); txt(c,'GAME',980,250,26,'#fff');txt(c,'IDEAS?',980,280,26,'#ffd23f');emo(c,'๐Ÿ’ก',980,330,44); } if(has('deco','balloons')){ for(const [bx,cc] of [[300,'๐ŸŽˆ'],[575,'๐ŸŽˆ'],[1545,'๐ŸŽˆ']]){emo(c,cc,bx,250+Math.sin(T*1.5+bx)*8,70);emo(c,cc,bx+28,280+Math.sin(T*1.7+bx)*8,60);} } if(has('deco','disco')){ c.strokeStyle='#ccc';c.lineWidth=2;c.beginPath();c.moveTo(1050,0);c.lineTo(1050,150);c.stroke();emo(c,'๐Ÿชฉ',1050,180,70,T); c.save();c.globalCompositeOperation='lighter';for(let i=0;i<8;i++){const a=T*.8+i*.8;c.fillStyle=BC[i%5]+'55';ell(c,1050+Math.cos(a)*420,420+Math.sin(a*1.3)*160,14,8);c.fill();}c.restore(); } // TV c.fillStyle='#14142a';rr(c,TV.x-16,TV.y-16,TV.w+32,TV.h+32,18);c.fill(); drawTVScreen(c,TV.x,TV.y,TV.w,TV.h,T); c.fillStyle='#14142a';c.fillRect(TV.x+TV.w/2-12,TV.y+TV.h+16,24,40);rr(c,TV.x+60,TV.y+TV.h+50,TV.w-120,16,8);c.fill(); c.fillStyle=SHOP.tvOn>0?'#4cf2a0':'#ff4f6d';ell(c,TV.x+TV.w-6,TV.y+TV.h+6,4,4);c.fill(); // counter (back part), owner, counter front const owner=people.find(p=>p.owner); c.fillStyle='#c2387a';c.fillRect(580,555,290,20); // couch back c.fillStyle='#2b8be0';rr(c,1150,600,360,120,34);c.fill(); c.fillStyle='#3fa8ff';for(let i=0;i<3;i++){rr(c,1168+i*110,614,104,90,26);c.fill();} // waiting bean bags back for(const wx of WAITS){c.fillStyle=wx===WAITS[0]?'#19c37d':'#ff8a3d';ell(c,wx,770,52,40);c.fill();} c.fillStyle='#fff';rr(c,955,690,70,10,4);c.fill();c.fillStyle='#ffb86b';c.fillRect(985,700,10,60); emo(c,'๐Ÿฟ',968,672,36);emo(c,'๐Ÿงƒ',1008,674,32); if(!owner||!owner.behind){c.fillStyle='#ff4fa3';rr(c,570,565,310,200,18);c.fill();c.fillStyle='#ffd23f';c.fillRect(570,600,310,14);for(let i=0;i<5;i++)emo(c,'โญ',612+i*58,680,30);} // people sorted by depth const ord=people.slice().sort((a,b)=>(a.owner&&a.behind?-1:0)-(b.owner&&b.behind?-1:0)||a.y-b.y); for(const p of ord){ if(p===owner&&owner.behind){drawPerson(c,p,T); c.fillStyle='#ff4fa3';rr(c,570,565,310,200,18);c.fill();c.fillStyle='#ffd23f';c.fillRect(570,600,310,14); for(let i=0;i<5;i++)emo(c,'โญ',612+i*58,680,30,Math.sin(T+i)*.2); c.fillStyle='#fff';rr(c,590,520,60,40,10);c.fill();emo(c,'๐Ÿฌ',620,530,34); continue;} drawPerson(c,p,T); } // couch arms (front) c.fillStyle='#2070c0';rr(c,1128,660,50,130,22);c.fill();rr(c,1482,660,50,130,22);c.fill(); c.fillStyle='#2b8be0';rr(c,1160,720,340,52,16);c.globalAlpha=.0;c.fill();c.globalAlpha=1; if(!people.some(p=>p.ctrl)){const cc=has('ctrl','rainbow')?'#ff4fa3':has('ctrl','gold')?'#ffc21a':'#2b2b3a';c.fillStyle=cc;rr(c,1135,646,40,20,9);c.fill();rr(c,1487,646,40,20,9);c.fill();} // spotlights if(Lt>.6){c.save();c.globalCompositeOperation='lighter'; for(const [sx,sp] of [[420,.7],[1320,.9]]){const a=Math.sin(T*sp)*.25;c.save();c.translate(sx,0);c.rotate(a); const sg2=c.createLinearGradient(0,0,0,800);sg2.addColorStop(0,'rgba(255,240,180,.22)');sg2.addColorStop(1,'rgba(255,240,180,0)'); c.fillStyle=sg2;c.beginPath();c.moveTo(-20,0);c.lineTo(20,0);c.lineTo(160,800);c.lineTo(-160,800);c.closePath();c.fill();c.restore();} c.restore();} if(Lt<1){c.fillStyle='rgba(10,0,30,'+(0.6*(1-Lt))+')';c.fillRect(x0,-600,x1-x0,1600);} } function drawTVScreen(c,x,y,w,h,T){ const on=SHOP.tvOn,gm=SHOP.tvGame; c.save();c.beginPath();c.rect(x,y,w,h);c.clip(); c.fillStyle='#0b0b1a';c.fillRect(x,y,w,h); if(on<=0){c.fillStyle='rgba(255,255,255,.06)';c.beginPath();c.moveTo(x+w*.6,y);c.lineTo(x+w*.8,y);c.lineTo(x+w*.4,y+h);c.lineTo(x+w*.2,y+h);c.fill();} else if(on<1){const lh=Math.max(2,h*Math.max(0,on*2-1));c.fillStyle='#fff';c.fillRect(x+w/2-w*Math.min(1,on*2)/2,y+h/2-lh/2,w*Math.min(1,on*2),lh);} else if(gm){ const wd=gm.world;const g=c.createLinearGradient(0,y,0,y+h);g.addColorStop(0,wd.sky[0]);g.addColorStop(1,wd.sky[1]); c.fillStyle=g;c.fillRect(x,y,w,h);c.fillStyle=wd.gr;c.fillRect(x,y+h*.72,w,h*.28); for(let i=0;i<5;i++)emo(c,wd.items[i%3],x+((i*83+T*40)%w),y+h*.3+Math.sin(T*2+i)*20,26); emo(c,gm.hero.e,x+w/2,y+h*.58+Math.sin(T*5)*-8,70); const ls=wrap(c,gm.name,w-30,24);ls.slice(0,2).forEach((l,i)=>txt(c,l,x+w/2,y+24+i*26,24,'#fff',0,'#2a1460')); if(S.st==='tvon'&&Math.sin(T*5)>0)txt(c,'PRESS PLAY',x+w/2,y+h-18,18,'#ffd23f',0,'#2a1460'); } else { const hh=(T*40)%360;c.fillStyle='hsl('+hh+',70%,30%)';c.fillRect(x,y,w,h);txt(c,'KIDOPIA',x+w/2,y+h/2,40,'#fff',0,'#2a1460'); } c.restore(); } function drawBubble(c,p,T){ const b=p.bubble;if(!b)return; const size=30,lines=wrap(c,b.text,380,size),bw=Math.min(420,Math.max(...lines.map(l=>c.measureText(l).width))+44),bh=lines.length*36+30; const hy=p.y-270*(p.scale||1)-(p.sit?62:0); let bx=clamp(p.x,CAM.x-CAM.vw/2+bw/2+10,CAM.x+CAM.vw/2-bw/2-10),by=hy-bh; const sc=Math.min(1,b.age*6); c.save();c.translate(bx,by+bh);c.scale(sc,sc);c.translate(-bx,-(by+bh)); c.fillStyle='#fff';c.strokeStyle='#2a1460';c.lineWidth=5;rr(c,bx-bw/2,by,bw,bh,22);c.fill();c.stroke(); c.beginPath();const tx=clamp(p.x,bx-bw/2+30,bx+bw/2-30);c.moveTo(tx-14,by+bh-3);c.lineTo(tx,by+bh+22);c.lineTo(tx+14,by+bh-3);c.fill(); c.beginPath();c.moveTo(tx-14,by+bh);c.lineTo(tx,by+bh+22);c.lineTo(tx+14,by+bh);c.stroke(); lines.forEach((l,i)=>txt(c,l,bx,by+33+i*36,size,'#2a1460')); c.restore(); } function drawStorefront(c,T){ c.setTransform(DPR,0,0,DPR,0,0); const g=c.createLinearGradient(0,0,0,H);g.addColorStop(0,'#2a1460');g.addColorStop(.6,'#ff7eb3');g.addColorStop(1,'#ffcf8a'); c.fillStyle=g;c.fillRect(0,0,W,H); for(let i=0;i<30;i++){c.fillStyle='rgba(255,255,255,'+(.4+.4*Math.sin(T*2+i))+')';ell(c,(i*137)%W,(i*71)%(H*.4),1.5,1.5);c.fill();} const s=Math.min(W/900,H/900)*1.1,cx=W/2,base=H*.7; c.save();c.translate(cx,base);c.scale(s,s); c.fillStyle='#7b5cff';rr(c,-380,-460,760,460,30);c.fill(); c.fillStyle='#9b7bff';for(let i=0;i<8;i++)c.fillRect(-380+i*95,-460,48,460); c.fillStyle='#ff4fa3';c.beginPath();for(let i=0;i<9;i++){c.moveTo(-400+i*90,-470);c.arc(-355+i*90,-470,45,Math.PI,0);}c.fill(); c.fillStyle='#fff';for(let i=0;i<9;i++){c.beginPath();c.arc(-355+i*90,-470,45,Math.PI,Math.PI*1.5);c.lineTo(-355+i*90,-470);c.fill();} c.fillStyle='#2a1460';rr(c,-300,-600,600,130,40);c.fill();c.strokeStyle='#ffd23f';c.lineWidth=8;rr(c,-292,-592,584,114,34);c.stroke(); const cols=['#ff4f6d','#ffd23f','#4cf2a0','#3fa8ff','#ff8fd0','#ff8a3d','#c79bff'];c.font='700 92px '+FONT;c.textAlign='center';c.textBaseline='middle'; for(let i=0;i<7;i++){c.fillStyle=cols[i];c.fillText('KIDOPIA'[i],-210+i*70,-535+Math.sin(T*3+i*.7)*6);} for(const wx of [-330,130]){c.fillStyle='#ffe9a8';rr(c,wx,-380,200,220,16);c.fill();c.fillStyle='#ffd23f';c.fillRect(wx,-280,200,6); emo(c,wx<0?'๐Ÿ“บ':'๐ŸŽฎ',wx+100,-320,70);emo(c,wx<0?'๐Ÿ›‹๏ธ':'๐Ÿ“ฑ',wx+100,-210,70);} c.fillStyle='#ff8a3d';rr(c,-90,-330,180,330,10);c.fill();c.fillStyle='#bfeaff';c.fillRect(-75,-315,150,315); c.fillStyle='rgba(255,255,255,.5)';c.fillRect(-75,-315,4,315);c.fillRect(-2,-315,4,315); c.fillStyle='#9a9aac';c.fillRect(-W/s,0,W*2/s,400);c.fillStyle='#b8b8c8';c.fillRect(-W/s,0,W*2/s,20); c.restore(); for(let i=0;i<3;i++){const px=((T*60+i*W/3)%(W+200))-100;const p=TITLE_KIDS[i];p.x=px/s;p.y=0;p.moving=true;p.walk=T*9+i; c.save();c.setTransform(DPR*s*.8,0,0,DPR*s*.8,DPR*0,DPR*(base+30*s));drawPerson(c,Object.assign({},p,{x:px/(s*.8)}),T);c.restore();} } const TITLE_KIDS=[0,1,2].map(()=>mkPerson({look:mkLook()})); /* ================= particles ================= */ let PW=[],PS=[]; function confettiW(x,y,n){for(let i=0;ip.ttoastEl.classList.remove('on'),ms||2600);} function h(tag,cls,html){const e=document.createElement(tag);if(cls)e.className=cls;if(html!=null)e.innerHTML=html;return e;} function clearUI(){ui.innerHTML='';} function setSt(st){S.st=st;S.t=0;} function btn(label,cls,fn){const b=h('button','btn '+(cls||''),label);b.addEventListener('click',()=>{SFX.tap();fn();});return b;} function updHud(){ if(!S.day)return; document.getElementById('hCoins').textContent='๐Ÿช™ '+S.day.coins; document.getElementById('hStars').textContent='โญ '+S.day.stars; const ck=document.getElementById('hClock'); if(S.creative){ck.textContent='โˆž Creative';ck.classList.remove('low');} else{const t=Math.max(0,Math.ceil(S.timeLeft));ck.textContent='โฐ '+Math.floor(t/60)+':'+String(t%60).padStart(2,'0');ck.classList.toggle('low',t<=30);} } document.getElementById('bMute').textContent=SAVE.mute?'๐Ÿ”‡':'๐Ÿ”Š'; document.getElementById('bFree').classList.add('hide'); document.getElementById('bMute').addEventListener('click',toggleMute); document.getElementById('bMenu').addEventListener('click',()=>{SFX.tap();openMenu();}); function toggleMute(){SAVE.mute=!SAVE.mute;save();if(master)master.gain.value=SAVE.mute?0:.85; document.querySelectorAll('.muteb').forEach(b=>b.textContent=SAVE.mute?'๐Ÿ”‡':'๐Ÿ”Š');document.getElementById('bMute').textContent=SAVE.mute?'๐Ÿ”‡':'๐Ÿ”Š';if(!SAVE.mute)initAudio();} /* ---------- title ---------- */ function showTitle(){ setSt('title');clearUI();hud.classList.add('hide');setMusic('shop'); const c=h('div','card title-card'); c.appendChild(h('h1','','Kidopia')); c.appendChild(h('div','by','The Magical Game Shop
Game idea by a young player')); c.appendChild(h('p','lead','Customers bring their game ideas. You make each game on a magic phone. Then everyone plays it on the big TV!')); const r=h('div','row'); r.appendChild(btn('โ–ถ Open the shop','g',()=>{initAudio();startDay(false);})); r.appendChild(btn('โˆž Creative mode','w',()=>{initAudio();startDay(true);})); c.appendChild(r); if(SAVE.games)c.appendChild(h('p','small','Your shop so far: '+SAVE.games+' games made, '+SAVE.coins+' coins, '+SAVE.unl.length+' prizes unlocked.')); c.appendChild(h('p','small','A day in the shop lasts 5 minutes. No sound? Turn the volume up with the side buttons and tap the screen once. It plays even when an iPhone is on silent.
All games ยท How it was made')); ui.appendChild(c); } /* ---------- a day in the shop ---------- */ function startDay(creative){ S.creative=creative;S.timeLeft=300;S.day={coins:0,stars:0,games:0,happy:0,sat:[],made:[],unl:[],cust:0}; S.people=[OWNER];S.cur=null;S.waiting=null;S.lastModes=[];PW=[];PS=[]; Object.assign(OWNER,{x:720,y:760,tx:720,facing:-1,behind:true,sit:false,ctrl:false,happy:0,holdPhone:false,bubble:null,arrive:null}); SHOP.door=0;SHOP.lights=0;SHOP.tvOn=0;SHOP.tvGame=null; clearUI();hud.classList.remove('hide');updHud();setMusic('shop'); setSt('open');CAM.x=420; } function spawnCustomer(toWait){ const c=mkPerson({look:mkLook(),name:pick(NAMES),pers:pick(PERS),decided:Math.random()<.55,speed:rnd(240,300)}); if(S.cur&&c.name===S.cur.name)c.name=pick(NAMES); S.day.cust++;S.people.push(c); if(toWait){c.tx=WAITS[0];c.arrive=()=>{c.sit=true;c.facing=1;c.y=800;say(c,c.pers.wait,2.5);};} return c; } function walkTo(p,x,cb){p.tx=x;p.arrive=cb||null;} function callNext(c){ S.cur=c;c.sit=false;c.wave=0;c.happy=0; if(!S.creative&&S.timeLeft<100){c.final=true;setTimeout(()=>toast('Last customer of the day! ๐ŸŒŸ'),300);} setSt('enter'); walkTo(c,505,()=>{c.facing=1;setSt('talk');showTalk(c);}); } function showTalk(c){ clearUI(); say(c,c.pers.hi+' '+(c.decided?c.pers.know:c.pers.dunno),4); const s=h('div','sheet'); s.appendChild(h('h2','',esc(c.name)+' wants a new game!')); s.appendChild(h('p','sub','What does '+esc(c.name)+' say?')); const o=h('div','opts'); const mk=(cls,e,t,fn)=>{const b=h('button','opt '+cls,''+e+''+t+'');b.addEventListener('click',()=>{SFX.pick();fn();});o.appendChild(b);}; mk('o1','๐Ÿ’ก','I have my own game idea!',()=>ownIdea(c)); mk('o2','๐Ÿ–ผ๏ธ','Show me some game ideas!',()=>showIdeas(c)); mk('o3','๐ŸŽ','Surprise me!',()=>surprise(c)); s.appendChild(o);ui.appendChild(s); } function availHeroes(){return HEROES.filter(h=>okHero(h)&&!h.custom);} function availWorlds(){return WORLDS.filter(w=>okWorld(w)&&!w.custom);} function freshMode(){const ms=MODES.filter(m=>S.lastModes.indexOf(m.id)<0);return pick(ms.length?ms:MODES).id;} /* ---------- the idea engine (idea.js) turns words into a game plan ---------- */ const MIXES=[{id:'none',n:'Nothing',e:'โญ•'},{id:'collect',n:'+ Collecting',e:'๐Ÿงบ'},{id:'rescue',n:'+ Rescue friends',e:'๐Ÿ›Ÿ'}, {id:'dodge',n:'+ More dodging',e:'๐Ÿ’จ'},{id:'treasure',n:'+ Big treasure',e:'๐Ÿ’ฐ'},{id:'clock',n:'+ Beat the clock',e:'โฑ๏ธ'}]; function reg(list,o){const f=list.find(x=>x.id===o.id);if(f){Object.assign(f,o);return f;}list.push(o);return o;} function planFrom(text){ const P=window.KidIdea.read(text,{worldOf:id=>WORLDS.find(w=>w.id===id)}); let hero=null; if(P.heroE){const known=HEROES.find(x=>x.e===P.heroE&&!x.custom);hero=known&&okHero(known)?known.id:reg(HEROES,{id:'x_'+P.heroWord,n:P.heroN,e:P.heroE,custom:1}).id;} else hero=pick(availHeroes()).id; let world=null; if(P.place){const pl=window.KidIdea.places[P.place];const base=byId(WORLDS,pl?pl.w:P.place); if(pl&&pl.x)world=reg(WORLDS,Object.assign({},base,pl.x,{id:'x_'+P.place,custom:1,u:0})).id; else if(!okWorld(base))world=reg(WORLDS,Object.assign({},base,{id:'x_'+base.id,custom:1,u:0})).id; else world=base.id;} else world=P.heroSea?'ocean':P.heroFl?'sky':pick(availWorlds()).id; const w={hero,world,mode:P.mode,plan:P,text}; if(P.mix)w.mix=P.mix;if(P.power)w.power=P.power;if(P.music)w.music=P.music; if(P.haz)w.obs=reg(OBST,{id:'x_'+P.haz,n:(P.hazN||'Enemie')+'s',e:P.haz,custom:1}).id; w.items=P.items.slice();w.friendsE=P.friends.slice(); w.mods={night:P.night,weather:P.weather,size:P.size,tint:P.tint,im:P.im,hm:P.hm}; w.level=P.level||'easy'; const hr=byId(HEROES,hero),wd=byId(WORLDS,world); w.name=window.KidIdea.nameFor(P,hr.n,wd.s,P.mode,P.mix); return w; } function ideaHTML(P){ const roleOf={};P.marks.forEach(m=>{roleOf[m.w]=m.role;}); return P.text.split(/(\s+)/).map(tok=>{ const k=tok.toLowerCase().replace(/[^a-z']/g,''); let r=roleOf[k]; if(!r){for(const m of P.marks){if(k.length>2&&(k.indexOf(m.w)===0||m.w.indexOf(k)===0)){r=m.role;break;}}} return r?''+esc(tok)+'':esc(tok); }).join(''); } function showReader(c,w,title){ clearUI();const P=w.plan; const s=h('div','sheet reader'); s.appendChild(h('h2','',title||'๐Ÿง  The magic engine reads the idea')); s.appendChild(h('div','said','โ€œ'+ideaHTML(P)+'โ€')); const chips=h('div','chips'); const all=P.notes.slice(); if(w.mix)all.push({w:'',e:'โž•',what:'Mixed: '+window.KidIdea.MIX_LABEL[w.mix],role:'mode'}); all.forEach((n,i)=>{const ch=h('span','chip r-'+n.role,''+n.e+' '+(n.w?''+esc(n.w)+' โ†’ ':'')+esc(n.what));ch.style.animationDelay=(i*0.18)+'s';chips.appendChild(ch);}); if(!all.length)chips.appendChild(h('span','chip','๐Ÿค” I will pick the rest!')); s.appendChild(chips); P.swaps.forEach(m=>s.appendChild(h('p','sub',esc(m)))); const hr=byId(HEROES,w.hero),wd=byId(WORLDS,w.world),md=byId(MODES,w.mode); s.appendChild(h('div','wish',''+hr.e+' '+wd.e+' '+md.e+(w.mix?' โž•':'')+' '+esc(w.name)+'')); const r=h('div','row');r.appendChild(btn('๐Ÿ“ฑ Make it on the phone!','y',()=>openPhone(c,w)));s.appendChild(r); const ti=h('div','typein');const inp=h('input');inp.type='text';inp.maxLength=120;inp.placeholder='Type any game idea...';inp.setAttribute('aria-label','Type a game idea');inp.autocomplete='off'; const go=btn('โœจ','p',()=>{ const v=inp.value.trim();if(!v){inp.focus();return;} const nw=planFrom(v);nw.typed=true;c.wish=nw;say(c,'Yes! I love that idea!',3);SFX.pick(); showReader(c,nw,'๐Ÿง  The magic engine reads your idea'); }); inp.addEventListener('keydown',e=>{if(e.key==='Enter')go.click();e.stopPropagation();}); ti.appendChild(inp);ti.appendChild(go);s.appendChild(ti); ui.appendChild(s); } function ownIdea(c){ const text=window.KidIdea.makeRequest({avoid:S.lastModes}); const w=c.wish=planFrom(text); say(c,(c.decided?'':'Hmm... I\'ve got it! ')+text,6); showReader(c,w,'๐Ÿง  The magic engine reads '+esc(c.name)+'โ€™s idea'); } function showIdeas(c){ clearUI();say(c,'Ooh, show me! Can I mix two?',3); const s=h('div','sheet');s.appendChild(h('h2','','Pick one idea, or pick two to mix them!')); const g=h('div','ideas');const n=(W>H&&H<520)?6:(W<=380?4:6); const list=shuffle(IDEAS.slice()).slice(0,n);let sel=[]; const go=btn('๐Ÿ“ฑ Make it!','y',()=>{ if(!sel.length)return; const a=sel[0],b=sel[1]; const text=b?a.t+', mixed with '+b.t.replace(/^an? /,''):a.t; const w=planFrom(text);if(!b)w.name=a.n; c.wish=w;say(c,b?'Mix them together!':'That one! '+a.n+'!',3); showReader(c,w,b?'๐Ÿง  The magic engine mixes two ideas':'๐Ÿง  The magic engine reads the idea'); });go.disabled=true; list.forEach(id=>{ const card=h('button','idea',''+byId(HEROES,id.hero).e+byId(WORLDS,id.world).e+''+esc(id.n)+''); card.dataset.c0=id.c[0];card.dataset.c1=id.c[1]; card.addEventListener('click',()=>{ SFX.pick();const k=sel.indexOf(id); if(k>=0)sel.splice(k,1);else{if(sel.length>=2)sel.shift();sel.push(id);} g.querySelectorAll('.idea').forEach((el,i)=>{const on=sel.indexOf(list[i]);el.classList.toggle('on',on>=0);el.querySelector('.chk').textContent=on>=0?(on===0?'1๏ธโƒฃ':'2๏ธโƒฃ'):'';}); go.disabled=!sel.length;go.innerHTML=sel.length===2?'โœจ Mix them!':'๐Ÿ“ฑ Make it!'; }); g.appendChild(card); }); s.appendChild(g); g.querySelectorAll('.idea').forEach(el=>{el.style.background='linear-gradient(150deg,'+el.dataset.c0+','+el.dataset.c1+')';}); const r=h('div','row');r.appendChild(btn('๐Ÿ”„ More ideas','w',()=>showIdeas(c)));r.appendChild(go);s.appendChild(r); ui.appendChild(s); } function surprise(c){ let text; if(Math.random()<.3){const sc=pick(SECRETS.filter(x=>!byId(HEROES,x.h).u||okHero(byId(HEROES,x.h)))); const hh=byId(HEROES,sc.h).n.toLowerCase(),wd=byId(WORLDS,sc.w).n.toLowerCase();text='A '+hh+' in the '+wd+' '+pick(['racing','flying','exploring','collecting treats','dodging storms','saving friends','hunting for treasure']);} else text=window.KidIdea.makeRequest({avoid:S.lastModes}); const w=planFrom(text);w.surprise=true;c.wish=w;say(c,'Surprise me! I love surprises! ๐ŸŽ',3); showReader(c,w,'๐ŸŽ The magic engine dreams up a surprise'); } /* ---------- the magic phone ---------- */ let PH=null; const ADJ=['Super','Magic','Mega','Sparkly','Turbo','Happy','Cosmic','Wild','Tiny','Giant']; function autoName(cfg){const hr=byId(HEROES,cfg.hero),wd=byId(WORLDS,cfg.world),md=byId(MODES,cfg.mode); return (pick(ADJ)+' '+hr.n+' '+(wd.s===hr.n?'':wd.s+' ')+md.noun).replace('Pirate Parrot Pirate','Pirate Parrot').slice(0,34);} function openPhone(c,w){ clearUI();OWNER.holdPhone=true;say(OWNER,'Let me make it on my magic phone!',2.5); const cfg={hero:w.hero,world:w.world,mode:w.mode,mix:w.mix||'none',power:w.power||DEF_POWER[w.mode], goal:w.mix==='collect'||w.mode==='collect'?'collect':w.mix==='rescue'||w.mode==='rescue'?'friends':'finish', obs:w.obs||'world',music:w.music||byId(WORLDS,w.world).mus,level:w.level||'easy', items:w.items||[],friendsE:w.friendsE||[],mods:w.mods||{}}; cfg.name=w.name||autoName(cfg); S.cfg=cfg;S.wish=w;setSt('phone'); PH={tab:'mode',named:!!w.name}; const ph=h('div','phone'+(has('phone','gold')?' gold':has('phone','rainbow')?' rainbow':'')); const scr=h('div','pscr');ph.appendChild(scr); scr.appendChild(h('div','notch')); const top=h('div','ptop','โœจ Magic Game Maker ยท for '+esc(c.name)+''); const x=h('button','x','โœ–');x.setAttribute('aria-label','Close the phone');x.addEventListener('click',()=>{SFX.tap();OWNER.holdPhone=false;showTalk(c);setSt('talk');}); top.appendChild(x);scr.appendChild(top); const nm=h('div','pname');const inp=h('input');inp.type='text';inp.maxLength=34;inp.value=cfg.name;inp.setAttribute('aria-label','Game name');inp.autocomplete='off'; inp.addEventListener('input',()=>{cfg.name=inp.value;PH.named=true;});inp.addEventListener('keydown',e=>e.stopPropagation()); const dice=h('button','','๐ŸŽฒ');dice.setAttribute('aria-label','Make up a new name');dice.addEventListener('click',()=>{SFX.pick();cfg.name=autoName(cfg);inp.value=cfg.name;PH.named=false;}); nm.appendChild(inp);nm.appendChild(dice);scr.appendChild(nm); const tabs=h('div','tabs');scr.appendChild(tabs); const match=h('div','match');scr.appendChild(match); const tiles=h('div','tiles');scr.appendChild(tiles); const foot=h('div','pfoot');const cb=h('button','create','โœจ CREATE GAME โœจ');cb.addEventListener('click',()=>{createGame(c);});foot.appendChild(cb);scr.appendChild(foot); PH.el={ph,scr,tabs,tiles,match,inp}; ui.appendChild(ph);renderPhone(); } const mine=(list,k)=>()=>list.filter(x=>!x.custom||x.id===S.cfg[k]||(S.wish&&x.id===S.wish[k])); const TABS=[ {k:'mode',n:'Game type',e:'๐ŸŽฎ',list:()=>MODES},{k:'mix',n:'Mix in',e:'โž•',list:()=>MIXES},{k:'hero',n:'Hero',e:'๐Ÿฆธ',list:mine(HEROES,'hero')},{k:'world',n:'World',e:'๐ŸŒ',list:mine(WORLDS,'world')}, {k:'power',n:'Power',e:'โšก',list:()=>POWERS},{k:'goal',n:'Goal',e:'๐ŸŽฏ',list:()=>GOALS},{k:'obs',n:'Obstacles',e:'๐Ÿšง',list:mine(OBST,'obs')}, {k:'music',n:'Music',e:'๐ŸŽต',list:()=>MUSICS},{k:'level',n:'Level',e:'๐ŸŽš๏ธ',list:()=>LEVELS} ]; function matchInfo(){ const w=S.wish,cfg=S.cfg;if(!w||w.surprise)return {n:1,of:1,keys:[]}; const keys=['hero','world','mode'].concat(['mix','power','music','obs'].filter(k=>w[k])); let n=0;keys.forEach(k=>{if(cfg[k]===w[k])n++;});return {n,of:keys.length,keys}; } function extrasLine(cfg){ const m=cfg.mods||{},bits=[]; if(cfg.items&&cfg.items.length)bits.push(cfg.items.join('')+' treats'); if(cfg.friendsE&&cfg.friendsE.length)bits.push(cfg.friendsE.join('')+' friends'); if(m.night)bits.push('๐ŸŒ™ night');if(m.weather)bits.push(window.KidIdea.WEA_E[m.weather]+' '+m.weather); if(m.size>1)bits.push('โฌ†๏ธ giant hero');if(m.size<1)bits.push('โฌ‡๏ธ tiny hero');if(m.tint)bits.push('๐ŸŽจ sky'); return bits.length?'
๐Ÿง  From the words: '+bits.join(' ยท '):''; } function renderPhone(){ const {tabs,tiles,match,inp}=PH.el,cfg=S.cfg,w=S.wish; tabs.innerHTML=''; TABS.forEach(t=>{const b=h('button','tab'+(PH.tab===t.k?' on':''),''+t.e+''+t.n+(w&&w[t.k]&&!w.surprise?'โค๏ธ':'')); b.addEventListener('click',()=>{SFX.tap();PH.tab=t.k;renderPhone();});tabs.appendChild(b);}); const mi=matchInfo(); match.innerHTML=(w.surprise?'๐ŸŽ A surprise! Anything you pick will be a happy surprise.':'โค๏ธ = what '+esc(S.cur.name)+' wished for. You have '+mi.n+' of '+mi.of+'.')+extrasLine(cfg); tiles.innerHTML=''; const tab=TABS.find(t=>t.k===PH.tab); tab.list().forEach(it=>{ const locked=(tab.k==='hero'&&!okHero(it))||(tab.k==='world'&&!okWorld(it)); const b=h('button','tile'+(cfg[tab.k]===it.id?' on':'')+(locked?' lock':'')+(it.custom?' idea':''),''+(locked?'๐Ÿ”’':it.e)+''+esc(it.n)+(w&&w[tab.k]===it.id&&!w.surprise?'โค๏ธ':'')); b.addEventListener('click',()=>{ if(locked){const u=UNLOCKS.find(x=>x.id===it.id);toast('Earn '+(u?u.c:'more')+' coins in total to unlock '+it.n+'!');return;} SFX.pick();cfg[tab.k]=it.id; if(tab.k==='mix'){if(it.id==='collect')cfg.goal='collect';if(it.id==='rescue')cfg.goal='friends';} if(!PH.named){cfg.name=autoName(cfg);inp.value=cfg.name;} renderPhone(); }); tiles.appendChild(b); }); } function createGame(c){ const cfg=S.cfg;if(!cfg.name.trim())cfg.name=autoName(cfg); SFX.create();setSt('creating'); const fast=has('phone','rainbow')||has('phone','gold');const dur=fast?1500:2300; const hr=byId(HEROES,cfg.hero); const mk=h('div','making','
'+hr.e+'
Drawing the hero...
'); PH.el.scr.appendChild(mk); const steps=['Drawing the hero...','Building the world...','Adding the music...','Adding magic sparkles...']; const lbl=mk.querySelector('.lbl'),bar=mk.querySelector('.bar i');const t0=performance.now(); say(c,'Whoa! It\'s working!',2); const iv=setInterval(()=>{const k=Math.min(1,(performance.now()-t0)/dur);bar.style.width=(k*100)+'%';lbl.textContent=steps[Math.min(3,Math.floor(k*4))]; if(k>=1){clearInterval(iv);transfer(c);}},60); } function transfer(c){ const cfg=S.cfg; const r=PH.el.ph.getBoundingClientRect();const sx=r.left+r.width/2,sy=r.top+r.height*.4; PH.el.ph.classList.add('fly');setTimeout(clearUI,600); SFX.whoosh();setSt('transfer');OWNER.holdPhone=true; const cols=['#ff4f6d','#ffd23f','#4cf2a0','#3fa8ff','#ff8fd0','#fff']; const hr=byId(HEROES,cfg.hero),wd=byId(WORLDS,cfg.world); S.stream=[];for(let i=0;i<70;i++)S.stream.push({sx:sx+rnd(-40,40),sy:sy+rnd(-60,60),d:rnd(0,.9),dur:rnd(.9,1.4),c:pick(cols),s:rnd(5,11),wob:rnd(-200,200),e:i%9===0?pick([hr.e,wd.items[0],'โญ']):null}); S.game={cfg,hero:hr,world:wd,name:cfg.name}; say(OWNER,'Zap! Off to the TV!',2); c.wave=0;walkTo(c,SEATS[0],()=>{c.sit=true;c.facing=1;c.y=800;c.ctrl=true;}); } function tvOn(){ setSt('tvon');SFX.tvon();SHOP.tvGame=S.game;SHOP.tvOn=.01; const c=S.cur;OWNER.holdPhone=false;OWNER.behind=false; walkTo(OWNER,SEATS[1],()=>{OWNER.sit=true;OWNER.facing=-1;OWNER.y=800;OWNER.ctrl=true;}); setTimeout(()=>{if(S.st!=='tvon')return;say(c,c.pers.couch,3); clearUI();const s=h('div','sheet');s.appendChild(h('h2','','๐Ÿ“บ '+esc(S.game.name)+' is on the TV!')); s.appendChild(h('p','sub',esc(c.name)+' is on the couch with a controller. Join in!')); const r=h('div','row');r.appendChild(btn('๐ŸŽฎ Play together!','g',startPlay));s.appendChild(r);ui.appendChild(s);},900); } function startPlay(){ clearUI();setSt('zoom');S.zoom=0; if(!S.creative&&S.timeLeft>110&&!S.waiting&&!S.cur.final){S.waiting=spawnCustomer(true);} } /* ---------- results and the end of the day ---------- */ function gameDone(res){ const c=S.cur,cfg=S.cfg,day=S.day; hud.classList.remove('hide');setMusic('shop'); SHOP.tvOn=1; const mi=matchInfo(),match=mi.of?mi.n/mi.of:1; const secret=SECRETS.find(x=>x.h===cfg.hero&&x.w===cfg.world); const sat=Math.round(clamp(100*(.4*match+.6*(res.stars/3))+(secret?8:0),35,100)); let coins=10+res.stars*6+Math.round(match*10)+(secret?15:0)+Math.min(15,Math.floor(res.score/60)); day.coins+=coins;day.stars+=res.stars;day.games++;day.sat.push(sat);if(sat>=60)day.happy++; const md=byId(MODES,cfg.mode),hr=byId(HEROES,cfg.hero); day.made.push(hr.e+' '+cfg.name);S.lastModes.push(cfg.mode);if(S.lastModes.length>4)S.lastModes.shift(); SAVE.coins+=coins;SAVE.stars+=res.stars;SAVE.games++;SAVE.made.push({n:cfg.name.slice(0,34),e:hr.e});if(SAVE.made.length>30)SAVE.made.shift(); let newSecret=false;if(secret&&SAVE.secrets.indexOf(secret.n)<0){SAVE.secrets.push(secret.n);newSecret=true;} const unl=[];UNLOCKS.forEach(u=>{if(SAVE.coins>=u.c&&!has(u.k,u.id)){SAVE.unl.push(u.k+':'+u.id);unl.push(u);day.unl.push(u);}}); save();updHud(); c.ctrl=false;OWNER.ctrl=false;c.sit=false;c.y=800;c.happy=3;OWNER.sit=false;OWNER.y=800; const happy=sat>=60; say(c,happy?pick(['Best. Game. Ever!','You\'re a game wizard!','I want to play it again!','That was AMAZING!']):'That was fun! Thank you!',3.5); confettiW(c.x,560,happy?90:40);SFX.win(); setTimeout(()=>{if(unl.length)SFX.unlock();else SFX.coin();},700); clearUI();setSt('result'); const cd=h('div','card'); cd.appendChild(h('div','big',happy?'๐Ÿ˜„':'๐Ÿ™‚')); cd.appendChild(h('h2','',esc(c.name)+(happy?' loved it!':' liked it!'))); cd.appendChild(h('div','stars','โญ'.repeat(res.stars)+'โ˜†'.repeat(3-res.stars))); cd.appendChild(h('p','lead',res.msg)); const st=h('div','stats'); st.innerHTML='
+'+coins+' ๐Ÿช™coins
'+sat+'%happy
'+ (S.wish.surprise?'
๐ŸŽsurprise game
':'
'+'โค๏ธ'.repeat(mi.n)+(mi.n?'':'0')+'wishes made true
'); cd.appendChild(st); if(secret)cd.appendChild(h('div','unl','๐Ÿคซ '+(newSecret?'New secret game found: ':'Secret game: ')+''+esc(secret.n)+'!')); unl.forEach(u=>cd.appendChild(h('div','unl',''+u.e+' Unlocked! '+esc(u.t)))); const nx=UNLOCKS.find(u=>!has(u.k,u.id)); if(nx)cd.appendChild(h('p','small','Next prize at '+nx.c+' coins: '+nx.e+' '+esc(nx.t)+' (you have '+SAVE.coins+')')); const r=h('div','row'); const end=!S.creative&&(c.final||S.timeLeft<=0); r.appendChild(btn(end?'๐ŸŽ‰ Finish the day':'โ–ถ Next customer',end?'p':'g',()=>{clearUI();nextCustomer(end);})); cd.appendChild(r);ui.appendChild(cd); } function nextCustomer(end){ const c=S.cur;c.happy=0;c.wave=1;say(c,'Bye! See you soon!',2); walkTo(c,-220,()=>{S.people=S.people.filter(p=>p!==c);}); OWNER.behind=false;walkTo(OWNER,720,()=>{OWNER.behind=true;OWNER.facing=-1;OWNER.y=760;});OWNER.y=800; setTimeout(()=>{SHOP.tvOn=0;SHOP.tvGame=null;},800); if(end){setTimeout(endDay,900);setSt('leaving');return;} const w=S.waiting;S.waiting=null;setSt('leaving'); setTimeout(()=>{ if(w){w.sit=false;w.y=800;callNext(w);} else{const n=spawnCustomer(false);callNext(n);} },700); } function endDay(){ setSt('end');clearUI();const d=S.day; const avg=d.sat.length?Math.round(d.sat.reduce((a,b)=>a+b,0)/d.sat.length):0; const rating=avg>=90?5:avg>=78?4:avg>=62?3:avg>=45?2:1; SAVE.best=Math.max(SAVE.best,rating);save(); SFX.party();setTimeout(SFX.win,500); confettiW(800,300,160); OWNER.happy=4;say(OWNER,'What a great day at Kidopia!',4); const cd=h('div','card'); cd.appendChild(h('h1','','Shop closed!')); cd.appendChild(h('p','lead','What a magical day at Kidopia!')); cd.appendChild(h('div','stars','โญ'.repeat(rating)+'โ˜†'.repeat(5-rating))); cd.appendChild(h('p','small','Shop rating: '+rating+' of 5 stars')); const st=h('div','stats'); st.innerHTML=[['๐ŸŽฎ '+d.games,'games created'],['๐Ÿ˜„ '+d.happy,'happy customers'],['๐Ÿช™ '+d.coins,'coins earned'],['โญ '+d.stars,'stars collected'],['๐Ÿ’– '+avg+'%','customer happiness'],['๐Ÿ† '+rating+'/5','shop rating']] .map(a=>'
'+a[0]+''+a[1]+'
').join(''); cd.appendChild(st); if(d.made.length)cd.appendChild(h('p','made','Games you made today:
'+d.made.map(esc).join('
'))); if(d.unl.length)cd.appendChild(h('div','unl','New today: '+d.unl.map(u=>''+u.e+'').join(' '))); const r=h('div','row'); r.appendChild(btn('๐Ÿ” Play again','g',()=>startDay(false))); r.appendChild(btn('โˆž Creative mode','w',()=>startDay(true))); cd.appendChild(r); cd.appendChild(h('p','small','All games ยท How it was made')); ui.appendChild(cd); } function openMenu(){ if(S.st==='title'||S.paused)return; S.paused=true;const old=Array.from(ui.children);old.forEach(e=>e.classList.add('hide')); const cd=h('div','card');cd.appendChild(h('h2','','Paused')); cd.appendChild(h('p','lead','Help customers make their dream games. Tap the choices, make the game on the magic phone, then press Play together and play it on the TV.')); cd.appendChild(h('p','small','Controls in the TV games: drag on the screen or use the arrow keys to move. The big round button (or Space) is jump, boost or dash. In the puzzle, tap the cards.
No sound? Turn the volume up with the side buttons and tap the screen once. It plays even when an iPhone is on silent.
Progress is saved only on this device. Kidopia asks for no names or personal details.')); const r=h('div','row'); const close=()=>{cd.remove();old.forEach(e=>e.classList.remove('hide'));S.paused=false;}; r.appendChild(btn('โ–ถ Keep playing','g',close)); r.appendChild(btn('๐Ÿ” New day','w',()=>{cd.remove();S.paused=false;if(G)G=null;gamebar.classList.add('hide');startDay(false);})); r.appendChild(btn('โˆž Creative','w',()=>{cd.remove();S.paused=false;if(G)G=null;gamebar.classList.add('hide');startDay(true);})); r.appendChild(btn('๐Ÿ  Title','w',()=>{cd.remove();S.paused=false;if(G)G=null;gamebar.classList.add('hide');showTitle();})); cd.appendChild(r);ui.appendChild(cd); } /* ================= the mini-game engine ================= */ let G=null; const gamebar=h('div','gamebar hide'); (function(){const m=h('button','ib muteb',SAVE.mute?'๐Ÿ”‡':'๐Ÿ”Š');m.setAttribute('aria-label','Sound on or off');m.addEventListener('click',toggleMute); const q=h('button','ib','โœ–');q.setAttribute('aria-label','Stop this game');q.addEventListener('click',()=>{if(G&&G.phase==='play'){G.phase='end';G.endT=0;G.endMsg='Game over!';}}); const p=h('button','ib','โ˜ฐ');p.setAttribute('aria-label','Menu');p.addEventListener('click',openMenu); gamebar.appendChild(m);gamebar.appendChild(q);gamebar.appendChild(p);document.body.appendChild(gamebar);})(); const INP={ax:0,ay:0,act:false,actP:false,taps:[],keys:{},joy:null,actId:null,padAct:false}; function newGame(cfg,cust){ const lv={easy:0,medium:1,hard:2}[cfg.level]||0; const md=cfg.mods||{};let wd=byId(WORLDS,cfg.world);const hr=byId(HEROES,cfg.hero); if(md.tint)wd=Object.assign({},wd,{sky:md.tint}); const secret=!!SECRETS.find(x=>x.h===cfg.hero&&x.w===cfg.world); const g={cfg,cust,mode:cfg.mode,lv,dif:[.85,1,1.2][lv],wd,hr,secret, t:0,dur:[40,36,32][lv],score:0,hits:0,items:0,friends:0,main:false,phase:'intro',introT:0,endT:0, inv:0,shield:cfg.power==='shield'?3:0,spd:cfg.power==='speed'?1.3:1,mag:cfg.power==='magnet'?150:0,dbl:cfg.power==='double'?2:1, hz:cfg.power==='slow'?.65:1,jmp:cfg.power==='jump', hazE:cfg.obs==='world'?wd.haz:byId(OBST,cfg.obs).e,itemE:cfg.items&&cfg.items.length?cfg.items:wd.items,pops:[],fx:[],shake:0,react:null,reactT:0, W:800,H:540,cam:{x:0,y:0},o:[],p:{x:0,y:0,vx:0,vy:0,face:1}}; const fe=cfg.friendsE||[];g.frE=fe.concat(FRIENDS.filter(x=>fe.indexOf(x)<0)); g.im=md.im||1;g.hm=md.hm||1;g.hs=md.size||1;g.frOn=cfg.goal==='friends'||cfg.mix==='rescue'; if(cfg.mix==='collect')g.im*=1.5;if(cfg.mix==='dodge')g.hm*=1.5;if(cfg.mix==='treasure')g.bigT=true; if(cfg.mix==='clock'){g.dur-=6;g.spd*=1.12;} g.stage=1;g.won=0;g.mixN=0;g.L=[];g.base0={spd:g.spd,mag:g.mag,dbl:g.dbl}; g.goalN={collect:[10,12,14][lv],friends:3,score:[300,400,500][lv]}[cfg.goal]||0; if(cfg.goal==='collect'&&cfg.mode==='collect')g.goalN=[18,22,26][lv]; if(cfg.goal==='collect'&&cfg.mode==='puzzle')g.goalN=0; return g; } function gArea(){ const port=W/H<1;const ctrl=(TOUCH&&port&&G&&G.mode!=='puzzle')?Math.min(230,H*.3):0; const top=0,aw=W,ah=H-ctrl; return {x:0,y:top,w:aw,h:ah,ctrl}; } function gSetup(g){ const A=gArea();g.H=540;g.W=clamp(Math.round(A.w/A.h*540),320,1100);g.sc=Math.min(A.w/g.W,A.h/g.H); g.ox=A.x+(A.w-g.W*g.sc)/2;g.oy=A.y+(A.h-g.H*g.sc)/2;g.A=A; } function pop(g,x,y,t,col){g.pops.push({x,y,t,col:col||'#fff',age:0});} function gfx(g,x,y,col,n){for(let i=0;i<(n||10);i++){const a=rnd(0,6.28),v=rnd(60,260);g.fx.push({x,y,vx:Math.cos(a)*v,vy:Math.sin(a)*v,life:rnd(.3,.7),t:0,c:col||pick(['#ffd23f','#fff','#ff8fd0','#4cf2ff']),s:rnd(3,7)});}} function react(g,t){if(g.reactT>0&&Math.random()<.5)return;g.react=t;g.reactT=1.6;} function gotItem(g,x,y){g.items++;g.score+=10*g.dbl;pop(g,x,y,'+'+10*g.dbl,'#ffd23f');gfx(g,x,y);SFX.collect();if(g.bigT&&Math.random()<.2){g.score+=40*g.dbl;pop(g,x,y-34,'Big treasure! +'+40*g.dbl,'#ffc21a');SFX.star();}if(g.items%5===0)react(g,pick(['Yay!','Wow, so many!','Go go go!','You\'re so good!']));} function gotFriend(g,x,y){g.friends++;g.score+=50*g.dbl;pop(g,x,y,'Friend saved! +'+50*g.dbl,'#4cf2a0');gfx(g,x,y,'#4cf2a0',18);SFX.friend();react(g,'You saved a friend!');} function hurt(g,x,y){ if(g.inv>0)return false; if(g.starT>0){pop(g,x,y,'Star power!','#ffd23f');return false;} if(g.shield>0){g.shield--;g.inv=1;pop(g,x,y,'Shield!','#4cf2ff');SFX.bonk();return false;} g.hits++;g.inv=1.3;g.shake=.3;pop(g,x,y,'Oops!','#ff8fa8');SFX.hit();react(g,pick(['Oh no!','Watch out!','Try again!','Ouch, keep going!']));return true; } function realFinish(g,msg,main){if(g.phase==='end')return;g.main=main!==false;g.phase='end';g.endT=0;g.endMsg=msg||'You did it!';SFX.win();} function finishMain(g,msg){stageDone(g,true,msg);} /* ---- each kind of game ---- */ const MG={}; MG.race={ how:'Steer left and right. Tap the round button to boost!',btn:'โšก', init(g){g.len=8400*(g.dur/36);g.base=290;g.dist=0;g.boost=0;g.cool=0;g.slow=0;g.p.x=g.W/2;g.p.y=g.H-110;g.rw=Math.min(g.W*.86,560); const others=shuffle(HEROES.filter(x=>x.id!==g.hr.id&&!x.u)).slice(0,3); g.riv=others.map((h,i)=>({e:h.e,d:-80-i*70,v:g.base*(.9+i*.03)*g.dif,x:g.W/2+(i-1)*g.rw*.28,fin:0})); g.place=0;g.fin=0; for(let d=500;d0?1.6:1)*(g.slow>0?.55:1)*(g.spd>1?1.08:1);g.dist+=v*dt; for(const r of g.riv){const gap=r.d-g.dist;const rb=gap>500?.85:gap<-500?1.15:1;r.d+=r.v*rb*dt*(g.hz<1?.92:1);r.x+=Math.sin(g.t*1.3+r.v)*20*dt;if(r.d>=g.len&&!r.fin){r.fin=++g.fin;}} for(const o of g.o){if(o.gone)continue;let sy=p.y-(o.d-g.dist); if(g.mag&&o.k!=='haz'&&Math.abs(sy-p.y)=g.len){g.place=g.fin+1;g.score+=[150,100,60,30][g.place-1]*g.dbl;finishMain(g,['1st place! ๐Ÿฅ‡','2nd place! ๐Ÿฅˆ','3rd place! ๐Ÿฅ‰','You finished! ๐Ÿ'][g.place-1]);} }, draw(g,c,T){ const p=g.p,wd=g.wd;c.fillStyle=wd.gr;c.fillRect(0,0,g.W,g.H); const off=g.dist%120; for(let y=-120;y100?1:0))%wd.deco.length],sx,y+off,44);}} const L=g.W/2-g.rw/2;c.fillStyle=wd.gr2;c.fillRect(L,0,g.rw,g.H); const rc=['#ff4f6d','#ffd23f','#4cf2a0','#3fa8ff'];for(let i=0;i<4;i++){c.fillStyle=rc[i];c.fillRect(L-8-i*6,0,6,g.H);c.fillRect(L+g.rw+2+i*6,0,6,g.H);} c.fillStyle='rgba(255,255,255,.6)';for(let y=-60;y-40&&fyg.H+40)continue;emo(c,o.e,o.x,sy,o.k==='haz'?52:40,o.k==='it'?Math.sin(T*4+o.d)*.2:0);} for(const r of g.riv){const sy=p.y-(r.d-g.dist);if(sy<-60||sy>g.H+60)continue;kart(c,r.x,sy,r.e,'#9b5cff',T);} if(g.boost>0)for(let i=0;i<4;i++)emo(c,'โœจ',p.x+rnd(-14,14),p.y+40+i*16,24,0,.8-i*.18); if(!(g.inv>0&&Math.floor(T*12)%2))kart(c,p.x,p.y,g.hr.e,'#ff4fa3',T,g.shield>0); const pr=clamp(g.dist/g.len,0,1);c.fillStyle='rgba(0,0,0,.3)';rr(c,g.W-26,70,12,g.H-160,6);c.fill();c.fillStyle='#ffd23f';rr(c,g.W-26,70+(g.H-160)*(1-pr),12,(g.H-160)*pr,6);c.fill(); let place=1;for(const r of g.riv)if(r.d>g.dist)place++;txt(c,['1st','2nd','3rd','4th'][place-1],g.W-20,g.H-70,22,'#fff','center','#2a1460'); }, goal(g){return '๐Ÿ '+Math.round(clamp(g.dist/g.len,0,1)*100)+'%';} }; function kart(c,x,y,e,col,T,sh){c.fillStyle='rgba(0,0,0,.25)';ell(c,x,y+26,30,9);c.fill();c.fillStyle=col;rr(c,x-26,y-4,52,32,12);c.fill();c.fillStyle='#222';rr(c,x-30,y-2,10,14,4);c.fill();rr(c,x+20,y-2,10,14,4);c.fill();rr(c,x-30,y+16,10,14,4);c.fill();rr(c,x+20,y+16,10,14,4);c.fill();emo(c,e,x,y-12+Math.sin(T*12)*1.5,46);if(sh){c.strokeStyle='rgba(76,242,255,.8)';c.lineWidth=4;ell(c,x,y,40,40);c.stroke();}} MG.fly={ how:'Hold the round button (or push up) to fly up. Let go to glide down.',btn:'โฌ†๏ธ', init(g){g.p.x=g.W*.26;g.p.y=g.H/2;g.p.vy=0;g.scroll=0;g.next=0;g.nextH=1.5;g.portal=null;g.flyT=g.dur-6;}, update(g,dt,I){ const p=g.p,sp=250*g.dif;g.scroll+=sp*dt; if(Math.abs(I.ay)>.25&&!I.act)p.vy=lerp(p.vy,I.ay*330*g.spd,Math.min(1,dt*8)); else if(I.act)p.vy-=(g.jmp?1500:1200)*dt; else p.vy+=650*dt; p.vy=clamp(p.vy,-420,380);p.y+=p.vy*dt;if(p.y<70){p.y=70;p.vy=0;}if(p.y>g.H-50){p.y=g.H-50;p.vy=-200;} g.next-=dt;if(g.next<=0&&!g.portal){g.next=rnd(.35,.6)/g.im;const by=rnd(110,g.H-90); if(g.frOn&&Math.random()<.06)g.o.push({k:'fr',x:g.W+40,y:by,e:pick(g.frE),v:sp}); else for(let j=0;j<3;j++)g.o.push({k:'it',x:g.W+40+j*44,y:by+Math.sin(j)*20,e:pick(g.itemE),v:sp});} g.nextH-=dt;if(g.nextH<=0&&!g.portal){g.nextH=rnd(1.1,1.7)/(g.dif*g.hm);g.o.push({k:'haz',x:g.W+50,y:rnd(90,g.H-70),e:g.hazE,v:sp*rnd(1.1,1.4)*g.hz,w:rnd(0,3)});} if(g.t>g.flyT&&!g.portal)g.portal={x:g.W+80,y:g.H/2}; if(g.portal){g.portal.x-=sp*dt;if(Math.hypot(g.portal.x-p.x,g.portal.y-p.y)<70||g.portal.x!o.gone); }, draw(g,c,T){const p=g.p;sideBG(g,c,g.scroll,T); for(const o of g.o)emo(c,o.e,o.x,o.y,o.k==='haz'?56:40,o.k==='it'?Math.sin(T*4+o.x*.02)*.2:0); if(g.portal){emo(c,'๐ŸŒ€',g.portal.x,g.portal.y,140,T*3);} for(let i=0;i<3;i++)emo(c,'โœจ',p.x-30-i*18,p.y+rnd(-6,6),20,0,.7-i*.2); if(!(g.inv>0&&Math.floor(T*12)%2)){emo(c,g.hr.e,p.x,p.y,64*g.hs,clamp(p.vy/900,-.4,.4));if(g.shield>0){c.strokeStyle='rgba(76,242,255,.8)';c.lineWidth=4;ell(c,p.x,p.y,42,42);c.stroke();}} }, goal(g){return '๐ŸŒ€ '+Math.round(clamp(g.t/g.flyT,0,1)*100)+'%';} }; MG.platform={ how:'Move left and right. Tap the round button to jump. Jump on top of enemies!',btn:'โฌ†๏ธ', init(g){const P=g.plats=[];let x=0,y=430;P.push({x:-200,y,w:700});x=500; const gapMax=[120,150,175][g.lv],end=900+g.stage*450+g.lv*200; while(x230&&Math.random()<.55*g.dif*g.hm)g.o.push({k:'haz',x:x+w*.7,y:y-26,e:g.hazE,a:x+20,b:x+w-20,v:rnd(50,90)*g.hz*g.dif}); if(g.frOn&&Math.random()<.13)g.o.push({k:'fr',x:x+w*.3,y:y-110,e:pick(g.frE)}); x+=w;} P.push({x:x+90,y:400,w:400});g.flag={x:x+300,y:400};g.endX=x+300; Object.assign(g.p,{x:120,y:380,vx:0,vy:0,ground:false,coy:0,buf:0,jumps:0,safe:{x:120,y:380}});g.cx=0;}, update(g,dt,I){ const p=g.p,run=300*g.spd;p.vx=lerp(p.vx,I.ax*run,Math.min(1,dt*10));if(I.ax)p.face=I.ax>0?1:-1; if(I.actP||(I.ay<-.6&&!g.upHeld))p.buf=.14;g.upHeld=I.ay<-.6; p.buf-=dt;p.coy-=dt; if(p.buf>0&&(p.coy>0||(g.jmp&&p.jumps<2))){p.vy=g.jmp?-800:-700;p.buf=0;p.coy=0;p.jumps++;SFX.jump();} if(!I.act&&p.vy<-200)p.vy+=1400*dt; p.vy+=1650*dt;p.vy=Math.min(p.vy,900); const oy=p.y;p.x+=p.vx*dt;p.y+=p.vy*dt;p.ground=false; for(const q of g.plats){if(p.x>q.x-14&&p.x=q.y-26){p.y=q.y-26;p.vy=0;p.ground=true;p.coy=.1;p.jumps=0;p.safe={x:clamp(p.x,q.x+30,q.x+q.w-30),y:q.y-60};}} if(p.x<20)p.x=20; if(p.y>g.H+120){hurt(g,p.x,g.H-40);g.inv=1.3;p.x=p.safe.x;p.y=p.safe.y;p.vy=0;} for(const o of g.o){if(o.gone)continue; if(o.k==='haz'){o.x+=o.v*dt;if(o.xo.b)o.v*=-1;} if(g.mag&&o.k!=='haz'&&Math.hypot(o.x-p.x,o.y-p.y)50&&p.y=g.flag.x-10){g.score+=100*g.dbl;finishMain(g,'You reached the flag! ๐Ÿ');} }, draw(g,c,T){const p=g.p;sideBG(g,c,g.cx,T);c.save();c.translate(-g.cx,0); for(const q of g.plats){if(q.x+q.wg.cx+g.W+20)continue;c.fillStyle=g.wd.gr;rr(c,q.x,q.y,q.w,g.H-q.y+40,14);c.fill();c.fillStyle=g.wd.gr2;rr(c,q.x,q.y,q.w,16,8);c.fill(); c.fillStyle='rgba(0,0,0,.08)';for(let i=q.x+20;ig.cx+g.W+40)continue;emo(c,o.e,o.x,o.y,o.k==='haz'?50:38,o.k==='haz'?Math.sin(T*8)*.1:Math.sin(T*4+o.x)*.2);} if(!(g.inv>0&&Math.floor(T*12)%2)){c.save();c.translate(p.x,p.y);c.scale(-p.face,1);emo(c,g.hr.e,0,-4-(g.hs-1)*24,58*g.hs,p.ground?Math.sin(T*14)*Math.abs(p.vx)/2000:0);c.restore(); if(g.shield>0){c.strokeStyle='rgba(76,242,255,.8)';c.lineWidth=4;ell(c,p.x,p.y-4,38,38);c.stroke();}} c.restore(); }, goal(g){return '๐Ÿ '+Math.round(clamp(g.p.x/g.flag.x,0,1)*100)+'%';} }; function sideBG(g,c,scroll,T){ const wd=g.wd;const gr=c.createLinearGradient(0,0,0,g.H);gr.addColorStop(0,wd.sky[0]);gr.addColorStop(1,wd.sky[1]);c.fillStyle=gr;c.fillRect(0,0,g.W,g.H); if(wd.id==='space'||wd.id==='robot'){for(let i=0;i<40;i++){c.fillStyle='rgba(255,255,255,'+(.4+.4*Math.sin(T*3+i))+')';const x=((i*97-scroll*.1)%g.W+g.W)%g.W;ell(c,x,(i*53)%g.H,1.6,1.6);c.fill();}} for(let k=0;k<2;k++){const sp=k?.5:.2,col=k?'rgba(255,255,255,.28)':'rgba(255,255,255,.18)';c.fillStyle=col;c.beginPath();c.moveTo(0,g.H); for(let x=0;x<=g.W+40;x+=40){const wx=x+scroll*sp;c.lineTo(x,g.H-(k?120:200)-Math.sin(wx*.006+k)*50-Math.sin(wx*.017)*20);}c.lineTo(g.W,g.H);c.fill();} for(let i=0;i<6;i++){const sp=.35;const x=((i*190-scroll*sp)%(g.W+200)+g.W+200)%(g.W+200)-100;emo(c,wd.deco[i%wd.deco.length],x,80+(i*67)%180,40+(i%3)*14,0,.75);} } /* top-down games: treasure, explore, dodge, rescue */ function tdInit(g,o){ const arena=g.mode==='dodge';g.MW=arena?g.W:Math.max(g.W*2.1,1500);g.MH=arena?g.H:1300; Object.assign(g.p,{x:g.MW/2,y:g.MH/2,dash:0,cool:0,trail:[]}); const free=(r)=>{for(let k=0;k<40;k++){const x=rnd(70,g.MW-70),y=rnd(110,g.MH-70);if(Math.hypot(x-g.p.x,y-g.p.y)>r)return {x,y};}return {x:rnd(70,g.MW-70),y:rnd(110,g.MH-70)};}; g.free=free; const nItems=Math.round((arena?6:24)*g.im);for(let i=0;i1){ax/=m;ay/=m;} p.cool-=dt;if(I.actP&&p.cool<=0){p.dash=.28;p.cool=1;SFX.boost();} p.dash-=dt;const sp=270*g.spd*(p.dash>0?2.3:1); p.x=clamp(p.x+ax*sp*dt,30,g.MW-30);p.y=clamp(p.y+ay*sp*dt,80,g.MH-30);if(ax)p.face=ax>0?1:-1; p.trail.unshift({x:p.x,y:p.y});if(p.trail.length>120)p.trail.pop(); g.cam.x=clamp(p.x-g.W/2,0,g.MW-g.W);g.cam.y=clamp(p.y-g.H/2,0,g.MH-g.H); for(const o of g.o){if(o.gone)continue; if(o.k==='haz'){o.x+=o.vx*o.v*dt;o.y+=o.vy*o.v*dt; if(o.bul){if(o.x<-80||o.x>g.MW+80||o.y<-80||o.y>g.MH+80)o.gone=1;} else{if(o.x<30||o.x>g.MW-30)o.vx*=-1;if(o.y<90||o.y>g.MH-30)o.vy*=-1;if(Math.random()g.cam.x-60&&d.xg.cam.y-60&&d.yg.cam.x+g.W+60||o.yg.cam.y+g.H+60)continue; if(o.k==='fr'){c.fillStyle='rgba(180,240,255,.5)';c.strokeStyle='#fff';c.lineWidth=3;ell(c,o.x,o.y,30,30);c.fill();c.stroke();} emo(c,o.e,o.x,o.y,o.k==='haz'?52:o.k==='fr'?40:36,o.k==='haz'?Math.sin(T*6+o.x)*.15:Math.sin(T*4+o.y)*.2);} if(g.followers)g.followers.forEach((f,i)=>{const tp=p.trail[Math.min(p.trail.length-1,(i+1)*12)]||p;emo(c,f,tp.x,tp.y,40,Math.sin(T*8+i)*.15);}); if(p.dash>0)for(let i=1;i<5;i++){const tp=p.trail[i*3];if(tp)emo(c,g.hr.e,tp.x,tp.y,56,0,.3-i*.05);} if(!(g.inv>0&&Math.floor(T*12)%2)){c.save();c.translate(p.x,p.y);c.scale(-(p.face||1),1);emo(c,g.hr.e,0,Math.sin(T*10)*2,60*g.hs);c.restore(); if(g.shield>0){c.strokeStyle='rgba(76,242,255,.8)';c.lineWidth=4;ell(c,p.x,p.y,40,40);c.stroke();}} c.restore(); } function arrowTo(g,c,tx,ty,col){const p=g.p;const sx=p.x-g.cam.x,sy=p.y-g.cam.y;const a=Math.atan2(ty-p.y,tx-p.x);const d=Math.hypot(tx-p.x,ty-p.y);if(d<90)return; c.save();c.translate(sx+Math.cos(a)*62,sy+Math.sin(a)*62);c.rotate(a);c.fillStyle=col||'#ffd23f';c.strokeStyle='#2a1460';c.lineWidth=3;c.beginPath();c.moveTo(16,0);c.lineTo(-8,-12);c.lineTo(-3,0);c.lineTo(-8,12);c.closePath();c.fill();c.stroke();c.restore();} function chest(c,x,y,open,T){c.fillStyle='#8b4a1c';rr(c,x-26,y-12,52,32,6);c.fill();c.fillStyle='#ffc21a';c.fillRect(x-26,y-2,52,6); if(open){c.fillStyle='#a0612a';rr(c,x-26,y-34,52,18,6);c.fill();emo(c,'๐Ÿ’Ž',x,y-20,28);}else{c.fillStyle='#a0612a';rr(c,x-28,y-24,56,16,8);c.fill();c.fillStyle='#ffc21a';ell(c,x,y-6,5,5);c.fill();}} MG.treasure={ how:'Drag or use the arrows to walk. Find the treasure under every red X!',btn:'๐Ÿ’จ', init(g){tdInit(g);g.chests=[];for(let i=0;i<[2,3,3][g.stage-1];i++){const q=g.free(300);g.chests.push({x:q.x,y:q.y,open:false});}}, update(g,dt,I){tdMove(g,dt,I);const p=g.p; for(const ch of g.chests)if(!ch.open&&Math.hypot(ch.x-p.x,ch.y-p.y)<52){ch.open=true;g.score+=100*g.dbl;pop(g,ch.x,ch.y-40,'Treasure! +'+100*g.dbl,'#ffd23f');gfx(g,ch.x,ch.y,'#ffd23f',24);SFX.star();react(g,'Treasure! Woo-hoo!');} if(g.chests.every(c=>c.open))finishMain(g,'You found all the treasure! ๐Ÿ’ฐ');}, draw(g,c,T){tdDraw(g,c,T,cc=>{for(const ch of g.chests){if(ch.open)chest(cc,ch.x,ch.y,true,T);else{cc.strokeStyle='#ff2d55';cc.lineWidth=9;cc.lineCap='round';cc.beginPath();cc.moveTo(ch.x-18,ch.y-18);cc.lineTo(ch.x+18,ch.y+18);cc.moveTo(ch.x+18,ch.y-18);cc.lineTo(ch.x-18,ch.y+18);cc.stroke();if(Math.sin(T*6+ch.x)>.6)emo(cc,'โœจ',ch.x+16,ch.y-20,22);}}}); const nx=nearest(g,g.chests.filter(c=>!c.open));if(nx)arrowTo(g,c,nx.x,nx.y);}, goal(g){return '๐Ÿ’ฐ '+g.chests.filter(c=>c.open).length+'/'+g.chests.length;} }; function nearest(g,list){let b=null,bd=1e9;for(const o of list){const d=Math.hypot(o.x-g.p.x,o.y-g.p.y);if(d