STARBOUND - Pixel Quest
by MegaOtter89372 lines10.8 KB
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>STARBOUND - Pixel Quest</title>
<style>
*{box-sizing:border-box}
body{margin:0;background:#10152b;color:white;font-family:Arial;overflow:hidden;touch-action:none}
canvas{display:block;width:100vw;height:100dvh;image-rendering:pixelated}
#hud{position:absolute;top:12px;left:12px;right:12px;display:flex;justify-content:space-between;align-items:center;pointer-events:none;gap:8px}
.hudbox{background:#10152bdc;border:2px solid #5266a5;padding:8px 12px;border-radius:10px;font-size:13px;font-weight:bold}
#touch{position:absolute;bottom:15px;left:0;right:0;display:flex;justify-content:space-between;padding:0 17px;pointer-events:none}
.pad{display:flex;gap:12px}
.ctrl{pointer-events:auto;width:62px;height:62px;border:2px solid #8da8ff;background:#273761dd;color:white;border-radius:14px;font-size:27px;touch-action:none}
#jump{width:75px;height:75px;border-radius:50%;background:#684bd8;border-color:#c5a8ff}
#screen{position:absolute;inset:0;background:#10152bed;display:flex;justify-content:center;align-items:center;padding:15px;text-align:center}
.panel{width:min(420px,95%);padding:25px;background:#1c2850;border:3px solid #8b72ff;border-radius:20px;box-shadow:0 0 35px #8055ff44}
h1{font-size:32px;color:#a9a0ff;margin:0 0 8px}
p{line-height:1.8;color:#d9e2ff;font-size:14px}
button.start{background:#8b69ff;color:white;border:0;border-radius:12px;padding:14px 32px;font-size:18px;font-weight:bold}
.small{font-size:12px;color:#9eacd8}
</style>
</head>
<body>
<canvas id="game" width="480" height="270"></canvas>
<div id="hud">
<div class="hudbox">⭐ <span id="score">0</span></div>
<div class="hudbox">💎 <span id="gems">0</span></div>
<div class="hudbox">❤️ <span id="lives">3</span></div>
<div class="hudbox">🌍 <span id="level">1/3</span></div>
</div>
<div id="touch">
<div class="pad">
<button class="ctrl" id="left">◀</button>
<button class="ctrl" id="right">▶</button>
</div>
<button class="ctrl" id="jump">⬆</button>
</div>
<div id="screen">
<div class="panel">
<h1>🌟 STARBOUND</h1>
<h3>PIXEL QUEST</h3>
<p>انطلق في مغامرة سحرية! اجمع البلورات، اقفز فوق العقبات، واكتشف أسرار عالم النجوم.</p>
<p>🎮 الأسهم للحركة و Space للقفز<br>📱 استخدم الأزرار على الشاشة</p>
<button class="start" id="start">ابدأ المغامرة</button>
<p class="small">ثلاث عوالم تنتظرك!</p>
</div>
</div>
<script>
(()=>{
const c=document.getElementById("game");
const ctx=c.getContext("2d");
const $=id=>document.getElementById(id);
const W=480,H=270,T=20;
let state="menu",level=0,score=0,gems=0,lives=3;
let camera=0,worldWidth=1900,player,platforms,crystals,spikes,enemies,exit;
let keys={left:false,right:false,jump:false};
let jumpPressed=false,frame=0,checkpoint=0;
let best=0;
try{best=Number(localStorage.getItem("starboundBest"))||0}catch(e){}
const palettes=[
{sky:"#18264d",mount:"#344c78",grass:"#75c96d",ground:"#604b71",accent:"#b8a0ff"},
{sky:"#102c40",mount:"#245b65",grass:"#60d6ad",ground:"#315d63",accent:"#7ffff0"},
{sky:"#301c48",mount:"#593c78",grass:"#dc8bd4",ground:"#704b79",accent:"#ffd27b"}
];
function makeLevel(n){
platforms=[];crystals=[];spikes=[];enemies=[];
worldWidth=1900+n*150;
// الأرض
let gaps=n===0?[[340,420],[760,840],[1190,1270]]:n===1?[[300,380],[700,800],[1100,1180],[1500,1580]]:[[280,380],[620,720],[990,1090],[1370,1470]];
let x=0;
for(let i=0;i<=worldWidth/T;i++){
let px=i*T;
if(!gaps.some(g=>px>=g[0]&&px<g[1]))platforms.push({x:px,y:230,w:T,h:40});
}
// المنصات
for(let i=0;i<13;i++){
let px=130+i*135;
let py=170-(i%3)*27;
platforms.push({x:px,y:py,w:65+(i%2)*20,h:12});
}
// بلورات
for(let i=0;i<28;i++){
let px=95+i*65;
let py=185-(i%4)*27;
crystals.push({x:px,y:py,r:5,got:false,phase:i});
}
// الأشواك
for(let g of gaps){
spikes.push({x:g[0]-30,y:210,w:30});
if(n>0)spikes.push({x:g[1]+10,y:210,w:30});
}
// وحوش
for(let i=0;i<8;i++){
let px=210+i*210;
enemies.push({x:px,y:215,w:17,h:15,dir:i%2?1:-1,min:px-35,max:px+35,alive:true});
}
exit={x:worldWidth-90,y:190};
player={x:35,y:170,w:14,h:19,vx:0,vy:0,onGround:false,face:1,inv:0};
camera=0;
checkpoint=35;
}
function start(){
level=0;score=0;gems=0;lives=3;
makeLevel(level);state="play";
$("screen").style.display="none";updateHUD();
}
function updateHUD(){
$("score").textContent=score;
$("gems").textContent=gems;
$("lives").textContent=lives;
$("level").textContent=(level+1)+"/3";
}
function rectHit(a,b){
return a.x<b.x+b.w&&a.x+a.w>b.x&&a.y<b.y+b.h&&a.y+a.h>b.y;
}
function movePlayer(){
let p=player;
let dx=(keys.right?1:0)-(keys.left?1:0);
p.vx=dx*2.2;
if(dx)p.face=dx;
if(jumpPressed&&p.onGround){
p.vy=-7.2;p.onGround=false;
}
jumpPressed=false;
p.vy=Math.min(p.vy+.32,8);
p.x+=p.vx;
for(let b of platforms){
if(rectHit(p,b)){
if(p.vx>0)p.x=b.x-p.w;
if(p.vx<0)p.x=b.x+b.w;
}
}
p.y+=p.vy;
p.onGround=false;
for(let b of platforms){
if(rectHit(p,b)){
if(p.vy>0){p.y=b.y-p.h;p.vy=0;p.onGround=true;}
else if(p.vy<0){p.y=b.y+b.h;p.vy=0;}
}
}
p.x=Math.max(0,Math.min(worldWidth-p.w,p.x));
if(p.inv>0)p.inv--;
}
function hurt(){
if(player.inv>0)return;
lives--;
updateHUD();
if(lives<=0){finish(false);return;}
player.x=Math.max(checkpoint,player.x-100);
player.y=130;player.vy=0;player.inv=100;
}
function update(){
if(state!=="play")return;
frame++;
movePlayer();
for(let s of spikes){
let hit={x:s.x,y:s.y,w:s.w,h:20};
if(rectHit(player,hit))hurt();
}
if(state!=="play")return;
for(let e of enemies){
if(!e.alive)continue;
e.x+=e.dir*.65;
if(e.x<e.min||e.x>e.max)e.dir*=-1;
if(rectHit(player,e)){
if(player.vy>0&&player.y+player.h-e.y<10){
e.alive=false;player.vy=-5;score+=30;
}else hurt();
}
}
if(state!=="play")return;
for(let g of crystals){
if(g.got)continue;
if(Math.abs(player.x+7-g.x)<12&&Math.abs(player.y+8-g.y)<14){
g.got=true;gems++;score+=10;
}
}
if(player.y>H+30)hurt();
if(player.x>exit.x&&player.y<exit.y+65&&player.y+player.h>exit.y-25){
if(level<2){
level++;makeLevel(level);checkpoint=35;
score+=100;updateHUD();
}else finish(true);
}
camera=Math.max(0,Math.min(worldWidth-W,player.x-190));
updateHUD();
}
function finish(win){
state=win?"win":"over";
$("screen").style.display="flex";
$("screen").querySelector("h1").textContent=win?"🏆 YOU WIN!":"💫 GAME OVER";
$("screen").querySelector("h3").textContent=win?"لقد أنقذت عالم النجوم!":"انتهت المغامرة";
$("screen").querySelector("p").textContent="نتيجتك: "+score+" | البلورات: "+gems+" 💎";
$("start").textContent="العب من جديد";
try{
if(score>best){best=score;localStorage.setItem("starboundBest",best);}
}catch(e){}
}
function pixelRect(x,y,w,h,color){
ctx.fillStyle=color;ctx.fillRect(Math.round(x),Math.round(y),w,h);
}
function drawBackground(){
let pal=palettes[level];
ctx.fillStyle=pal.sky;ctx.fillRect(0,0,W,H);
// النجوم
for(let i=0;i<45;i++){
let x=((i*97-camera*.12)%W+W)%W;
let y=(i*47)%170;
pixelRect(x,y,2,2,"#ffffff99");
}
// الجبال البعيدة
for(let i=0;i<9;i++){
let x=((i*100-camera*.25)%650+650)%650-80;
ctx.fillStyle=pal.mount;
ctx.beginPath();
ctx.moveTo(x,230);ctx.lineTo(x+55,100+(i%3)*20);
ctx.lineTo(x+115,230);ctx.fill();
}
// سحب
for(let i=0;i<5;i++){
let x=((i*145-camera*.35)%580+580)%580;
pixelRect(x,55+i%2*35,28,5,"#ffffff33");
pixelRect(x+7,49+i%2*35,17,6,"#ffffff33");
}
}
function drawWorld(){
let pal=palettes[level];
for(let b of platforms){
let x=Math.floor(b.x-camera);
if(x<-30||x>W+20)continue;
pixelRect(x,b.y,b.w,b.h,pal.ground);
pixelRect(x,b.y,b.w,4,pal.grass);
for(let j=0;j<b.w;j+=10){
pixelRect(x+j,b.y+8,3,3,"#ffffff18");
}
}
// الأشواك
for(let s of spikes){
let x=s.x-camera;
ctx.fillStyle="#ff678c";
for(let j=0;j<3;j++){
ctx.beginPath();ctx.moveTo(x+j*10,s.y+20);
ctx.lineTo(x+j*10+5,s.y);ctx.lineTo(x+j*10+10,s.y+20);
ctx.fill();
}
}
// البلورات
for(let g of crystals){
if(g.got)continue;
let x=g.x-camera;
if(x<-10||x>W+10)continue;
let pulse=Math.sin(frame*.1+g.phase)*2;
pixelRect(x-3,g.y-5+pulse,6,10,"#5cecff");
pixelRect(x-5,g.y-2+pulse,10,4,"#b6faff");
pixelRect(x-1,g.y-4+pulse,2,7,"#ffffff");
}
// الأعداء
for(let e of enemies){
if(!e.alive)continue;
let x=e.x-camera;
pixelRect(x,e.y,17,13,"#70e58b");
pixelRect(x+3,e.y+4,3,4,"#192b42");
pixelRect(x+11,e.y+4,3,4,"#192b42");
pixelRect(x+2,e.y+12,4,3,"#a5ff9d");
pixelRect(x+12,e.y+12,4,3,"#a5ff9d");
}
// بوابة الخروج
let ex=exit.x-camera;
pixelRect(ex,exit.y,28,40,pal.accent);
pixelRect(ex+5,exit.y+5,18,30,"#29204d");
pixelRect(ex+9,exit.y+9,10,20,"#fff1a1");
pixelRect(ex+12,exit.y+13,4,10,"#ffffff");
}
function drawPlayer(){
let p=player;
if(p.inv>0&&Math.floor(frame/5)%2===0)return;
let x=Math.floor(p.x-camera),y=Math.floor(p.y);
// ظل
pixelRect(x+2,y+19,12,3,"#00000055");
// الجسم
pixelRect(x+3,y+6,9,11,"#5c8dff");
pixelRect(x+2,y+8,11,7,"#82b0ff");
// الرأس
pixelRect(x+1,y,12,9,"#ffcf9c");
// الشعر
pixelRect(x+1,y,12,4,"#563b75");
pixelRect(x,y+3,3,4,"#563b75");
// العين
pixelRect(x+(p.face>0?9:3),y+4,2,2,"#20274a");
// الحقيبة
pixelRect(x-2,y+9,4,7,"#e8a34f");
// القدم
pixelRect(x+2,y+16,5,4,"#47375f");
pixelRect(x+9,y+16,5,4,"#47375f");
}
function render(){
drawBackground();
drawWorld();
drawPlayer();
// نص المنطقة
ctx.fillStyle="#ffffff99";ctx.font="10px Arial";
ctx.textAlign="left";
ctx.fillText(["GREEN VALLEY","MYSTIC LAKE","STAR CASTLE"][level],12,18);
}
function loop(){
if(state==="play")update();
render();
requestAnimationFrame(loop);
}
function bind(id,key){
let el=$(id);
el.addEventListener("pointerdown",e=>{
e.preventDefault();keys[key]=true;
if(key==="jump")jumpPressed=true;
});
const release=e=>{e.preventDefault();keys[key]=false;};
el.addEventListener("pointerup",release);
el.addEventListener("pointercancel",release);
el.addEventListener("lostpointercapture",release);
}
bind("left","left");
bind("right","right");
bind("jump","jump");
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"||e.key==="w"){
if(!keys.jump)jumpPressed=true;
keys.jump=true;
}
});
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===" "||e.key==="ArrowUp"||e.key==="w")keys.jump=false;
});
$("start").addEventListener("click",start);
makeLevel(0);
loop();
})();
</script>
</body>
</html>
Game Source: STARBOUND - Pixel Quest
Creator: MegaOtter89
Libraries: none
Complexity: complex (372 lines, 10.8 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: starbound-pixel-quest-megaotter89" to link back to the original. Then publish at arcadelab.ai/publish.