🎮ArcadeLab

One Piece Adventure

by ShadowTurtle30
196 lines5.2 KB
▶ Play

<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>One Piece Adventure</title>
<style>
*{box-sizing:border-box}
body{
 margin:0;background:#102b45;color:white;
 font-family:Arial;text-align:center;
}
h1{color:#ffcf35;margin:12px}
#hud{display:flex;justify-content:space-around;
 flex-wrap:wrap;padding:10px;font-weight:bold}
#game{
 width:min(950px,98vw);height:520px;
 margin:auto;display:block;background:#65c9df;
 border:5px solid #d7a34b;border-radius:12px;
}
button{
 background:#e7a927;color:#17283b;
 border:0;padding:13px 20px;
 border-radius:9px;font-size:17px;
 font-weight:bold;margin:5px;cursor:pointer
}
#controls{margin:12px}
#msg{color:#ffdf63;font-weight:bold}
</style>
</head>
<body>
<h1>🏴‍☠️ ONE PIECE ADVENTURE</h1>
<div id="hud">
 <span>❤️ Vita: <b id="hp">100</b></span>
 <span>🪙 Monete: <b id="coins">0</b></span>
 <span>⚔️ Nemici: <b id="kills">0</b></span>
</div>
<canvas id="game" width="950" height="520"></canvas>
<div id="controls">
 <button onclick="keys.left=true">⬅️</button>
 <button onclick="keys.right=true">➡️</button>
 <button onclick="jump()">⬆️ SALTA</button>
 <button onclick="attack()">👊 ATTACCA</button>
 <button onclick="restart()">🔄 RICOMINCIA</button>
