refactor: Spread game code into modular files for better maintainability

This commit reorganizes the game's source code into multiple files within a `js/` directory, creating a more modular and maintainable structure. The changes include:

- Created separate files for different game components:
  - `constants.js`: Game constants and element types
  - `world.js`: World management functions
  - `terrain.js`: Terrain generation logic
  - `physics.js`: Physics simulation
  - `render.js`: Rendering functions
  - `input.js`: Input handling
  - `main.js`: Main game initialization and loop
  - Element-specific files in `js/elements/`:
    - `basic.js`: Sand, water, dirt behaviors
    - `plants.js`: Grass, seeds, flowers
    - `trees.js`: Tree growth and leaf generation
    - `fire.js`: Fire and lava behaviors

- Updated `index.html` to load modules in the correct order
- Removed the monolithic `script.js`

The modular approach improves code readability, makes future extensions easier, and separates concerns more effectively.
This commit is contained in:
Kacper Kostka (aider)
2025-04-04 12:15:30 +02:00
parent a5702a210f
commit a86acfff3a
13 changed files with 1363 additions and 1351 deletions

View File

@@ -37,6 +37,17 @@
</div>
<canvas id="simulation-canvas"></canvas>
</div>
<script src="script.js"></script>
<!-- Load modules in the correct order -->
<script src="js/constants.js"></script>
<script src="js/world.js"></script>
<script src="js/elements/basic.js"></script>
<script src="js/elements/plants.js"></script>
<script src="js/elements/trees.js"></script>
<script src="js/elements/fire.js"></script>
<script src="js/render.js"></script>
<script src="js/input.js"></script>
<script src="js/physics.js"></script>
<script src="js/terrain.js"></script>
<script src="js/main.js"></script>
</body>
</html>