Box Fury
by BoldGecko67347 lines10.4 KB
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Box Fury</title>
<style>
*{box-sizing:border-box}
body{margin:0;background:#050505;color:white;font-family:Arial,Helvetica,sans-serif;overflow:hidden;touch-action:manipulation}
canvas{display:block;width:100vw;height:100vh;background:#050505}
</style>
</head>
<body>
<canvas id="game"></canvas>
<script>
const canvas=document.getElementById("game");
const ctx=canvas.getContext("2d");
let W=0,H=0;
function resize(){
W=canvas.width=window.innerWidth;
H=canvas.height=window.innerHeight;
}
window.addEventListener("resize",resize);
resize();
let state="menu";
let boxes=[],coins=0,xp=0,level=1,lives=3;
let paused=false,countdown=0;
let spawnTimer=0,lastTime=0;
let buttons=[];
let tutorialStep=0;
let shopScroll=0;
let selectedSkin="Classic";
let owned=["Classic"];
let profileName="Jugador";
let gameTime=0;
let transition=0;
let brushDots=[];
let audioCtx=null;
let musicTimer=null;
let musicEnabled=true;
const skins=[
{name:"Classic",price:0,color:"#8b4513",base:"#8b4513"},
{name:"Cat",price:150,color:"#2478e8",base:"#2478e8"},
{name:"Ice",price:250,color:"#8a36c8",base:"#8a36c8"},
{name:"Galactic",price:450,color:"#8b4513",base:"#8b4513"},
{name:"Dragon",price:700,color:"#2478e8",base:"#2478e8"},
{name:"Golden",price:1000,color:"#8a36c8",base:"#8a36c8"},
{name:"Cactus",price:350,color:"#8b4513",base:"#8b4513"},
{name:"Ghost",price:600,color:"#2478e8",base:"#2478e8"}
];
function initAudio(){
if(!audioCtx)audioCtx=new (window.AudioContext||window.webkitAudioContext)();
if(audioCtx.state==="suspended")audioCtx.resume();
}
function tone(freq,duration=.12,type="sine",vol=.035){
if(!musicEnabled)return;
initAudio();
let o=audioCtx.createOscillator(),g=audioCtx.createGain();
o.type=type;o.frequency.value=freq;
g.gain.setValueAtTime(vol,audioCtx.currentTime);
g.gain.exponentialRampToValueAtTime(.001,audioCtx.currentTime+duration);
o.connect(g);g.connect(audioCtx.destination);
o.start();o.stop(audioCtx.currentTime+duration);
}
function music(){
if(musicTimer)return;
const notes=[392,494,587,494,392,330,440,523,440,330,392,523,659,523];
let i=0;
musicTimer=setInterval(()=>{
if(!musicEnabled||state==="pause"||state==="menu"||state==="shop"||state==="profile"||state==="tutorial")return;
tone(notes[i++%notes.length],.18,"triangle",.018);
},240);
}
function stopMusic(){
if(musicTimer){clearInterval(musicTimer);musicTimer=null}
}
function startGame(){
initAudio();music();
boxes=[];lives=3;state="game";paused=false;
spawnTimer=0;gameTime=0;
}
function menu(){
boxes=[];paused=false;state="menu";
}
function rand(a,b){return a+Math.random()*(b-a)}
function spawnBox(){
let r=Math.random()*100;
let type=r<70?"brown":r<90?"blue":"purple";
boxes.push({
x:rand(40,W-40),y:-45,
size:Math.min(55,Math.max(38,W*.07)),
type, speed:rand(75,150),
skin:selectedSkin,
rotation:rand(-.08,.08)
});
}
function getColor(type){
return type==="brown"?"#8b4513":type==="blue"?"#2478e8":"#8a36c8";
}
function reward(type){
if(type==="brown"){coins+=5;xp+=10}
if(type==="blue"){coins+=10;xp+=20}
if(type==="purple"){xp+=30}
updateLevel();
}
function updateLevel(){
while(xp>=level*100){
xp-=level*100;
level++;
tone(880,.3,"sine",.08);
}
}
function drawBox(b){
ctx.save();
ctx.translate(b.x,b.y);ctx.rotate(b.rotation);
let c=getColor(b.type);
ctx.fillStyle=c;
ctx.fillRect(-b.size/2,-b.size/2,b.size,b.size);
ctx.strokeStyle="#ffffff55";ctx.lineWidth=3;
ctx.strokeRect(-b.size/2,-b.size/2,b.size,b.size);
ctx.strokeStyle="#00000033";ctx.lineWidth=4;
ctx.beginPath();ctx.moveTo(-b.size/2,-b.size/2);
ctx.lineTo(b.size/2,b.size/2);
ctx.moveTo(b.size/2,-b.size/2);
ctx.lineTo(-b.size/2,b.size/2);ctx.stroke();
ctx.fillStyle="#ffffff";
ctx.font="bold "+Math.floor(b.size*.45)+"px Arial";
ctx.textAlign="center";ctx.textBaseline="middle";
ctx.fillText("BOX",0,0);
ctx.restore();
}
function drawBackground(){
ctx.fillStyle="#050505";ctx.fillRect(0,0,W,H);
}
function text(str,x,y,size,color="white",align="center"){
ctx.fillStyle=color;ctx.font="bold "+size+"px Arial";
ctx.textAlign=align;ctx.textBaseline="middle";
ctx.fillText(str,x,y);
}
function button(str,x,y,w,h,color,action){
ctx.fillStyle=color;roundRect(x,y,w,h,12);
text(str,x+w/2,y+h/2,Math.min(18,h*.36),"white");
buttons.push({x,y,w,h,action});
}
function roundRect(x,y,w,h,r){
ctx.beginPath();ctx.roundRect(x,y,w,h,r);
ctx.fill();
}
function title(){
text("BOX FURY",W/2,H*.25,Math.min(60,W*.12),"#ff6a30");
text("🐱",W/2,H*.13,Math.min(50,W*.1));
}
function drawMenu(){
drawBackground();buttons=[];
title();
button("PLAY",W*.35,H*.42,W*.30,H*.13,"#2478e8",()=>{
state="tutorial";tutorialStep=0;boxes=[];
});
button("TIENDA",20,20,110,45,"#253d79",()=>state="shop");
button("LVL "+level,W-120,20,100,45,"#253d79",()=>state="profile");
text("MONEDAS: "+coins,W/2,H*.76,20,"#ffca28");
text("Queen Cat Present",W/2,H*.91,13,"#aaaaaa");
}
function drawTutorial(){
drawBackground();buttons=[];
const messages=[
["BIENVENIDO A BOX FURY","Vamos a empezar el tutorial."],
["ESTAS SON LAS CAJAS","Hay diferentes colores de caja."],
["TOCA LAS CAJAS","Toca las cajas para romperlas y ganar XP o monedas."],
["CAJA MARRÓN","Te da 5 monedas y 10 XP."],
["CAJA AZUL","Te da 10 monedas y 20 XP."],
["CAJA MORADA","Te da 30 XP. Explota las cajas cercanas."],
["¡PRACTICA!","Toca las cajas antes de que salgan del plano."],
["¡TUTORIAL TERMINADO!","Ahora podrás jugar todo lo que quieras."]
];
text(messages[tutorialStep][0],W/2,H*.3,Math.min(32,W*.07),"#ff7339");
text(messages[tutorialStep][1],W/2,H*.45,Math.min(20,W*.045),"white");
if(tutorialStep===1||tutorialStep===3||tutorialStep===4||tutorialStep===5){
let types=tutorialStep===1?["brown","blue","purple"]:[tutorialStep===3?"brown":tutorialStep===4?"blue":"purple"];
types.forEach((t,i)=>{
let b={x:W/2+(i-(types.length-1)/2)*90,y:H*.65,size:55,type:t,rotation:0};
drawBox(b);
});
}
if(tutorialStep===6){
if(boxes.length<4)spawnBox();
boxes.forEach(drawBox);
boxes.forEach(b=>b.y+=0);
}
button(tutorialStep===7?"ENTRAR AL JUEGO":"CONTINUAR",W*.35,H*.78,W*.30,55,"#2478e8",()=>{
if(tutorialStep<7){tutorialStep++}
else startGame();
});
button("SALIR",20,20,100,45,"#555555",()=>menu());
}
function drawGame(){
drawBackground();buttons=[];
// UI
text("❤️ ".repeat(lives),70,32,25,"#ff4444");
text("XP: "+xp,W*.22,32,18);
text("🪙 "+coins,W*.42,32,18);
text("LVL "+level,W*.65,32,18);
button("Ⅱ",W-65,15,50,45,"#263d78",()=>{paused=true;state="pause"});
boxes.forEach(drawBox);
}
function drawPause(){
drawBackground();buttons=[];
text("PAUSA",W/2,H*.25,Math.min(40,W*.08));
button("SEGUIR PARTIDA",W*.25,H*.38,W*.50,60,"#2478e8",()=>{
state="countdown";countdown=3;
});
button("ABANDONAR PARTIDA",W*.25,H*.58,W*.50,60,"#dc2626",()=>{
state="transition";transition=0;
});
}
function drawCountdown(){
drawBackground();buttons=[];
text(""+countdown,W/2,H/2,Math.min(100,W*.22),"#ffca28");
}
function drawShop(){
drawBackground();buttons=[];
text("TIENDA",W/2,40,36);
text("MONEDAS: "+coins,130,40,20,"#ffca28");
button("VOLVER",20,20,100,45,"#555",()=>state="menu");
let cols=4,rows=Math.ceil(skins.length/cols);
let cw=W/cols,ch=Math.min(135,H*.28);
skins.forEach((s,i)=>{
let x=(i%cols)*cw+cw*.08,y=90+Math.floor(i/cols)*ch;
ctx.fillStyle="#18254b";roundRect(x,y,cw*.84,ch*.85,12);
let b={x:x+cw*.42,y:y+ch*.25,size:40,type:s.base==="#8b4513"?"brown":s.base==="#2478e8"?"blue":"purple",rotation:0};
drawBox(b);
text(s.name,x+cw*.42,y+ch*.55,16);
text(s.price===0?"GRATIS":s.price+" monedas",x+cw*.42,y+ch*.68,14,"#ffca28");
let bought=owned.includes(s.name);
button(bought?(selectedSkin===s.name?"EQUIPADA":"EQUIPAR"):"COMPRAR",x+cw*.12,y+ch*.72,cw*.60,35,bought?"#2478e8":"#e07a22",()=>{
if(bought){selectedSkin=s.name}
else if(coins>=s.price){coins-=s.price;owned.push(s.name);selectedSkin=s.name}
});
});
}
function drawProfile(){
drawBackground();buttons=[];
text("PERFIL",W/2,40,36);
button("VOLVER",20,20,100,45,"#555",()=>state="menu");
text("LVL "+level,W*.25,H*.30,40,"#ffca28");
text("XP: "+xp+" / "+(level*100),W*.25,H*.43,20);
ctx.fillStyle="#333";roundRect(W*.10,H*.5,W*.3,22,10);
ctx.fillStyle="#2478e8";roundRect(W*.10,H*.5,W*.3*(xp/(level*100)),22,10);
text(profileName,W*.70,H*.30,30);
text("Estilo: Rompecajas",W*.70,H*.43,20);
text("Cajas rompidas: "+(coins/5|0),W*.70,H*.57,18);
}
function drawTransition(){
drawBackground();buttons=[];
text("BOX FURY",W/2,H/2,50,"#ff6a30");
if(transition<1){
for(let i=0;i<8;i++){
ctx.fillStyle="#e34b25";
ctx.save();
ctx.translate(rand(0,W),rand(0,H));
ctx.rotate(rand(-1,1));
ctx.fillRect(-30,-8,60,16);ctx.restore();
}
}
}
function update(dt){
if(state==="game"&&!paused){
gameTime+=dt;
spawnTimer+=dt;
if(spawnTimer>1.05){
spawnTimer=0;spawnBox();
}
for(let b of boxes)b.y+=b.speed*dt;
for(let i=boxes.length-1;i>=0;i--){
if(boxes[i].y>H+boxes[i].size){
boxes.splice(i,1);lives--;
if(lives<=0)state="transition";
}
}
}
if(state==="countdown"){
countdown-=dt;
if(countdown<=0){state="game";paused=false;countdown=0}
}
if(state==="transition"){
transition+=dt;
if(transition>1.8)menu();
}
}
function draw(){
buttons=[];
if(state==="menu")drawMenu();
if(state==="tutorial")drawTutorial();
if(state==="game")drawGame();
if(state==="pause")drawPause();
if(state==="countdown")drawCountdown();
if(state==="shop")drawShop();
if(state==="profile")drawProfile();
if(state==="transition")drawTransition();
}
function loop(t){
let dt=Math.min(.05,(t-lastTime)/1000||0);
lastTime=t;
update(dt);draw();
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
canvas.addEventListener("pointerdown",e=>{
initAudio();
let rect=canvas.getBoundingClientRect();
let x=e.clientX-rect.left,y=e.clientY-rect.top;
// boxes first during gameplay
if(state==="game"){
for(let i=boxes.length-1;i>=0;i--){
let b=boxes[i];
if(Math.abs(x-b.x)<b.size*.7&&Math.abs(y-b.y)<b.size*.7){
let type=b.type;
reward(type);
tone(440,.1,"square");
if(type==="purple"){
for(let j=boxes.length-1;j>=0;j--){
if(j!==i&&Math.hypot(boxes[j].x-b.x,boxes[j].y-b.y)<b.size*2.5){
reward(boxes[j].type);
boxes.splice(j,1);
if(j<i)i--;
}
}
}
boxes.splice(i,1);return;
}
}
}
for(let btn of buttons){
if(x>=btn.x&&x<=btn.x+btn.w&&y>=btn.y&&y<=btn.y+btn.h){
btn.action();return;
}
}
});
</script>
</body>
</html>
Game Source: Box Fury
Creator: BoldGecko67
Libraries: none
Complexity: complex (347 lines, 10.4 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: box-fury-boldgecko67" to link back to the original. Then publish at arcadelab.ai/publish.