How anion15/web-fpsgame works
Project type and purpose
• This is a web-based real-time 3D first-person shooter built on Three.js.
• The “backend” is a minimal Python app (app.py, world_data.py) that serves HTML, JS, CSS, textures, and may expose game-world data or real-time APIs (e.g., via HTTP or WebSockets).
• The “frontend” is a single-page application (index.html + static/js/*.js) that initializes Three.js, loads textures, handles input, runs the game loop (requestAnimationFrame), and applies post-processing effects.
File structure
Top-level
• app.py – Python HTTP server (likely Flask or similar).
• world_data.py – Python module defining or serving map/world configuration.
• templates/index.html – Main HTML entry point, UI container for the canvas.
• static/ – All assets served statically.
├─ css/style.css
├─ js/ – Core game logic, separated by concern:
│ • world.js – Scene, camera, lighting, shadows, fog, sky, ground.
│ • controls.js – Input handling, camera recoil, FPM controls.
│ • network.js – Networking layer (multiplayer or data sync) via HTTP/WebSocket.
│ • player.js – Player model, movement, state.
│ • weapon.js – Weapons, firing logic, ammo, reload.
│ • game.js – Game loop, entity management, collision.
│ • gunshot.mp3 / reload.mp3 – Audio resources.
└─ textures/ – Image resources for terrain, sky, clouds, etc.
README for additional insights
• The README confirms: modular JS classes, requestAnimationFrame loop, TextureLoader, and describes each subsystem (sky, fog, clouds, ground, lighting, shadows).
a. Main components
1) Browser Client
– Rendering Engine (Three.js core)
– World Module (world.js)
– Controls Module (controls.js)
– Network Module (network.js)
– Player & Weapon Modules (player.js, weapon.js)
– Game Loop & Post-Processing (game.js + shaders)
– Asset Loader (TextureLoader, audio loader)
2) Backend Server
– HTTP Server (app.py)
– World Data Provider (world_data.py)
– Template Engine (index.html served via Jinja2 or static)
– Static Asset Server (serves /static, /templates)
3) Resources / External
– Textures (static/textures)
– Audio (gunshot.mp3, reload.mp3)
– Optional: Database or in-memory store if multiplayer state is persisted
b. Relationships / data flows
1) Browser → HTTP GET → Server → index.html + CSS + JS + textures
2) Browser’s Asset Loader → TextureLoader / AudioLoader → static/textures, mp3
3) After load: Browser initializes Three.js Scene
4) Input events (keyboard, mouse) → Controls Module → update camera / player state
5) Game Loop (requestAnimationFrame) → RenderPass → Post-Processing passes → Canvas
6) (If multiplayer) Browser ↔ WebSocket/API → Backend.network endpoints → sync positions, game events
7) Server may provide initial world parameters from world_data.py at startup or via API
c. Architectural patterns / design principles
• Modular separation (each JS class handles one concern)
• Single-page application pattern (index.html + dynamic modules)
• HTTP server for static assets + REST or WebSocket style API for real-time comms
• Rendering pipeline pattern: Scene graph → RenderPass → EffectComposer chain
• Asset caching: static files served with cache headers
d. Key technologies / frameworks
• Three.js (Scene, Camera, Mesh, Materials)
• EffectComposer (UnrealBloomPass, FXAAShader, custom post-processing)
• Python web framework (Flask or similar)
• Jinja2 or native templating for index.html (if used)
• Web Audio API (via AudioLoader)