silphius/app/ecs-systems/plant-growth.js
2024-06-28 07:03:56 -05:00

30 lines
707 B
JavaScript

import {System} from '@/ecs/index.js';
export default class PlantGrowth extends System {
static queries() {
return {
default: ['Plant'],
};
}
tick(elapsed) {
const variance = Math.random() * 0.4 + 0.8
for (const {Plant} of this.select('default')) {
if (65535 === Plant.growth || !Plant.mayGrow()) {
continue;
}
const stage = Math.floor(Plant.stage);
const growthFactor = (((Plant.growthFactor + 1) / 256) * 0.4 + 0.8) * variance
Plant.growth = Math.min(
Plant.growth + ((growthFactor * elapsed) / Plant.stages[stage]) * 65535,
65535,
);
if (65535 === Plant.growth) {
Plant.grow();
}
}
}
}