๐Ÿš€ Introduction

Over the past few weeks, Iโ€™ve been vibecoding my way through a 3D survival game project using Babylon.js. What started as a messy, monolithic JS file is now a clean, modular codebase โ€” installable as a Progressive Web App (PWA) right from GitHub Pages.

But what made this transformation possible was my decision to use Windsurf โ€” a modern JavaScript workspace tool that simplifies modularization, bundling, and deployment. In this post, Iโ€™ll break down how I used Windsurf to structure, build, and ship the game.

๐Ÿ‘‰ Try the game now: Play the Survival Game


๐ŸŽฎ The Game at a Glance

Built with Babylon.js, the game offers:

  • Procedural terrain using Perlin noise
  • Resource harvesting, crafting, and physics interactions
  • Combat mechanics with XP and leveling
  • AI-driven animal enemies
  • A double-jump flying mechanic
  • Day/night cycle
  • PWA support for offline play

๐Ÿงฑ Why Modularize?

My original JavaScript file had ballooned past 1,000 lines. Debugging became painful. Adding new features felt like tiptoeing through a minefield. Windsurf gave me the scaffolding I needed to break the game into bite-sized, testable modules.


๐ŸŒŠ Enter Windsurf: The Workflow

1. Breaking the Monolith

Windsurf encouraged me to identify boundaries between systems:

  • Terrain
  • Player
  • Inventory
  • Animals
  • Combat
  • UI

Each became its own file in /js/components/, making it easy to maintain and extend.

bashCopyEditsurvival/
โ”œโ”€โ”€ js/
โ”‚   โ”œโ”€โ”€ main.js
โ”‚   โ”œโ”€โ”€ game.js
โ”‚   โ””โ”€โ”€ components/
โ”‚       โ”œโ”€โ”€ terrain.js
โ”‚       โ”œโ”€โ”€ player.js
โ”‚       โ”œโ”€โ”€ inventory.js
โ”‚       โ”œโ”€โ”€ animals.js
โ”‚       โ”œโ”€โ”€ combat.js
โ”‚       โ””โ”€โ”€ ui.js

2. Scoped Development

Windsurfโ€™s built-in support for hot module reloading and scoped dev servers made it seamless to test changes in isolation. Each module could be validated on its own before integrating it into the main game loop.

3. ES Module Imports

Windsurf supports native ES Modules, which let me organize my code with clean, readable imports โ€” no bundler config required.

Editimport { TerrainSystem } from './components/terrain.js';

4. Progressive Web App Setup

With the modular structure in place, adding PWA support was painless:

  • A manifest.json for installability
  • A service worker for offline caching
  • Auto-reloading via Windsurf during testing

โœจ Cool Features Made Easy

Flying Mechanic (Double Jump + Flight)

jump() {
if (this.canDoubleJump) {
this.isFlying = true;
this.jumpVelocity = this.jumpHeight * 0.5;
}
}

Safe Spawn Area

createFlatSpawnArea() {
this.spawnPosition = { x: 0, y: 2, z: 0 };
}

Procedural Terrain with Physics

jsCopyEditrock.position.y = y + rockHeight / 2 + 0.05;

These were all easier to prototype and polish thanks to modular logic and reusable utility functions.


๐Ÿ“ฆ Installable as a PWA

With just a few lines of configuration, Windsurf helped me ship the entire game as an installable web app:

<link rel="manifest" href="/manifest.json" />
<script>navigator.serviceWorker.register('/sw.js')</script>

Now, you can play the game even when offline โ€” just โ€œAdd to Home Screen.โ€


๐Ÿ”ง Developer Setup

Want to tinker with the code?

Clone the repo
git clone https://github.com/CptNope/survival-game

# Serve with any local dev server
npx serve .
# or
python -m http.server 8000

๐Ÿง  Lessons Learned

  1. Start Modular Early โ€” Refactoring later takes time.
  2. Keep Systems Decoupled โ€” Clear interfaces are key.
  3. Document Everything โ€” Especially when juggling physics, AI, and crafting logic.
  4. Use the Right Tools โ€” Windsurf saved me days of config wrangling.

๐Ÿ—บ๏ธ Next Steps

Hereโ€™s what I plan to tackle next:

  • Multiplayer support
  • Save/load system
  • Weather + seasonal effects
  • Base building and blueprints

๐ŸŽ‰ Final Thoughts

This project taught me that code architecture is gameplay. A smoother dev experience means more energy to innovate. Windsurf turned my Babylon.js spaghetti code into a lean, mean, survival machine.

If you’re building a web-based game or 3D app, try structuring your code like this from day one โ€” or better yet, let Windsurf help you get there.

๐Ÿ”— View the Source on GitHub
๐Ÿ•น๏ธ Play the Game
๐Ÿ•น๏ธ https://cptnope.itch.io/survival-game-web-demo
๐Ÿงช Built with Babylon.js + Windsurf


Leave a Reply

Your email address will not be published. Required fields are marked *