feat: reset weight of spawn object when restart
parent
8f4734cee6
commit
d1a218f16b
|
@ -13,13 +13,15 @@ class weightedObject {
|
|||
@property(Prefab)
|
||||
public prefab: Prefab;
|
||||
@property(CCInteger)
|
||||
public weight = 0;
|
||||
public readonly weight = 0;
|
||||
@property(CCInteger)
|
||||
public weightStepOnGoal = 0;
|
||||
@property(CCInteger)
|
||||
public maxWeight = 0;
|
||||
@property(CCInteger)
|
||||
public maxObjects = -1;
|
||||
@property({ readonly: true })
|
||||
public currentWeight;
|
||||
}
|
||||
|
||||
@ccclass('SpawnObjectManager')
|
||||
|
@ -55,7 +57,10 @@ export class SpawnObjectManager extends Component {
|
|||
this._pools[i] = new ObjectPool(prefab, 10, true, ScoreObject);
|
||||
}
|
||||
|
||||
this._weights = this._objects.map((obj) => obj.weight);
|
||||
this._weights = this._objects.map((obj) => {
|
||||
obj.currentWeight = obj.weight;
|
||||
return obj.currentWeight;
|
||||
});
|
||||
}
|
||||
|
||||
protected update(dt: number): void {
|
||||
|
@ -87,14 +92,14 @@ export class SpawnObjectManager extends Component {
|
|||
private onScore(score: number, type: ScoreType) {
|
||||
if (type == ScoreType.Goal) {
|
||||
this._objects.forEach((object) => {
|
||||
if (object.weight >= object.maxWeight) {
|
||||
object.weight = object.maxWeight;
|
||||
if (object.currentWeight >= object.maxWeight) {
|
||||
object.currentWeight = object.maxWeight;
|
||||
return;
|
||||
}
|
||||
object.weight += object.weightStepOnGoal;
|
||||
object.currentWeight += object.weightStepOnGoal;
|
||||
});
|
||||
|
||||
this._weights = this._objects.map((obj) => obj.weight);
|
||||
this._weights = this._objects.map((obj) => obj.currentWeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,6 +115,7 @@ export class SpawnObjectManager extends Component {
|
|||
break;
|
||||
case GameState.GameOver:
|
||||
this._playing = false;
|
||||
this._objects.forEach((object) => (object.currentWeight = object.weight));
|
||||
this._pools.forEach((pool) => pool.releaseAll());
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue