30 lines
707 B
JavaScript
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();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|