feat: growth factor
This commit is contained in:
parent
646bb5344f
commit
c4908a8252
|
@ -48,6 +48,7 @@ export default class Plant extends Component {
|
|||
static properties = {
|
||||
growScript: {type: 'string'},
|
||||
growth: {type: 'uint16'},
|
||||
growthFactor: {defaultValue: 127, type: 'uint8'},
|
||||
mayGrowScript: {type: 'string'},
|
||||
stage: {type: 'uint8'},
|
||||
stages: {
|
||||
|
|
|
@ -9,13 +9,15 @@ export default class PlantGrowth extends System {
|
|||
}
|
||||
|
||||
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 + (((Math.random() + 0.5) * elapsed) / Plant.stages[stage]) * 65535,
|
||||
Plant.growth + ((growthFactor * elapsed) / Plant.stages[stage]) * 65535,
|
||||
65535,
|
||||
);
|
||||
if (65535 === Plant.growth) {
|
||||
|
|
|
@ -122,7 +122,7 @@ export default class Engine {
|
|||
Plant: {
|
||||
growScript: '/assets/tomato-plant/grow.js',
|
||||
mayGrowScript: '/assets/tomato-plant/may-grow.js',
|
||||
stages: [300, 300, 300, 300, 300],
|
||||
stages: Array(5).fill(60),
|
||||
},
|
||||
Sprite: {
|
||||
anchor: {x: 0.5, y: 0.75},
|
||||
|
@ -136,10 +136,14 @@ export default class Engine {
|
|||
VisibleAabb: {},
|
||||
};
|
||||
const promises = [];
|
||||
for (let y = 0; y < 10; ++y) {
|
||||
for (let x = 0; x < 10; ++x) {
|
||||
for (let y = 0; y < 5; ++y) {
|
||||
for (let x = 0; x < 5; ++x) {
|
||||
promises.push(ecs.create({
|
||||
...plant,
|
||||
Plant: {
|
||||
...plant.Plant,
|
||||
growthFactor: Math.floor(Math.random() * 256),
|
||||
},
|
||||
Position: {x: 8 + x * 16, y: 8 + y * 16},
|
||||
}));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user