Skip to content

sahmedhusain/spaceblaster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Space Blaster ๐Ÿš€

HTML CSS JavaScript License

Space Blaster Gameplay Preview

Classic arcade action.
Move fast. Shoot smart. Survive the waves.

Features โ€ข Tech Stack โ€ข Getting Started โ€ข How to Play โ€ข Screenshots



Overview

Space Blaster is a browser-based space shooter game built with HTML, CSS, and JavaScript. Players control a spaceship to defend against waves of enemies, fire lasers, survive increasingly challenging encounters, and aim for the highest possible score.

The project delivers a classic arcade-style experience while demonstrating clean game logic, DOM-based rendering, and structured JavaScript architecture.


โœจ Features

Space Blaster includes the following core gameplay and system features:

  • Player Movement and Controls ๐ŸŽฎ
    Control the spaceship using the left and right arrow keys with smooth and responsive movement.

  • Laser Shooting ๐Ÿ”ซ
    Fire lasers using the space bar to eliminate incoming enemies.

  • Enemy Waves ๐Ÿ‘พ
    Enemies appear in waves, move strategically, and shoot back, increasing the challenge over time.

  • Scoring System ๐Ÿ†
    Points are awarded for each enemy destroyed. The HUD displays score, time, and remaining lives.

  • Lives and Health โค๏ธ
    The player starts with multiple lives. Getting hit by enemy lasers reduces lives until game over.

  • Pause and Resume โธ๏ธ
    Pause or resume gameplay instantly using the P key.

  • Mute / Unmute Sounds ๐Ÿ”‡
    Toggle sound effects and background audio using the M key.

  • Game Over and Congratulations Screens ๐Ÿ…
    Display end-game results and milestone-based congratulatory messages.

  • Restart Functionality ๐Ÿ”„
    Restart the game easily after a game-over screen to attempt a higher score.


๐Ÿ› ๏ธ Technologies Used

Space Blaster is built entirely with standard web technologies:

  • HTML ๐ŸŒ โ€“ Structures the game layout and interface
  • CSS ๐ŸŽจ โ€“ Styles the game, HUD, and screens
  • JavaScript (ES6) โšก โ€“ Manages game logic, animations, and events
  • DOM Manipulation ๐Ÿ–ผ๏ธ โ€“ Renders and animates game elements
  • Audio API ๐Ÿ”Š โ€“ Controls sound effects and background music

These technologies ensure compatibility and smooth performance across modern browsers.


๐ŸŽฏ Project Objective

The objective of Space Blaster is to recreate the feel of classic arcade shooters while focusing on core gameplay mechanics:

Core Game Elements

  1. Player ๐Ÿ‘ค โ€“ User-controlled spaceship
  2. Enemies ๐Ÿ‘พ โ€“ AI-controlled opponents
  3. Lasers ๐Ÿ”ซ โ€“ Projectiles from both player and enemies
  4. HUD ๐Ÿ“Š โ€“ Displays score, time, and lives

Game state and logic are fully managed using JavaScript functions and variables.


๐Ÿ” Game Logic Overview

The game operates using a continuous update loop:

Player Input โ†’ Update Positions โ†’ Check Collisions โ†’ Render Frame โ†’ Repeat
Component Purpose Key Functions
Player User-controlled ship createPlayer(), updatePlayer()
Enemies AI opponents createEnemy(), updateEnemies()
Lasers Projectiles createLaser(), updateLasers()
HUD Game information display updateHUD()

๐Ÿ‘ฃ Player Flow

Start Game โ†’ Move & Shoot โ†’ Survive Waves โ†’ Game Over โ†’ Restart
  • Players begin the game, control the ship, defeat enemies, and attempt to survive as long as possible.
  • Scores increase progressively with each enemy destroyed.

๐Ÿš€ Getting Started

Prerequisites

  • A modern web browser (Chrome, Firefox, Safari, Edge)
  • No additional installations required

Installation

  1. Clone the repository:
    git clone https://github.com/sahmedhusain/spaceblaster.git
  2. Navigate to the project directory:
    cd spaceblaster
  3. Open the game:
    open index.html
    Alternatively, double-click the file.

