<!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>Pastelito Bros 💜</title>
<style>
*{box-sizing:border-box}
body{
margin:0;background:#100916;color:white;
font-family:system-ui,sans-serif;overflow:hidden;
touch-action:none;
}
header{
height:65px;display:flex;align-items:center;
justify-content:space-between;padding:10px 15px;
background:#25122e;border-bottom:2px solid #813b78;
}
h1{font-size:19px;color:#e9b5f0;margin:0}
#hud{font-size:13px;color:#f3d7ff}
#game{
display:block;width:100%;height:calc(100dvh - 175px);
background:#251332;touch-action:none;
}
#controls{
height:110px;display:flex;align-items:center;
justify-content:space-around;background:#160d20;
}
.group{display:flex;gap:12px}
.control{
width:65px;height:65px;border-radius:19px;
border:2px solid #b77bc7;background:#492449;
color:white;font-size:27px;
touch-action:none;user-select:none;
box-shadow:0 4px #25102d;
}
.control:active{background:#8b4b91;transform:translateY(3px)}
#jump{width:80px;height:80px;border-radius:50%;background:#71345f}
#hint{text-align:center;font-size:10px;color:#cba6d8;background:#160d20;padding-bottom:5px}
#overlay{
position:fixed;inset:0;background:#100916ed;
display:flex;align-items:center;justify-content:center;
padding:20px;z-index:5;
}
#box{
width:100%;max-width:390px;text-align:center;
padding:27px 20px;border-radius:23px;
border:2px solid #b47bc5;
background:linear-gradient(145deg,#55254d,#24152f);
box-shadow:0 0 40px #a34db455;
}
#box h2{color:#f1c2f3}
#box p{line-height:1.7;font-size:14px;color:#f4e1f5}
.start{
background:#963e80;border:1px solid #e7b4e9;
padding:13px 25px;border-radius:13px;
font-weight:bold;color:white;font-size:15px;
}
</style>
</head>
<body>
<header>
<h1>🍷 PASTELITO BROS</h1>
<div id="hud">⭐ 0 / 12</div>
</header>
<canvas id="game"></canvas>
<div id="controls">
<div class="group">
<button class="control" id="left">◀</button>
<button class="control" id="right">▶</button>
</div>
<button class="control" id="jump">⬆</button>
</div>
<div id="hint">MUEVE A PASTELITO · SALTA · RECOGE LAS ESTRELLAS</div>
<div id="overlay">
<div id="box">
<div style="font-size:55px">👑🌸</div>
<h2>¡Bienvenida, Pastelito!</h2>
<p>Un pequeño reino necesita una aventurera.<br><br>
Recorre el mundo, recoge las 12 estrellas y encuentra el castillo secreto.<br><br>
¿Estás lista para comenzar?</p>
<button class="start" onclick="startGame()">¡COMENZAR AVENTURA!</button>
</div>
</div>
<script>
const canvas=document.getElementById("game");
const ctx=canvas.getContext("2d");
let W=900,H=500;
let camera=0,started=false,won=false;
let score=0;
let keys={left:false,right:false,jump:false};
let last=0;
function resize(){
const rect=canvas.getBoundingClientRect();
W=canvas.width=Math.max(320,rect.width);
H=canvas.height=Math.max(280,rect.height);
}
window.addEventListener("resize",resize);
resize();
const worldWidth=3100;
const groundY=H-55;
let player={
x:65,y:0,w:36,h:48,vx:0,vy:0,
grounded:false,face:1
};
let platforms=[];
let stars=[];
let clouds=[];
let particles=[];
function buildWorld(){
const g=groundY;
platforms=[
{x:0,y:g,w:570,h:100},
{x:640,y:g,w:480,h:100},
{x:1200,y:g,w:520,h:100},
{x:1800,y:g,w:440,h:100},
{x:2320,y:g,w:780,h:100},
{x:220,y:g-100,w:125,h:18},
{x:440,y:g-165,w:120,h:18},
{x:720,y:g-105,w:130,h:18},
{x:940,y:g-175,w:140,h:18},
{x:1270,y:g-110,w:140,h:18},
{x:1500,y:g-180,w:140,h:18},
{x:1850,y:g-100,w:130,h:18},
{x:2080,y:g-170,w:120,h:18},
{x:2380,y:g-110,w:150,h:18},
{x:2600,y:g-180,w:140,h:18},
{x:2820,y:g-110,w:140,h:18}
];
stars=[];
let positions=[
[260,g-145],[480,g-210],[755,g-155],
[990,g-220],[1150,g-110],[1310,g-160],
[1540,g-225],[1710,g-100],[1890,g-150],
[2120,g-215],[2450,g-160],[2670,g-225]
];
positions.forEach(p=>stars.push({x:p[0],y:p[1],got:false}));
clouds=Array.from({length:25},(_,i)=>({
x:i*145+Math.random()*60,y:35+Math.random()*150,
size:20+Math.random()*25
}));
}
buildWorld();
function startGame(){
document.getElementById("overlay").style.display="none";
player.y=groundY-player.h;
started=true;
last=performance.now();
requestAnimationFrame(loop);
}
function bindButton(id,key){
const el=document.getElementById(id);
el.addEventListener("pointerdown",e=>{
e.preventDefault();keys[key]=true;
el.setPointerCapture(e.pointerId);
});
["pointerup","pointercancel","lostpointercapture"].forEach(ev=>
el.addEventListener(ev,e=>{keys[key]=false})
);
}
bindButton("left","left");
bindButton("right","right");
bindButton("jump","jump");
window.addEventListener("keydown",e=>{
if(["ArrowLeft","ArrowRight","ArrowUp"," "].includes(e.key))e.preventDefault();
if(e.key==="ArrowLeft"||e.key==="a")keys.left=true;
if(e.key==="ArrowRight"||e.key==="d")keys.right=true;
if(e.key==="ArrowUp"||e.key===" ")keys.jump=true;
});
window.addEventListener("keyup",e=>{
if(e.key==="ArrowLeft"||e.key==="a")keys.left=false;
if(e.key==="ArrowRight"||e.key==="d")keys.right=false;
if(e.key==="ArrowUp"||e.key===" ")keys.jump=false;
});
function roundRect(x,y,w,h,r,color){
ctx.fillStyle=color;
ctx.beginPath();
ctx.roundRect(x,y,w,h,r);
ctx.fill();
}
function drawBackground(){
const gradient=ctx.createLinearGradient(0,0,0,H);
gradient.addColorStop(0,"#211332");
gradient.addColorStop(1,"#70416d");
ctx.fillStyle=gradient;
ctx.fillRect(0,0,W,H);
// estrellas del cielo
for(let i=0;i<65;i++){
let x=((i*137-camera*.15)%(W+30)+W+30)%(W+30);
let y=(i*73)%Math.max(100,H*.65);
ctx.fillStyle="#ffffff";
ctx.globalAlpha=.3+(i%3)*.2;
ctx.fillRect(x,y,2,2);
}
ctx.globalAlpha=1;
// luna
ctx.fillStyle="#f7d9ed";
ctx.beginPath();
ctx.arc(W*.78,90,30,0,Math.PI*2);
ctx.fill();
// nubes
clouds.forEach(c=>{
let x=((c.x-camera*.35)%(W+150)+W+150)%(W+150)-50;
ctx.fillStyle="#b28cba";
ctx.globalAlpha=.65;
ctx.beginPath();
ctx.arc(x,c.y,c.size*.55,0,Math.PI*2);
ctx.arc(x+20,c.y-10,c.size*.65,0,Math.PI*2);
ctx.arc(x+42,c.y,c.size*.5,0,Math.PI*2);
ctx.fill();
});
ctx.globalAlpha=1;
}
function drawPlatforms(){
platforms.forEach(p=>{
const x=p.x-camera;
if(x+p.w<0||x>W)return;
roundRect(x,p.y,p.w,p.h,5,"#43234c");
roundRect(x,p.y,p.w,8,4,"#a36ab0");
for(let i=10;i<p.w;i+=35){
ctx.fillStyle="#67406c";
ctx.fillRect(x+i,p.y+18,4,5);
}
});
}
function drawStars(){
stars.forEach(s=>{
if(s.got)return;
const x=s.x-camera;
if(x< -30||x>W+30)return;
ctx.save();
ctx.translate(x,s.y);
ctx.rotate(performance.now()/600);
ctx.fillStyle="#ffe58a";
ctx.shadowColor="#ffda72";
ctx.shadowBlur=15;
ctx.beginPath();
for(let i=0;i<10;i++){
const r=i%2===0?12:5;
const a=i*Math.PI/5-Math.PI/2;
ctx.lineTo(Math.cos(a)*r,Math.sin(a)*r);
}
ctx.closePath();ctx.fill();
ctx.restore();
});
}
function drawPlayer(){
const x=player.x-camera,y=player.y;
// cabello
roundRect(x-2,y+2,40,25,13,"#291728");
// cabeza
roundRect(x+3,y+5,30,25,11,"#e6b18f");
// cabello frontal
ctx.fillStyle="#251323";
ctx.beginPath();
ctx.arc(x+18,y+10,15,Math.PI,Math.PI*2);
ctx.fill();
// gafas
ctx.strokeStyle="#302033";ctx.lineWidth=2;
ctx.strokeRect(x+5,y+14,11,8);
ctx.strokeRect(x+20,y+14,11,8);
ctx.beginPath();ctx.moveTo(x+16,y+17);ctx.lineTo(x+20,y+17);ctx.stroke();
// ojos
ctx.fillStyle="#251323";
ctx.fillRect(x+10,y+17,3,3);
ctx.fillRect(x+24,y+17,3,3);
// ropa
roundRect(x+5,y+29,27,16,5,"#75355f");
// piernas
ctx.fillStyle="#171020";
ctx.fillRect(x+8,y+43,8,5);
ctx.fillRect(x+22,y+43,8,5);
// flor
ctx.fillStyle="#f5b9df";
ctx.beginPath();
ctx.arc(x+31,y+7,4,0,Math.PI*2);
ctx.fill();
}
function update(dt){
const speed=235;
player.vx=0;
if(keys.left){player.vx=-speed;player.face=-1}
if(keys.right){player.vx=speed;player.face=1}
if(keys.jump&&player.grounded){
player.vy=-560;
player.grounded=false;
}
player.x+=player.vx*dt;
player.x=Math.max(0,Math.min(worldWidth-player.w,player.x));
let oldBottom=player.y+player.h;
player.vy+=1450*dt;
player.y+=player.vy*dt;
player.grounded=false;
platforms.forEach(p=>{
if(player.x+player.w>p.x&&player.x<p.x+p.w&&
oldBottom<=p.y+8&&player.y+player.h>=p.y&&
player.vy>=0){
player.y=p.y-player.h;
player.vy=0;
player.grounded=true;
}
});
// recoger estrellas
stars.forEach(s=>{
if(!s.got&&Math.abs((player.x+player.w/2)-s.x)<26&&
Math.abs((player.y+player.h/2)-s.y)<30){
s.got=true;score++;
document.getElementById("hud").textContent="⭐ "+score+" / 12";
particles.push({x:s.x,y:s.y,life:1});
}
});
// caida y reinicio
if(player.y>H+100){
player.x=Math.max(0,player.x-100);
player.y=groundY-player.h;
player.vy=0;
}
camera=Math.max(0,Math.min(worldWidth-W,player.x-W*.35));
if(player.x>worldWidth-150&&!won){
won=true;finish();
}
particles=particles.filter(p=>p.life>0);
particles.forEach(p=>p.life-=dt);
}
function drawCastle(){
const x=worldWidth-115-camera;
const y=groundY-150;
ctx.fillStyle="#562c65";
ctx.fillRect(x,y,110,150);
ctx.fillStyle="#a56aaf";
ctx.fillRect(x-13,y-17,136,20);
ctx.fillRect(x+8,y-50,23,35);
ctx.fillRect(x+79,y-50,23,35);
ctx.fillStyle="#f4d6a3";
ctx.beginPath();
ctx.arc(x+55,y+75,20,Math.PI,0);
ctx.fill();
ctx.fillRect(x+35,y+75,40,75);
ctx.fillStyle="#f6c8ed";
ctx.font="25px sans-serif";
ctx.fillText("♥",x+45,y-65);
}
function finish(){
started=false;
document.getElementById("overlay").style.display="flex";
document.getElementById("box").innerHTML=`
<div style="font-size:55px">👑🏰💜</div>
<h2>¡LO LOGRASTE, PASTELITO!</h2>
<p>¡Has llegado al castillo secreto!<br>
Recogiste ${score} de 12 estrellas.<br><br>
Pero hay algo más importante que todas las estrellas de este reino...</p>
<p style="font-size:19px;color:#f4c5f2">¡Tú eres la verdadera protagonista! 🌷</p>
<button class="start" onclick="location.reload()">VOLVER A JUGAR</button>`;
}
function loop(time){
if(!started)return;
const dt=Math.min((time-last)/1000,.032);
last=time;
update(dt);
drawBackground();
drawPlatforms();
drawStars();
drawCastle();
drawPlayer();
requestAnimationFrame(loop);
}
</script>
</body>
</html>