Space.io is a fast-paced, single-lane-dodging arcade game built entirely with pure HTML, CSS, and Vanilla JavaScript. Players dodge obstacles, collect coins, and utilize power-ups while the game engine dynamically ramps up difficulty over time. The project features advanced visual feedback, including screen shake, particle trails, parallax background scrolling, and a custom Web Audio API sound system.
- Core Features and Gameplay
- Tech Stack
- Visuals
- Installation and Setup
- Usage Examples
- Time Complexity and Performance
- Game Engine Pipeline
- Project Architecture
- Contributing
- Changelog
- License
- Contact and Support
- Features 4 vertical lanes with smooth transitioning.
- Increasing difficulty over time via faster obstacles and tighter spawn intervals.
- Obstacles spawn at randomized intervals between a configurable minimum and maximum.
- Burst spawns: Occasional groups of obstacles for intense moments.
- Lane clustering: New obstacles sometimes spawn near the previous lane to create recognizable patterns.
- Coins: Spinning 3D-style visual. Each coin increases the score by a fixed amount.
- Shield: Temporarily allows survival of one collision with an obstacle. Represented by a HUD pill.
- Slow-motion: Temporarily slows down obstacle movement.
- Parallax-Scrolling City: Main background moves horizontally, supported by three additional parallax layers for depth.
- Global Screen Shake: Triggered on direct collisions, shield-breaking, and near-misses.
- Player Trails: Soft, glowing particles spawn behind the player and smoothly fade out.
- Score HUD: Live score display increments with survival time and coin pickups. Best score persists via local storage.
- Background Music: Looped audio element respectful of browser autoplay policies.
- SFX System: Utilizes the Web Audio API for custom beep-based effects (start, coin collect, power-up, hit, level-up).
- Settings Panel: Allows independent volume control for music and SFX. Values are saved persistently.
- Keyboard: Arrow Up/W to move up, Arrow Down/S to move down.
- Mouse: Scroll wheel up/down to switch lanes.
- Touch: Tap top/bottom half of the game area, or use swipe gestures.
- Markup & Structure: HTML5 (including native Audio integration).
- Styling: CSS3 (Flexbox layout, Keyframe animations, Parallax layering).
- Logic & Engine: Vanilla JavaScript (ES6+).
- Browser APIs: DOM Manipulation, Web Audio API, LocalStorage API,
requestAnimationFrame.
[Insert screenshot, GIF, or gameplay footage demonstrating the parallax scrolling, obstacle dodging, and particle trails.] (Placeholder for gameplay GIF)
Because the game runs entirely in the browser using Vanilla web technologies, no build tools or package managers (like npm) are required. You only need a modern web browser.
-
Clone the repository to your local machine:
git clone [https://github.com/Mobx01/space-io.git](https://github.com/Mobx01/space-io.git) cd space-io -
Launch the game: Simply double-click the
index.htmlfile to open it in your default web browser.(Note: If your browser restricts local file audio playback due to CORS policies, you can run a quick local server instead:)
# If using Python python -m http.server 8000 # Or using Node.js npx http-server
Then navigate to
http://localhost:8000in your browser.
Below are snippets demonstrating how the custom game engine handles core logic.
Collision Detection Logic (AABB):
// Example of the Axis-Aligned Bounding Box (AABB) intersection check used in the game loop
function rectsIntersect(a, b) {
return !(a.right < b.left ||
a.left > b.right ||
a.bottom < b.top ||
a.top > b.bottom);
}Web Audio API Synthesizer (SFX):
// Example of how the engine dynamically generates sound effects without audio files
function beep(freq = 440, time = 0.08, gain = 0.12) {
if (state.muted || state.sfxVol === 0) return;
initAudio();
const oscillator = audioCtx.createOscillator();
const gainNode = audioCtx.createGain();
oscillator.type = 'sine';
oscillator.frequency.value = freq;
gainNode.gain.value = gain * state.sfxVol;
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
oscillator.start();
oscillator.stop(audioCtx.currentTime + time);
}- Collision Detection: O(N) per frame, where N is the number of active entities on screen. The engine optimizes this by strictly checking intersections only against the player's bounding box.
- Garbage Collection (DOM Recycling): O(K) where K is the number of off-screen entities purged per frame, keeping memory footprint low and stable.
- Rendering Update: O(N) per frame for DOM translation updates (adjusting
style.left).
The application utilizes a custom requestAnimationFrame loop that acts as the primary data pipeline, executing the following phases every frame:
- Time Delta Calculation: Computes the delta time (dt) between frames to ensure movement speeds are mathematically decoupled from the monitor's refresh rate.
- State & Environment Update: Translates the parallax background layers and checks dynamic difficulty timers to scale base speeds.
- Entity Processing: Iterates through all spawned entities (obstacles, coins, power-ups), applying velocity and calculating new screen coordinates.
- Collision Phase: Fetches DOM bounding boxes and executes AABB overlap checks to handle shield breaks, near-miss screen shakes, or game-over states.
- DOM Pruning: Detects entities that have crossed the left boundary threshold and removes their corresponding DOM nodes to prevent memory leaks.
The project is structured as a lightweight, single-page application to maximize load speed and accessibility:
index.html- Contains the entire application. It is divided into three distinct blocks:- HTML Structure: Defines the game container, UI overlays, scoreboards, and touch zones.
- CSS Styles: Handles all visual design, keyframe animations (coin spins, screen shakes), and z-index layering.
- JavaScript Engine: Contains the core configuration object (
CONFIG), state management, procedural generation logic, and the centralgameLoop.
/assets- Contains associated media such asbg-city.png,music.mp3, and entity sprites (obs1.png,shield.png, etc.).
We welcome contributions to improve this project. To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name). - Ensure your code follows the established conventions.
- Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature/your-feature-name). - Open a Pull Request.
Please report bugs or request features by opening an issue in the GitHub issue tracker.
- v1.0.0 - Initial release featuring dynamic lane clustering, parallax scrolling, Web Audio API sound effects, and persistent local storage saving.
This project is licensed under the MIT License - see the LICENSE file for details.