跳到正文

剪贴板

剪贴板 9d8n0cwe

原文
剪贴板信息

剪贴板信息

收录
更新
JavaScript
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<title>GameV0.0.23</title>
<style>
*{box-sizing:border-box;image-rendering:pixelated}
html,body{margin:0;overflow:hidden;background:#86c9ef;font-family:monospace}
canvas{display:block;width:100vw;height:100vh;background:#86c9ef}
.screen{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.52);z-index:10}
.card{background:#1e293b;color:#fff;border:4px solid #fff;padding:24px;width:min(780px,92vw);box-shadow:10px 10px 0 #000}
button{font:inherit;padding:10px 18px;border:3px solid #fff;background:#f59e0b;cursor:pointer;font-weight:bold;margin-right:8px}
.log{margin-top:12px;background:#0f172a;padding:12px;border:2px solid #475569;max-height:240px;overflow:auto;line-height:1.55}
.hidden{display:none}
</style>
</head>
<body>
<canvas id="game" width="960" height="540"></canvas>
<div class="screen" id="cover">
  <div class="card">
    <h1>GameV0.0.23</h1>
    <p>修复版:Minecraft 风格平台跑酷地图</p>
    <p>新增定距存档点、优化材质、十颗红色星星血量、更多群系/装饰、可达路线和移动障碍物。</p>
    <button id="startBtn">开始游戏</button>
    <button id="logBtn">更新日志</button>
    <div class="log hidden" id="log">
      <b>GameV0.0.23 修复日志</b><br><br>
      1. 每隔固定距离生成存档旗帜,不再只有少量固定点。<br>
      2. 保持 Minecraft 像素风,增强草块、泥土、石头、沙地、雪地、岩浆、矿石等材质细节。<br>
      3. 死亡或掉落重生后血量回满;HUD 改为 10 颗红色星星。<br>
      4. 地面加入平原、森林、沙漠、雪地、火山多群系色彩。<br>
      5. 降低/错开石墙,加入辅助平台,避免不可达跳跃。<br>
      6. 恢复并增加草、花、蘑菇、仙人掌、枯草、火山灰等装饰。<br>
      7. 重画存档旗子:旗杆插在平台上,旗面带阴影、轮廓和激活颜色。<br>
      8. 增加横向巡逻的移动障碍物,需要躲避。<br>
    </div>
  </div>
</div>
<script>
(()=>{
'use strict';
const canvas=document.getElementById('game');
const ctx=canvas.getContext('2d');
ctx.imageSmoothingEnabled=false;
const TILE=24,W=canvas.width,H=canvas.height;
const world={cols:1000,rows:1000,tiles:new Map(),cameraX:0,cameraY:0,time:0};
const movers=[],hazards=[],checkpoints=[],decorations=[];
const keys=new Set();
let running=false,won=false;
let spawn={x:24*TILE,y:966*TILE};
let finishPos={x:0,y:0,groundY:0};

function keyOf(x,y){return x+','+y;}
function setTile(x,y,t){if(x>=0&&y>=0&&x<world.cols&&y<world.rows){t?world.tiles.set(keyOf(x,y),t):world.tiles.delete(keyOf(x,y));}}
function getTile(x,y){if(x<0||y<0||x>=world.cols||y>=world.rows)return 1;return world.tiles.get(keyOf(x,y))||0;}
function fixed(n,m){return ((n*37+n*n*13+97)%m+m)%m;}
function biomeAt(i){if(i<34)return 'plain';if(i<72)return 'forest';if(i<110)return 'desert';if(i<150)return 'snow';return 'volcano';}
function topTile(b,i){if(b==='desert')return i%4===0?16:14;if(b==='snow')return i%3===0?15:5;if(b==='volcano')return i%3===0?17:4;if(b==='forest')return i%4===0?18:2;return i%5===0?19:2;}
function underTile(b){if(b==='desert')return 14;if(b==='snow')return 3;if(b==='volcano')return 4;return 3;}
function makePlatform(x,y,w,b,i){
 const top=topTile(b,i),under=underTile(b);
 for(let xx=x;xx<x+w;xx++){
   setTile(xx,y,top);
   const depth=2+fixed(xx+y+i,4);
   for(let d=1;d<=depth;d++)setTile(xx,y+d,under);
 }
}
function addOre(x,y,i){const ore=[11,13,20][i%3];setTile(x,y,ore);if(i%2===0)setTile(x+1,y,ore);if(i%4===0)setTile(x,y+1,ore);}
function addTree(x,y,b,i){
 const h=3+(i%3),leaf=b==='snow'?12:10;
 for(let k=1;k<=h;k++)setTile(x,y-k,9);
 for(let lx=-2;lx<=2;lx++)for(let ly=-2;ly<=1;ly++){if(Math.abs(lx)+Math.abs(ly)<4)setTile(x+lx,y-h+ly,leaf);}
 decorations.push({x:x,y:y-h-2,t:b==='snow'?'snowcap':'leafspark'});
}
function addCactus(x,y,i){const h=2+(i%3);for(let k=1;k<=h;k++)setTile(x,y-k,21);if(h>2){setTile(x-1,y-2,21);setTile(x+1,y-3,21);}}

function buildWorld(){
 world.tiles.clear();decorations.length=0;movers.length=0;hazards.length=0;checkpoints.length=0;won=false;
 const path=[];let px=22,py=970;
 for(let i=0;i<190;i++){
   if(i>0){
     const dx=4+(i%4); // 保证距离可跳
     let dy=(i%7===0)?-4:(i%5===0?3:-2);
     if(i%23===0)dy=6;
     px+=dx;py+=dy;
   }
   py=Math.max(118,Math.min(974,py));
   path.push({x:px,y:py,w:4+(i%3)+(i%11===0?1:0),b:biomeAt(i),i});
 }
 for(const p of path){
   makePlatform(p.x,p.y,p.w,p.b,p.i);
   // 低矮可跳石墙,不再生成过高不可达墙。
   if(p.i%9===0 && p.i>4){
     const h=1+(p.i%3), wx=p.x+p.w;
     for(let k=0;k<h;k++)setTile(wx,p.y-k,4);
     addOre(wx,p.y+1,p.i);
   }
   // 岩浆左右包裹,上方开放。
   if(p.i>10 && p.i%13===0){
     const lw=2+(p.i%4), lx=p.x+1;
     for(let k=0;k<lw;k++)setTile(lx+k,p.y-1,6);
     setTile(lx-1,p.y-1,4);setTile(lx+lw,p.y-1,4);
     decorations.push({x:lx+Math.floor(lw/2),y:p.y-2,t:'embers'});
   }
   // 史莱姆辅助可达路线。
   if(p.i%6===2)setTile(p.x+Math.min(2,p.w-1),p.y-1,7);
   // 装饰物按群系固定变化。
   if(p.b==='plain'){
     if(p.i%2===0)decorations.push({x:p.x+1,y:p.y-1,t:'grass'});
     if(p.i%7===1)decorations.push({x:p.x+2,y:p.y-1,t:'flower'});
   }else if(p.b==='forest'){
     if(p.i%3===0)decorations.push({x:p.x+1,y:p.y-1,t:'fern'});
     if(p.i%8===0)addTree(p.x+Math.min(2,p.w-1),p.y,p.b,p.i);
     if(p.i%10===4)decorations.push({x:p.x+2,y:p.y-1,t:'mushroom'});
   }else if(p.b==='desert'){
     if(p.i%5===0)addCactus(p.x+Math.min(2,p.w-1),p.y,p.i);
     if(p.i%4===0)decorations.push({x:p.x+1,y:p.y-1,t:'drygrass'});
   }else if(p.b==='snow'){
     if(p.i%3===0)decorations.push({x:p.x+1,y:p.y-1,t:'snowgrass'});
     if(p.i%11===0)addTree(p.x+Math.min(2,p.w-1),p.y,p.b,p.i);
   }else{
     if(p.i%3===0)decorations.push({x:p.x+1,y:p.y-1,t:'ash'});
     if(p.i%7===0)decorations.push({x:p.x+2,y:p.y-1,t:'embers'});
   }
 }
 // 定距离存档点:约每 24 个平台一个。
 for(let idx=0;idx<path.length;idx+=24){const p=path[idx];checkpoints.push({x:p.x+1,y:p.y,active:idx===0,idx});}
 const last=path[path.length-1];checkpoints.push({x:last.x,y:last.y,active:false,idx:path.length-1});
 // 移动平台与移动障碍物。
 for(let i=14;i<path.length-10;i+=18){const p=path[i];movers.push({x:(p.x+5)*TILE,y:(p.y-7)*TILE,w:TILE*3,h:TILE,min:(p.x+1)*TILE,max:(p.x+10)*TILE,dir:i%2?1:-1,type:'platform'});}
 for(let i=20;i<path.length-18;i+=22){const p=path[i];hazards.push({x:(p.x+2)*TILE,y:(p.y-3)*TILE,w:TILE,h:TILE,min:(p.x-1)*TILE,max:(p.x+p.w+3)*TILE,dir:i%2?1:-1});}
 finishPos={x:last.x+last.w-1,y:last.y-1,groundY:last.y};setTile(finishPos.x,finishPos.y,8);
 spawn={x:(path[0].x+1)*TILE,y:(path[0].y-2)*TILE};
}
buildWorld();

const player={x:spawn.x,y:spawn.y,w:18,h:18,vx:0,vy:0,hp:10,jumps:2,face:1,hurt:0,onGround:false};
function resetPlayer(full=true){player.x=spawn.x;player.y=spawn.y;player.vx=0;player.vy=0;player.jumps=2;player.onGround=false;if(full)player.hp=10;}
function solid(t){return t&&![6,7,8,10,12].includes(t);}
function lavaTouch(x,y,w,h){const l=Math.floor(x/TILE),r=Math.floor((x+w-1)/TILE),t=Math.floor(y/TILE),b=Math.floor((y+h-1)/TILE);for(let yy=t;yy<=b;yy++)for(let xx=l;xx<=r;xx++)if(getTile(xx,yy)===6)return true;return false;}
function hazardTouch(x,y,w,h){return hazards.some(o=>x<o.x+o.w&&x+w>o.x&&y<o.y+o.h&&y+h>o.y);}
function hit(x,y,w,h){
 const l=Math.floor(x/TILE),r=Math.floor((x+w-1)/TILE),t=Math.floor(y/TILE),b=Math.floor((y+h-1)/TILE);
 for(let yy=t;yy<=b;yy++)for(let xx=l;xx<=r;xx++)if(solid(getTile(xx,yy)))return true;
 for(const m of movers)if(x<m.x+m.w&&x+w>m.x&&y<m.y+m.h&&y+h>m.y)return true;
 return false;
}
function move(axis,v){const step=Math.sign(v);let left=Math.abs(v);while(left>0){const d=step*Math.min(4,left);left-=Math.abs(d);if(axis==='x'){if(!hit(player.x+d,player.y,player.w,player.h))player.x+=d;else{player.vx=0;break;}}else{if(!hit(player.x,player.y+d,player.w,player.h)){player.y+=d;player.onGround=false;}else{if(d>0){player.onGround=true;player.jumps=2;}player.vy=0;break;}}}}
function jump(){if(player.jumps>0){player.vy=player.jumps===2?-8.2:-7.0;player.jumps--;}}
function damage(v){if(player.hurt>0)return;player.hp-=v;player.hurt=38;if(player.hp<=0)resetPlayer(true);else resetPlayer(false);}
window.addEventListener('keydown',e=>{const k=e.key.toLowerCase();keys.add(k);if([' ','arrowup','arrowdown','arrowleft','arrowright'].includes(k))e.preventDefault();if((k==='w'||k==='arrowup'||k===' ')&&!e.repeat)jump();if(k==='r')resetPlayer(true);});
window.addEventListener('keyup',e=>keys.delete(e.key.toLowerCase()));
function update(){
 if(!running)return;world.time+=0.016;if(player.hurt>0)player.hurt--;
 if(keys.has('a')||keys.has('arrowleft')){player.vx=-3.25;player.face=-1;}else if(keys.has('d')||keys.has('arrowright')){player.vx=3.25;player.face=1;}else player.vx*=0.75;
 player.vy=Math.min(10,player.vy+0.35);
 for(const m of movers){m.x+=m.dir*1.15;if(m.x<m.min||m.x>m.max)m.dir*=-1;if(player.x+player.w>m.x&&player.x<m.x+m.w&&Math.abs(player.y+player.h-m.y)<7&&player.vy>=0){player.y=m.y-player.h;player.vy=0;player.onGround=true;player.jumps=2;player.x+=m.dir*1.15;}}
 for(const o of hazards){o.x+=o.dir*1.55;if(o.x<o.min||o.x>o.max)o.dir*=-1;}
 move('x',player.vx);move('y',player.vy);
 const cx=Math.floor((player.x+player.w/2)/TILE),cy=Math.floor((player.y+player.h/2)/TILE),tile=getTile(cx,cy);
 if(lavaTouch(player.x,player.y,player.w,player.h)||hazardTouch(player.x,player.y,player.w,player.h))damage(2);
 if(tile===7)player.vy=-13.2;
 if(tile===8||Math.abs(player.x-finishPos.x*TILE)<44&&Math.abs(player.y-finishPos.y*TILE)<72)won=true;
 for(const cp of checkpoints){if(Math.abs(player.x-cp.x*TILE)<44&&Math.abs(player.y-cp.y*TILE)<72){checkpoints.forEach(c=>c.active=false);cp.active=true;spawn={x:cp.x*TILE,y:(cp.y-2)*TILE};}}
 if(player.y>world.rows*TILE-160)resetPlayer(true);
 world.cameraX+=(player.x-W/2-world.cameraX)*0.08;world.cameraY+=(player.y-H/2-world.cameraY)*0.08;
 world.cameraX=Math.max(0,Math.min(world.cols*TILE-W,world.cameraX));world.cameraY=Math.max(0,Math.min(world.rows*TILE-H,world.cameraY));
}
function tileColor(t){return ({2:'#5fb14a',3:'#8b5a2b',4:'#777',5:'#e8f7ff',6:'#ff4d2d',7:'#6aff7d',8:'#ff2d55',9:'#8b5a2b',10:'#1f7a35',11:'#38bdf8',12:'#dff8ff',13:'#f59e0b',14:'#d8b45f',15:'#bfefff',16:'#e4c978',17:'#4a403f',18:'#3f9f3d',19:'#76bc52',20:'#a78bfa',21:'#2f9b55'})[t]||'#999';}
function drawTile(x,y,t){const sx=x*TILE-world.cameraX,sy=y*TILE-world.cameraY;ctx.fillStyle=tileColor(t);ctx.fillRect(sx,sy,TILE,TILE);ctx.fillStyle='rgba(255,255,255,.16)';ctx.fillRect(sx,sy,TILE,3);ctx.fillRect(sx,sy,3,TILE);ctx.fillStyle='rgba(0,0,0,.24)';ctx.fillRect(sx+TILE-3,sy,3,TILE);ctx.fillRect(sx,sy+TILE-3,TILE,3);ctx.fillStyle='rgba(0,0,0,.12)';if([2,3,4,5,14,15,16,17,18,19].includes(t)){ctx.fillRect(sx+5,sy+7,4,3);ctx.fillRect(sx+15,sy+13,5,3);ctx.fillRect(sx+8,sy+18,3,2);}if([11,13,20].includes(t)){ctx.fillStyle=t===11?'#7dd3fc':t===13?'#facc15':'#c4b5fd';ctx.fillRect(sx+6,sy+6,5,5);ctx.fillRect(sx+15,sy+14,4,4);}if(t===6){ctx.fillStyle='#ffb020';ctx.fillRect(sx+3,sy+4,8,5);ctx.fillRect(sx+13,sy+12,8,5);}if(t===7){ctx.fillStyle='#b7ffbf';ctx.fillRect(sx+5,sy+5,14,5);} }
function drawPlayer(){const x=player.x-world.cameraX,y=player.y-world.cameraY;if(player.hurt>0&&Math.floor(player.hurt/4)%2===0)return;ctx.fillStyle='#d97706';ctx.fillRect(x,y,18,18);ctx.fillStyle='#facc15';ctx.fillRect(x+4,y+2,10,4);ctx.fillStyle='#111';ctx.fillRect(x+(player.face>0?12:3),y+6,3,3);ctx.fillStyle='#7c2d12';ctx.fillRect(x+4,y+14,10,4);}
function drawFlag(cp){const x=cp.x*TILE-world.cameraX,y=cp.y*TILE-world.cameraY;ctx.lineWidth=2;ctx.strokeStyle='#111';ctx.fillStyle='#6b3f1d';ctx.fillRect(x+8,y-35,5,35);ctx.strokeRect(x+8,y-35,5,35);ctx.fillStyle=cp.active?'#ffd54a':'#f8fafc';ctx.fillRect(x+13,y-33,24,14);ctx.strokeRect(x+13,y-33,24,14);ctx.fillStyle=cp.active?'#f59e0b':'#cbd5e1';ctx.fillRect(x+30,y-29,7,10);ctx.fillStyle='#111';ctx.fillRect(x+5,y-2,12,3);}
function drawFinish(){const x=finishPos.x*TILE-world.cameraX,y=finishPos.groundY*TILE-world.cameraY;ctx.lineWidth=2;ctx.strokeStyle='#111';ctx.fillStyle='#222';ctx.fillRect(x+8,y-50,6,50);ctx.strokeRect(x+8,y-50,6,50);ctx.fillStyle='#ff2d55';ctx.fillRect(x+14,y-45,30,18);ctx.strokeRect(x+14,y-45,30,18);ctx.fillStyle='#fff';ctx.fillRect(x+19,y-41,6,6);ctx.fillRect(x+31,y-33,6,6);ctx.fillStyle='#111';ctx.fillRect(x+5,y-2,14,3);}
function drawDecor(){for(const d of decorations){const x=d.x*TILE-world.cameraX,y=d.y*TILE-world.cameraY;if(x<-40||x>W+40||y<-80||y>H+80)continue;if(d.t==='grass'||d.t==='snowgrass'||d.t==='fern'){ctx.fillStyle=d.t==='snowgrass'?'#b6f3ff':d.t==='fern'?'#15803d':'#2faa2f';ctx.fillRect(x+8,y+8,3,12);ctx.fillRect(x+14,y+5,3,15);ctx.fillRect(x+18,y+10,3,10);}else if(d.t==='flower'){ctx.fillStyle='#ff66cc';ctx.fillRect(x+10,y+7,5,5);ctx.fillStyle='#fde047';ctx.fillRect(x+15,y+6,4,4);ctx.fillStyle='#22c55e';ctx.fillRect(x+13,y+12,3,8);}else if(d.t==='mushroom'){ctx.fillStyle='#f8fafc';ctx.fillRect(x+12,y+12,4,8);ctx.fillStyle='#ef4444';ctx.fillRect(x+8,y+8,12,5);}else if(d.t==='drygrass'){ctx.fillStyle='#a16207';ctx.fillRect(x+9,y+10,3,10);ctx.fillRect(x+15,y+8,3,12);}else if(d.t==='ash'){ctx.fillStyle='#333';ctx.fillRect(x+8,y+15,13,4);}else if(d.t==='embers'){ctx.fillStyle='#ffb020';ctx.fillRect(x+8,y+13,3,3);ctx.fillRect(x+16,y+9,3,3);}else{ctx.fillStyle='#dff8ff';ctx.fillRect(x+6,y+12,16,4);}}}
function drawHUD(){ctx.font='17px monospace';for(let i=0;i<10;i++){ctx.fillStyle=i<player.hp?'#ff3030':'#555';const x=14+i*25,y=14;ctx.beginPath();ctx.moveTo(x+10,y);ctx.lineTo(x+13,y+7);ctx.lineTo(x+21,y+7);ctx.lineTo(x+15,y+12);ctx.lineTo(x+18,y+20);ctx.lineTo(x+10,y+15);ctx.lineTo(x+2,y+20);ctx.lineTo(x+5,y+12);ctx.lineTo(x-1,y+7);ctx.lineTo(x+7,y+7);ctx.closePath();ctx.fill();ctx.strokeStyle='#111';ctx.stroke();}ctx.fillStyle='#111';ctx.fillText('HP '+player.hp+'/10',16,52);ctx.fillText('GameV0.0.23 修复版',16,74);}
function render(){ctx.fillStyle='#86c9ef';ctx.fillRect(0,0,W,H);ctx.fillStyle='#c6f4ff';ctx.fillRect(0,0,W,Math.max(0,170-world.cameraY*.03));const sx=Math.floor(world.cameraX/TILE)-2,ex=sx+60,sy=Math.floor(world.cameraY/TILE)-2,ey=sy+40;for(let y=sy;y<ey;y++)for(let x=sx;x<ex;x++){const t=getTile(x,y);if(t)drawTile(x,y,t);}drawDecor();for(const m of movers){ctx.fillStyle='#9ca3af';ctx.fillRect(m.x-world.cameraX,m.y-world.cameraY,m.w,m.h);ctx.fillStyle='rgba(255,255,255,.22)';ctx.fillRect(m.x-world.cameraX,m.y-world.cameraY,m.w,4);}for(const o of hazards){const x=o.x-world.cameraX,y=o.y-world.cameraY;ctx.fillStyle='#7f1d1d';ctx.fillRect(x,y,o.w,o.h);ctx.fillStyle='#ef4444';ctx.fillRect(x+5,y+5,14,14);ctx.fillStyle='#111';ctx.fillRect(x+4,y+4,4,4);ctx.fillRect(x+16,y+4,4,4);}checkpoints.forEach(drawFlag);drawFinish();drawPlayer();drawHUD();if(won){ctx.fillStyle='rgba(0,0,0,.55)';ctx.fillRect(0,0,W,H);ctx.fillStyle='#fff';ctx.font='32px monospace';ctx.fillText('GameV0.0.23 通关成功!',275,220);ctx.font='18px monospace';ctx.fillText('按 R 可从最近存档点满血继续',330,260);}}
function loop(){update();render();requestAnimationFrame(loop);} 
document.getElementById('startBtn').onclick=()=>{running=true;document.getElementById('cover').classList.add('hidden');};
document.getElementById('logBtn').onclick=()=>document.getElementById('log').classList.toggle('hidden');
loop();
})();
</script>
</body>
</html>