Game HTML
Game HTML
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Shooting Game</title>
<style>
canvas {
background: #eee;
display: block;
margin: auto;
}
</style>
</head>
<body>
<canvas id="gameCanvas" width="800" height="600"></canvas>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
let player = {
x: canvas.width / 2,
y: canvas.height - 30,
width: 50,
height: 50,
color: 'blue',
};
function drawPlayer() {
ctx.fillStyle = player.color;
ctx.fillRect(player.x, player.y, player.width, player.height);
}
function drawBullets() {
ctx.fillStyle = 'red';
for (let bullet of bullets) {
ctx.fillRect(bullet.x, bullet.y, 5, 10);
}
}
function updateBullets() {
for (let i = bullets.length - 1; i >= 0; i--) {
bullets[i].y -= 5;
if (bullets[i].y < 0) {
bullets.splice(i, 1);
}
}
}
function gameLoop() {
if (isGameOver) return;
gameLoop();
</script>
</body>
</html>