One Piece Grand Line
by ShadowTurtle30573 lines16.5 KB
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>One Piece Grand Line</title>
<style>
*{box-sizing:border-box}
body{margin:0;background:#10283d;color:white;font-family:Arial;text-align:center}
h1{color:#ffd43b}
#hud{display:flex;justify-content:center;gap:8px;flex-wrap:wrap;padding:8px}
.stat{background:#21465f;padding:9px;border-radius:8px}
canvas{width:min(100%,1000px);height:auto;border:4px solid #d7aa48;border-radius:10px;display:block;margin:auto;touch-action:none}
button{background:#eab333;color:#172b3b;border:0;border-radius:9px;padding:12px;margin:4px;font-weight:bold;cursor:pointer;touch-action:none}
#controls{max-width:700px;margin:10px auto}
#message{color:#ffdc60;min-height:25px;font-weight:bold}
.panel{position:fixed;z-index:5;top:50%;left:50%;transform:translate(-50%,-50%);width:min(540px,95vw);max-height:85vh;overflow:auto;background:#173d56;border:4px solid #eab333;border-radius:15px;padding:16px;box-shadow:0 0 0 100vmax #0009}
.hidden{display:none!important}
.items{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.item{background:#285873;color:white;border:2px solid #7894a5;min-height:90px}
.item strong{display:block;color:#ffdf62;font-size:17px}
.item small{display:block;margin:6px}
</style>
</head>
<body>
<h1>🏴☠️ ONE PIECE: GRAND LINE</h1>
<div id="hud">
<span class="stat">❤️ <b id="hp">100</b></span>
<span class="stat">⚡ <b id="energy">100</b></span>
<span class="stat">💰 <b id="berry">500</b></span>
<span class="stat">🍎 <b id="fruit">Nessuno</b></span>
<span class="stat">🏝️ <b id="islandName">Isola 1</b></span>
<span class="stat">🏆 <b id="bossCount">0/6</b></span>
</div>
<canvas id="game" width="960" height="600"></canvas>
<div id="controls">
<div><button id="up">⬆️</button></div>
<div>
<button id="left">⬅️</button>
<button id="down">⬇️</button>
<button id="right">➡️</button>
</div>
<div>
<button id="attack">👊 ATTACCA</button>
<button id="power">🌪️ POTERE</button>
<button id="interact">🚢 INTERAGISCI</button>
<button id="shopButton">🏪 SHOP</button>
</div>
<div><button id="mapButton">🗺️ MAPPA</button><button onclick="restart()">🔄 RICOMINCIA</button></div>
</div>
<p id="message">Esplora le isole e sconfiggi i boss!</p>
<p>WASD / FRECCE: muovi | SPAZIO: attacco | X: potere | E: interagisci</p>
<div id="shop" class="panel hidden">
<h2>🏪 NEGOZIO DEI PIRATI</h2>
<h3>Berry: <span id="shopBerry">500</span></h3>
<div class="items">
<button class="item" onclick="buy('heal')"><strong>❤️ Pozione</strong><small>+40 vita</small>100 Berry</button>
<button class="item" onclick="buy('energy')"><strong>⚡ Energia</strong><small>+50 energia</small>80 Berry</button>
<button class="item" onclick="buy('sword')"><strong>⚔️ Spada</strong><small>Più danni</small>250 Berry</button>
<button class="item" onclick="buy('speed')"><strong>💨 Scarpe</strong><small>Più velocità</small>200 Berry</button>
</div>
<p id="shopMessage"></p>
<button onclick="closeShop()">CHIUDI</button>
</div>
<div id="fruitPanel" class="panel hidden">
<h2>🍎 FRUTTI DEL DIAVOLO</h2>
<p>Scegli un frutto da mangiare. Puoi averne uno solo!</p>
<div class="items" id="fruitChoices"></div>
<button onclick="document.getElementById('fruitPanel').classList.add('hidden')">CHIUDI</button>
</div>
<script>
const canvas=document.getElementById("game");
const ctx=canvas.getContext("2d");
const islands=[
{name:"EAST BLUE",x:200,y:200,color:"#389b50",boss:"Morgan",fruit:"Gom Gom"},
{name:"ORANGE TOWN",x:1500,y:200,color:"#c09b45",boss:"Buggy",fruit:"Bara Bara"},
{name:"SYRUP VILLAGE",x:2800,y:200,color:"#438a4c",boss:"Kuro",fruit:"Mera Mera"},
{name:"ALABASTA",x:200,y:1500,color:"#c6a45b",boss:"Crocodile",fruit:"Goro Goro"},
{name:"SKYPIEA",x:1500,y:1500,color:"#82c8dc",boss:"Enel",fruit:"Hie Hie"},
{name:"ONIGASHIMA",x:2800,y:1500,color:"#9b4542",boss:"Kaido",fruit:"Ope Ope"}
];
const world={w:4200,h:2600};
const camera={x:0,y:0};
let player,enemies,chests,trees,coins,showMap=false;
let keys={},gameOver=false,shopOpen=false;
let attackCooldown=0,powerCooldown=0,effect=0;
let currentIsland=0;
const fruitTypes=[
{name:"Gom Gom",emoji:"🍈",desc:"Pugno elastico potente",damage:4,color:"#b33ad1"},
{name:"Bara Bara",emoji:"🍊",desc:"Attacco rotante",damage:5,color:"#ed7133"},
{name:"Mera Mera",emoji:"🔥",desc:"Esplosione di fuoco",damage:7,color:"#e83e20"},
{name:"Goro Goro",emoji:"⚡",desc:"Fulmine potentissimo",damage:8,color:"#e8d52d"},
{name:"Hie Hie",emoji:"❄️",desc:"Esplosione di ghiaccio",damage:6,color:"#7ad9ef"},
{name:"Ope Ope",emoji:"💜",desc:"Attacco speciale ROOM",damage:9,color:"#a75ad8"}
];
function freshEnemy(i){
const island=islands[i];
return {
x:island.x+650,y:island.y+380,
hp: i===5?35:15,
max:i===5?35:15,
speed:1.1+i*.12,
name:island.boss,
island:i,
boss:true
};
}
function restart(){
player={
x:500,y:450,hp:100,maxHp:100,
energy:100,berry:500,speed:3.5,
damage:2,fruit:null,dead:false
};
enemies=islands.map((_,i)=>freshEnemy(i));
chests=[];
trees=[];
coins=[];
islands.forEach((island,i)=>{
chests.push(
{x:island.x+300,y:island.y+300,open:false,island:i},
{x:island.x+850,y:island.y+600,open:false,island:i}
);
for(let n=0;n<24;n++){
trees.push({
x:island.x+100+Math.random()*1050,
y:island.y+100+Math.random()*800,
island:i
});
}
for(let n=0;n<5;n++){
coins.push({
x:island.x+150+Math.random()*950,
y:island.y+150+Math.random()*700,
island:i,
taken:false
});
}
});
currentIsland=0;
gameOver=false;
shopOpen=false;
showMap=false;
attackCooldown=0;
powerCooldown=0;
document.getElementById("shop").classList.add("hidden");
document.getElementById("fruitPanel").classList.add("hidden");
msg("Benvenuto nella Grand Line! Cerca i frutti e i boss.");
updateHUD();
}
function msg(t){document.getElementById("message").textContent=t}
function updateHUD(){
document.getElementById("hp").textContent=Math.ceil(player.hp)+"/"+player.maxHp;
document.getElementById("energy").textContent=Math.floor(player.energy);
document.getElementById("berry").textContent=player.berry;
document.getElementById("fruit").textContent=player.fruit||"Nessuno";
document.getElementById("islandName").textContent=islands[currentIsland].name;
document.getElementById("bossCount").textContent=enemies.filter(e=>e.hp<=0).length+"/6";
document.getElementById("shopBerry").textContent=player.berry;
}
function buy(type){
const prices={heal:100,energy:80,sword:250,speed:200};
if(player.berry<prices[type]){
document.getElementById("shopMessage").textContent="Non hai abbastanza Berry!";
return;
}
if(type==="sword"&&player.damage>=4){
document.getElementById("shopMessage").textContent="Spada già potenziata!";
return;
}
if(type==="speed"&&player.speed>=5){
document.getElementById("shopMessage").textContent="Velocità già potenziata!";
return;
}
player.berry-=prices[type];
if(type==="heal")player.hp=Math.min(player.maxHp,player.hp+40);
if(type==="energy")player.energy=Math.min(100,player.energy+50);
if(type==="sword")player.damage+=2;
if(type==="speed")player.speed=5;
document.getElementById("shopMessage").textContent="Acquisto completato!";
updateHUD();
}
function closeShop(){
shopOpen=false;
document.getElementById("shop").classList.add("hidden");
}
function openShop(){
let near=player.x>islands[currentIsland].x+100&&
player.x<islands[currentIsland].x+280&&
player.y<islands[currentIsland].y+200;
if(!near){
msg("Devi avvicinarti al negozio dell'isola!");
return;
}
shopOpen=true;
document.getElementById("shop").classList.remove("hidden");
updateHUD();
}
function chooseFruit(f){
if(player.fruit){
msg("Hai già mangiato un Frutto del Diavolo!");
return;
}
player.fruit=f.name;
player.damage+=1;
document.getElementById("fruitPanel").classList.add("hidden");
msg("Hai mangiato "+f.name+"! Potere sbloccato!");
updateHUD();
}
function openFruitMenu(){
if(player.fruit){
msg("Hai già un Frutto del Diavolo!");
return;
}
let html="";
fruitTypes.forEach((f,i)=>{
html+=`<button class="item" onclick="chooseFruit(fruitTypes[${i}])">
<strong>${f.emoji} ${f.name}</strong>
<small>${f.desc}</small>SELEZIONA</button>`;
});
document.getElementById("fruitChoices").innerHTML=html;
document.getElementById("fruitPanel").classList.remove("hidden");
}
function drawText(t,x,y,size=18,color="white"){
ctx.font="bold "+size+"px Arial";
ctx.fillStyle=color;
ctx.fillText(t,x,y);
}
function drawIsland(island,i){
ctx.fillStyle="#268fc0";
ctx.fillRect(island.x-80,island.y-80,1260,1040);
ctx.fillStyle=island.color;
ctx.beginPath();
ctx.ellipse(island.x+540,island.y+430,570,460,0,0,Math.PI*2);
ctx.fill();
ctx.fillStyle="#e4d08c";
ctx.beginPath();
ctx.ellipse(island.x+540,island.y+430,570,460,0,0,Math.PI*2);
ctx.ellipse(island.x+540,island.y+430,525,415,0,0,Math.PI*2);
ctx.fill("evenodd");
ctx.fillStyle=island.color;
ctx.beginPath();
ctx.ellipse(island.x+540,island.y+430,525,415,0,0,Math.PI*2);
ctx.fill();
// Strada
ctx.fillStyle="#c5a16b";
ctx.fillRect(island.x+80,island.y+400,900,55);
ctx.fillRect(island.x+500,island.y+80,55,700);
// Alberi
trees.filter(t=>t.island===i).forEach(t=>{
ctx.fillStyle="#704627";
ctx.fillRect(t.x-6,t.y+5,12,25);
ctx.fillStyle="#145c31";
ctx.beginPath();
ctx.arc(t.x,t.y,21,0,Math.PI*2);
ctx.fill();
});
// Negozio
let sx=island.x+150,sy=island.y+200;
ctx.fillStyle="#f2d6a0";
ctx.fillRect(sx-35,sy-5,90,70);
ctx.fillStyle="#ad4431";
ctx.beginPath();
ctx.moveTo(sx-45,sy-5);
ctx.lineTo(sx+10,sy-60);
ctx.lineTo(sx+65,sy-5);
ctx.fill();
drawText("SHOP",sx-23,sy-68,19,"#ffdf49");
// Tesori
chests.filter(c=>c.island===i).forEach(c=>{
ctx.fillStyle=c.open?"#777":"#99501b";
ctx.fillRect(c.x,c.y,37,27);
ctx.fillStyle="#ffdc39";
ctx.fillRect(c.x,c.y+6,37,6);
drawText(c.open?"✓":"💰",c.x,c.y-8,18);
});
// Monete
coins.filter(c=>c.island===i&&!c.taken).forEach(c=>{
ctx.fillStyle="#ffd42c";
ctx.beginPath();
ctx.arc(c.x,c.y,10,0,Math.PI*2);
ctx.fill();
});
drawText(island.name,island.x+410,island.y+70,30);
}
function drawEnemy(e){
if(e.hp<=0)return;
ctx.fillStyle="#571f24";
ctx.fillRect(e.x-18,e.y-5,38,55);
ctx.fillStyle="#e4ad85";
ctx.beginPath();
ctx.arc(e.x,e.y-20,19,0,Math.PI*2);
ctx.fill();
ctx.fillStyle="#242020";
ctx.fillRect(e.x-15,e.y-40,30,10);
drawText("BOSS: "+e.name,e.x-65,e.y-55,16,"#ff5555");
ctx.fillStyle="#8d2020";
ctx.fillRect(e.x-30,e.y-70,60,8);
ctx.fillStyle="#45dc49";
ctx.fillRect(e.x-30,e.y-70,60*e.hp/e.max,8);
}
function drawPlayer(){
ctx.fillStyle="#1855a3";
ctx.fillRect(player.x-13,player.y+17,11,25);
ctx.fillRect(player.x+3,player.y+17,11,25);
ctx.fillStyle="#d72d27";
ctx.fillRect(player.x-16,player.y-10,32,32);
ctx.fillStyle="#e9b38b";
ctx.beginPath();
ctx.arc(player.x,player.y-23,15,0,Math.PI*2);
ctx.fill();
ctx.fillStyle="#efc43d";
ctx.fillRect(player.x-18,player.y-43,36,8);
ctx.fillStyle="#d82b24";
ctx.fillRect(player.x-13,player.y-35,26,4);
if(effect>0){
ctx.strokeStyle=player.fruit?fruitTypes.find(f=>f.name===player.fruit).color:"#fff";
ctx.lineWidth=8;
ctx.beginPath();
ctx.arc(player.x,player.y,65,0,Math.PI*2);
ctx.stroke();
}
}
function drawShip(){
ctx.fillStyle="#55351f";
ctx.beginPath();
ctx.moveTo(player.x-40,player.y+20);
ctx.lineTo(player.x+40,player.y+20);
ctx.lineTo(player.x+20,player.y+45);
ctx.lineTo(player.x-20,player.y+45);
ctx.fill();
ctx.strokeStyle="white";
ctx.lineWidth=4;
ctx.beginPath();
ctx.moveTo(player.x,player.y+15);
ctx.lineTo(player.x,player.y-75);
ctx.stroke();
ctx.fillStyle="#fff";
ctx.fillRect(player.x,player.y-70,35,45);
}
function drawMap(){
ctx.fillStyle="#101b29";
ctx.fillRect(650,12,295,205);
islands.forEach((island,i)=>{
let x=665+island.x/world.w*260;
let y=25+island.y/world.h*170;
ctx.fillStyle=island.color;
ctx.beginPath();
ctx.arc(x,y,13,0,Math.PI*2);
ctx.fill();
drawText(""+(i+1),x-4,y+5,13,"white");
});
ctx.fillStyle="#ffec32";
ctx.beginPath();
ctx.arc(665+player.x/world.w*260,25+player.y/world.h*170,6,0,Math.PI*2);
ctx.fill();
drawText("LA TUA POSIZIONE",710,230,13);
}
function attack(){
if(gameOver||shopOpen||attackCooldown>0)return;
attackCooldown=25;
effect=8;
enemies.forEach(e=>{
if(e.hp>0&&Math.hypot(player.x-e.x,player.y-e.y)<110){
e.hp-=player.damage;
if(e.hp<=0){
player.berry+=500;
msg("🏆 BOSS SCONFITTO! +500 Berry!");
}
}
});
updateHUD();
}
function special(){
if(gameOver||shopOpen)return;
if(!player.fruit){
msg("Devi mangiare un Frutto del Diavolo!");
return;
}
if(player.energy<30||powerCooldown>0)return;
let f=fruitTypes.find(f=>f.name===player.fruit);
player.energy-=30;
powerCooldown=90;
effect=30;
enemies.forEach(e=>{
if(e.hp>0&&Math.hypot(player.x-e.x,player.y-e.y)<250){
e.hp-=f.damage;
if(e.hp<=0)player.berry+=500;
}
});
msg("🌪️ POTERE "+player.fruit.toUpperCase()+"!");
updateHUD();
}
function interact(){
// Frutti sparsi per le isole
let nearFruit=islands.findIndex((island,i)=>
!fruitTaken[i]&&Math.hypot(player.x-(island.x+700),player.y-(island.y+220))<65
);
if(nearFruit>=0&&!player.fruit){
openFruitMenu();
fruitTaken[nearFruit]=true;
msg("Hai trovato un Frutto del Diavolo!");
return;
}
chests.forEach(c=>{
if(!c.open&&Math.hypot(player.x-c.x,player.y-c.y)<55){
c.open=true;
player.berry+=250;
msg("💰 TESORO! +250 Berry");
}
});
coins.forEach(c=>{
if(!c.taken&&Math.hypot(player.x-c.x,player.y-c.y)<30){
c.taken=true;
player.berry+=25;
}
});
// Viaggio tra le isole: vicino al porto
if(player.x<islands[currentIsland].x+110&&
player.y<islands[currentIsland].y+160){
let next=(currentIsland+1)%islands.length;
currentIsland=next;
player.x=islands[next].x+180;
player.y=islands[next].y+250;
msg("🚢 Sei arrivato a "+islands[next].name+"!");
updateHUD();
}
updateHUD();
}
let fruitTaken=[false,false,false,false,false,false];
function update(){
if(!gameOver&&!shopOpen){
let dx=0,dy=0;
if(keys.ArrowLeft||keys.a||keys.left)dx--;
if(keys.ArrowRight||keys.d||keys.right)dx++;
if(keys.ArrowUp||keys.w||keys.up)dy--;
if(keys.ArrowDown||keys.s||keys.down)dy++;
if(dx||dy){
let l=Math.hypot(dx,dy);
player.x+=dx/l*player.speed;
player.y+=dy/l*player.speed;
}
player.x=Math.max(80,Math.min(world.w-80,player.x));
player.y=Math.max(80,Math.min(world.h-80,player.y));
enemies.forEach(e=>{
if(e.hp<=0)return;
let dx=player.x-e.x,dy=player.y-e.y;
let d=Math.hypot(dx,dy);
if(d<450&&d>40){
e.x+=dx/d*e.speed;
e.y+=dy/d*e.speed;
}
if(d<45)player.hp-=0.18;
});
player.energy=Math.min(100,player.energy+0.06);
if(attackCooldown>0)attackCooldown--;
if(powerCooldown>0)powerCooldown--;
if(effect>0)effect--;
currentIsland=islands.reduce((best,island,i)=>{
let d=Math.hypot(player.x-island.x-540,player.y-island.y-430);
return d<Math.hypot(player.x-islands[best].x-540,player.y-islands[best].y-430)?i:best;
},0);
camera.x=Math.max(0,Math.min(world.w-960,player.x-480));
camera.y=Math.max(0,Math.min(world.h-600,player.y-300));
if(player.hp<=0){
player.hp=0;
gameOver=true;
msg("💀 GAME OVER! Premi R per ricominciare.");
}
updateHUD();
}
ctx.clearRect(0,0,960,600);
ctx.save();
ctx.translate(-camera.x,-camera.y);
ctx.fillStyle="#238fc1";
ctx.fillRect(0,0,world.w,world.h);
islands.forEach(drawIsland);
enemies.forEach(drawEnemy);
drawShip();
drawPlayer();
ctx.restore();
if(showMap)drawMap();
if(gameOver){
ctx.fillStyle="#000b";
ctx.fillRect(0,0,960,600);
drawText("GAME OVER",360,280,50,"#ffda39");
}
requestAnimationFrame(update);
}
// Controlli
document.addEventListener("keydown",e=>{
keys[e.key]=true;
if(e.key===" "){e.preventDefault();attack()}
if(e.key.toLowerCase()==="x")special();
if(e.key.toLowerCase()==="e")interact();
if(e.key.toLowerCase()==="r"&&gameOver)restart();
});
document.addEventListener("keyup",e=>keys[e.key]=false);
function bind(id,key){
let b=document.getElementById(id);
b.addEventListener("pointerdown",e=>{
e.preventDefault();keys[key]=true;
});
["pointerup","pointercancel","pointerleave"].forEach(ev=>{
b.addEventListener(ev,()=>keys[key]=false);
});
}
bind("up","up");bind("down","down");
bind("left","left");bind("right","right");
document.getElementById("attack").onclick=attack;
document.getElementById("power").onclick=special;
document.getElementById("interact").onclick=interact;
document.getElementById("shopButton").onclick=openShop;
document.getElementById("mapButton").onclick=()=>showMap=!showMap;
restart();
update();
</script>
</body>
</html>
Game Source: One Piece Grand Line
Creator: ShadowTurtle30
Libraries: none
Complexity: complex (573 lines, 16.5 KB)
The full source code is displayed above on this page.
Remix Instructions
To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: one-piece-open-world-shadowturtle30" to link back to the original. Then publish at arcadelab.ai/publish.