Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

3.7 KB
Raw Blame
<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Moonlight</title><style>*{box-sizing:border-box}body{margin:0;background:#192b42;color:#f4e9c8;font-family:monospace}header{display:flex;justify-content:space-between;align-items:center;padding:25px 6%;letter-spacing:2px}button{font:inherit;background:transparent;color:inherit;border:0;padding:12px;cursor:pointer}canvas{display:block;width:100%;aspect-ratio:800/480;max-height:70vh;object-fit:contain}footer{display:flex;gap:10px;justify-content:center;align-items:center;padding:16px;flex-wrap:wrap}footer button{background:#294158;min-width:50px;touch-action:none}small{color:#a5b6c8;text-align:center;display:block;margin:15px}</style>
<header><span>MOONLIGHT</span><span id="score" aria-live="polite">0 / 5</span><button id="restart">Restart</button></header><canvas id="game" width="800" height="480" aria-label="A platform game. Move with arrow keys or A and D. Jump with Space or the touch controls."></canvas><footer><button id="left" aria-label="Move left">←</button><button id="jump">Jump</button><button id="right" aria-label="Move right">→</button></footer><small>Arrows or A / D to move · Space to jump · Collect all five stars</small>
<script>const c=document.getElementById('game'),g=c.getContext('2d'),keys={};const platforms=[{x:0,y:440,w:800},{x:125,y:351,w:125},{x:320,y:275,w:125},{x:515,y:205,w:115},{x:650,y:320,w:120}];let player,stars,won=false;function restart(){player={x:35,y:400,vx:0,vy:0,ground:0};stars=[{x:180,y:320},{x:380,y:245},{x:575,y:175},{x:710,y:290},{x:760,y:410}];won=false;document.getElementById('score').textContent='0 / 5'}restart();let jump=false;addEventListener('keydown',e=>{if(['ArrowLeft','ArrowRight',' ','a','d','w','ArrowUp'].includes(e.key))e.preventDefault();keys[e.key]=true;if([' ','w','ArrowUp'].includes(e.key)&&!e.repeat)jump=true});addEventListener('keyup',e=>keys[e.key]=false);addEventListener('blur',()=>Object.keys(keys).forEach(k=>keys[k]=false));for(const [id,key]of[['left','ArrowLeft'],['right','ArrowRight']]){const b=document.getElementById(id);b.onpointerdown=e=>{b.setPointerCapture(e.pointerId);keys[key]=true};b.onpointerup=b.onpointercancel=()=>keys[key]=false}document.getElementById('jump').onclick=()=>jump=true;document.getElementById('restart').onclick=restart;let last=0;function step(now){const dt=Math.min((now-last)/16.67,2)||1;last=now;player.vx=(keys.ArrowRight||keys.d?3.6:0)-(keys.ArrowLeft||keys.a?3.6:0);if(jump&&player.ground>0){player.vy=-11;player.ground=0}jump=false;const bottom=player.y+28;player.ground-=dt;player.vy+=.45*dt;player.x=Math.max(0,Math.min(776,player.x+player.vx*dt));player.y+=player.vy*dt;for(const p of platforms)if(player.vy>=0&&player.x+24>p.x&&player.x<p.x+p.w&&bottom<=p.y+2&&player.y+28>=p.y){player.y=p.y-28;player.vy=0;player.ground=7}stars=stars.filter(s=>Math.hypot(player.x+12-s.x,player.y+14-s.y)>26);won=stars.length===0;document.getElementById('score').textContent=won?'All yours. Well played!':(5-stars.length)+' / 5';g.fillStyle='#192b42';g.fillRect(0,0,800,480);g.fillStyle='#e4daba';g.beginPath();g.arc(695,74,32,0,7);g.fill();g.fillStyle='#33485b';for(let i=0;i<12;i++){g.beginPath();g.moveTo(i*85-50,440);g.lineTo(i*85,190+(i%3)*35);g.lineTo(i*85+50,440);g.fill()}for(const p of platforms){g.fillStyle='#436c58';g.fillRect(p.x,p.y,p.w,480-p.y);g.fillStyle='#91b27f';g.fillRect(p.x,p.y,p.w,9)}g.fillStyle='#e6c572';for(const s of stars){g.save();g.translate(s.x,s.y);g.rotate(now/800);g.fillRect(-6,-6,12,12);g.restore()}g.fillStyle='#f2b552';g.fillRect(player.x,player.y,24,28);g.fillStyle='#192b42';g.fillRect(player.x+16,player.y+7,4,4);requestAnimationFrame(step)}requestAnimationFrame(step);</script></html>