๐Ÿ“– How to Play

  1. Click Start to begin the game
  2. Move using Left / Right Arrow Keys
  3. Shoot using the Space Bar
  4. Pause / Resume using P
  5. Mute / Unmute audio using M
  6. Restart after game over

โš™๏ธ Game Mechanics

  • Movement: Horizontal movement within screen boundaries
  • Shooting: Unlimited lasers with cooldown control
  • Enemies: Spawn from the top and move downward
  • Collisions: Lasers and entities are destroyed on contact

๐Ÿง  Application Logic

Game Loop

  • Uses requestAnimationFrame for smooth 60 FPS updates
  • Continuously updates player, enemies, lasers, and HUD

Event Handling

  • Listens for key presses and releases
  • Prevents invalid or unintended inputs

State Management

  • Tracks active, paused, and game-over states
  • Maintains score, time, and lives

๐Ÿ” Detailed Logic Breakdown

Game Initialization

The init() function:

  • Creates the player object
  • Initializes enemy and laser arrays
  • Sets initial score, lives, and time
  • Loads and prepares audio assets

Main Update Cycle

Executed every frame:

  1. Calculate delta time
  2. Update player position
  3. Update lasers
  4. Update enemies
  5. Detect collisions
  6. Update HUD
  7. Check end-game conditions

Enemy Behavior

  • Grid-based movement
  • Random laser firing
  • New wave spawns after elimination

Laser Mechanics

  • Player lasers travel upward
  • Enemy lasers travel downward
  • Rectangle overlap collision detection

Scoring & Lives

  • Enemy destroyed: +10 points
  • Player hit: โˆ’1 life
  • Time bonus applied at game end

Pause & Audio Control

  • Pause halts the game loop
  • Mute sets all audio volume to zero

๐Ÿ“Š ERD (Entity Relationship Diagram)

Although no database is used, this diagram represents in-game entity relationships:

ERD


๐Ÿ“ˆ Game Flowchart

Game Flowchart


๐Ÿ’ป Terminal Examples

Open the Game

cd spaceblaster
open index.html

Project Structure

ls -la

Optional Local Server

python3 -m http.server 8000

๐Ÿ“ธ Screenshots

Game Demo Gameplay Game Over Start Screen


๐Ÿ› ๏ธ Code Structure

  • index.html โ€“ Game layout
  • css/main.css โ€“ UI styling
  • js/game.js โ€“ Main game loop
  • js/player.js โ€“ Player logic
  • js/enemy.js โ€“ Enemy behavior
  • js/laser.js โ€“ Laser mechanics
  • js/control.js โ€“ Input handling

โš ๏ธ Error Handling

  • Invalid inputs are ignored
  • DOM rendering issues are logged
  • Audio loading failures default to silent mode

๐Ÿค Contributing

Fork the repository, apply improvements, and submit a pull request. Please follow JavaScript best practices and test across multiple browsers.


๐Ÿ“„ License

Licensed under the MIT License. See LICENSE.md for details.


๐Ÿ™ Acknowledgments

Created as part of a web game development learning experience, inspired by classic space shooter games.


๐Ÿ‘ฅ Authors


๐Ÿ“š What I Learned

  • HTML5 and DOM-based game development
  • JavaScript game loops and event handling
  • Object-oriented programming concepts
  • Audio and graphics integration
  • Cross-browser compatibility

๐Ÿšซ Limitations

  • No progressive difficulty levels
  • Limited enemy variety
  • Basic visuals and sound effects
  • No high-score persistence

๐Ÿ”ฎ Future Improvements

  • Multiple levels with increasing difficulty
  • Power-ups and special weapons
  • Enhanced graphics and animations
  • Online leaderboards
  • Multiplayer support

About

A thrilling space shooter game built with HTML, CSS, and JavaScript. Defend against enemy waves, shoot lasers, and achieve high scores in this classic arcade-style web game!

Topics

Resources

License

Stars

Watchers

Forks

Contributors