🎮ArcadeLab

墩墩鸡腿鸡大冒险

by GoldenWizard78
489 lines14.8 KB
▶ Play
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>墩墩鸡腿鸡大冒险</title>
<style>
*{margin:0;padding:0;box-sizing:border-box}
html,body{height:100%;overflow:hidden;background:#111;touch-action:none}
#game{display:block;background:#17222e}
.ctrl{position:fixed;bottom:20px;left:0;right:0;padding:0 20px;display:flex;justify-content:space-between;align-items:flex-end;pointer-events:none}
.joystick{width:140px;height:140px;border-radius:50%;background:rgba(255,255,255,0.15);border:2px solid rgba(255,255,255,0.3);pointer-events:auto;position:relative}
.joy-knob{width:60px;height:60px;border-radius:50%;background:rgba(255,180,100,0.7);position:absolute;left:50%;top:50%;transform:translate(-50%,-50%)}
.fire-btn{width:110px;height:110px;border-radius:50%;background:rgba(255,100,100,0.45);border:2px solid rgba(255,150,150,0.6);color:#fff;font-size:26px;font-weight:bold;pointer-events:auto}
.upgrade-box{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:#222;border:3px solid #ff9944;border-radius:20px;padding:20px;display:none;z-index:100;min-width:320px}
.upgrade-title{color:#ffaa55;font-size:28px;text-align:center;margin-bottom:16px;font-weight:bold}
.opt{display:block;width:100%;margin:8px 0;padding:14px;border:none;border-radius:12px;font-size:20px;color:white;background:#333}
.menu-box{position:fixed;inset:0;background:rgba(20,20,30,0.92);z-index:200;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:20px}
.hidden{display:none !important}
.menu-btn{padding:16px 32px;margin:10px;border:none;border-radius:14px;font-size:22px;background:#ff9848;color:#111;font-weight:bold}
.skin-item,.partner-item{padding:12px 20px;margin:6px;border-radius:12px;background:#333;color:#fff;font-size:19px}
.selected{background:#ff9848;color:#111}
.back-btn{margin-top:20px;background:#666}
</style>
</head>
<body>
<canvas id="game"></canvas>
<div class="ctrl">
  <div class="joystick" id="joy">
    <div class="joy-knob" id="knob"></div>
  </div>
  <button class="fire-btn" id="fireBtn">发射</button>
</div>

<div class="upgrade-box" id="upgradeUI">
  <div class="upgrade-title">升级!选择强化</div>
  <button class="opt" id="opt1"></button>
  <button class="opt" id="opt2"></button>
  <button class="opt" id="opt3"></button>
</div>

<div class="menu-box" id="mainMenu">
  <h2 style="color:#ff9848;font-size:36px;margin-bottom:24px">墩墩鸡腿鸡大冒险</h2>
  <button class="menu-btn" id="btnStart">开始游戏</button>
  <button class="menu-btn" id="btnSkin">选择皮肤</button>
  <button class="menu-btn" id="btnPartner">选择队友</button>
</div>

<div class="menu-box hidden" id="skinMenu">
  <h2 style="color:#ff9848;font-size:30px;margin-bottom:16px">挑选皮肤</h2>
  <div id="skinList"></div>
  <button class="menu-btn back-btn" id="skinBack">返回</button>
</div>

<div class="menu-box hidden" id="partnerMenu">
  <h2 style="color:#ff9848;font-size:30px;margin-bottom:16px">挑选队友</h2>
  <div id="partnerList"></div>
  <button class="menu-btn back-btn" id="partnerBack">返回</button>
</div>

<script>
const canvas = document.getElementById("game");
const ctx = canvas.getContext("2d");
const upgradeUI = document.getElementById("upgradeUI");
const opt1 = document.getElementById("opt1");
const opt2 = document.getElementById("opt2");
const opt3 = document.getElementById("opt3");

const mainMenu = document.getElementById("mainMenu");
const skinMenu = document.getElementById("skinMenu");
const partnerMenu = document.getElementById("partnerMenu");
const skinList = document.getElementById("skinList");
const partnerList = document.getElementById("partnerList");

function resize(){
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
}
resize();
window.addEventListener("resize",resize);

const skinData = [
  {id:"dundun", name:"墩墩鸡腿鸡"},
  {id:"guoguo", name:"果果哒"},
  {id:"egg", name:"蛋仔"}
];
const partnerData = [
  {id:"none", name:"不要队友"},
  {id:"guoguo", name:"果果哒队友"},
  {id:"egg", name:"蛋仔队友"}
];
let chosenSkin = "dundun";
let chosenPartner = "none";

function renderSkinMenu(){
  skinList.innerHTML = "";
  skinData.forEach(s=>{
    const b = document.createElement("button");
    b.className = "skin-item " + (chosenSkin === s.id ? "selected":"");
    b.innerText = s.name;
    b.onclick = ()=>{ chosenSkin = s.id; renderSkinMenu(); };
    skinList.appendChild(b);
  })
}
function renderPartnerMenu(){
  partnerList.innerHTML = "";
  partnerData.forEach(p=>{
    const b = document.createElement("button");
    b.className = "partner-item " + (chosenPartner === p.id ? "selected":"");
    b.innerText = p.name;
    b.onclick = ()=>{ chosenPartner = p.id; renderPartnerMenu(); };
    partnerList.appendChild(b);
  })
}

document.getElementById("btnStart").onclick = ()=>{
  mainMenu.classList.add("hidden");
  resetGame();
  state = "play";
}
document.getElementById("btnSkin").onclick = ()=>{
  mainMenu.classList.add("hidden");
  skinMenu.classList.remove("hidden");
  renderSkinMenu();
}
document.getElementById("skinBack").onclick = ()=>{
  skinMenu.classList.add("hidden");
  mainMenu.classList.remove("hidden");
}
document.getElementById("btnPartner").onclick = ()=>{
  mainMenu.classList.add("hidden");
  partnerMenu.classList.remove("hidden");
  renderPartnerMenu();
}
document.getElementById("partnerBack").onclick = ()=>{
  partnerMenu.classList.add("hidden");
  mainMenu.classList.remove("hidden");
}

let state = "menu";
let hp = 100;
let maxHp = 100;
let exp = 0;
let expNeed = 80;
let level = 1;
let score = 0;
let px, py;
let baseSpd = 6;
let moveSpd = baseSpd;
let bulletSpeed = 12;
let bulletCount = 1;
let bulletSize = 9;
let bulletDmg = 1;
let enemySpeedMult = 1;

let vx = 0, vy = 0;
let bullets = [];
let partnerBullets = [];
let enemies = [];
let spawnTimer = 0;
let partnerX, partnerY;
let partnerShootTimer = 0;

const joy = document.getElementById("joy");
const knob = document.getElementById("knob");
const fireBtn = document.getElementById("fireBtn");
let joyActive = false;
let joyCX, joyCY;

const upgrades = [
  {name:"生命上限 +25", run:()=>{maxHp +=25; hp +=25;}},
  {name:"立刻回满血量", run:()=>{hp = maxHp;}},
  {name:"连发 +1", run:()=>{bulletCount +=1;}},
  {name:"移动加速", run:()=>{moveSpd +=1.2;}},
  {name:"鸡腿子弹提速", run:()=>{bulletSpeed +=2.5;}},
  {name:"大鸡腿,伤害+1", run:()=>{bulletSize +=4; bulletDmg +=1;}},
  {name:"敌人减速", run:()=>{enemySpeedMult *=0.75;}},
  {name:"回血 40", run:()=>{hp = Math.min(hp+40,maxHp);}}
];
let pendingUpgrades = [];

function resetGame(){
  hp = 100; maxHp = 100;
  exp = 0; expNeed = 80; level = 1;
  score = 0;
  moveSpd = baseSpd;
  bulletSpeed = 12;
  bulletCount = 1;
  bulletSize =9;
  bulletDmg =1;
  enemySpeedMult = 1;
  px = canvas.width / 2;
  py = canvas.height - 160;
  partnerX = px + 70;
  partnerY = py;
  bullets = [];
  partnerBullets = [];
  enemies = [];
  spawnTimer = 0;
  partnerShootTimer = 0;
  vx = 0; vy = 0;
}

function pickThree(){
  const arr = [...upgrades];
  const out = [];
  for(let i=0;i<3;i++){
    const idx = Math.floor(Math.random()*arr.length);
    out.push(arr.splice(idx,1)[0]);
  }
  return out;
}
function showUpgrade(){
  state = "upgrade";
  pendingUpgrades = pickThree();
  opt1.innerText = pendingUpgrades[0].name;
  opt2.innerText = pendingUpgrades[1].name;
  opt3.innerText = pendingUpgrades[2].name;
  upgradeUI.style.display = "block";
}
function selectUpgrade(n){
  pendingUpgrades[n].run();
  upgradeUI.style.display = "none";
  state = "play";
}
opt1.onclick = ()=>selectUpgrade(0);
opt2.onclick = ()=>selectUpgrade(1);
opt3.onclick = ()=>selectUpgrade(2);

joy.addEventListener("touchstart", e=>{
  e.preventDefault();
  const t = e.touches[0];
  const r = joy.getBoundingClientRect();
  joyCX = r.left + r.width/2;
  joyCY = r.top + r.height/2;
  joyActive = true;
})
document.addEventListener("touchmove", e=>{
  if(!joyActive) return;
  e.preventDefault();
  const t = e.touches[0];
  let dx = t.clientX - joyCX;
  let dy = t.clientY - joyCY;
  const limit = 40;
  const dist = Math.hypot(dx,dy);
  if(dist > limit){
    dx = dx / dist * limit;
    dy = dy / dist * limit;
  }
  knob.style.transform = `translate(calc(-50% + ${dx}px), calc(-50% + ${dy}px))`;
  vx = dx / limit;
  vy = dy / limit;
})
document.addEventListener("touchend", ()=>{
  joyActive = false;
  knob.style.transform = "translate(-50%,-50%)";
  vx = 0; vy = 0;
})

fireBtn.addEventListener("touchstart", e=>{
  e.preventDefault();
  if(state === "play"){
    const spread = 0.18;
    for(let i=0;i<bulletCount;i++){
      const off = (i - (bulletCount-1)/2)*spread;
      bullets.push({x:px, y:py-30, ang:off});
    }
  }
  if(state === "over"){
    state = "menu";
    mainMenu.classList.remove("hidden");
  }
})

function spawnEnemy(){
  const isZombie = Math.random()>0.5;
  enemies.push({
    x: Math.random()*(canvas.width - 80)+40,
    y: -60,
    w:55, h:55,
    isZombie,
    hp: bulletDmg
  })
}

function drawChicken(x,y){
  ctx.save();
  ctx.fillStyle="#ff9848";
  ctx.beginPath();
  ctx.ellipse(x, y, 36, 32, 0, 0, Math.PI*2);
  ctx.fill();
  ctx.fillStyle="#fff8ee";
  ctx.beginPath();
  ctx.moveTo(x-18, y-28);
  ctx.quadraticCurveTo(x, y-60, x+18, y-28);
  ctx.fill();
  ctx.fillStyle="#fff";
  ctx.beginPath();
  ctx.arc(x-14, y-12,11,0,Math.PI*2);
  ctx.arc(x+14, y-12,11,0,Math.PI*2);
  ctx.fill();
  ctx.fillStyle="#000";
  ctx.beginPath();
  ctx.arc(x-14, y-12,5,0,Math.PI*2);
  ctx.arc(x+14, y-12,5,0,Math.PI*2);
  ctx.fill();
  ctx.fillStyle="#ffbb44";
  ctx.beginPath();
  ctx.ellipse(x, y+4,7,5,0,0,Math.PI*2);
  ctx.fill();
  ctx.fillStyle="#ff9848";
  ctx.beginPath();
  ctx.ellipse(x-32, y+12,9,13,-0.3,0,Math.PI*2);
  ctx.ellipse(x+32, y+12,9,13,0.3,0,Math.PI*2);
  ctx.fill();
  ctx.fillStyle="#ff6677";
  ctx.beginPath();
  ctx.ellipse(x-22, y+38,12,7,0,0,Math.PI*2);
  ctx.ellipse(x+22, y+38,12,7,0,0,Math.PI*2);
  ctx.fill();
  ctx.restore();
}
function drawGuoguo(x,y){
  ctx.fillStyle="#ffdc66";
  ctx.beginPath();
  ctx.ellipse(x, y, 30, 22,0,0,Math.PI*2);
  ctx.fill();
  ctx.fillStyle="#000";
  ctx.beginPath(); ctx.arc(x-12, y-8,5,0,Math.PI*2); ctx.fill();
  ctx.beginPath(); ctx.arc(x+12, y-8,5,0,Math.PI*2); ctx.fill();
  ctx.beginPath();
  ctx.arc(x, y+4,14,0.2,Math.PI-0.2);
  ctx.lineWidth=2; ctx.stroke();
}
function drawEgg(x,y){
  ctx.fillStyle="#fefefe";
  ctx.beginPath();
  ctx.ellipse(x,y,30,34,0,0,Math.PI*2);
  ctx.fill();
  ctx.fillStyle="#222";
  ctx.beginPath(); ctx.arc(x-11,y-10,6,0,Math.PI*2); ctx.fill();
  ctx.beginPath(); ctx.arc(x+11,y-10,6,0,Math.PI*2); ctx.fill();
}

function drawPlayer(){
  if(chosenSkin === "dundun") drawChicken(px,py);
  else if(chosenSkin === "guoguo") drawGuoguo(px,py);
  else drawEgg(px,py);
}
function drawPartner(){
  if(chosenPartner === "none") return;
  if(chosenPartner === "guoguo") drawGuoguo(partnerX, partnerY);
  else drawEgg(partnerX, partnerY);
}

function drawChickenBullet(b){
  ctx.save();
  ctx.fillStyle="#c96b2f";
  ctx.beginPath();
  ctx.ellipse(b.x, b.y, bulletSize, bulletSize*0.7,0,0,Math.PI*2);
  ctx.fill();
  ctx.fillStyle="#fff8ee";
  ctx.beginPath();
  ctx.ellipse(b.x, b.y - bulletSize - 3, bulletSize*0.45, bulletSize*0.8, 0,0,Math.PI*2);
  ctx.fill();
  ctx.restore();
}

function drawEnemy(e){
  if(e.isZombie){
    ctx.fillStyle="#50c850";
    ctx.fillRect(e.x,e.y,e.w,e.h);
    ctx.fillStyle="#dd3c3c";
    ctx.beginPath(); ctx.arc(e.x+15,e.y+18,6,0,Math.PI*2); ctx.fill();
    ctx.beginPath(); ctx.arc(e.x+40,e.y+18,6,0,Math.PI*2); ctx.fill();
  }else{
    ctx.fillStyle="#3c78dc";
    ctx.fillRect(e.x,e.y,e.w,e.h);
    ctx.fillStyle="#fff";
    ctx.beginPath(); ctx.arc(e.x+16,e.y+20,7,0,Math.PI*2); ctx.fill();
    ctx.beginPath(); ctx.arc(e.x+39,e.y+20,7,0,Math.PI*2); ctx.fill();
  }
}

function loop(){
  ctx.fillStyle="#17222e";
  ctx.fillRect(0,0,canvas.width,canvas.height);
  if(state === "play"){
    px += vx * moveSpd;
    py += vy * moveSpd;
    px = Math.max(40, Math.min(canvas.width - 40, px));
    py = Math.max(40, Math.min(canvas.height - 180, py));
    partnerX += (px + 80 - partnerX)*0.07;
    partnerY += (py - partnerY)*0.07;

    spawnTimer++;
    const spawnRate = Math.max(50,140-level*6);
    if(spawnTimer >= spawnRate){
      spawnEnemy();
      spawnTimer = 0;
    }

    if(chosenPartner !== "none"){
      partnerShootTimer++;
      if(partnerShootTimer >= 90){
        partnerShootTimer = 0;
        partnerBullets.push({x:partnerX, y:partnerY-26, ang:0});
      }
    }

    for(let i=enemies.length-1;i>=0;i--){
      const e = enemies[i];
      e.y += 2.5 * enemySpeedMult;
      const dx = (e.x+e.w/2)-px;
      const dy = (e.y+e.h/2)-py;
      const dist = Math.hypot(dx,dy);
      if(dist < 60){
        hp -= 22;
        enemies.splice(i,1);
        if(hp <= 0) state = "over";
        continue;
      }
      if(e.y > canvas.height + 60) enemies.splice(i,1);
    }

    const allBullets = [...bullets, ...partnerBullets];
    for(let i=allBullets.length-1;i>=0;i--){
      const b = allBullets[i];
      b.y -= bulletSpeed;
      b.x += b.ang * bulletSpeed * 0.6;
      if(b.y < -20){
        if(b === bullets[bullets.indexOf(b)]) bullets.splice(bullets.indexOf(b),1);
        else partnerBullets.splice(partnerBullets.indexOf(b),1);
        continue;
      }
      for(let j=enemies.length-1;j>=0;j--){
        const e = enemies[j];
        if(b.x>e.x && b.x<e.x+e.w && b.y>e.y && b.y<e.y+e.h){
          e.hp -= 1;
          if(b === bullets[bullets.indexOf(b)]) bullets.splice(bullets.indexOf(b),1);
          else partnerBullets.splice(partnerBullets.indexOf(b),1);
          if(e.hp <= 0){
            enemies.splice(j,1);
            score +=10;
            exp +=18;
            if(exp >= expNeed){
              exp -= expNeed;
              level++;
              expNeed = Math.floor(expNeed * 1.15);
              showUpgrade();
            }
          }
          break;
        }
      }
    }

    drawPlayer();
    drawPartner();
    bullets.forEach(drawChickenBullet);
    partnerBullets.forEach(drawChickenBullet);
    enemies.forEach(drawEnemy);

    ctx.textAlign="left";
    ctx.fillStyle="#dd3c3c";
    ctx.font="28px sans-serif";
    ctx.fillText(`生命:${Math.ceil(hp)}/${maxHp}`, 20,40);
    ctx.fillStyle="#ffbb55";
    ctx.fillText(`Lv.${level} 经验:${exp}/${expNeed}`, 20,72);
    ctx.fillStyle="#fff";
    ctx.fillText(`分数:${score}`, 20,104);
  }else if(state === "over"){
    ctx.textAlign="center";
    ctx.fillStyle="#dd3c3c";
    ctx.font="bold 44px sans-serif";
    ctx.fillText("游戏结束", canvas.width/2, canvas.height*0.26);
    ctx.fillStyle="#fff";
    ctx.font="30px sans-serif";
    ctx.fillText(`最终等级:${level}|得分:${score}`, canvas.width/2, canvas.height*0.34);
    ctx.fillStyle="#ffaa55";
    ctx.fillText("点返回菜单重新开始", canvas.width/2, canvas.height*0.44);
  }
  requestAnimationFrame(loop);
}
loop();
</script>
</body>
</html>

Game Source: 墩墩鸡腿鸡大冒险

Creator: GoldenWizard78

Libraries: none

Complexity: complex (489 lines, 14.8 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: game-goldenwizard78" to link back to the original. Then publish at arcadelab.ai/publish.