Emberkeeper Objective is a lightweight JavaScript game objective for keeping a fire burning with firewood. It provides fire-fueling objective logic, burn timing, win/loss states, fire-intensity status, and optional proximity-based firewood collection.
- Place
fire_objective.jsandfirewood_interaction.jsin the same directory. - Use them from a Node.js project with CommonJS. No additional dependencies are required.
Create and fuel the objective, then call update(deltaSeconds) from your game loop:
const { FireFuelObjective } = require("./fire_objective");
const objective = new FireFuelObjective({
targetSeconds: 120,
maxFuelSeconds: 30,
});
objective.addFirewood(3);
console.log(objective.fuelFire(1));
function gameUpdate(deltaSeconds) {
const status = objective.update(deltaSeconds);
console.log(status.state, status.fireIntensity);
}Each piece of firewood adds up to 10 seconds of fuel, capped by maxFuelSeconds. Check the returned status for the objective state, remaining time, fuel, firewood, and fire intensity.
To add nearby firewood collection, create a player and interaction handler:
const { FireFuelObjective } = require("./fire_objective");
const { FirewoodInteraction } = require("./firewood_interaction");
const objective = new FireFuelObjective();
const player = { position: { x: 0, y: 0 }, firewood: 0 };
const interaction = new FirewoodInteraction({ objective, player });
const sources = [{ x: 1, y: 0, remaining: 5 }];
console.log(interaction.collectNearbyFirewood(sources, 1));
console.log(interaction.fuelFire(1));Call update(deltaSeconds) to advance the objective and determine whether it is won or lost.
More open source project projects by EnderDevelopment: https://github.com/EnderDevelopment