A simple 2D space shooter game built with HTML5 Canvas and JavaScript.
- Clone or download this repository.
- Open the
index.htmlfile in your web browser. - Use the arrow keys to move your spaceship.
- Press the spacebar to shoot bullets.
- Avoid enemy bullets and destroy enemy ships to earn points.
.
├── images/
│ ├── background.jpg
│ ├── bullet.png
│ ├── enemyred.png
│ ├── enemyyellow.png
│ ├── gameover.png
│ ├── laser.png
│ └── ship.png
├── index.html
└── main.js
- Canvas Setup: Creates and configures the HTML5 canvas.
- Image Loading: Loads all necessary game assets (images).
- Player Spaceship:
- Controlled by arrow keys.
- Shoots bullets with the spacebar.
- Enemies:
- Spawn at regular intervals.
- Move down the screen.
- Have their own HP.
- Bullets:
- Player and enemy bullets are handled separately.
- Collision detection with ships.
- Game Loop (
mainfunction):- Updates game state (
updatefunction). - Renders the game on the canvas (
renderfunction). - Uses
requestAnimationFramefor smooth animations.
- Updates game state (
- Game Over: The game ends when the player's HP drops to 0.
