🎮ArcadeLab

Shadow Escape

by PixelStar14
243 lines5.3 KB
▶ Play
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Shadow Escape</title>
<style>
* { box-sizing: border-box; }
body {
  margin: 0;
  background: #090d1b;
  color: white;
  font-family: monospace;
  text-align: center;
}
h1 { color: #70eaff; }
canvas {
  width: min(95vw, 800px);
  background: #10172d;
  border: 3px solid #70eaff;
  image-rendering: pixelated;
  display: block;
  margin: auto;
}
p { color: #b5c8e8; }
button {
  padding: 12px 22px;
  margin: 8px;
  border: 0;
  border-radius: 8px;
  background: #167caa;
  color: white;
  font-weight: bold;
}
</style>
</head>
<body>
<h1>SHADOW ESCAPE</h1>
<p>Move: A/D or arrows | Jump: W, Up or Space</p>
<canvas id="game" width="800" height="450"></canvas>
<h2 id="status">Collect the coins and reach the exit!</h2>
<button onclick="restart()">RESTART</button>

<script>
const canvas = document.getElementById("game");
const ctx = canvas.getContext("2d");
const statusText = document.getElementById("status");

const keys = {};
let player, coins, enemies, camera, won, dead, score;

const platforms = [
  {x:0,y:400,w:800,h:50},
  {x:150,y:330,w:130,h:18},
  {x:340,y:270,w:130,h:18},
  {x:530,y:320,w:120,h:18},
  {x:690,y:240,w:110,h:18},
  {x:900,y:400,w:350,h:50},
  {x:1000,y:320,w:120,h:18},
  {x:1200,y:270,w:120,h:18}
];

const spikes = [
  {x:300,y:380,w:55,h:20},
  {x:700,y:380,w:70,h:20},
  {x:1080,y:380,w:65,h:20}
];

function restart() {
  player = {x:40,y:340,w:25,h:35,vx:0,vy:0,ground:false};
  coins = [
    {x:200,y:295},{x:390,y:235},{x:580,y:285},
    {x:740,y:205},{x:1050,y:285},{x:1250,y:235}
  ];
  enemies = [
    {x:450,y:370,w:30,h:30,vx:1.5},
    {x:950,y:370,w:30,h:30,vx:2}
  ];
  camera = 0;
  won = false;
  dead = false;
  score = 0;
  statusText.textContent = "Collect the coins and reach the exit!";
}

window.addEventListener("keydown", e => {
  keys[e.key.toLowerCase()] = true;
  if([" ","arrowup","arrowleft","arrowright"].includes(e.key.toLowerCase()))
    e.preventDefault();
  if((e.key === " " || e.key.toLowerCase() === "w" || e.key === "ArrowUp")
      && player.ground && !won && !dead) {
    player.vy = -12;
    player.ground = false;
  }
});

window.addEventListener("keyup", e => {
  keys[e.key.toLowerCase()] = false;
});

function overlap(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 update() {
  if(won || dead) return;

  player.vx = 0;
  if(keys.a || keys.arrowleft) player.vx = -4;
  if(keys.d || keys.arrowright) player.vx = 4;

  player.x += player.vx;
  player.vy += 0.55;
  player.vy = Math.min(player.vy, 12);
  player.y += player.vy;
  player.ground = false;

  for(const p of platforms) {
    if(overlap(player,p) && player.vy >= 0 &&
       player.y + player.h - player.vy <= p.y + 5) {
      player.y = p.y-player.h;
      player.vy = 0;
      player.ground = true;
    }
  }

  for(const s of spikes) {
    if(overlap(player,s)) dead = true;
  }

  for(const e of enemies) {
    e.x += e.vx;
    if(e.x < 430 || e.x > 1150) e.vx *= -1;
    if(overlap(player,e)) dead = true;
  }

  coins = coins.filter(c => {
    if(overlap(player,{x:c.x-10,y:c.y-10,w:20,h:20})) {
      score++;
      return false;
    }
    return true;
  });

  if(player.y > 480) dead = true;

  if(player.x > 1300) won = true;

  camera = Math.max(0, Math.min(650, player.x-250));

  if(dead) statusText.textContent = "GAME OVER! Press RESTART.";
  if(won) statusText.textContent = "YOU ESCAPED! Coins: "+score;
}

function draw() {
  ctx.clearRect(0,0,800,450);

  ctx.save();
  ctx.translate(-camera,0);

  // Background
  ctx.fillStyle = "#10172d";
  ctx.fillRect(camera,0,800,450);

  // Stars
  ctx.fillStyle = "#455b89";
  for(let i=0;i<50;i++) {
    let x=(i*137)%1400;
    ctx.fillRect(x,30+(i*71)%190,3,3);
  }

  // Platforms
  for(const p of platforms) {
    ctx.fillStyle="#354b70";
    ctx.fillRect(p.x,p.y,p.w,p.h);
    ctx.fillStyle="#65d5e8";
    ctx.fillRect(p.x,p.y,p.w,4);
  }

  // Spikes
  for(const s of spikes) {
    ctx.fillStyle="#ff426e";
    for(let x=s.x;x<s.x+s.w;x+=18) {
      ctx.beginPath();
      ctx.moveTo(x,s.y+s.h);
      ctx.lineTo(x+9,s.y);
      ctx.lineTo(x+18,s.y+s.h);
      ctx.fill();
    }
  }

  // Coins
  for(const c of coins) {
    ctx.fillStyle="#ffd84d";
    ctx.beginPath();
    ctx.arc(c.x,c.y,9,0,Math.PI*2);
    ctx.fill();
    ctx.fillStyle="#fff5a0";
    ctx.fillRect(c.x-2,c.y-5,3,8);
  }

  // Enemies
  for(const e of enemies) {
    ctx.fillStyle="#e94770";
    ctx.fillRect(e.x,e.y,e.w,e.h);
    ctx.fillStyle="white";
    ctx.fillRect(e.x+6,e.y+7,5,5);
    ctx.fillRect(e.x+20,e.y+7,5,5);
  }

  // Exit
  ctx.fillStyle="#35e7a0";
  ctx.fillRect(1320,325,45,75);
  ctx.fillStyle="#ffffff";
  ctx.fillRect(1330,340,7,7);

  // Player
  ctx.fillStyle="#64e9ff";
  ctx.fillRect(player.x,player.y,player.w,player.h);
  ctx.fillStyle="#ffffff";
  ctx.fillRect(player.x+15,player.y+8,5,5);

  ctx.restore();

  ctx.fillStyle="white";
  ctx.font="20px monospace";
  ctx.fillText("COINS: "+score,20,30);
}

function loop() {
  update();
  draw();
  requestAnimationFrame(loop);
}

restart();
loop();
</script>
</body>
</html>

Game Source: Shadow Escape

Creator: PixelStar14

Libraries: none

Complexity: complex (243 lines, 5.3 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: shadow-escape-pixelstar14" to link back to the original. Then publish at arcadelab.ai/publish.