Skip to content

Commit

Permalink
Adjust battery blinking
Browse files Browse the repository at this point in the history
  • Loading branch information
Golen87 committed Apr 22, 2024
1 parent d4edd79 commit d193171
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/components/DJ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ export class DJ extends Phaser.GameObjects.Container {
}

setMoodPower(power: number) {
let factor = 1 - (power - 1) / 9;
this.battery.setVolume(factor * this.volume);
if (power > 0) {
let factor = 1 - (power - 1) / 9;
this.battery.setVolume(factor * this.volume);
} else {
this.battery.setVolume(0);
}
this.toggle(this.drums, power > 0);
}

toggle(track: Music, active: boolean) {
this.scene.tweens.addCounter({
from: track.volume,
to: active ? this.volume : 0,
duration: 500,
duration: 250,
ease: Phaser.Math.Easing.Sine.InOut,
onUpdate: (tween, target, key, current: number) => {
track.setVolume(current);
Expand Down
3 changes: 1 addition & 2 deletions src/components/UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export class UI extends Phaser.GameObjects.Container {
}

setBatteryBlink(barTime: number, power: number) {
// https://www.desmos.com/calculator/epofb3ricb
let factor = 1.05 - 0.5 * (barTime % 2) - 0.05 * ((barTime + 1) % 2);
let factor = 1 - 0.5 * (barTime % 2);
let fade = (1 - power / 10) * factor;
this.battery.setAlpha(1 - fade);
}
Expand Down

0 comments on commit d193171

Please sign in to comment.