<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>草原の騎士 - 大型アップデート</title>
<style>
*{box-sizing:border-box;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}
html,body{margin:0;padding:0;background:#182333;color:white;font-family:system-ui,sans-serif;touch-action:pan-y;overflow-x:hidden;min-height:100%}
#wrap{width:100%;max-width:800px;margin:auto;text-align:center;padding:8px 8px 20px}
h2{margin:4px 0 8px;font-size:20px}
#info{display:flex;justify-content:space-around;gap:5px;flex-wrap:wrap;font-size:13px;margin-bottom:5px}
#gameFrame{position:relative;width:100%;max-width:760px;margin:auto}
canvas{display:block;width:100%;max-width:760px;height:auto;border:3px solid #dce8f0;border-radius:8px;background:#83d7ef;touch-action:none}
#hud{position:absolute;top:8px;left:8px;z-index:2;width:150px;padding:6px 8px;background:#142334dd;border:2px solid #dce8f0;border-radius:9px;text-align:left;pointer-events:none;box-shadow:0 3px 10px #0005;backdrop-filter:blur(3px)}
#hudTop{display:flex;justify-content:space-between;margin-bottom:3px;font-size:11px;font-weight:800}
#hudLevel{color:#ffe58b}
#hearts{min-height:18px;margin-bottom:3px;font-size:15px;line-height:1}
.barLabel{display:flex;justify-content:space-between;font-size:9px;font-weight:800;margin-bottom:2px}
.barTrack{height:7px;background:#465365;border:1px solid #ffffff88;border-radius:8px;overflow:hidden}
.barFill{height:100%;width:100%;border-radius:8px;transition:width .18s}
#expBar{background:linear-gradient(90deg,#e6a928,#fff078)}
#hud.damage{animation:blink .14s steps(2,end) infinite}
@keyframes blink{50%{opacity:.35}}
#controls{display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:8px;margin:9px auto 0;max-width:760px}
.group{display:flex;gap:6px}
button{border:2px solid #dce8f0;border-radius:10px;background:#385c7c;color:white;font-weight:bold;padding:12px 8px;font-size:15px;touch-action:none}
button:active{background:#648db0}
button:disabled{opacity:.35}
.control{min-width:48px;min-height:53px;font-size:17px;padding:8px;background:#344e68}
.attack{background:#81503b}
#hint{font-size:12px;color:#d7e6f3;margin:7px 0}
#menu{position:fixed;inset:0;background:#101a28ef;display:flex;align-items:center;justify-content:center;padding:15px;z-index:10}
#menuBox{width:min(440px,95%);background:#263b50;border:3px solid #e5d99c;border-radius:15px;padding:18px;max-height:90%;overflow:auto;box-shadow:0 12px 35px #0008}
#menuBox h1{margin:3px 0 8px;color:#ffe58b}
#menuBox p{font-size:14px;line-height:1.6}
#menuBox button{min-height:48px}
.menuButtons{display:grid;grid-template-columns:1fr 1fr;gap:9px;margin-top:12px}
@media(max-width:520px){
#controls{justify-content:center}
.control{min-width:42px;font-size:15px}
.group{gap:4px}
#hud{width:135px;padding:5px 7px}
#hudTop{font-size:10px}
#hearts{font-size:14px;min-height:16px}
.barLabel{font-size:8px}
.barTrack{height:6px}
#hint{font-size:11px}
}
</style>
</head>
<body>
<div id="wrap">
<h2>⚔️ 草原の騎士 - 大型アップデート</h2>
<div id="info">
<span id="stageInfo">ステージ:草原</span>
<span id="hpInfo">HP:3</span>
<span id="lvInfo">Lv.1 EXP:0</span>
<span id="coinInfo">撃破:0</span>
<span id="buffInfo">強化:なし</span>
</div>
<div id="gameFrame">
<div id="hud">
<div id="hudTop"><span>⚔ KNIGHT</span><span id="hudLevel">Lv.1</span></div>
<div id="hearts">❤️ ❤️ ❤️</div>
<div>
<div class="barLabel"><span>EXP</span><span id="hudExpText">0 / 5</span></div>
<div class="barTrack"><div class="barFill" id="expBar"></div></div>
</div>
</div>
<canvas id="game" width="900" height="420"></canvas>
</div>
<div id="controls">
<div class="group">
<button class="control" id="left">◀</button>
<button class="control" id="right">▶</button>
<button class="control" id="jump">ジャンプ</button>
</div>
<div class="group">
<button class="control attack" id="slash">斬</button>
<button class="control attack" id="strong">強</button>
<button class="control attack" id="combo">連</button>
</div>
</div>
<div id="hint">宝箱の近くで攻撃すると開く! 敵を倒してLvアップ! PC:← → / Space / X C V</div>
</div>
<div id="menu">
<div id="menuBox">
<h1>⚔️ 草原の騎士</h1>
<p id="menuText">4つのステージを冒険しよう!</p>
<div class="menuButtons" id="menuButtons"></div>
</div>
</div>
<script>
const canvas=document.getElementById("game"),ctx=canvas.getContext("2d");
const W=900,H=420,FLOOR=355,$=id=>document.getElementById(id);
const stages=[
{name:"草原",sky:"#83d7ef",ground:"#55a94b",hill:"#79c66c",boss:"キングスライム",bossColor:"#8b4bd1",hazard:"none"},
{name:"砂漠",sky:"#f6c77d",ground:"#d8a34e",hill:"#e6b96b",boss:"砂漠のドラゴン",bossColor:"#d45b28",hazard:"sand"},
{name:"氷の洞窟",sky:"#9ed8ef",ground:"#b9e6f1",hill:"#d9f4fa",boss:"氷のゴーレム",bossColor:"#438bbd",hazard:"ice"},
{name:"魔王城",sky:"#51466e",ground:"#55445e",hill:"#79618d",boss:"魔王",bossColor:"#9b3a55",hazard:"castle"}
];
let stageIndex=0,unlocked=1,gameState="menu";
let player,boss,enemies,platforms,particles,chests,drops;
let camera=0,worldWidth=2300,defeated=0,level=1,exp=0;
let keys={},stageTime=0,cooldown=0,bossIntro=0,bossAppeared=false;
let message="",messageTimer=0;
function makeStage(index){
stageIndex=index;worldWidth=2300;
player={x:65,y:FLOOR-48,w:32,h:48,vx:0,vy:0,hp:3,maxHp:3,onGround:true,face:1,inv:0,attack:0,attackType:"normal",damage:1,speed:3.6,jumpPower:11.5,powerTimer:0};
enemies=[];particles=[];drops=[];camera=0;stageTime=0;defeated=0;cooldown=0;bossIntro=0;bossAppeared=false;
chests=[{x:520,y:FLOOR-32,opened:false},{x:1120,y:FLOOR-32,opened:false},{x:1690,y:FLOOR-32,opened:false}];
platforms=[
{x:340,y:285,w:130,h:15,move:false},
{x:690,y:260,w:150,h:15,move:false},
{x:1080,y:285,w:130,h:15,move:false},
{x:1500,y:250,w:160,h:15,move:false},
{x:1840,y:285,w:130,h:15,move:false}
];
if(index===3){
platforms.push({x:900,y:220,w:110,h:15,move:true,base:220,phase:0});
platforms.push({x:1300,y:195,w:120,h:15,move:true,base:195,phase:2});
}
for(let i=0;i<9;i++){
let type=index===0?(i%4===0?"fast":"normal"):
index===1?(i%3===0?"scorpion":"fast"):
index===2?(i%3===0?"crystal":"ice"):
(i%3===0?"skeleton":"dark");
let tough=["crystal","skeleton"].includes(type);
let hp=tough?4:["scorpion","ice","dark"].includes(type)?3:2;
enemies.push({x:260+i*210,y:FLOOR-30,w:tough?38:34,h:30,hp,maxHp:hp,type,dir:i%2?1:-1,alive:true,hit:0});
}
boss={x:2070,y:FLOOR-76,w:76,h:76,hp:index===3?22:17,maxHp:index===3?22:17,alive:true,flash:0};
updateInfo();
}
function updateInfo(){
$("stageInfo").textContent="ステージ:"+stages[stageIndex].name;
$("hpInfo").textContent="HP:"+player.hp+"/"+player.maxHp;
$("lvInfo").textContent="Lv."+level+" EXP:"+exp;
$("coinInfo").textContent="撃破:"+defeated;
$("buffInfo").textContent=player.powerTimer>0?"強化:"+Math.ceil(player.powerTimer/60)+"秒":"強化:なし";
$("hudLevel").textContent="Lv."+level;
$("hearts").textContent="❤️ ".repeat(player.hp)+"🖤 ".repeat(Math.max(0,player.maxHp-player.hp));
$("hudExpText").textContent=exp+" / 5";
$("expBar").style.width=(exp/5*100)+"%";
$("hud").classList.toggle("damage",player.inv>0);
}
function menu(title,description,buttons){
gameState="menu";$("menu").style.display="flex";$("menuText").innerHTML=description;
$("menuBox").querySelector("h1").textContent=title;
const box=$("menuButtons");box.innerHTML="";
buttons.forEach(b=>{
const el=document.createElement("button");
el.textContent=b.text;el.disabled=!!b.disabled;el.onclick=b.action;box.appendChild(el);
});
}
function stageMenu(){
menu("⚔️ ステージ選択","冒険するステージを選ぼう!<br>クリアすると次のステージが解放されるぞ。",
stages.map((s,i)=>({text:(i<unlocked?"▶ ":"🔒 ")+(i+1)+":"+s.name,disabled:i>=unlocked,action:()=>{makeStage(i);startGame()}})));
}
function startGame(){gameState="play";$("menu").style.display="none"}
function showTitle(){
menu("⚔️ 草原の騎士","敵を倒して経験値を集めよう!<br>宝箱を開けてアイテムを手に入れよう!",[
{text:"ステージ選択",action:stageMenu},
{text:"遊び方",action:()=>menu("遊び方","◀ ▶:移動<br>ジャンプ:足場を飛び越える<br>斬:通常攻撃<br>強:強力な攻撃<br>連:すばやい攻撃<br><br>宝箱の近くで攻撃すると開く!<br>アイテムに触れると自動で獲得!",[{text:"戻る",action:showTitle}])}
]);
}
function gainExp(n){
exp+=n;
while(exp>=5){exp-=5;level++;player.maxHp=Math.min(6,player.maxHp+1);player.hp=Math.min(player.maxHp,player.hp+1);player.damage+=.15}
updateInfo();
}
function formatTime(frames){
let sec=Math.floor(frames/60);
return Math.floor(sec/60)+":"+String(sec%60).padStart(2,"0");
}
function clearSummary(){
return "ステージ:"+stages[stageIndex].name+"<br>撃破数:"+defeated+"体 | クリアタイム:"+formatTime(stageTime)+"<br>到達レベル:Lv."+level;
}
function chooseUpgrade(){
const upgrades=[
{name:"⚔️ 攻撃力アップ",desc:"攻撃力が上がる",apply:()=>player.damage+=1},
{name:"💨 移動速度アップ",desc:"移動速度が上がる",apply:()=>player.speed+=.55},
{name:"❤️ 最大HPアップ",desc:"最大HPとHPが1増える",apply:()=>{player.maxHp++;player.hp=player.maxHp}}
];
menu("✨ STAGE CLEAR!","<b>ステージリザルト</b><br>"+clearSummary()+"<br><br>次の冒険に向けて強化を選ぼう!",
upgrades.map(u=>({text:u.name+":"+u.desc,action:()=>{
u.apply();updateInfo();unlocked=Math.max(unlocked,stageIndex+2);
if(stageIndex===3){
menu("🏆 ALL STAGES CLEAR!","魔王を倒した! 騎士は伝説の英雄に!<br><br><b>最終ステージリザルト</b><br>"+clearSummary(),[
{text:"もう一度遊ぶ",action:()=>{level=1;exp=0;stageMenu()}},
{text:"タイトルへ",action:showTitle}
]);
}else{
menu("次のステージへ!","騎士が強くなった!<br>次のステージに進もう!",[
{text:"次のステージ",action:()=>{makeStage(stageIndex+1);startGame()}},
{text:"ステージ選択",action:stageMenu}
]);
}
}}))
);
}
function loseGame(){
menu("GAME OVER","今回の記録<br>"+clearSummary()+"<br><br>もう一度挑戦してみよう。",[
{text:"再挑戦",action:()=>{makeStage(stageIndex);startGame()}},
{text:"ステージ選択",action:stageMenu}
]);
}
function burst(x,y,color,count){
for(let i=0;i<count;i++){
let a=Math.PI*2*i/count+Math.random()*.35,s=1.2+Math.random()*3.2;
particles.push({x,y,vx:Math.cos(a)*s,vy:Math.sin(a)*s-1,life:18+Math.random()*16,maxLife:34,color,size:2+Math.random()*4,kind:"spark"});
}
}
function openChest(c){
if(c.opened)return;c.opened=true;
let r=Math.random(),type=r<.4?"heal":r<.75?"power":"crystal";
drops.push({x:c.x+12,y:c.y-15,type,life:1200});
burst(c.x+15,c.y-12,"#ffe66d",12);
}
function showMessage(t){message=t;messageTimer=100}
function collectDrop(d){
if(d.type==="heal"){player.hp=Math.min(player.maxHp,player.hp+2);showMessage("❤️ HP回復!")}
else if(d.type==="power"){player.powerTimer=480;showMessage("⚔️ 攻撃力2倍!")}
else{gainExp(2);showMessage("💎 EXP +2!")}
d.collected=true;updateInfo();
}
function bindHold(id,key){
const el=$(id);
el.addEventListener("pointerdown",e=>{e.preventDefault();keys[key]=true;try{el.setPointerCapture(e.pointerId)}catch(_){}});
const release=e=>{e.preventDefault();keys[key]=false};
el.addEventListener("pointerup",release);el.addEventListener("pointercancel",release);
el.addEventListener("lostpointercapture",()=>keys[key]=false);
}
bindHold("left","left");bindHold("right","right");bindHold("jump","jump");
function bindAttack(id,key){$(id).addEventListener("pointerdown",e=>{e.preventDefault();attack(key)})}
bindAttack("slash","normal");bindAttack("strong","strong");bindAttack("combo","combo");
document.addEventListener("keydown",e=>{
if(["ArrowLeft","ArrowRight","ArrowUp"," "].includes(e.key))e.preventDefault();
keys[e.key.toLowerCase()]=true;
if(!e.repeat){if(e.key.toLowerCase()==="x")attack("normal");if(e.key.toLowerCase()==="c")attack("strong");if(e.key.toLowerCase()==="v")attack("combo")}
});
document.addEventListener("keyup",e=>keys[e.key.toLowerCase()]=false);
document.addEventListener("contextmenu",e=>e.preventDefault());
document.addEventListener("selectstart",e=>e.preventDefault());
document.addEventListener("dragstart",e=>e.preventDefault());
function attack(type){
if(gameState!=="play"||cooldown>0)return;
const settings={normal:{cool:22,damage:1,range:65,color:"#fff0a0"},strong:{cool:48,damage:2,range:90,color:"#ffbd45"},combo:{cool:32,damage:1,range:78,color:"#75d9ff"}};
const a=settings[type];cooldown=a.cool;player.attack=12;player.attackType=type;
for(const c of chests){
if(!c.opened&&Math.abs((c.x+15)-(player.x+player.w/2))<a.range&&Math.abs(c.y-player.y)<75&&Math.sign(c.x-player.x)===player.face)openChest(c);
}
let multiplier=player.powerTimer>0?2:1;
for(const e of enemies){
if(e.alive&&Math.abs((e.x+e.w/2)-(player.x+player.w/2))<a.range&&Math.sign(e.x-player.x)===player.face){
e.hp-=a.damage*player.damage*multiplier;e.hit=12;
burst(e.x+e.w/2,e.y+12,e.type==="crystal"?"#75edff":"#fff0a0",5);
if(e.hp<=0)killEnemy(e);
}
}
if(boss.alive&&Math.abs((boss.x+boss.w/2)-(player.x+player.w/2))<a.range+15&&Math.sign(boss.x-player.x)===player.face){
boss.hp-=a.damage*player.damage*multiplier;boss.flash=10;
burst(boss.x+boss.w/2,boss.y+boss.h/2,"#ffe58b",7);
if(boss.hp<=0){boss.alive=false;burst(boss.x+boss.w/2,boss.y+boss.h/2,stages[stageIndex].bossColor,24);gainExp(5);chooseUpgrade()}
}
particles.push({x:player.x+player.w/2+player.face*35,y:player.y+20,life:12,maxLife:12,color:a.color,size:17,kind:"slash"});
}
function killEnemy(e){
e.alive=false;defeated++;
burst(e.x+e.w/2,e.y+e.h/2,e.type==="crystal"?"#6deaff":e.type==="skeleton"?"#d9d2c5":"#8dff8b",e.type==="crystal"?18:10);
gainExp(1);updateInfo();
}
function hurt(){
if(player.inv>0)return;
player.hp--;player.inv=80;player.vy=-5;updateInfo();
if(player.hp<=0)loseGame();
}
function update(){
if(gameState!=="play")return;
stageTime++;if(cooldown>0)cooldown--;if(player.inv>0)player.inv--;if(player.attack>0)player.attack--;
if(player.powerTimer>0)player.powerTimer--;if(messageTimer>0)messageTimer--;
let left=keys.left||keys.arrowleft||keys.a,right=keys.right||keys.arrowright||keys.d;
if(left){player.vx=-player.speed;player.face=-1}
else if(right){player.vx=player.speed;player.face=1}
else player.vx*=.72;
if((keys.jump||keys[" "]||keys.arrowup||keys.w)&&player.onGround){player.vy=-player.jumpPower;player.onGround=false}
const s=stages[stageIndex];
if(s.hazard==="ice"&&player.onGround&&Math.abs(player.vx)>.2)player.vx*=1.04;
if(s.hazard==="sand"&&player.x>700&&player.x<1300&&player.onGround)player.vx*=.78;
player.x+=player.vx;player.vy+=.52;player.y+=player.vy;player.onGround=false;
if(player.y+player.h>=FLOOR){player.y=FLOOR-player.h;player.vy=0;player.onGround=true}
for(const p of platforms){
if(p.move)p.y=p.base+Math.sin(stageTime/45+p.phase)*35;
if(player.vy>=0&&player.x+player.w>p.x&&player.x<p.x+p.w&&player.y+player.h>=p.y&&player.y+player.h<=p.y+18&&player.y<p.y){
player.y=p.y-player.h;player.vy=0;player.onGround=true;
}
}
player.x=Math.max(0,Math.min(worldWidth-player.w,player.x));
if(player.y>H+80){hurt();player.y=FLOOR-player.h}
enemies.forEach(e=>{
if(!e.alive)return;
e.x+=e.dir*(e.type==="fast"||e.type==="scorpion"?1.7:.8);
if(e.x<120||e.x>1950)e.dir*=-1;
if(Math.abs(e.x-player.x)<35&&Math.abs(e.y-player.y)<40)hurt();
if(e.hit>0)e.hit--;
});
if(boss.alive){
if(!bossAppeared&&player.x>1650){bossAppeared=true;bossIntro=115;showMessage("⚠ BOSS BATTLE!")}
if(bossIntro>0)bossIntro--;
boss.x+=Math.sign(player.x-boss.x)*.65;
boss.x=Math.max(1900,Math.min(2180,boss.x));
if(Math.abs(boss.x-player.x)<55&&Math.abs(boss.y-player.y)<60)hurt();
}
if(boss.flash>0)boss.flash--;
drops.forEach(d=>{
if(d.collected)return;d.life--;d.y+=Math.sin(stageTime/12+d.x)*.15;
if(Math.abs((d.x+10)-(player.x+player.w/2))<28&&Math.abs(d.y-(player.y+player.h/2))<38)collectDrop(d);
});
drops=drops.filter(d=>!d.collected&&d.life>0);
particles.forEach(p=>{p.life--;if(p.kind==="spark"){p.x+=p.vx||0;p.y+=p.vy||0;p.vy=(p.vy||0)+.13}});
particles=particles.filter(p=>p.life>0);
camera=Math.max(0,Math.min(worldWidth-W,player.x-W*.42));updateInfo();
}
function drawBackground(){
const s=stages[stageIndex];ctx.fillStyle=s.sky;ctx.fillRect(0,0,W,H);
ctx.fillStyle="#fff3a0";ctx.beginPath();ctx.arc(760,65,30,0,Math.PI*2);ctx.fill();
for(let i=0;i<6;i++){
let x=((i*240-camera*.25)%(W+150)+W+150)%(W+150)-60;
ctx.fillStyle="#ffffffaa";ctx.beginPath();
ctx.arc(x,70+i%2*35,19,0,Math.PI*2);ctx.arc(x+22,62+i%2*35,23,0,Math.PI*2);ctx.arc(x+45,70+i%2*35,17,0,Math.PI*2);ctx.fill();
}
ctx.fillStyle=s.hill;
for(let i=0;i<7;i++){let x=((i*210-camera*.48)%(W+250)+W+250)%(W+250)-80;ctx.beginPath();ctx.arc(x,290,100,Math.PI,0);ctx.fill()}
if(stageIndex===1){
ctx.fillStyle="#c98a45";
for(let i=0;i<7;i++){let x=((i*190-camera*.38)%(W+220)+W+220)%(W+220)-50;ctx.beginPath();ctx.moveTo(x,290);ctx.lineTo(x+55,170+(i%3)*22);ctx.lineTo(x+115,290);ctx.fill()}
ctx.fillStyle="#ffe0a0";ctx.beginPath();ctx.arc(760,65,27,0,Math.PI*2);ctx.fill();
}else if(stageIndex===2){
ctx.fillStyle="#d9f7ff";
for(let i=0;i<9;i++){let x=((i*145-camera*.42)%(W+160)+W+160)%(W+160)-30;ctx.beginPath();ctx.moveTo(x,295);ctx.lineTo(x+25,175+(i%3)*25);ctx.lineTo(x+55,295);ctx.fill()}
ctx.fillStyle="#ffffff55";ctx.fillRect(0,0,W,H);
}else if(stageIndex===3){
ctx.fillStyle="#30283f";
for(let i=0;i<7;i++){let x=((i*180-camera*.35)%(W+200)+W+200)%(W+200)-40;ctx.fillRect(x,120,42,180);ctx.fillRect(x-12,105,66,18);ctx.fillStyle="#c5a2d8";ctx.fillRect(x+18,150,6,28);ctx.fillStyle="#30283f"}
ctx.fillStyle="#b94a68";ctx.beginPath();ctx.arc(760,65,25,0,Math.PI*2);ctx.fill();
}
}
function drawWorld(){
const s=stages[stageIndex];ctx.fillStyle=s.ground;ctx.fillRect(0,FLOOR,W,H-FLOOR);
ctx.fillStyle="#ffffff22";ctx.fillRect(0,FLOOR,W,5);
for(let i=0;i<35;i++){let x=((i*75-camera)%(W+75)+W+75)%(W+75);ctx.fillStyle=stageIndex===2?"#ffffff":"#356d35";ctx.fillRect(x,FLOOR+18+(i%3)*12,3,3)}
if(stageIndex===1){let x=700-camera;ctx.fillStyle="#a96e30";ctx.fillRect(x,FLOOR-4,600,5);ctx.fillStyle="#f4d18a";ctx.fillText("流砂",x+250,FLOOR-12)}
if(stageIndex===2){ctx.fillStyle="#e6ffff";ctx.fillRect(0,FLOOR-4,W,4)}
if(stageIndex===0){for(let i=0;i<12;i++){let x=((i*155-camera)%(W+80)+W+80)%(W+80);ctx.fillStyle="#2f8b42";ctx.fillRect(x,FLOOR-14,3,14);ctx.fillRect(x+4,FLOOR-10,3,10)}}
if(stageIndex===1){ctx.fillStyle="#f6d18c";for(let i=0;i<15;i++){let x=((i*90-camera)%(W+90)+W+90)%(W+90);ctx.fillRect(x,FLOOR+9,18,2)}}
if(stageIndex===3){ctx.fillStyle="#32283d";for(let i=0;i<12;i++){let x=((i*100-camera)%(W+100)+W+100)%(W+100);ctx.fillRect(x,FLOOR-18,9,18);ctx.fillRect(x-4,FLOOR-22,17,5)}}
platforms.forEach(p=>{
let x=p.x-camera;ctx.fillStyle=p.move?"#b58a63":stageIndex===2?"#e9fbff":stageIndex===3?"#51445f":stageIndex===1?"#c58a43":"#896342";
ctx.fillRect(x,p.y,p.w,15);ctx.fillStyle="#ffffff66";ctx.fillRect(x,p.y,p.w,4);
if(stageIndex===2){ctx.fillStyle="#8bd8ee";ctx.fillRect(x+8,p.y+5,p.w-16,3)}
if(stageIndex===3){ctx.fillStyle="#a44c68";ctx.fillRect(x+8,p.y+5,p.w-16,3)}
});
chests.forEach(c=>{
let x=c.x-camera;ctx.fillStyle=c.opened?"#704b2c":"#9a5a25";ctx.fillRect(x,c.y,30,25);
ctx.fillStyle=c.opened?"#b58b54":"#e7a83e";ctx.fillRect(x,c.y,30,8);
ctx.fillStyle="#f8d66d";ctx.fillRect(x+12,c.y+8,6,8);
ctx.strokeStyle="#54351d";ctx.lineWidth=2;ctx.strokeRect(x,c.y,30,25);
if(!c.opened){ctx.fillStyle="#fff";ctx.font="12px sans-serif";ctx.fillText("攻撃!",x-5,c.y-8)}
});
drops.forEach(d=>{
let x=d.x-camera;
if(d.type==="heal"){
ctx.fillStyle="#f04455";ctx.fillRect(x+3,d.y,15,19);ctx.fillStyle="#fff";ctx.fillRect(x+9,d.y+3,4,13);ctx.fillRect(x+5,d.y+7,12,4);
}else{
ctx.fillStyle=d.type==="power"?"#ffdc45":"#55eaff";ctx.beginPath();ctx.moveTo(x+10,d.y-3);ctx.lineTo(x+22,d.y+10);ctx.lineTo(x+12,d.y+23);ctx.lineTo(x,d.y+10);ctx.closePath();ctx.fill();
ctx.fillStyle="#fff";ctx.fillRect(x+9,d.y+4,4,12);
}
});
enemies.forEach(drawEnemy);drawBoss();drawKnight();
particles.forEach(p=>{
ctx.globalAlpha=Math.max(0,p.life/(p.maxLife||25));ctx.fillStyle=p.color;
if(p.kind==="slash"){ctx.strokeStyle=p.color;ctx.lineWidth=5;ctx.beginPath();ctx.arc(p.x-camera,p.y,22,-1.15,1.15);ctx.stroke()}
else{ctx.beginPath();ctx.arc(p.x-camera,p.y,p.size||4,0,Math.PI*2);ctx.fill()}
ctx.globalAlpha=1;
});
if(bossIntro>0){
ctx.fillStyle="#111827bb";ctx.fillRect(205,105,490,72);ctx.strokeStyle="#ffe58b";ctx.lineWidth=3;ctx.strokeRect(205,105,490,72);
ctx.fillStyle="#ffe58b";ctx.font="bold 30px sans-serif";ctx.textAlign="center";ctx.fillText("BOSS BATTLE",450,137);
ctx.fillStyle="#fff";ctx.font="bold 20px sans-serif";ctx.fillText(stages[stageIndex].boss,450,163);ctx.textAlign="left";
}
if(messageTimer>0){ctx.fillStyle="#142334cc";ctx.fillRect(300,25,300,42);ctx.fillStyle="#fff";ctx.font="bold 22px sans-serif";ctx.textAlign="center";ctx.fillText(message,450,54);ctx.textAlign="left"}
}
function drawEnemy(e){
if(!e.alive)return;let x=e.x-camera,y=e.y;ctx.save();if(e.hit>0)ctx.globalAlpha=.65;
if(e.type==="scorpion"){
ctx.fillStyle=e.hit>0?"#fff":"#c77b35";ctx.fillRect(x+5,y+12,25,13);ctx.fillRect(x+1,y+18,8,5);
ctx.strokeStyle="#713b24";ctx.lineWidth=4;ctx.beginPath();ctx.moveTo(x+27,y+13);ctx.quadraticCurveTo(x+42,y-8,x+36,y-13);ctx.stroke();
ctx.fillStyle="#ffdf77";ctx.beginPath();ctx.arc(x+36,y-13,4,0,Math.PI*2);ctx.fill();
ctx.strokeStyle="#713b24";for(let i=0;i<3;i++){ctx.beginPath();ctx.moveTo(x+9+i*7,y+23);ctx.lineTo(x+4+i*8,y+30);ctx.stroke()}
}else if(e.type==="crystal"){
ctx.fillStyle=e.hit>0?"#fff":"#3bc6e6";ctx.beginPath();ctx.moveTo(x+18,y-5);ctx.lineTo(x+35,y+10);ctx.lineTo(x+31,y+29);ctx.lineTo(x+7,y+29);ctx.lineTo(x+1,y+11);ctx.closePath();ctx.fill();
ctx.fillStyle="#b8f7ff";ctx.beginPath();ctx.moveTo(x+18,y-5);ctx.lineTo(x+23,y+13);ctx.lineTo(x+13,y+20);ctx.closePath();ctx.fill();
ctx.fillStyle="#173c55";ctx.fillRect(x+11,y+13,3,4);ctx.fillRect(x+24,y+13,3,4);
}else if(e.type==="skeleton"){
ctx.fillStyle=e.hit>0?"#fff":"#c9c4b8";ctx.fillRect(x+7,y+7,22,21);
ctx.fillStyle="#4b4052";ctx.fillRect(x+10,y+13,5,5);ctx.fillRect(x+22,y+13,5,5);
ctx.fillStyle="#e8dfc9";ctx.fillRect(x+5,y+26,7,5);ctx.fillRect(x+24,y+26,7,5);
}else{
let color=e.hit>0?"#fff":e.type==="fast"?"#ee9940":e.type==="ice"?"#7bdcf5":e.type==="dark"?"#9b547e":"#54c85b";
ctx.fillStyle=color;ctx.beginPath();ctx.ellipse(x+17,y+17,18,14,0,Math.PI,Math.PI*2);ctx.fill();ctx.fillRect(x,y+17,34,11);
ctx.fillStyle="#fff";ctx.fillRect(x+8,y+12,5,5);ctx.fillRect(x+22,y+12,5,5);
ctx.fillStyle="#222";ctx.fillRect(x+10,y+14,2,3);ctx.fillRect(x+24,y+14,2,3);
}
ctx.globalAlpha=1;ctx.fillStyle="#202b39";ctx.fillRect(x,y-9,e.w,4);
ctx.fillStyle=e.type==="crystal"?"#56eaff":"#ed5555";ctx.fillRect(x,y-9,e.w*Math.max(0,e.hp/e.maxHp),4);ctx.restore();
}
function drawBoss(){
if(!boss||!boss.alive)return;let x=boss.x-camera,y=boss.y,color=boss.flash>0?"#fff":stages[stageIndex].bossColor;ctx.save();ctx.fillStyle=color;
if(stageIndex===1){
ctx.beginPath();ctx.ellipse(x+38,y+44,39,31,0,0,Math.PI*2);ctx.fill();
ctx.beginPath();ctx.moveTo(x+8,y+27);ctx.lineTo(x-5,y+4);ctx.lineTo(x+21,y+22);ctx.fill();
ctx.beginPath();ctx.moveTo(x+67,y+27);ctx.lineTo(x+81,y+4);ctx.lineTo(x+56,y+22);ctx.fill();
}else if(stageIndex===2){
ctx.beginPath();ctx.moveTo(x+38,y-5);ctx.lineTo(x+74,y+27);ctx.lineTo(x+67,y+70);ctx.lineTo(x+38,y+82);ctx.lineTo(x+7,y+68);ctx.lineTo(x+1,y+27);ctx.closePath();ctx.fill();
ctx.fillStyle="#d7faff";ctx.fillRect(x+17,y+7,9,27);ctx.fillRect(x+48,y+7,9,27);
}else if(stageIndex===3){
ctx.fillRect(x+12,y+19,52,55);ctx.beginPath();ctx.moveTo(x+13,y+26);ctx.lineTo(x+2,y-3);ctx.lineTo(x+30,y+14);ctx.lineTo(x+38,y-10);ctx.lineTo(x+48,y+14);ctx.lineTo(x+74,y-3);ctx.lineTo(x+64,y+29);ctx.fill();
ctx.fillStyle="#e9c6ff";ctx.fillRect(x+19,y+29,12,8);ctx.fillRect(x+47,y+29,12,8);
}else{ctx.beginPath();ctx.ellipse(x+38,y+42,39,38,0,0,Math.PI*2);ctx.fill();ctx.fillRect(x+8,y+38,60,37)}
if(stageIndex!==2&&stageIndex!==3){ctx.fillStyle="#fff";ctx.fillRect(x+17,y+27,12,12);ctx.fillRect(x+47,y+27,12,12)}
ctx.fillStyle="#222";ctx.fillRect(x+21,y+31,5,6);ctx.fillRect(x+51,y+31,5,6);
ctx.fillStyle="#182333";ctx.fillRect(245,12,410,14);ctx.fillStyle="#e64e61";ctx.fillRect(248,15,404*Math.max(0,boss.hp/boss.maxHp),8);
ctx.strokeStyle="#fff";ctx.lineWidth=2;ctx.strokeRect(245,12,410,14);ctx.fillStyle="#fff";ctx.font="bold 14px sans-serif";ctx.textAlign="center";ctx.fillText(stages[stageIndex].boss,450,42);ctx.textAlign="left";ctx.restore();
}
function drawKnight(){
if(!player)return;let x=player.x-camera;if(player.inv>0&&Math.floor(player.inv/5)%2===0)return;
ctx.fillStyle="#2463bc";ctx.beginPath();ctx.moveTo(x+10,player.y+12);ctx.lineTo(x-7,player.y+42);ctx.lineTo(x+17,player.y+38);ctx.fill();
ctx.fillStyle="#aebbc8";ctx.fillRect(x+7,player.y+17,20,24);ctx.fillStyle="#e0e8ef";ctx.fillRect(x+8,player.y+3,19,18);
ctx.fillStyle="#28394a";ctx.fillRect(x+10,player.y+11,15,5);ctx.fillStyle="#d5dce3";ctx.fillRect(x+5,player.y+39,10,9);ctx.fillRect(x+19,player.y+39,10,9);
ctx.save();ctx.translate(x+16,player.y+24);ctx.scale(player.face,1);ctx.fillStyle="#e7eff8";
if(player.attack>0){
ctx.fillRect(12,-25,7,42);ctx.strokeStyle=player.attackType==="strong"?"#ffbd45":player.attackType==="combo"?"#75d9ff":"#fff0a0";
ctx.lineWidth=player.attackType==="strong"?8:5;ctx.shadowColor=player.attackType==="strong"?"#ffbd45":player.attackType==="combo"?"#75d9ff":"#fff0a0";
ctx.shadowBlur=14;ctx.beginPath();ctx.arc(10,0,43,-1.1,1.1);ctx.stroke();ctx.shadowBlur=0;
}else ctx.fillRect(12,-15,5,27);ctx.restore();
}
function loop(){update();drawBackground();drawWorld();requestAnimationFrame(loop)}
makeStage(0);showTitle();requestAnimationFrame(loop);
</script>
</body>
</html>