Skip to content

Commit

Permalink
Merge pull request #196 from jyorien/randomise-speed
Browse files Browse the repository at this point in the history
Added method to randomise speed by +/- 30% to prevent pets from overlapping so much
  • Loading branch information
tonybaloney authored Oct 7, 2022
2 parents dc7ffb5 + 2f6d768 commit 0bcb2c5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/panel/pets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ abstract class BasePetType implements IPetType {
this.currentState = resolveState(this.currentStateEnum, this);

this._name = name;
this._speed = speed; // TODO #183 : Add a random modifier (+/- 30%) to this value.
this._speed = this.randomizeSpeed(speed);

// Increment the static count of the Pet class that the constructor belongs to
(this.constructor as any).count += 1;
Expand Down Expand Up @@ -285,6 +285,13 @@ abstract class BasePetType implements IPetType {
return this._speed;
}

randomizeSpeed(speed: number): number {
const min = speed * 0.7;
const max = speed * 1.3;
const newSpeed = Math.random() * (max - min) + min;
return newSpeed;
}

isMoving(): boolean {
return this._speed !== PetSpeed.still;
}
Expand Down

0 comments on commit 0bcb2c5

Please sign in to comment.