<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>RAINBOW BRAWL.IO - ONLINE</title>
<link href="https://googleapis.com" rel="stylesheet">
<style>
* { box-sizing: border-box; }
body {
margin: 0; overflow: hidden; background: #111;
font-family: 'Press Start 2P', 'M PLUS Rounded 1c', sans-serif;
color: white; user-select: none;
}
canvas { display: block; }
.rainbow-text {
background: linear-gradient(90deg, #ff0000, #ff7f00, #ffff00, #00ff00, #00ffff, #0000ff, #8b00ff);
background-size: 400%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: rainbow 3s linear infinite;
}
@keyframes rainbow { 0% { background-position: 0% 50%; } 100% { background-position: 400% 50%; } }
#ui {
position: absolute; top: 15px; left: 15px; pointer-events: none;
text-shadow: 2px 2px 0 #000, -2px -2px 0 #000; line-height: 1.7; font-size: 13px;
}
#topRightBtns {
position: absolute; top: 15px; right: 15px; display: flex; gap: 10px; flex-wrap: wrap;
}
.game-btn {
padding: 10px 14px; font-family: inherit; font-size: 11px;
color: #fff; border: 3px solid #fff; border-radius: 8px; cursor: pointer;
box-shadow: 0 4px 0 rgba(0,0,0,0.6);
}
.game-btn:active { transform: translateY(3px); box-shadow: none; }
#inventoryBar {
position: absolute; bottom: 15px; left: 50%; transform: translateX(-50%);
display: flex; gap: 12px; background: rgba(0,0,0,0.75);
padding: 10px 18px; border: 3px solid #fff; border-radius: 12px;
}
.inv-slot {
width: 75px; height: 70px; background: #222; border: 2px solid #888; border-radius: 8px;
display: flex; flex-direction: column; align-items: center; justify-content: center;
cursor: pointer; font-size: 10px; text-align: center; position: relative;
}
.inv-slot:hover { border-color: #00e5ff; background: #333; }
.inv-count {
position: absolute; top: 4px; right: 6px; color: #ffea00; font-size: 11px;
}
.modal {
position: absolute; inset: 0; background: rgba(0,0,0,0.85);
display: none; flex-direction: column; justify-content: center; align-items: center;
z-index: 10; padding: 20px;
}
.modal-box {
background: #1e1e2f; border: 4px solid #fff; border-radius: 16px;
padding: 25px; width: 90%; max-width: 550px; text-align: center;
box-shadow: 0 0 30px rgba(0, 229, 255, 0.4);
}
input, select {
width: 85%; padding: 12px; margin: 8px 0; font-family: inherit; font-size: 13px;
border-radius: 8px; border: 3px solid #00e5ff; background: #111; color: #fff; text-align: center;
}
.row-item {
display: flex; justify-content: space-between; align-items: center;
background: #2a2a40; padding: 10px 15px; margin: 8px 0; border-radius: 8px; font-size: 11px;
}
</style>
</head>
<body>
<!-- ログイン / 新規登録画面 -->
<div id="authModal" class="modal" style="display: flex;">
<div class="modal-box">
<h1 class="rainbow-text" style="font-size: 24px;">RAINBOW BRAWL.IO</h1>
<p style="font-size: 11px; color: #aaa;">オンライン対戦:ログインまたは新規登録</p>
<input type="text" id="authUser" placeholder="プレイヤー名 (例: Kaito)">
<input type="password" id="authPass" placeholder="パスワード">
<div style="margin-top: 15px;">
<button class="game-btn" style="background:#00e676; color:#000;" onclick="handleAuth('login')">ログイン</button>
<button class="game-btn" style="background:#00e5ff; color:#000;" onclick="handleAuth('register')">新規登録</button>
</div>
<p id="authMsg" style="color: #ff5252; font-size: 11px; margin-top: 10px;"></p>
</div>
</div>
<!-- 左上ステータスUI -->
<div id="ui">
<div style="font-size: 18px;" class="rainbow-text">RAINBOW BRAWL</div>
<div>TIME: <span id="timer">20:00</span> | SCORE: <span id="score">10</span></div>
<div>ONLINE: <span id="onlineCount" style="color:#00e676;">1</span>人</div>
<div>COIN: <span id="coinUI" style="color:#ffd60a;">0</span> 💰</div>
<div>RANK: <span id="currentRankUI">[MEMBER]</span></div>
<div>ABILITY: <span id="abilityUI" style="color:#00e5ff;">なし</span></div>
<div style="font-size: 11px; color: #ffeb3b;" id="buffText"></div>
</div>
<!-- 右上メニューボタン -->
<div id="topRightBtns">
<button class="game-btn" style="background:#ff9500;" onclick="openModal('upgradeModal')">⬆ UPGRADE</button>
<button class="game-btn" style="background:#af52de;" onclick="openModal('gachaModal')">🎰 GACHA</button>
<button class="game-btn" style="background:#ffd60a; color:#000;" onclick="openAdminAuth()">👑 ADMIN</button>
<button class="game-btn" style="background:#ff007f;" onclick="togglePause()">❚❚ PAUSE</button>
</div>
<!-- 下部インベントリ(アイテム貯蔵バー) -->
<div id="inventoryBar">
<div class="inv-slot" onclick="useStoredItem('speed')">
<span class="inv-count" id="inv-speed">0</span>
<span style="font-size:20px;">⚡</span><span>加速</span>
</div>
<div class="inv-slot" onclick="useStoredItem('magnet')">
<span class="inv-count" id="inv-magnet">0</span>
<span style="font-size:20px;">🧲</span><span>磁力</span>
</div>
<div class="inv-slot" onclick="useStoredItem('shield')">
<span class="inv-count" id="inv-shield">0</span>
<span style="font-size:20px;">🛡️</span><span>無敵</span>
</div>
<div class="inv-slot" onclick="useStoredItem('bomb')">
<span class="inv-count" id="inv-bomb">0</span>
<span style="font-size:20px;">💣</span><span>吸収爆弾</span>
</div>
</div>
<!-- アップグレードモーダル -->
<div id="upgradeModal" class="modal">
<div class="modal-box">
<h2 style="color:#ff9500;">⬆ プレイヤー強化</h2>
<p style="font-size:11px;">所持コイン: <span id="upgCoin" style="color:#ffd60a;">0</span> 💰</p>
<div id="upgradeList"></div>
<button class="game-btn" style="background:#555; margin-top:15px;" onclick="closeModals()">閉じる</button>
</div>
</div>
<!-- 能力・性能ガチャモーダル -->
<div id="gachaModal" class="modal">
<div class="modal-box">
<h2 class="rainbow-text">🎰 能力 & 性能ガチャ</h2>
<p style="font-size:11px;">1回 100コイン / 所持: <span id="gachaCoin" style="color:#ffd60a;">0</span> 💰</p>
<div id="gachaResult" style="margin: 15px 0; padding: 15px; background:#111; border-radius:10px; min-height:60px; font-size:12px;">
ボタンを押して強力なパッシブ能力を引き当てよう!
</div>
<button class="game-btn" style="background:#af52de;" onclick="spinGacha()">ガチャを引く (100💰)</button>
<div style="margin-top:15px; text-align:left; font-size:10px;">
<p style="color:#aaa;">▼ 所持能力(クリックで装備):</p>
<div id="ownedAbilities"></div>
</div>
<button class="game-btn" style="background:#555; margin-top:15px;" onclick="closeModals()">閉じる</button>
</div>
</div>
<!-- 管理者パネルモーダル -->
<div id="adminModal" class="modal">
<div class="modal-box" style="border-color: #ffd60a;">
<h2 class="rainbow-text">👑 管理者パネル (ADMIN)</h2>
<div class="row-item">
<span>対象ユーザー名:</span>
<input type="text" id="adminTargetUser" style="width:55%; padding:6px;">
</div>
<div class="row-item">
<span>ランク変更:</span>
<select id="adminRankSelect" style="width: 55%;" onchange="adminAction('setRank', this.value)">
<option value="ADMIN">[ADMIN] 虹色</option>
<option value="MOD">[MOD] 赤</option>
<option value="HELPER">[HELPER] オレンジ</option>
<option value="VIP">[VIP] 水色</option>
<option value="MVP">[MVP] 黄色</option>
<option value="MEMBER">[MEMBER] 緑</option>
</select>
</div>
<div class="row-item">
<span>コイン付与:</span>
<button class="game-btn" style="background:#ffd60a; color:#000;" onclick="adminAction('addCoins', 10000)">+10,000 💰</button>
</div>
<div class="row-item">
<span>巨大化&スコア+500 (自分):</span>
<button class="game-btn" style="background:#00e5ff; color:#000;" onclick="adminBoostSize()">実行</button>
</div>
<div class="row-item">
<span>貯蔵アイテム全種+10個:</span>
<button class="game-btn" style="background:#00e676; color:#000;" onclick="adminAction('giveItems', 10)">付与</button>
</div>
<button class="game-btn" style="background:#555; margin-top:15px;" onclick="closeModals()">閉じる</button>
</div>
</div>
<!-- 一時停止画面 -->
<div id="pauseModal" class="modal">
<div class="modal-box">
<h1 class="rainbow-text">PAUSED</h1>
<p style="font-size:12px;">一時停止中(他プレイヤーから食べられない無敵シールド中!)</p>
<button class="game-btn" style="background:#00e5ff; color:#000;" onclick="togglePause()">再開する</button>
</div>
</div>
<canvas id="gameCanvas"></canvas>
<script>
// =========================================================
// ★ここをあなたのCloudflare WorkersのURLに書き換えてください★
const API_URL = "https://rainbow-brawl-server.torisasami.workers.dev/";
// =========================================================
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const RANKS = {
ADMIN: { tag: '[ADMIN]', color: 'rainbow' },
MOD: { tag: '[MOD]', color: '#ff3b30' },
HELPER: { tag: '[HELPER]', color: '#ff9500' },
VIP: { tag: '[VIP]', color: '#00e5ff' },
MVP: { tag: '[MVP]', color: '#ffd60a' },
MEMBER: { tag: '[MEMBER]', color: '#30d158' }
};
const ABILITIES = [
{ id: 'rainbow_king', name: '【UR】虹の覇王 (速度1.4倍 & スコア2倍)', rate: 10, color: 'rainbow' },
{ id: 'black_hole', name: '【SSR】ブラックホール (常時吸収範囲2倍)', rate: 20, color: '#ffd60a' },
{ id: 'gold_rush', name: '【SR】ゴールドラッシュ (コイン獲得3倍)', rate: 30, color: '#af52de' },
{ id: 'dash_master', name: '【R】ダッシュマスター (移動速度+20%)', rate: 40, color: '#00e5ff' }
];
let currentUser = null;
let userData = null;
let adminSessionPass = "";
let onlinePlayers = []; // 他プレイヤー一覧
// ログイン・新規登録(Cloudflare Workersと通信)
async function handleAuth(mode) {
const u = document.getElementById('authUser').value.trim();
const p = document.getElementById('authPass').value.trim();
const msg = document.getElementById('authMsg');
if (!u || !p) { msg.innerText = "名前とパスワードを入力してください"; return; }
msg.innerText = "サーバー通信中...";
try {
const res = await fetch(${API_URL}/api/auth, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ mode, username: u, password: p })
});
const data = await res.json();
if (!res.ok) { msg.innerText = data.error || "エラーが発生しました"; return; }
userData = data.user;
currentUser = userData.username;
startGame();
} catch (e) {
msg.innerText = "通信エラー:API_URLが正しく設定されているか確認してください";
}
}
// クラウドへ自動セーブ
let saveTimeout = null;
function saveUserData() {
refreshAllUI();
if (!currentUser) return;
clearTimeout(saveTimeout);
saveTimeout = setTimeout(async () => {
await fetch(${API_URL}/api/save, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username: currentUser, passHash: userData.passHash, userData })
});
}, 500);
}
function startGame() {
document.getElementById('authModal').style.display = 'none';
player.name = currentUser;
player.radius = 28 + (userData.upgrades.size - 1) * 6;
isPaused = false;
refreshAllUI();
}
// オンライン位置同期ループ(0.8秒ごとに他のプレイヤーと座標交換)
setInterval(async () => {
if (!currentUser) return;
try {
const res = await fetch(${API_URL}/api/sync, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: player.name,
rank: userData.rank,
x: Math.round(player.x),
y: Math.round(player.y),
radius: Math.round(player.radius),
score: Math.floor(player.score),
paused: isPaused || player.buffs.shield > 0
})
});
const data = await res.json();
if (data.players) {
onlinePlayers = data.players;
document.getElementById('onlineCount').innerText = onlinePlayers.length + 1;
}
} catch (e) {}
}, 800);
// 管理者パネル認証(Workersのシークレットと照合)
function openAdminAuth() {
const pw = prompt("管理者パスワードを入力してください:");
if (!pw) return;
adminSessionPass = pw;
document.getElementById('adminTargetUser').value = currentUser;
document.getElementById('adminRankSelect').value = userData.rank;
openModal('adminModal');
}
async function adminAction(action, value) {
const targetUsername = document.getElementById('adminTargetUser').value.trim() || currentUser;
const res = await fetch(${API_URL}/api/admin, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ adminPassword: adminSessionPass, targetUsername, action, value })
});
const data = await res.json();
if (!res.ok) {
alert(data.error || "認証失敗:パスワードが違います");
closeModals();
return;
}
if (targetUsername === currentUser) {
userData = data.user;
refreshAllUI();
}
alert("管理者操作を実行しました!");
}
function adminBoostSize() {
player.score += 500;
player.radius += 25;
closeModals();
}
// アップグレード機能
const UPGRADE_DEFS = [
{ key: 'speed', label: '移動スピード強化', baseCost: 50 },
{ key: 'magnet', label: 'アイテム吸収範囲強化', baseCost: 50 },
{ key: 'size', label: '初期サイズ強化', baseCost: 80 },
{ key: 'coinMult', label: 'コイン獲得倍率UP', baseCost: 100 }
];
function renderUpgrades() {
document.getElementById('upgCoin').innerText = userData.coins;
const list = document.getElementById('upgradeList');
list.innerHTML = '';
UPGRADE_DEFS.forEach(u => {
const lv = userData.upgrades[u.key];
const cost = u.baseCost * lv;
list.innerHTML += <div class="row-item"> <span>${u.label} (Lv.${lv})</span> <button class="game-btn" style="background:#00e676; color:#000;" onclick="buyUpgrade('${u.key}', ${cost})"> 強化 (${cost}💰) </button> </div>;
});
}
function buyUpgrade(key, cost) {
if (userData.coins < cost) { alert("コインが足りません!"); return; }
userData.coins -= cost;
userData.upgrades[key]++;
if (key === 'size') player.radius += 6;
saveUserData();
renderUpgrades();
}
// ガチャ機能
function spinGacha() {
if (userData.coins < 100) { alert("コインが足りません!(100💰必要)"); return; }
userData.coins -= 100;
const r = Math.random() * 100;
let sum = 0, won = ABILITIES;
for (let a of ABILITIES) {
sum += a.rate;
if (r <= sum) { won = a; break; }
}
if (!userData.abilities.includes(won.id)) userData.abilities.push(won.id);
userData.equippedAbility = won.id;
document.getElementById('gachaResult').innerHTML = <span style="color:#ffd60a;">🎉 獲得&装備!</span><br><br>${won.name};
saveUserData();
renderGacha();
}
function renderGacha() {
document.getElementById('gachaCoin').innerText = userData.coins;
const box = document.getElementById('ownedAbilities');
box.innerHTML = '';
userData.abilities.forEach(id => {
const ab = ABILITIES.find(a => a.id === id);
const eq = userData.equippedAbility === id ? '【装備中】' : '';
box.innerHTML += <div class="row-item" style="cursor:pointer;" onclick="equipAbility('${id}')"> <span>${eq} ${ab.name}</span> </div>;
});
}
function equipAbility(id) { userData.equippedAbility = id; saveUserData(); renderGacha(); }
// アイテム貯蔵(使用)
function useStoredItem(type) {
if (isPaused || !currentUser) return;
if (userData.inventory[type] <= 0) return;
userData.inventory[type]--;
if (type === 'speed') player.buffs.speed = 360;
if (type === 'magnet') player.buffs.magnet = 480;
if (type === 'shield') player.buffs.shield = 360;
if (type === 'bomb') {
items.forEach(it => {
if (Math.hypot(player.x - it.x, player.y - it.y) < 600) {
it.x = player.x; it.y = player.y;
}
});
}
saveUserData();
}
function openModal(id) {
isPaused = true;
document.getElementById(id).style.display = 'flex';
if (id === 'upgradeModal') renderUpgrades();
if (id === 'gachaModal') renderGacha();
}
function closeModals() {
document.querySelectorAll('.modal').forEach(m => m.style.display = 'none');
isPaused = false;
}
function togglePause() {
if (!currentUser) return;
isPaused = !isPaused;
document.getElementById('pauseModal').style.display = isPaused ? 'flex' : 'none';
}
function refreshAllUI() {
if (!userData) return;
document.getElementById('coinUI').innerText = userData.coins;
const r = RANKS[userData.rank] || RANKS.MEMBER;
const rEl = document.getElementById('currentRankUI');
rEl.innerText = r.tag;
rEl.className = r.color === 'rainbow' ? 'rainbow-text' : '';
rEl.style.color = r.color === 'rainbow' ? '' : r.color;
const eqAb = ABILITIES.find(a => a.id === userData.equippedAbility);
document.getElementById('abilityUI').innerText = eqAb ? eqAb.name.split(' ') : 'なし';
for (let k in userData.inventory) {
document.getElementById('inv-' + k).innerText = userData.inventory[k];
}
}
// ゲーム本体ループ
let timeLeft = 20 * 60;
let isPaused = true;
let hue = 0;
const MAP_SIZE = 3000;
const player = {
name: "GUEST", x: MAP_SIZE / 2, y: MAP_SIZE / 2, radius: 28,
score: 10, baseSpeed: 5, targetX: MAP_SIZE / 2, targetY: MAP_SIZE / 2,
buffs: { speed: 0, magnet: 0, shield: 0 }
};
window.addEventListener('mousemove', e => {
player.targetX = player.x + (e.clientX - canvas.width / 2);
player.targetY = player.y + (e.clientY - canvas.height / 2);
});
window.addEventListener('keydown', e => {
if (e.key === 'Escape') togglePause();
if (e.key === '1') useStoredItem('speed');
if (e.key === '2') useStoredItem('magnet');
if (e.key === '3') useStoredItem('shield');
if (e.key === '4') useStoredItem('bomb');
});
const items = [];
const ITEM_TYPES = [
{ type: 'normal', color: 'rainbow', weight: 75 },
{ type: 'speed', color: '#ffea00', weight: 7 },
{ type: 'magnet', color: '#00e5ff', weight: 7 },
{ type: 'shield', color: '#00e676', weight: 6 },
{ type: 'bomb', color: '#ff3b30', weight: 5 }
];
function spawnItem() {
const r = Math.random() * 100;
let sum = 0, chosen = ITEM_TYPES;
for (let t of ITEM_TYPES) { sum += t.weight; if (r <= sum) { chosen = t; break; } }
items.push({ x: Math.random() * MAP_SIZE, y: Math.random() * MAP_SIZE, type: chosen.type, color: chosen.color, radius: chosen.type === 'normal' ? 10 : 16 });
}
for (let i = 0; i < 300; i++) spawnItem();
setInterval(() => {
if (isPaused || !currentUser) return;
timeLeft--;
if (timeLeft <= 0) { alert("TIME UP! FINAL SCORE: " + Math.floor(player.score)); location.reload(); }
const m = String(Math.floor(timeLeft / 60)).padStart(2, '0');
const s = String(timeLeft % 60).padStart(2, '0');
document.getElementById('timer').innerText = ${m}:${s};
}, 1000);
function drawNametag(x, y, radius, name, rankKey, paused) {
const rankInfo = RANKS[rankKey] || RANKS.MEMBER;
const tagText = rankInfo.tag;
const nameText = paused ? ${name} [PAUSE] : ${name};
ctx.font = 'bold 12px "Press Start 2P", "M PLUS Rounded 1c", sans-serif';
const tagW = ctx.measureText(tagText).width;
const totalW = tagW + ctx.measureText(nameText).width;
const tagY = y - radius - 22;
ctx.fillStyle = 'rgba(0, 0, 0, 0.7)';
ctx.beginPath();
ctx.roundRect(x - totalW / 2 - 8, tagY - 16, totalW + 16, 24, 6);
ctx.fill();
ctx.lineWidth = 2;
ctx.strokeStyle = rankInfo.color === 'rainbow' ? hsl(${hue}, 100%, 60%) : rankInfo.color;
ctx.stroke();
ctx.textAlign = 'left';
if (rankInfo.color === 'rainbow') {
let ox = x - totalW / 2;
for (let i = 0; i < tagText.length; i++) {
ctx.fillStyle = hsl(${(hue + i * 35) % 360}, 100%, 60%);
ctx.fillText(tagText[i], ox, tagY);
ox += ctx.measureText(tagText[i]).width;
}
} else {
ctx.fillStyle = rankInfo.color;
ctx.fillText(tagText, x - totalW / 2, tagY);
}
ctx.fillStyle = paused ? '#aaa' : '#fff';
ctx.fillText(nameText, x - totalW / 2 + tagW, tagY);
}
function update() {
if (!isPaused && currentUser && userData) {
hue = (hue + 3) % 360;
for (let k in player.buffs) if (player.buffs[k] > 0) player.buffs[k]--;
let spd = player.baseSpeed + (userData.upgrades.speed - 1) * 0.6;
if (userData.equippedAbility === 'rainbow_king') spd *= 1.4;
if (userData.equippedAbility === 'dash_master') spd *= 1.2;
if (player.buffs.speed > 0) spd *= 1.6;
const dx = player.targetX - player.x, dy = player.targetY - player.y;
const dist = Math.hypot(dx, dy);
if (dist > 5) { player.x += (dx / dist) * spd; player.y += (dy / dist) * spd; }
player.x = Math.max(player.radius, Math.min(MAP_SIZE - player.radius, player.x));
player.y = Math.max(player.radius, Math.min(MAP_SIZE - player.radius, player.y));
let magnetRange = player.radius + (userData.upgrades.magnet - 1) * 25;
if (userData.equippedAbility === 'black_hole') magnetRange *= 2;
if (player.buffs.magnet > 0) magnetRange += 160;
for (let i = items.length - 1; i >= 0; i--) {
const it = items[i];
const d = Math.hypot(player.x - it.x, player.y - it.y);
if (d < magnetRange) {
it.x += (player.x - it.x) * 0.12;
it.y += (player.y - it.y) * 0.12;
}
if (d < player.radius + it.radius) {
if (it.type === 'normal') {
const scoreMult = userData.equippedAbility === 'rainbow_king' ? 2 : 1;
const coinMult = (userData.upgrades.coinMult) * (userData.equippedAbility === 'gold_rush' ? 3 : 1);
player.score += 2 * scoreMult;
userData.coins += 2 * coinMult;
player.radius = 28 + (userData.upgrades.size - 1) * 6 + Math.sqrt(player.score) * 2;
} else {
userData.inventory[it.type]++;
}
saveUserData();
items.splice(i, 1);
spawnItem();
}
}
// オンライン他プレイヤーとの吸収判定
onlinePlayers.forEach(op => {
if (op.paused) return; // 一時停止中の相手は無敵
const d = Math.hypot(player.x - op.x, player.y - op.y);
if (d < player.radius + op.radius) {
if (player.radius > op.radius * 1.15) {
player.score += Math.floor(op.radius);
userData.coins += 30;
saveUserData();
} else if (op.radius > player.radius * 1.15 && player.buffs.shield <= 0) {
player.score = 10;
player.radius = 28 + (userData.upgrades.size - 1) * 6;
player.x = Math.random() * MAP_SIZE;
player.y = Math.random() * MAP_SIZE;
}
}
});
document.getElementById('score').innerText = Math.floor(player.score);
let buffs = [];
if (player.buffs.speed > 0) buffs.push("⚡SPEED");
if (player.buffs.magnet > 0) buffs.push("🧲MAGNET");
if (player.buffs.shield > 0) buffs.push("🛡️SHIELD");
document.getElementById('buffText').innerText = buffs.join(" ");
}
draw();
requestAnimationFrame(update);
}
function draw() {
ctx.fillStyle = '#181824';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.save();
ctx.translate(canvas.width / 2 - player.x, canvas.height / 2 - player.y);
ctx.strokeStyle = hsla(${hue}, 80%, 50%, 0.15);
ctx.lineWidth = 2;
for (let x = 0; x <= MAP_SIZE; x += 100) { ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, MAP_SIZE); ctx.stroke(); }
for (let y = 0; y <= MAP_SIZE; y += 100) { ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(MAP_SIZE, y); ctx.stroke(); }
ctx.strokeStyle = hsl(${hue}, 100%, 50%); ctx.lineWidth = 10;
ctx.strokeRect(0, 0, MAP_SIZE, MAP_SIZE);
items.forEach(it => {
ctx.beginPath(); ctx.arc(it.x, it.y, it.radius, 0, Math.PI * 2);
ctx.fillStyle = it.color === 'rainbow' ? hsl(${(hue + it.x) % 360}, 100%, 60%) : it.color;
ctx.fill(); ctx.lineWidth = 2; ctx.strokeStyle = '#fff'; ctx.stroke();
});
// オンラインの他プレイヤー描画
onlinePlayers.forEach(op => {
const rInfo = RANKS[op.rank] || RANKS.MEMBER;
ctx.globalAlpha = op.paused ? 0.45 : 1.0;
ctx.beginPath(); ctx.arc(op.x, op.y, op.radius, 0, Math.PI * 2);
ctx.fillStyle = '#2c2c3e'; ctx.fill();
ctx.lineWidth = 4; ctx.strokeStyle = rInfo.color === 'rainbow' ? hsl(${hue}, 100%, 60%) : rInfo.color; ctx.stroke();
drawNametag(op.x, op.y, op.radius, op.name, op.rank, op.paused);
ctx.globalAlpha = 1.0;
});
// 自分の描画
if (userData) {
const pRank = RANKS[userData.rank] || RANKS.MEMBER;
const grad = ctx.createRadialGradient(player.x, player.y, 5, player.x, player.y, player.radius);
grad.addColorStop(0, hsl(${hue}, 100%, 70%));
grad.addColorStop(1, hsl(${(hue + 120) % 360}, 100%, 50%));
ctx.globalAlpha = isPaused ? 0.5 : 1.0;
ctx.beginPath(); ctx.arc(player.x, player.y, player.radius, 0, Math.PI * 2);
ctx.fillStyle = grad; ctx.fill();
ctx.lineWidth = 5;
ctx.strokeStyle = player.buffs.shield > 0 ? '#00e676' : (pRank.color === 'rainbow' ? hsl(${(hue+180)%360}, 100%, 60%) : pRank.color);
ctx.stroke();
drawNametag(player.x, player.y, player.radius, player.name, userData.rank, isPaused);
ctx.globalAlpha = 1.0;
}
ctx.restore();
}
update();