Game Configuration
Relevant source files
The following files were used as context for generating this wiki page: - [src/values.json](https://github.com/wotschofsky/farmsiege/blob/HEAD/src/values.json) - [src/tips.json](https://github.com/wotschofsky/farmsiege/blob/HEAD/src/tips.json) - [src/Game.ts](https://github.com/wotschofsky/farmsiege/blob/HEAD/src/Game.ts) - [src/main.ts](https://github.com/wotschofsky/farmsiege/blob/HEAD/src/main.ts) - [src/store/MiscStore.ts](https://github.com/wotschofsky/farmsiege/blob/HEAD/src/store/MiscStore.ts) - [src/screens/GameOverScreen.ts](https://github.com/wotschofsky/farmsiege/blob/HEAD/src/screens/GameOverScreen.ts) - [api/submitScore.ts](https://github.com/wotschofsky/farmsiege/blob/HEAD/api/submitScore.ts) - [lib/Canvas.ts](https://github.com/wotschofsky/farmsiege/blob/HEAD/lib/Canvas.ts)The configuration for Farm Siege is managed through a combination of static JSON files for gameplay values, server-side environment variables for backend services, and in-code constants for engine and component initialization. This decentralized approach separates core game balance, textual content, and system-level settings.
The primary configuration file is src/values.json, which dictates the behavior and difficulty of various game mechanics, from enemy spawning to scoring. Other configurations include in-game tips, canvas dimensions, and API keys for services like reCAPTCHA and Redis.
Core Gameplay Values
Core gameplay parameters are defined in src/values.json. This centralized file allows for easy tuning of game balance and difficulty. The values are used throughout the game logic to control entity behavior, spawning rates, and scoring.
Sources: src/values.json
The diagram below illustrates the top-level structure of the values.json configuration file.
Sources: src/values.json:2-81
Rabbits
Configuration for rabbit enemies, including their spawning logic and movement speed.
| Parameter | Type | Description |
|---|---|---|
spawning.min | number | Minimum time (ms) between rabbit spawns. |
spawning.max | number | Maximum time (ms) between rabbit spawns. |
grace.min | number | Minimum grace period (ms) at the start of the game before rabbits can spawn. |
grace.max | number | Maximum grace period (ms) at the start of the game before rabbits can spawn. |
amount.min | number | Minimum number of rabbits in a spawn wave. |
amount.max | number | Maximum number of rabbits in a spawn wave. |
speed | number | Movement speed multiplier for rabbits. |
timeToClear | number | Time (ms) a rabbit takes to eat a plant. |
| Sources: src/values.json:2-14 |
Moles, Lightning, and Weeds
These sections define the spawning behavior for other hazards in the game.
| Entity | Parameter | Description |
|---|---|---|
| Mole | spawning | Min/max time (ms) between potential mole appearances. |
grace | Min/max grace period (ms) before moles can appear. | |
newChance | The probability (0-1) of a mole appearing during a check. | |
| Lightning | spawning | Min/max time (ms) between lightning strikes. |
grace | Min/max grace period (ms) before lightning can strike. | |
| Weed | spawning | Min/max time (ms) between potential weed growth. |
grace | Min/max grace period (ms) before weeds can grow. | |
newChance | The probability (0-3) of a weed appearing during a check. | |
| Sources: src/values.json:15-45 |
Plant
Defines the initial state and growth cycle of player-grown plants.
| Parameter | Type | Description |
|---|---|---|
startAmount | number | The number of plants the game starts with. |
age.maxStart | number | The maximum age (ms) a starting plant can have. |
age.fullyGrown | number | The age (ms) at which a plant is considered fully grown and yields points. |
| Sources: src/values.json:46-52 |
Game Speed
Parameters that control the dynamic increase of game speed over time.
| Parameter | Type | Description |
|---|---|---|
max | number | The maximum multiplier for game speed. |
base | number | The base value added to the speed calculation. |
exponent | number | The exponent used in the speed calculation formula. |
divideBy | number | A divisor to scale down the duration, slowing the speed increase. |
| Sources: src/values.json:53-59 |
Character and Guns
Defines player character attributes and weapon properties.
| Entity | Parameter | Description |
|---|---|---|
| Character | size | A size multiplier (not currently used in provided files). |
movementSpeed | The speed of the player character in pixels per second. | |
| Guns | pumpgun.maxAge | The lifespan of a bullet in ticks. |
pumpgun.amount | The number of pellets fired per shot. | |
pumpgun.spread | The spread angle of the pellets. | |
| Sources: src/values.json:60-71 |
Scores
Defines the point values awarded for various in-game actions.
| Action | Score Value |
|---|---|
rabbit | 5 |
weed | 2 |
plant | 15 |
mole | 50 |
| Sources: src/values.json:72-77 |
In-Game Tips
The game displays helpful tips on the "Game Over" screen. These tips are stored in a simple JSON array.
Sources: src/tips.json, src/screens/GameOverScreen.ts:145-156
[
"Use the first seconds to plant as many plants as possible",
"Customize your appearance in the cosmetics menu",
"Spread out your plants to survive a lightning strike",
...
]
Sources: src/tips.json:2-5
The MiscStore is responsible for managing and cycling through these tips to avoid showing the same one consecutively.
The following diagram shows the flow of how a tip is selected and displayed.
Engine and Initialization
Canvas Setup
The game's canvas is initialized in src/main.ts. The core configuration here is the logical grid size, which defines the coordinate system for all game components.
// src/main.ts:8-14
new Canvas({
el: <HTMLCanvasElement>document.getElementById('canvas'),
grid: new Dimensions(1600, 1200),
// Use the custom root component
root: new Game(),
showFPS: true
});
The grid dimension of 1600x1200 serves as the base resolution for positioning all in-game elements. The Canvas class then handles scaling this logical grid to fit the player's browser window.
Sources: src/main.ts:8-14, lib/Canvas.ts:70-80
Game and Music
The main Game component initializes various game stores and manages the background music. The soundtrack changes based on the active game screen, switching between soundtrackMoonBase for menus and soundtrackThermal for active gameplay.
// src/Game.ts:70-76
screensStore.subscribe((state: ScreensStoreContent) => {
switch (state.active) {
case Screens.Game:
audio.src = soundtrackThermal;
break;
case Screens.GameOver:
audio.src = soundtrackMoonBase;
}
});
Sources: src/Game.ts:70-76
Server-Side Configuration
The backend, responsible for submitting high scores, is configured via environment variables. These are not stored in the repository and must be set in the deployment environment.
Sources: api/submitScore.ts:7-9
Required Environment Variables
| Variable | Description |
|---|---|
UPSTASH_REDIS_REST_URL | The REST API URL for the Upstash Redis database. |
UPSTASH_REDIS_REST_TOKEN | The authorization token for the Upstash Redis database. |
RECAPTCHA_SECRET | The secret key for Google reCAPTCHA v3 service to validate scores. |
VITE_RECAPTCHA_SITE_KEY | The client-side site key for Google reCAPTCHA, exposed to the frontend. |
Sources: api/submitScore.ts:7-9, 13-16, src/Game.ts:81
High Score Submission Flow
The following sequence diagram shows how these configurations are used when a player submits a high score.
Summary
Farm Siege's configuration is multifaceted, leveraging JSON files for game design parameters, environment variables for secure backend integration, and hardcoded values for fundamental engine setup. This separation allows different aspects of the game to be modified independently: game designers can tweak values.json to alter the gameplay experience, while system administrators can manage API keys and database connections through environment variables without touching the codebase.