diff --git a/fog.js b/fog.js index c8ac9d7..2b04d86 100644 --- a/fog.js +++ b/fog.js @@ -9,6 +9,7 @@ const START_POS = [38.891, 139.824]; const REVEAL_RADIUS = 40; // m const MAX_EXPLORE_POINTS = 300; // 制圧率100% + const BASE_CAPTURE_RADIUS = 30; // 拠点制圧距離 // ============================= // DOM @@ -16,14 +17,8 @@ const titleEl = document.getElementById("title"); const startBtn = document.getElementById("start"); const stopBtn = document.getElementById("stop"); - const controls = document.getElementById("controls"); - - // 制圧率表示(HTMLに無いので作る) - const rateEl = document.createElement("span"); - rateEl.textContent = " 制圧率: 0%"; - rateEl.style.marginLeft = "12px"; - rateEl.style.fontWeight = "bold"; - controls.appendChild(rateEl); + const rateEl = document.getElementById("rate"); + const baseStatusEl = document.getElementById("baseStatus"); // ============================= // 状態 @@ -32,10 +27,18 @@ let playerMarker; let watchId = null; - // 解除済みポイント const revealedPoints = []; // ============================= + // 拠点データ + // ============================= + const bases = [ + { latlng: L.latLng(38.892, 139.825), captured: false, marker: null }, + { latlng: L.latLng(38.889, 139.823), captured: false, marker: null }, + { latlng: L.latLng(38.893, 139.827), captured: false, marker: null } + ]; + + // ============================= // Fog Layer // ============================= const FogLayer = L.GridLayer.extend({ @@ -47,7 +50,6 @@ const ctx = tile.getContext("2d"); - // 霧 ctx.fillStyle = "rgba(0,0,0,0.85)"; ctx.fillRect(0, 0, size.x, size.y); @@ -60,13 +62,10 @@ const point = map.latLngToContainerPoint(latlng); const tilePoint = map.latLngToContainerPoint(bounds.getNorthWest()); - const x = point.x - tilePoint.x; - const y = point.y - tilePoint.y; - ctx.beginPath(); ctx.arc( - x, - y, + point.x - tilePoint.x, + point.y - tilePoint.y, metersToPixels(REVEAL_RADIUS, latlng.lat), 0, Math.PI * 2 @@ -104,10 +103,18 @@ 100, Math.floor((revealedPoints.length / MAX_EXPLORE_POINTS) * 100) ); - rateEl.textContent = ` 制圧率: ${rate}%`; + rateEl.textContent = `制圧率: ${rate}%`; + } - if (rate === 100) { - titleEl.textContent = "完全制圧!"; + // ============================= + // 拠点UI更新 + // ============================= + function updateBaseStatus() { + const captured = bases.filter(b => b.captured).length; + baseStatusEl.textContent = `拠点: ${captured} / ${bases.length}`; + + if (captured === bases.length) { + titleEl.textContent = "全拠点制圧!"; } } @@ -127,15 +134,43 @@ playerMarker = L.marker(map.getCenter()).addTo(map); playerMarker.bindPopup("STARTで探索開始").openPopup(); - // デバッグ用クリック探索 + // 拠点マーカー配置 + bases.forEach(b => { + b.marker = L.circleMarker(b.latlng, { + radius: 8, + color: "red", + fillColor: "red", + fillOpacity: 1 + }).addTo(map).bindPopup("未制圧拠点"); + }); + map.on("click", e => updateLocation(e.latlng)); + updateBaseStatus(); + } + + // ============================= + // 拠点判定 + // ============================= + function checkBases(latlng) { + bases.forEach(b => { + if (b.captured) return; + + if (latlng.distanceTo(b.latlng) <= BASE_CAPTURE_RADIUS) { + b.captured = true; + b.marker.setStyle({ + color: "blue", + fillColor: "blue" + }); + b.marker.setPopupContent("制圧済み拠点"); + updateBaseStatus(); + } + }); } // ============================= // 霧解除 // ============================= function reveal(latlng) { - // 同じ場所での重複解除防止 if (isNearExisting(latlng)) return; revealedPoints.push(latlng); @@ -149,7 +184,9 @@ function updateLocation(latlng) { map.panTo(latlng, { animate: false }); playerMarker.setLatLng(latlng); + reveal(latlng); + checkBases(latlng); } // =============================