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.
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
// Game constants
|
|
const CHUNK_SIZE = 200;
|
|
const PIXEL_SIZE = 4;
|
|
const GRAVITY = 0.5;
|
|
const WATER_SPREAD = 3;
|
|
|
|
// Colors
|
|
const SAND_COLOR = '#e6c588';
|
|
const WATER_COLOR = '#4a80f5';
|
|
const WALL_COLOR = '#888888';
|
|
const DIRT_COLOR = '#8B4513';
|
|
const STONE_COLOR = '#A9A9A9';
|
|
const GRASS_COLOR = '#7CFC00';
|
|
const WOOD_COLOR = '#8B5A2B';
|
|
const SEED_COLOR = '#654321';
|
|
const FLOWER_COLORS = ['#FF0000', '#FFFF00', '#FF00FF', '#FFA500', '#FFFFFF', '#00FFFF'];
|
|
const LEAF_COLOR = '#228B22';
|
|
const FIRE_COLORS = ['#FF0000', '#FF3300', '#FF6600', '#FF9900', '#FFCC00', '#FFFF00'];
|
|
const LAVA_COLORS = ['#FF0000', '#FF3300', '#FF4500', '#FF6600', '#FF8C00'];
|
|
|
|
// Element types
|
|
const EMPTY = 0;
|
|
const SAND = 1;
|
|
const WATER = 2;
|
|
const WALL = 3;
|
|
const DIRT = 4;
|
|
const STONE = 5;
|
|
const GRASS = 6;
|
|
const WOOD = 7;
|
|
const SEED = 8;
|
|
const GRASS_BLADE = 9;
|
|
const FLOWER = 10;
|
|
const TREE_SEED = 11;
|
|
const LEAF = 12;
|
|
const FIRE = 13;
|
|
const LAVA = 14;
|
|
|
|
// Flammable materials
|
|
const FLAMMABLE_MATERIALS = [GRASS, WOOD, SEED, GRASS_BLADE, FLOWER, TREE_SEED, LEAF];
|