'use strict'; // === WEAPON DRAWING === function drawWeaponHeld(weapon, px, py, dir) { const def = WEAPONS.find(w => w.name === weapon.name || w.id === weapon.id); if (!def || !def.drawFunction) return; const drawFn = window[def.drawFunction]; if (typeof drawFn !== 'function') return; drawFn(ctx, px, py, dir); } function drawWeaponInHUD(weapon, x, y) { const def = WEAPONS.find(w => w.name === weapon.name || w.id === weapon.id); if (!def || !drawWeaponIcon) return; drawWeaponIcon(ctx, def, x, y); } // Sword function drawSwordHeld(ctx, px, py, dir) { ctx.fillStyle = COLORS.swordBlade; const sx = px + TILE / 2 + DIRS[dir].x * 10; const sy = py + TILE / 2 + DIRS[dir].y * 10; ctx.fillRect(sx - 2, sy - 2, 4, 4); ctx.fillStyle = COLORS.swordHandle; const hx = px + TILE / 2 + DIRS[dir].x * 5; const hy = py + TILE / 2 + DIRS[dir].y * 5; ctx.fillRect(hx - 1.5, hy - 1.5, 3, 3); } function drawMasterSwordHeld(ctx, px, py, dir) { ctx.fillStyle = '#E8E8FF'; const sx = px + TILE / 2 + DIRS[dir].x * 12; const sy = py + TILE / 2 + DIRS[dir].y * 12; ctx.fillRect(sx - 2, sy - 2, 4, 4); // Aura ctx.fillStyle = 'rgba(100,100,255,0.3)'; ctx.beginPath(); ctx.arc(sx, sy, 6, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#DAA520'; const hx = px + TILE / 2 + DIRS[dir].x * 5; const hy = py + TILE / 2 + DIRS[dir].y * 5; ctx.fillRect(hx - 2, hy - 2, 4, 4); } // Bow function drawBowHeld(ctx, px, py, dir) { ctx.fillStyle = '#8B4513'; const bx = px + TILE / 2 + DIRS[dir].x * 6; const by = py + TILE / 2 + DIRS[dir].y * 6; ctx.beginPath(); if (dir === 0 || dir === 1) { ctx.arc(bx, by, 6, dir === 0 ? -0.8 : 0.8, dir === 0 ? 0.8 : 2.4); } else { ctx.arc(bx, by, 6, dir === 2 ? 0.3 : 2.9, dir === 2 ? 1.1 : 3.7); } ctx.strokeStyle = '#8B4513'; ctx.lineWidth = 2; ctx.stroke(); // String ctx.strokeStyle = '#FFFFFF'; ctx.lineWidth = 1; ctx.beginPath(); ctx.moveTo(bx + DIRS[dir].x * 2, by + DIRS[dir].y * 2); ctx.lineTo(bx - DIRS[dir].x * 2, by - DIRS[dir].y * 2); ctx.stroke(); } // Boomerang function drawBoomerangHeld(ctx, px, py, dir) { ctx.fillStyle = '#FFD700'; const bx = px + TILE / 2 + DIRS[dir].x * 8; const by = py + TILE / 2 + DIRS[dir].y * 8; ctx.beginPath(); ctx.moveTo(bx, by); ctx.lineTo(bx + DIRS[dir].x * 4, by + DIRS[dir].y * 2); ctx.lineTo(bx + DIRS[dir].x * 2, by + DIRS[dir].y * 4); ctx.closePath(); ctx.fill(); } // Bombs function drawBombHeld(ctx, px, py, dir) { ctx.fillStyle = '#333'; const bx = px + TILE / 2 + DIRS[dir].x * 6; const by = py + TILE / 2 + DIRS[dir].y * 6; ctx.beginPath(); ctx.arc(bx, by, 4, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#FF0000'; ctx.fillRect(bx - 1, by - 6, 2, 3); } // Hammer function drawHammerHeld(ctx, px, py, dir) { ctx.fillStyle = '#8B4513'; const hx = px + TILE / 2 + DIRS[dir].x * 8; const hy = py + TILE / 2 + DIRS[dir].y * 8; ctx.fillRect(hx - 1, hy - 1, 3, 10); ctx.fillStyle = '#666'; ctx.fillRect(hx - 4, hy - 5, 8, 6); } // Fire Rod function drawFireRodHeld(ctx, px, py, dir) { ctx.fillStyle = '#8B4513'; const rx = px + TILE / 2 + DIRS[dir].x * 6; const ry = py + TILE / 2 + DIRS[dir].y * 6; ctx.fillRect(rx - 1, ry - 1, 3, 8); ctx.fillStyle = '#FFD700'; ctx.beginPath(); ctx.arc(rx + DIRS[dir].x * 2, ry + DIRS[dir].y * 2, 3, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#FF4500'; ctx.beginPath(); ctx.arc(rx + DIRS[dir].x * 2, ry + DIRS[dir].y * 2, 2, 0, Math.PI * 2); ctx.fill(); } // Ice Rod function drawIceRodHeld(ctx, px, py, dir) { ctx.fillStyle = '#8B4513'; const rx = px + TILE / 2 + DIRS[dir].x * 6; const ry = py + TILE / 2 + DIRS[dir].y * 6; ctx.fillRect(rx - 1, ry - 1, 3, 8); ctx.fillStyle = '#B0E0E6'; ctx.beginPath(); ctx.arc(rx + DIRS[dir].x * 2, ry + DIRS[dir].y * 2, 3, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#00BFFF'; ctx.beginPath(); ctx.arc(rx + DIRS[dir].x * 2, ry + DIRS[dir].y * 2, 2, 0, Math.PI * 2); ctx.fill(); } // Slingshot function drawSlingshotHeld(ctx, px, py, dir) { ctx.fillStyle = '#8B4513'; const sx = px + TILE / 2 + DIRS[dir].x * 6; const sy = py + TILE / 2 + DIRS[dir].y * 6; ctx.beginPath(); ctx.moveTo(sx - 3, sy); ctx.lineTo(sx, sy - 4); ctx.lineTo(sx + 3, sy); ctx.strokeStyle = '#8B4513'; ctx.lineWidth = 2; ctx.stroke(); ctx.strokeStyle = '#DEB887'; ctx.lineWidth = 1; ctx.beginPath(); ctx.moveTo(sx - 3, sy); ctx.lineTo(sx + 3, sy); ctx.stroke(); } // Hookshot function drawHookshotHeld(ctx, px, py, dir) { ctx.fillStyle = '#C0C0C0'; const hx = px + TILE / 2 + DIRS[dir].x * 6; const hy = py + TILE / 2 + DIRS[dir].y * 6; ctx.fillRect(hx - 1, hy - 1, 3, 8); ctx.fillStyle = '#808080'; ctx.beginPath(); ctx.arc(hx + DIRS[dir].x * 2, hy + DIRS[dir].y * 2, 3, 0, Math.PI); ctx.strokeStyle = '#808080'; ctx.lineWidth = 2; ctx.stroke(); } // Register weapon draw functions const WEAPON_DRAW = { sword: { held: drawSwordHeld }, master_sword: { held: drawMasterSwordHeld }, bow: { held: drawBowHeld }, boomerang: { held: drawBoomerangHeld }, bomb: { held: drawBombHeld }, hammer: { held: drawHammerHeld }, fire_rod: { held: drawFireRodHeld }, ice_rod: { held: drawIceRodHeld }, slingshot: { held: drawSlingshotHeld }, hookshot: { held: drawHookshotHeld }, }; function drawWeaponIcon(ctx, weapon, x, y) { const drawFn = WEAPON_DRAW[weapon.id]; if (drawFn && drawFn.held) { ctx.save(); drawFn.held(ctx, x, y, 0); ctx.restore(); } else { ctx.fillStyle = weapon.color || '#C0C0C0'; ctx.fillRect(x - 3, y - 8, 6, 16); } } if (typeof module !== 'undefined' && module.exports) { module.exports = { drawWeaponHeld, drawWeaponInHUD, drawSwordHeld, drawMasterSwordHeld, drawBowHeld, drawBoomerangHeld, drawBombHeld, drawHammerHeld, drawFireRodHeld, drawIceRodHeld, drawSlingshotHeld, drawHookshotHeld, drawWeaponIcon }; }