/
GameFly
/
FlyGame
Обзор
Документация
Войти
/
GameFly
/
FlyGame
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
da
58 строк
3 KB
GameFly
create da
28 ноя 2025, 21:04
28 ноя 2025, 21:04
ae272b7
Код
Авторство
О чём код?
function updateHUD(){ scoreEl.textContent = Math.round(score); sizeEl.textContent = (player?player.size:0).toFixed(2); const tops = entities.slice().sort((a,b)=>b.size-a.size).slice(0,5); document.getElementById('leaderboard')?.remove(); document.getElementById('leader')?.; /* board rendered separately */ } function loop(){ update(); draw(); requestAnimationFrame(loop); } loop(); /* ------- game flow ------- */ function startGame(){ spawnInitial(); running=true; paused=false; document.getElementById('menu').style.display='none'; } function togglePause(){ if(!running) return; paused=!paused; document.getElementById('pause').style.display = paused?'block':'none'; } function restart(){ spawnInitial(); running=true; paused=false; document.getElementById('menu').style.display='none'; } /* UI */ document.getElementById('startBtn').onclick = ()=>startGame(); document.getElementById('howBtn').onclick = ()=>alert('Fly or Grow — локал + мульти. Ешьте корм и мелких существ. Управление: мышь/клавиши. Нажмите и держите для ускорения. P — пауза, R — рестарт.'); document.getElementById('resumeBtn').onclick = ()=>togglePause(); document.getElementById('menuBtn').onclick = ()=>{ running=false; document.getElementById('menu').style.display='block'; document.getElementById('pause').style.display='none'; }; /* ------- util & spawn ------- */ function spawnFoodAt(x,y,n=1){ for(let i=0;i<n;i++) foods.push(new Food(x+rand(-12,12), y+rand(-12,12))); } function randomColor(){ const pal = ['#ffd27a','#ff9b9b','#aaf7c7','#a0d6ff','#d9b3ff','#fff0a8']; return pal[Math.floor(rand(0,pal.length))]; } function spawnInitial(){ entities=[]; foods=[]; bots=[]; player = new Creature('you_'+Math.floor(rand(1000,9999)), W/2, H/2, 1.0, '#7be0ff', 'You', 'hunter'); player.isPlayer=true; entities.push(player); const roles = ['predator','hunter','roamer']; for(let i=0;i<botCount;i++){ let b=new Creature('bot'+i, rand(80,W-80), rand(80,H-80), rand(0.6,2.8), randomColor(), 'Bot'+(i+1), roles[Math.floor(rand(0,roles.length))]); entities.push(b); bots.push(b); } for(let i=0;i<foodCount;i++) foods.push(new Food(rand(20,W-20), rand(20,H-20))); score=0; renderBoard(); updateHUD(); } /* ------- resize handling ------- */ function fitCanvas(){ const ratio = window.devicePixelRatio || 1; const parent = canvas.parentElement; let targetW = Math.min(980, parent.clientWidth - 24); let targetH = Math.min(620, parent.clientHeight - 24); canvas.style.width = targetW + 'px'; canvas.style.height = targetH + 'px'; canvas.width = Math.floor(targetW * ratio); canvas.height = Math.floor(targetH * ratio); ctx.setTransform(ratio,0,0,ratio,0,0); W = canvas.width / ratio; H = canvas.height / ratio; } window.addEventListener('resize', fitCanvas); fitCanvas(); /* initial menu */ document.getElementById('menu').style.display='block'; document.getElementById('pause').style.display='none'; spawnInitial(); renderBoard(); </script> </body> </html>