Meta Description" name="description" />
<!DOCTYPE html><html>
<head>
<meta charset="UTF-8">
<title>Mini Subway Runner</title>
<style>
body{margin:0;background:#111;color:white;font-family:sans-serif;text-align:center}
canvas{background:#222;display:block;margin:20px auto;border:2px solid #555}
</style>
</head>
<body>
<h2>Mini Subway Runner (Use ← → to move, ↑ to jump)</h2>
<canvas id="game" width="400" height="500"></canvas>
<script>
const canvas=document.getElementById('game');
const ctx=canvas.getContext('2d');let player={x:180,y:420,w:40,h:40,vy:0,jumping:false}; let obstacles=[]; let gravity=0.8; let score=0;
function spawnObstacle(){ obstacles.push({x:Math.random()*360,y:-40,w:40,h:40}); }
setInterval(spawnObstacle,1200);
document.addEventListener('keydown',e=>{ if(e.key==='ArrowLeft') player.x-=40; if(e.key==='ArrowRight') player.x+=40; if(e.key==='ArrowUp' && !player.jumping){ player.vy=-12; player.jumping=true; } });
function update(){ ctx.clearRect(0,0,400,500);
player.vy+=gravity; player.y+=player.vy;
if(player.y>=420){ player.y=420; player.vy=0; player.jumping=false; }
ctx.fillStyle='cyan'; ctx.fillRect(player.x,player.y,player.w,player.h);
ctx.fillStyle='red';
obstacles.forEach((o,i)=>{ o.y+=5; ctx.fillRect(o.x,o.y,o.w,o.h);
if(o.x < player.x+player.w && o.x+o.w > player.x && o.y < player.y+player.h && o.y+o.h > player.y){ alert('Game Over! Score: '+score); document.location.reload(); }
if(o.y>500) obstacles.splice(i,1); });
score++; ctx.fillStyle='white'; ctx.fillText('Score: '+score,10,20);
requestAnimationFrame(update); }
update(); <<!DOCTYPE html>
<html>
<head>
<title>Snake Game</title>
<style>
body{
text-align:center;
font-family:Arial;
}
canvas{
background:black;
}
</style>
</head>
<body>
<h2>Snake Game</h2>
<canvas id="game" width="400" height="400"></canvas>
<script>
const canvas = document.getElementById("game");
const ctx = canvas.getContext("2d");
let box = 20;
let snake = [{x:200,y:200}];
let food = {
x: Math.floor(Math.random()*20)*box,
y: Math.floor(Math.random()*20)*box
};
let direction = "RIGHT";
document.addEventListener("keydown",dir);
function dir(e){
if(e.keyCode==37 && direction!="RIGHT") direction="LEFT";
else if(e.keyCode==38 && direction!="DOWN") direction="UP";
else if(e.keyCode==39 && direction!="LEFT") direction="RIGHT";
else if(e.keyCode==40 && direction!="UP") direction="DOWN";
}
function draw(){
ctx.fillStyle="black";
ctx.fillRect(0,0,400,400);
for(let i=0;i<snake.length;i++){
ctx.fillStyle = i==0 ? "lime" : "green";
ctx.fillRect(snake[i].x,snake[i].y,box,box);
}
ctx.fillStyle="red";
ctx.fillRect(food.x,food.y,box,box);
let snakeX = snake[0].x;
let snakeY = snake[0].y;
if(direction=="LEFT") snakeX-=box;
if(direction=="UP") snakeY-=box;
if(direction=="RIGHT") snakeX+=box;
if(direction=="DOWN") snakeY+=box;
if(snakeX==food.x && snakeY==food.y){
food = {
x: Math.floor(Math.random()*20)*box,
y: Math.floor(Math.random()*20)*box
};
} else {
snake.pop();
}
let newHead = {x:snakeX,y:snakeY};
if(snakeX<0 || snakeY<0 || snakeX>=400 || snakeY>=400){
clearInterval(game);
alert("Game Over");
}
snake.unshift(newHead);
}
let game = setInterval(draw,100);
</script>
</body>
</html>/script>
</body>
</html>
1
1
4KB
4KB
65.0ms
112.0ms
65.0ms