<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Level Devil</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
background: #1b1b2b;
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
color: #fff;
overflow: hidden;
}
h1 { margin: 10px 0 0 0; color: #ff5050; text-shadow: 2px 2px #000; }
#info { margin: 4px 0; font-size: 14px; color: #ccc; }
#counter { color: gold; font-weight: bold; }
#gameWrap {
position: relative;
width: 900px;
height: 500px;
max-width: 96vw;
background: linear-gradient(#4a4a6a, #232334);
border: 4px solid #555;
margin-top: 6px;
overflow: hidden;
}
.plat {
position: absolute;
background: #6b4b2b;
border-top: 4px solid #8a6a3a;
}
.spike {
position: absolute;
width: 0;
height: 0;
border-left: 12px solid transparent;
border-right: 12px solid transparent;
border-bottom: 20px solid #ddd;
}
.goal {
position: absolute;
width: 30px;
height: 50px;
background: gold;
box-shadow: 0 0 15px gold;
}
#player {
position: absolute;
width: 26px;
height: 34px;
background: #4da6ff;
border-radius: 4px;
box-shadow: 0 0 8px #4da6ff;
}
#msg {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 36px;
font-weight: bold;
color: #ff2b2b;
text-shadow: 3px 3px #000;
display: none;
text-align: center;
pointer-events: none;
background: rgba(0,0,0,0.5);
padding: 10px 20px;
border-radius: 10px;
}
#hint {
position: absolute;
bottom: 6px;
left: 8px;
font-size: 12px;
color: #ccc;
}
#restartBtn {
margin-top: 10px;
padding: 8px 20px;
font-size: 16px;
background: #ff5050;
border: none;
border-radius: 6px;
color: #fff;
cursor: pointer;
}
</style>
</head>
<body>
<h1>😈 LEVEL DEVIL 😈</h1>
<div id="info">Arrow keys / WASD to move, SPACE / UP to jump. Deaths: <span id="counter">0</span></div>
<div id="gameWrap">
<div id="player"></div>
<div id="msg"></div>
<div id="hint">Nothing is safe.</div>
</div>
<button id="restartBtn">Restart Level</button>
<script>
const wrap = document.getElementById('gameWrap');
const player = document.getElementById('player');
const msg = document.getElementById('msg');
const counterEl = document.getElementById('counter');
const restartBtn = document.getElementById('restartBtn');
const W = wrap.clientWidth, H = wrap.clientHeight;
const GRAVITY = 0.6;
const JUMP = -12;
const SPEED = 4;
const PW = 26, PH = 34;
let deaths = 0;
let elements = [];
function clearLevel() {
elements.forEach(e => e.el && e.el.remove());
elements = [];
}
function addPlat(x, y, w, h, fake) {
const el = document.createElement('div');
el.className = 'plat';
el.style.left = x + 'px';
el.style.top = y + 'px';
el.style.width = w + 'px';
el.style.height = h + 'px';
wrap.appendChild(el);
const obj = { type: fake ? 'fake' : 'solid', x, y, w, h, el, triggered: false, gone: false };
elements.push(obj);
return obj;
}
function addSpike(x, y) {
const el = document.createElement('div');
el.className = 'spike';
el.style.left = x + 'px';
el.style.top = y + 'px';
wrap.appendChild(el);
elements.push({ type: 'spike', x: x - 8, y: y + 6, w: 20, h: 14, el });
}
function addGoal(x, y) {
const el = document.createElement('div');
el.className = 'goal';
el.style.left = x + 'px';
el.style.top = y + 'px';
wrap.appendChild(el);
elements.push({ type: 'goal', x, y, w: 30, h: 50, el });
}
function makeLevel() {
clearLevel();
addPlat(0, 460, 160, 40, false);
addPlat(160, 460, 100, 40, false);
addPlat(300, 400, 90, 20, false);
addPlat(430, 350, 100, 20, true);
addSpike(440, 440);
addSpike(465, 440);
addSpike(490, 440);
addSpike(515, 440);
addPlat(580, 300, 90, 20, false);
addPlat(700, 250, 80, 20, true);
addSpike(705, 440);
addSpike(730, 440);
addSpike(755, 440);
addPlat(800, 200, 100, 20, false);
addGoal(850, 150);
resetPlayer();
}
let px, py, vx, vy, onGround, dead, won, invuln = 0;
let gameStarted = false;
const keys = {};
function resetPlayer() {
px = 20; py = 420; vx = 0; vy = 0; onGround = true; dead = false; won = false;
msg.style.display = 'none';
invuln = 30;
updatePlayerPos();
}
function updatePlayerPos() {
player.style.left = px + 'px';
player.style.top = py + 'px';
}
document.addEventListener('keydown', e => {
keys[e.key.toLowerCase()] = true;
if (e.key === ' ') e.preventDefault();
});
document.addEventListener('keyup', e => { keys[e.key.toLowerCase()] = false; });
restartBtn.addEventListener('click', () => makeLevel());
function rectsOverlap(ax, ay, aw, ah, bx, by, bw, bh) {
return ax < bx + bw && ax + aw > bx && ay < by + bh && ay + ah > by;
}
function die(reason) {
if (dead || won || invuln > 0) return;
dead = true;
deaths++;
counterEl.textContent = deaths;
msg.textContent = reason;
msg.style.display = 'block';
setTimeout(() => makeLevel(), 800);
}
function win() {
if (dead || won) return;
won = true;
msg.textContent = "YOU MADE IT! 🎉";
msg.style.display = 'block';
}
function loop() {
if (!dead && !won) {
if (keys['arrowleft'] || keys['a']) vx = -SPEED;
else if (keys['arrowright'] || keys['d']) vx = SPEED;
else vx = 0;
if ((keys[' '] || keys['arrowup'] || keys['w']) && onGround) {
vy = JUMP;
onGround = false;
}
vy += GRAVITY;
let nx = px + vx;
let ny = py + vy;
nx = Math.max(0, Math.min(W - PW, nx));
let landed = false;
let landY = ny;
for (const e of elements) {
if ((e.type === 'solid' || e.type === 'fake') && !e.gone) {
const willOverlapX = nx + PW > e.x + 3 && nx < e.x + e.w - 3;
const wasAbove = (py + PH) <= e.y + 1;
const willReach = (ny + PH) >= e.y;
if (willOverlapX && vy >= 0 && wasAbove && willReach) {
landY = e.y - PH;
landed = true;
if (e.type === 'fake' && !e.triggered) {
e.triggered = true;
e.el.style.transition = 'opacity 0.25s';
setTimeout(() => {
e.el.style.opacity = '0';
e.gone = true;
}, 160);
}
}
}
}
if (landed) {
ny = landY;
vy = 0;
onGround = true;
} else {
onGround = false;
}
px = nx;
py = ny;
if (invuln > 0) invuln--;
if (invuln <= 0) {
for (const e of elements) {
if (e.type === 'spike') {
if (rectsOverlap(px, py, PW, PH, e.x, e.y, e.w, e.h)) {
die("SPIKED! 💀");
}
}
if (e.type === 'goal') {
if (rectsOverlap(px, py, PW, PH, e.x, e.y, e.w, e.h)) {
win();
}
}
}
if (py > H) {
die("You fell into the void!");
}
}
updatePlayerPos();
}
requestAnimationFrame(loop);
}
makeLevel();
loop();
</script>
</body>
</html>