<!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>SHADOW ROYALE</title>
<style>
*{box-sizing:border-box}
body{margin:0;background:#080b13;color:white;font-family:Arial,sans-serif;overflow:hidden}
button,input,select{font:inherit}
button{border:0;border-radius:10px;padding:11px;background:#7045ff;color:white;font-weight:bold;cursor:pointer}
button:active{transform:scale(.96)}
#lobby{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;background:linear-gradient(135deg,#11152a,#25204c,#080b14);background-size:cover;background-position:center;padding:12px;overflow:auto}
.logo{font-size:clamp(35px,8vw,65px);font-weight:1000;letter-spacing:4px;text-shadow:0 0 22px #855bff}
.subtitle{color:#b7a8ff;letter-spacing:4px;margin:5px 0 15px}
.panel{background:#101626ed;border:1px solid #7557ff;border-radius:16px;padding:13px;width:min(92vw,440px);margin:7px auto}
.panel h3{margin:0 0 10px;color:#b9a5ff}
.field{display:flex;gap:8px;margin:6px 0;align-items:center;text-align:left}
.field label{width:100px;font-size:13px;color:#c9c9dc}
.field input,.field select{min-width:0;flex:1;background:#202a3e;color:white;border:1px solid #59617d;border-radius:7px;padding:8px}
#play{width:min(90vw,360px);font-size:24px;padding:17px;margin:8px;background:linear-gradient(90deg,#663bff,#a14fff);box-shadow:0 0 25px #774cff}
#bgm{display:block;width:min(90vw,360px);padding:13px;margin:4px auto 8px;background:linear-gradient(90deg,#147b48,#1db954);color:white;text-decoration:none;border-radius:10px;font-weight:bold;font-size:16px;box-shadow:0 0 18px #1db95455}
#bgm:active{transform:scale(.97)}
#game{display:none;position:absolute;inset:0;background:#192c25}
canvas#world{display:block;width:100%;height:100%;touch-action:none}
#hud{position:absolute;inset:0;pointer-events:none}
.hudbox{position:absolute;background:#080d1be8;border:1px solid #7b67ff;border-radius:9px;padding:8px 11px;font-size:13px}
#stats{top:8px;left:8px;line-height:1.8;min-width:142px}
#zone{top:8px;right:8px;text-align:right}
#mapbox{position:absolute;right:8px;top:88px;width:clamp(110px,22vw,165px);height:clamp(110px,22vw,165px);background:#07100d;border:2px solid #b49cff;border-radius:9px;overflow:hidden;pointer-events:auto}
#map{width:100%;height:100%}
.hpLine{display:flex;justify-content:space-between;gap:12px;margin-top:3px}
.bar{height:9px;background:#303746;border-radius:8px;overflow:hidden;margin:3px 0 5px;border:1px solid #ffffff35}
#hpbar{height:100%;width:100%;background:linear-gradient(90deg,#16c75a,#8cff9b);transition:width .12s}
#shieldbar{height:100%;width:50%;background:linear-gradient(90deg,#168de8,#76d5ff);transition:width .12s}
#inventory{position:absolute;bottom:12px;left:50%;transform:translateX(-50%);display:flex;gap:7px;pointer-events:auto;max-width:calc(100vw - 185px)}
.slot{background:#10182cee;border:2px solid #64708b;padding:10px 12px;min-width:78px;min-height:58px;text-align:center;font-size:13px}
.slot.active{border-color:#ffe66d;background:#55451e}
#controls{position:absolute;inset:0;pointer-events:none}
#joy{position:absolute;bottom:112px;left:16px;width:158px;height:158px;border-radius:50%;background:#ffffff25;border:3px solid #ffffff90;pointer-events:auto;touch-action:none;box-shadow:0 0 18px #0008}
#knob{position:absolute;width:62px;height:62px;border-radius:50%;background:#a48aff;left:45px;top:45px;box-shadow:0 0 16px #a48aff;border:2px solid #e2d8ff}
#fire{position:absolute;right:20px;bottom:118px;width:116px;height:116px;border-radius:50%;background:#ef4e68;border:4px solid #ffb5bd;pointer-events:auto;font-size:20px;box-shadow:0 0 18px #ef4e6880}
#reload{position:absolute;right:25px;bottom:25px;pointer-events:auto;background:#394c70;padding:14px 20px;font-size:16px;min-width:112px;min-height:48px}
#back{display:none;position:absolute;left:50%;top:58%;transform:translate(-50%,-50%);z-index:5;padding:16px 35px;font-size:19px;pointer-events:auto;background:#7045ff}
#message{position:absolute;top:42%;left:50%;transform:translate(-50%,-50%);font-size:27px;font-weight:bold;text-shadow:0 2px 6px black;text-align:center;pointer-events:none;white-space:nowrap}
#modal{display:none;position:absolute;inset:0;background:#000b;align-items:center;justify-content:center;padding:15px;z-index:10}
#modal .panel{max-height:85vh;overflow:auto}
.toggle{display:flex;justify-content:space-between;align-items:center;margin:12px 0;font-size:16px;padding:8px 10px;background:#1b2440;border-radius:10px}
.toggle input{width:28px;height:28px;accent-color:#8d6bff;cursor:pointer}
.toggle .state{font-size:12px;color:#b9a5ff;margin-left:auto;margin-right:10px}
@media(max-width:520px){
#joy{width:142px;height:142px;bottom:105px;left:10px}
#knob{width:58px;height:58px;left:40px;top:40px}
#fire{width:104px;height:104px;right:12px;bottom:112px}
#inventory{max-width:calc(100vw - 150px);gap:4px}
.slot{min-width:58px;padding:7px 6px;font-size:11px;min-height:52px}
#stats{font-size:12px;padding:6px 8px}
#mapbox{width:112px;height:112px}
#reload{right:15px;bottom:20px}
}
@media(max-height:480px){
#joy{width:112px;height:112px;bottom:12px}
#knob{width:48px;height:48px;left:30px;top:30px}
#fire{width:86px;height:86px;bottom:14px}
#inventory{bottom:8px}
#reload{bottom:105px}
}
#bgfile{max-width:100%;font-size:12px}
@media(min-width:800px){
#joy{width:158px;height:158px}
#knob{left:45px;top:45px}
#fire{width:116px;height:116px}
}
</style>
</head>
<body>
<div id="lobby">
<div class="logo">SHADOW ROYALE</div>
<div class="subtitle">BATTLE • SURVIVE • WIN</div>
<div class="panel">
<h3>PLAYER CUSTOMIZE</h3>
<div class="field"><label>プレイヤー名</label><input id="pname" value="PLAYER" maxlength="14"></div>
<div class="field"><label>顔</label><select id="face"><option>🙂</option><option>😎</option><option>😐</option><option>🤖</option><option>👽</option></select></div>
<div class="field"><label>服の色</label><input id="shirt" type="color" value="#6e55ff"></div>
<div class="field"><label>ズボンの色</label><input id="pants" type="color" value="#242b42"></div>
<div class="field"><label>髪型</label><select id="hair"><option value="short">ショート</option><option value="spiky">ツンツン</option><option value="long">ロング</option><option value="none">なし</option></select></div>
<div class="field"><label>髪の色</label><input id="haircolor" type="color" value="#222222"></div>
</div>
<div class="panel">
<h3>LOBBY BACKGROUND</h3>
<input id="bgfile" type="file" accept="image/*">
<p style="font-size:11px;color:#aaa">写真を選ぶとロビー背景に設定できるよ</p>
</div>
<button id="play">▶ PLAY</button>
<a id="bgm" href="https://apps.apple.com/jp/app/spotify-%E9%9F%B3%E6%A5%BD%E3%81%A8%E3%83%9D%E3%83%83%E3%83%89%E3%82%AD%E3%83%A3%E3%82%B9%E3%83%88/id324684580" target="_blank" rel="noopener">🎵 ロビーBGMを設定(Spotify)</a>
<button id="safe" style="background:#303b55">🔒 金庫 / SAFE</button>
<div style="font-size:11px;color:#9298ae;margin-top:8px">SOLO • BOT BATTLE • OFFLINE</div>
</div>
<div id="game">
<canvas id="world"></canvas>
<div id="hud">
<div id="stats" class="hudbox">
👥 残り <span id="alive">31</span><br>
💀 KILLS <span id="kills">0</span><br>
❤️ HP <span id="hp">100</span>
<div class="bar"><div id="hpbar"></div></div>
🛡️ SHIELD <span id="shield">50</span>
<div class="bar"><div id="shieldbar"></div></div>
</div>
<div id="zone" class="hudbox">STORM<br><span id="timer">縮小開始まで 20</span></div>
<div id="mapbox"><canvas id="map" width="165" height="165"></canvas></div>
<div id="inventory">
<button class="slot active" data-slot="0">🔫<br>ブラスター</button>
<button class="slot" data-slot="1">⚡<br>ショック</button>
<button class="slot" data-slot="2">💥<br>バースト</button>
</div>
<div id="controls">
<div id="joy"><div id="knob"></div></div>
<button id="fire">FIRE</button>
<button id="reload">リロード</button>
</div>
<div id="message"></div>
<button id="back">ロビーへ戻る</button>
</div>
</div>
<div id="modal">
<div class="panel">
<h3>🔐 チートモード</h3>
<div id="passarea">
<p>パスワードを入力</p>
<input id="password" type="password" inputmode="numeric" maxlength="4" placeholder="数字4桁">
<button id="unlock">解除</button>
<p id="passmsg" style="color:#ff7777"></p>
</div>
<div id="cheats" style="display:none">
<p style="color:#a99aff">CHEAT MODE ACTIVATED</p>
<div class="toggle">全員キル <span class="state" id="allkillState">OFF</span><input type="checkbox" id="allkill"></div>
<div class="toggle">ワンパン <span class="state" id="onePunchState">OFF</span><input type="checkbox" id="onePunch"></div>
<div class="toggle">オートエイム <span class="state" id="autoState">OFF</span><input type="checkbox" id="auto"></div>
<div class="toggle">Fly(飛行) <input type="checkbox" id="fly"></div>
<div class="toggle">無敵 <input type="checkbox" id="god"></div>
<div class="toggle">無限ジャンプ <input type="checkbox" id="jump"></div>
</div>
<button id="close">閉じる</button>
</div>
</div>
<script>
const $=id=>document.getElementById(id);
const canvas=$("world"),ctx=canvas.getContext("2d");
const map=$("map"),mctx=map.getContext("2d");
const W=5000,H=5000;
let camX=0,camY=0,zoom=1,playing=false,last=0;
let player,enemies=[],bullets=[],chests=[],buildings=[],heals=[];
let kills=0,selected=0,fireHeld=false,lastShot=0,messageTimer=0;
let joy={x:0,y:0,active:false};
let storm={x:2500,y:2500,r:2450,elapsed:0};
let cheats={auto:false,fly:false,god:false,jump:false,onePunch:false,allkill:false};
let playerStyle={};
let inventory=[
{name:"ブラスター",ammo:60,max:60,damage:22,speed:10,unlocked:true},
{name:"ショック",ammo:30,max:30,damage:35,speed:8,unlocked:false},
{name:"バースト",ammo:18,max:18,damage:48,speed:7,unlocked:false}
];
function resize(){
const d=Math.min(devicePixelRatio||1,2);
canvas.width=innerWidth*d;
canvas.height=innerHeight*d;
ctx.setTransform(d,0,0,d,0,0);
}
addEventListener("resize",resize);
resize();
$("bgfile").onchange=e=>{
const f=e.target.files[0];
if(!f)return;
const url=URL.createObjectURL(f);
$("lobby").style.backgroundImage=`linear-gradient(#080b1477,#080b1477),url("${url}")`;
};
function readStyle(){
playerStyle={
name:$("pname").value||"PLAYER",
face:$("face").value,
shirt:$("shirt").value,
pants:$("pants").value,
hair:$("hair").value,
haircolor:$("haircolor").value
};
}
$("play").onclick=()=>{
readStyle();
startGame();
};
$("safe").onclick=()=>{$("modal").style.display="flex"};
$("close").onclick=()=>{$("modal").style.display="none"};
$("unlock").onclick=()=>{
if($("password").value==="0309"){
$("passarea").style.display="none";
$("cheats").style.display="block";
}else{
$("passmsg").textContent="パスワードが違います";
}
};
$("auto").onchange=e=>{cheats.auto=e.target.checked;$("autoState").textContent=e.target.checked?"ON":"OFF";};
$("onePunch").onchange=e=>{cheats.onePunch=e.target.checked;$("onePunchState").textContent=e.target.checked?"ON":"OFF";};
$("allkill").onchange=e=>{
cheats.allkill=e.target.checked;
$("allkillState").textContent=e.target.checked?"ON":"OFF";
if(e.target.checked&&playing){
const count=enemies.filter(bot=>bot.alive).length;
enemies.forEach(bot=>{if(bot.alive){bot.alive=false;bot.hp=0;}});
kills+=count;
showMessage("ALL BOTS ELIMINATED!");
}
};
$("fly").onchange=e=>cheats.fly=e.target.checked;
$("god").onchange=e=>cheats.god=e.target.checked;
$("jump").onchange=e=>cheats.jump=e.target.checked;
$("back").onclick=()=>{
playing=false;
$("game").style.display="none";
$("lobby").style.display="flex";
$("back").style.display="none";
};
function startGame(){
$("lobby").style.display="none";
$("game").style.display="block";
$("back").style.display="none";
resize();
playing=true;
kills=0;
bullets=[];
selected=0;
inventory.forEach((w,i)=>{
w.ammo=w.max;
w.unlocked=i===0;
});
player={x:2500,y:2500,hp:100,shield:50,dir:0};
enemies=[];
chests=[];
buildings=[];
heals=[];
for(let i=0;i<30;i++){
const a=Math.random()*Math.PI*2;
const r=350+Math.random()*2100;
enemies.push({
x:2500+Math.cos(a)*r,
y:2500+Math.sin(a)*r,
hp:100,dir:0,alive:true,
shoot:1+Math.random()*3
});
}
for(let i=0;i<80;i++){
chests.push({
x:100+Math.random()*4800,
y:100+Math.random()*4800,
open:false
});
}
for(let i=0;i<65;i++){
heals.push({
x:100+Math.random()*4800,
y:100+Math.random()*4800,
used:false
});
}
for(let i=0;i<100;i++){
buildings.push({
x:100+Math.random()*4800,
y:100+Math.random()*4800,
w:55+Math.random()*65,
h:45+Math.random()*65
});
}
storm={x:2500,y:2500,r:2450,elapsed:0};
showMessage("BATTLE START!");
last=performance.now();
requestAnimationFrame(loop);
}
function drawHuman(x,y,style,dir=0){
ctx.save();
ctx.translate(x,y);
ctx.rotate(dir);
ctx.fillStyle="#0007";
ctx.beginPath();
ctx.ellipse(0,13,13,6,0,0,Math.PI*2);
ctx.fill();
ctx.fillStyle=style.pants||"#30394c";
ctx.fillRect(-9,2,7,15);
ctx.fillRect(3,2,7,15);
ctx.fillStyle=style.shirt||"#db4d57";
ctx.fillRect(-11,-13,22,21);
ctx.fillStyle="#d7a27e";
ctx.fillRect(-16,-11,5,17);
ctx.fillRect(11,-11,5,17);
ctx.fillStyle="#d9a783";
ctx.beginPath();
ctx.arc(0,-21,9,0,Math.PI*2);
ctx.fill();
if(style.hair!=="none"){
ctx.fillStyle=style.haircolor||"#222";
if(style.hair==="long"){
ctx.fillRect(-10,-29,5,20);
ctx.fillRect(5,-29,5,20);
ctx.fillRect(-8,-30,16,6);
}else if(style.hair==="spiky"){
ctx.beginPath();
ctx.moveTo(-9,-25);
ctx.lineTo(-7,-36);
ctx.lineTo(-1,-29);
ctx.lineTo(3,-37);
ctx.lineTo(7,-28);
ctx.lineTo(10,-32);
ctx.lineTo(9,-22);
ctx.closePath();
ctx.fill();
}else{
ctx.beginPath();
ctx.arc(0,-25,9,Math.PI,Math.PI*2);
ctx.fill();
ctx.fillRect(-9,-26,18,5);
}
}
ctx.font="12px Arial";
ctx.textAlign="center";
ctx.fillText(style.face||"🙂",0,-18);
// 銃を持っているように見せる
ctx.fillStyle="#292d38";
ctx.fillRect(7,-8,23,6);
ctx.fillStyle="#87909c";
ctx.fillRect(22,-10,10,3);
ctx.fillStyle="#171a22";
ctx.fillRect(13,-3,5,8);
ctx.restore();
}
function draw(){
const vw=innerWidth,vh=innerHeight;
camX=Math.max(0,Math.min(W-vw,player.x-vw/2));
camY=Math.max(0,Math.min(H-vh,player.y-vh/2));
ctx.clearRect(0,0,vw,vh);
ctx.save();
ctx.translate(-camX,-camY);
ctx.fillStyle="#294a3a";
ctx.fillRect(0,0,W,H);
ctx.strokeStyle="#ffffff0b";
ctx.lineWidth=1;
for(let x=0;x<=W;x+=100){
ctx.beginPath();ctx.moveTo(x,0);ctx.lineTo(x,H);ctx.stroke();
}
for(let y=0;y<=H;y+=100){
ctx.beginPath();ctx.moveTo(0,y);ctx.lineTo(W,y);ctx.stroke();
}
buildings.forEach(b=>{
ctx.fillStyle="#59616a";
ctx.fillRect(b.x,b.y,b.w,b.h);
ctx.fillStyle="#8a9298";
ctx.fillRect(b.x+7,b.y+7,b.w-14,b.h-14);
ctx.strokeStyle="#303b42";
ctx.strokeRect(b.x,b.y,b.w,b.h);
});
chests.forEach(c=>{
if(c.open)return;
ctx.fillStyle="#d49a31";
ctx.fillRect(c.x-13,c.y-10,26,20);
ctx.fillStyle="#ffe17b";
ctx.fillRect(c.x-3,c.y-3,6,7);
});
heals.forEach(h=>{
if(h.used)return;
ctx.fillStyle="#f4f4f4";
ctx.fillRect(h.x-9,h.y-9,18,18);
ctx.fillStyle="#e83c54";
ctx.fillRect(h.x-3,h.y-7,6,14);
ctx.fillRect(h.x-7,h.y-3,14,6);
});
ctx.save();
ctx.fillStyle="#5133b755";
ctx.beginPath();
ctx.rect(0,0,W,H);
ctx.arc(storm.x,storm.y,storm.r,0,Math.PI*2,true);
ctx.fill("evenodd");
ctx.restore();
ctx.strokeStyle="#a47cff";
ctx.lineWidth=6;
ctx.beginPath();
ctx.arc(storm.x,storm.y,storm.r,0,Math.PI*2);
ctx.stroke();
bullets.forEach(b=>{
ctx.fillStyle=b.owner==="player"?"#ffe76a":"#ff6767";
ctx.beginPath();
ctx.arc(b.x,b.y,4,0,Math.PI*2);
ctx.fill();
});
enemies.forEach(e=>{
if(!e.alive)return;
drawHuman(e.x,e.y,{
shirt:"#d94d52",
pants:"#292d3c",
haircolor:"#252020",
hair:"short",
face:"😈"
},e.dir);
ctx.fillStyle="#222";
ctx.fillRect(e.x-15,e.y-40,30,4);
ctx.fillStyle="#ff4545";
ctx.fillRect(e.x-15,e.y-40,30*Math.max(0,e.hp)/100,4);
});
drawHuman(player.x,player.y,playerStyle,player.dir);
ctx.restore();
drawMap();
}
function drawMap(){
const size=map.width;
mctx.clearRect(0,0,size,size);
mctx.fillStyle="#203b30";
mctx.fillRect(0,0,size,size);
const scale=(size/900)/zoom;
mctx.strokeStyle="#a98aff";
mctx.lineWidth=2;
mctx.beginPath();
mctx.arc(
size/2+(storm.x-player.x)*scale,
size/2+(storm.y-player.y)*scale,
storm.r*scale,0,Math.PI*2
);
mctx.stroke();
enemies.forEach(e=>{
if(!e.alive)return;
const x=size/2+(e.x-player.x)*scale;
const y=size/2+(e.y-player.y)*scale;
if(x>=0&&x<=size&&y>=0&&y<=size){
mctx.fillStyle="#ff4444";
mctx.beginPath();
mctx.arc(x,y,4,0,Math.PI*2);
mctx.fill();
}
});
mctx.fillStyle="#fff";
mctx.beginPath();
mctx.arc(size/2,size/2,5,0,Math.PI*2);
mctx.fill();
}
function shoot(){
const w=inventory[selected];
if(!w||!w.unlocked||w.ammo<=0)return;
const now=performance.now();
if(now-lastShot<260)return;
lastShot=now;
w.ammo--;
let dx=Math.cos(player.dir),dy=Math.sin(player.dir);
if(cheats.auto){
const target=enemies.filter(e=>e.alive)
.sort((a,b)=>Math.hypot(a.x-player.x,a.y-player.y)-Math.hypot(b.x-player.x,b.y-player.y))[0];
if(target){
const a=Math.atan2(target.y-player.y,target.x-player.x);
dx=Math.cos(a);dy=Math.sin(a);
}
}
bullets.push({
x:player.x+dx*18,y:player.y+dy*18,
vx:dx*w.speed,vy:dy*w.speed,
damage:cheats.onePunch?9999:w.damage,
life:90,owner:"player"
});
}
function enemyShoot(e,target){
if(!target)return;
const a=Math.atan2(target.y-e.y,target.x-e.x);
bullets.push({
x:e.x,y:e.y,
vx:Math.cos(a)*4.8,vy:Math.sin(a)*4.8,
damage:e.weapon||14,life:100,
owner:e,target:target,enemy:true
});
}
function update(dt){
const speed=cheats.fly?5:3.2;
if(joy.active){
player.x+=joy.x*speed*dt*60;
player.y+=joy.y*speed*dt*60;
if(Math.hypot(joy.x,joy.y)>.12){
player.dir=Math.atan2(joy.y,joy.x);
}
}
player.x=Math.max(15,Math.min(W-15,player.x));
player.y=Math.max(15,Math.min(H-15,player.y));
if(fireHeld)shoot();
// BOT同士も戦う
enemies.forEach(e=>{
if(!e.alive)return;
let target=null,nearest=620;
const pd=Math.hypot(player.x-e.x,player.y-e.y);
if(pd<nearest){nearest=pd;target=player;}
enemies.forEach(other=>{
if(other===e||!other.alive)return;
const d=Math.hypot(other.x-e.x,other.y-e.y);
if(d<nearest){nearest=d;target=other;}
});
e.target=target;
if(target){
const dx=target.x-e.x,dy=target.y-e.y,d=Math.hypot(dx,dy)||1;
e.dir=Math.atan2(dy,dx);
if(d>150){
e.x+=dx/d*.72*dt*60;
e.y+=dy/d*.72*dt*60;
}
e.shoot-=dt;
if(d<430&&e.shoot<=0){
enemyShoot(e,target);
e.shoot=1.2+Math.random()*1.5;
}
}else{
const loot=chests.find(c=>!c.open);
if(loot){
const dx=loot.x-e.x,dy=loot.y-e.y,d=Math.hypot(dx,dy)||1;
e.dir=Math.atan2(dy,dx);
e.x+=dx/d*.55*dt*60;
e.y+=dy/d*.55*dt*60;
}
}
const chest=chests.find(c=>!c.open&&Math.hypot(c.x-e.x,c.y-e.y)<28);
if(chest){
chest.open=true;
e.weapon=Math.max(e.weapon||14,Math.random()<.5?22:30);
}
const heal=heals.find(h=>!h.used&&e.hp<85&&Math.hypot(h.x-e.x,h.y-e.y)<24);
if(heal){
heal.used=true;
e.hp=Math.min(100,e.hp+45);
}
});
bullets.forEach(b=>{
b.x+=b.vx*dt*60;
b.y+=b.vy*dt*60;
b.life--;
if(b.owner==="player"){
enemies.forEach(e=>{
if(e.alive&&Math.hypot(e.x-b.x,e.y-b.y)<18){
e.hp-=b.damage;
b.life=0;
if(e.hp<=0){
e.alive=false;
kills++;
showMessage("ENEMY DOWN!");
}
}
});
}else if(b.target===player){
if(Math.hypot(player.x-b.x,player.y-b.y)<18){
if(!cheats.god)damagePlayer(b.damage);
b.life=0;
}
}else if(b.target&&b.target.alive&&Math.hypot(b.target.x-b.x,b.target.y-b.y)<18){
b.target.hp-=b.damage;
b.life=0;
if(b.target.hp<=0)b.target.alive=false;
}
});
bullets=bullets.filter(b=>b.life>0);
chests.forEach(c=>{
if(!c.open&&Math.hypot(c.x-player.x,c.y-player.y)<30){
c.open=true;
const locked=inventory.filter(w=>!w.unlocked);
if(locked.length){
const w=locked[Math.floor(Math.random()*locked.length)];
w.unlocked=true;
w.ammo=w.max;
showMessage("NEW WEAPON! "+w.name);
refreshSlots();
}else{
const w=inventory[Math.floor(Math.random()*3)];
w.ammo=Math.min(w.max,w.ammo+Math.ceil(w.max*.5));
showMessage("AMMO GET!");
}
}
});
heals.forEach(h=>{
if(!h.used&&player.hp<100&&Math.hypot(h.x-player.x,h.y-player.y)<30){
h.used=true;
player.hp=Math.min(100,player.hp+40);
showMessage("❤️ HP +40");
}
});
storm.elapsed+=dt;
if(storm.elapsed>20){
storm.r=Math.max(100,storm.r-dt*3.1);
}
if(Math.hypot(player.x-storm.x,player.y-storm.y)>storm.r&&!cheats.god){
damagePlayer(dt*5);
}
$("hp").textContent=Math.max(0,Math.ceil(player.hp));
$("shield").textContent=Math.max(0,Math.ceil(player.shield));
$("hpbar").style.width=Math.max(0,player.hp)+"%";
$("shieldbar").style.width=Math.max(0,player.shield/50*100)+"%";
$("kills").textContent=kills;
$("alive").textContent=1+enemies.filter(e=>e.alive).length;
$("timer").textContent=storm.elapsed<20
?"縮小開始まで "+Math.ceil(20-storm.elapsed)
:"ストーム縮小中";
if(player.hp<=0)endGame(false);
if(enemies.every(e=>!e.alive))endGame(true);
}
function damagePlayer(amount){
if(player.shield>0){
const used=Math.min(player.shield,amount);
player.shield-=used;
amount-=used;
}
player.hp-=amount;
}
function showMessage(t){
$("message").textContent=t;
messageTimer=1.5;
}
function refreshSlots(){
document.querySelectorAll(".slot").forEach((b,i)=>{
const w=inventory[i];
b.style.opacity=w.unlocked?"1":".35";
b.innerHTML=(w.unlocked?["🔫","⚡","💥"][i]:"🔒")+"<br>"+w.name+"<br>"+(w.unlocked?w.ammo:"未入手");
});
}
function endGame(win){
if(!playing)return;
playing=false;
if(win){
$("message").textContent="🏆 VICTORY!";
$("back").style.display="block";
}else{
$("message").textContent="💀 GAME OVER";
$("back").style.display="block";
}
}
function loop(t){
if(!playing)return;
const dt=Math.min((t-last)/1000,.04);
last=t;
update(dt);
draw();
if(messageTimer>0){
messageTimer-=dt;
if(messageTimer<=0)$("message").textContent="";
}
if(playing)requestAnimationFrame(loop);
}
document.querySelectorAll(".slot").forEach(b=>{
b.onclick=()=>{
const i=Number(b.dataset.slot);
if(!inventory[i].unlocked){
showMessage("宝箱から入手してね");
return;
}
selected=i;
document.querySelectorAll(".slot").forEach(x=>x.classList.toggle("active",x===b));
};
});
$("reload").onclick=()=>{
const w=inventory[selected];
if(w.unlocked){
w.ammo=w.max;
refreshSlots();
showMessage("RELOADED");
}
};
$("fire").addEventListener("pointerdown",e=>{
fireHeld=true;
shoot();
$("fire").setPointerCapture(e.pointerId);
});
["pointerup","pointercancel","pointerleave"].forEach(ev=>{
$("fire").addEventListener(ev,()=>fireHeld=false);
});
function setJoy(e){
const r=$("joy").getBoundingClientRect();
const cx=r.left+r.width/2,cy=r.top+r.height/2;
let dx=e.clientX-cx,dy=e.clientY-cy;
const len=Math.hypot(dx,dy),max=42;
if(len>max){dx=dx/len*max;dy=dy/len*max}
joy.x=dx/max;
joy.y=dy/max;
$("knob").style.left=(r.width/2-22+dx)+"px";
$("knob").style.top=(r.height/2-22+dy)+"px";
}
$("joy").addEventListener("pointerdown",e=>{
joy.active=true;
$("joy").setPointerCapture(e.pointerId);
setJoy(e);
});
$("joy").addEventListener("pointermove",e=>{
if(joy.active)setJoy(e);
});
function resetJoy(){
joy.active=false;
joy.x=joy.y=0;
$("knob").style.left="33px";
$("knob").style.top="33px";
}
$("joy").addEventListener("pointerup",resetJoy);
$("joy").addEventListener("pointercancel",resetJoy);
map.addEventListener("click",()=>{
zoom=zoom>=3?.75:zoom+.35;
drawMap();
});
refreshSlots();
</script>
</body>
</html>