</div>
<p id="msg">Trova i tesori e sconfiggi i nemici!</p>
<script>
const c=document.getElementById("game");
const ctx=c.getContext("2d");
let keys={left:false,right:false};
let player, enemies, treasures, coins,kills,gameOver;
function restart(){
 player={x:100,y:350,w:42,h:65,vx:0,vy:0,hp:100,ground:false,face:1};
 enemies=[
 {x:430,y:410,hp:2},
 {x:680,y:410,hp:2},
 {x:850,y:410,hp:4}
 ];
 treasures=[250,550,780];
 coins=0;kills=0;gameOver=false;
 updateHUD();
}
function updateHUD(){
 document.getElementById("hp").textContent=player.hp;
 document.getElementById("coins").textContent=coins;
 document.getElementById("kills").textContent=kills;
}
function jump(){
 if(player.ground&&!gameOver){player.vy=-13;player.ground=false}
}
function attack(){
 if(gameOver)return;
 enemies.forEach(e=>{
 if(Math.abs(e.x-player.x)<100 && e.hp>0){
 e.hp--;if(e.hp<=0)kills++;
 }
 });
 updateHUD();
}
function drawPlayer(){
 let p=player;
 // corpo
 ctx.fillStyle="#e9b38b";
 ctx.fillRect(p.x+9,p.y,25,25);
 // cappello
 ctx.fillStyle="#d92c20";
 ctx.fillRect(p.x+4,p.y-7,35,10);
 ctx.fillStyle="#ffcc35";
 ctx.fillRect(p.x+10,p.y-19,24,14);
 // maglia rossa
 ctx.fillStyle="#d92825";
 ctx.fillRect(p.x+5,p.y+26,34,23);
 // pantaloni
 ctx.fillStyle="#1765b7";
 ctx.fillRect(p.x+6,p.y+49,13,16);
 ctx.fillRect(p.x+25,p.y+49,13,16);
}
function draw(){
 ctx.clearRect(0,0,950,520);
 // cielo e mare
 ctx.fillStyle="#72d6ed";ctx.fillRect(0,0,950,520);
 ctx.fillStyle="#218fc3";ctx.fillRect(0,420,950,100);
 // isola
 ctx.fillStyle="#e6ca82";
 ctx.fillRect(0,395,950,35);
 ctx.fillStyle="#318c38";
 ctx.fillRect(0,380,950,20);
 // palma
 ctx.fillStyle="#79502a";
 ctx.fillRect(800,280,17,110);
 ctx.fillStyle="#168d40";
 for(let i=0;i<6;i++){
 ctx.save();ctx.translate(808,285);
 ctx.rotate(i*Math.PI/3);
 ctx.beginPath();ctx.ellipse(0,-35,12,43,0,0,Math.PI*2);
 ctx.fill();ctx.restore();
 }
 // tesori
 treasures.forEach((x,i)=>{
 if(x!==null){
 ctx.fillStyle="#99551f";ctx.fillRect(x,365,30,27);
 ctx.fillStyle="#ffdb32";ctx.fillRect(x,365,30,8);
 ctx.fillText("✨",x,355);
 }
 });
 // nemici
 enemies.forEach(e=>{
 if(e.hp>0){
 ctx.fillStyle="#7d2631";ctx.fillRect(e.x,350,40,65);
 ctx.fillStyle="#fff";ctx.fillRect(e.x+8,360,8,8);
 ctx.fillRect(e.x+25,360,8,8);
 ctx.fillStyle="#222";ctx.fillRect(e.x+8,385,24,5);
 ctx.fillStyle="#fff";ctx.fillText("HP "+e.hp,e.x,340);
 }
 });
 drawPlayer();
 if(gameOver){
 ctx.fillStyle="rgba(0,0,0,.7)";
 ctx.fillRect(0,0,950,520);
 ctx.fillStyle="#ffce32";
 ctx.font="bold 48px Arial";
 ctx.fillText(player.hp<=0?"SEI STATO SCONFITTO!":"RE DEI PIRATI!",230,240);
 ctx.font="24px Arial";
 ctx.fillText("Premi RICOMINCIA",350,290);
 }
}
function update(){
 if(!gameOver){
 let p=player;
 p.vx=0;
 if(keys.left){p.vx=-4;p.face=-1}
 if(keys.right){p.vx=4;p.face=1}
 p.x=Math.max(0,Math.min(900,p.x+p.vx));
 p.vy+=0.6;p.y+=p.vy;
 if(p.y>=350){p.y=350;p.vy=0;p.ground=true}
 treasures.forEach((x,i)=>{
 if(x!==null&&Math.abs(x-p.x)<35){
 coins+=10;treasures[i]=null;updateHUD();
 }
 });
 enemies.forEach(e=>{
 if(e.hp>0&&Math.abs(e.x-p.x)<38){
 if(Math.random()<0.012){p.hp-=5;updateHUD()}
 }
 });
 if(p.hp<=0)gameOver=true;
 if(kills===3){
 document.getElementById("msg").textContent="🏆 HAI SCONFITTO TUTTI I NEMICI!";
 }
 }
 draw();
 requestAnimationFrame(update);
}
document.addEventListener("keydown",e=>{
 if(e.key==="ArrowLeft"||e.key==="a")keys.left=true;
 if(e.key==="ArrowRight"||e.key==="d")keys.right=true;
 if(e.key===" "||e.key==="ArrowUp")jump();
 if(e.key==="x")attack();
 if(e.key==="r")restart();
});
document.addEventListener("keyup",e=>{
 if(e.key==="ArrowLeft"||e.key==="a")keys.left=false;
 if(e.key==="ArrowRight"||e.key==="d")keys.right=false;
});
document.querySelectorAll("#controls button").forEach((b,i)=>{
 if(i===0||i===1){
 b.addEventListener("pointerup",()=>{keys.left=false;keys.right=false});
 b.addEventListener("pointerleave",()=>{keys.left=false;keys.right=false});
 }
});
restart();update();
</script>
</body>
</html>

Game Source: One Piece Adventure

Creator: ShadowTurtle30

Libraries: none

Complexity: moderate (196 lines, 5.2 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-adventure-shadowturtle30" to link back to the original. Then publish at arcadelab.ai/publish.