diff --git a/src/assets/assets.ts b/src/assets/assets.ts index ca5d9f7..93098dc 100644 --- a/src/assets/assets.ts +++ b/src/assets/assets.ts @@ -26,6 +26,7 @@ const images: Image[] = [ // Characters image('characters/player', 'player'), image('characters/worker', 'worker'), + image('characters/workerSing', 'workerSing'), // WALK ANIMATION SHOULD LOOP LIKE THIS: walk1 - walk2 - walk3 - walk2 image('characters/workerWalkDown1', 'workerWalk1'), image('characters/workerWalkDown2', 'workerWalk2'), @@ -36,6 +37,7 @@ const images: Image[] = [ // ALT WORKER SKINS // Skin 1 image('characters/workerAlt1', 'workerAlt1'), + image('characters/workerAlt1Sing', 'workerAlt1Sing'), image('characters/workerAlt1WalkDown1', 'workerAlt1Walk1'), image('characters/workerAlt1WalkDown2', 'workerAlt1Walk2'), image('characters/workerAlt1WalkDown3', 'workerAlt1Walk3'), @@ -44,6 +46,7 @@ const images: Image[] = [ // Skin 2 image('characters/workerAlt2', 'workerAlt2'), + image('characters/workerAlt2Sing', 'workerAlt2Sing'), image('characters/workerAlt2WalkDown1', 'workerAlt2Walk1'), image('characters/workerAlt2WalkDown2', 'workerAlt2Walk2'), image('characters/workerAlt2WalkDown3', 'workerAlt2Walk3'), @@ -52,6 +55,7 @@ const images: Image[] = [ // Skin 3 image('characters/workerAlt3', 'workerAlt3'), + image('characters/workerAlt3Sing', 'workerAlt3Sing'), image('characters/workerAlt3WalkDown1', 'workerAlt3Walk1'), image('characters/workerAlt3WalkDown2', 'workerAlt3Walk2'), image('characters/workerAlt3WalkDown3', 'workerAlt3Walk3'), @@ -60,6 +64,7 @@ const images: Image[] = [ // Skin 4 image('characters/workerAlt4', 'workerAlt4'), + image('characters/workerAlt4Sing', 'workerAlt4Sing'), image('characters/workerAlt4WalkDown1', 'workerAlt4Walk1'), image('characters/workerAlt4WalkDown2', 'workerAlt4Walk2'), image('characters/workerAlt4WalkDown3', 'workerAlt4Walk3'), diff --git a/src/assets/images/characters/workerAlt1Sing.png b/src/assets/images/characters/workerAlt1Sing.png new file mode 100644 index 0000000..771b289 Binary files /dev/null and b/src/assets/images/characters/workerAlt1Sing.png differ diff --git a/src/assets/images/characters/workerAlt2Sing.png b/src/assets/images/characters/workerAlt2Sing.png new file mode 100644 index 0000000..8ea0c19 Binary files /dev/null and b/src/assets/images/characters/workerAlt2Sing.png differ diff --git a/src/assets/images/characters/workerAlt3Sing.png b/src/assets/images/characters/workerAlt3Sing.png new file mode 100644 index 0000000..1a6e20a Binary files /dev/null and b/src/assets/images/characters/workerAlt3Sing.png differ diff --git a/src/assets/images/characters/workerAlt4Sing.png b/src/assets/images/characters/workerAlt4Sing.png new file mode 100644 index 0000000..72fc108 Binary files /dev/null and b/src/assets/images/characters/workerAlt4Sing.png differ diff --git a/src/assets/images/characters/workerSing.png b/src/assets/images/characters/workerSing.png new file mode 100644 index 0000000..19ec482 Binary files /dev/null and b/src/assets/images/characters/workerSing.png differ diff --git a/src/assets/music/salondowntime.mp3 b/src/assets/music/salondowntime.mp3 index 0ae0abb..07c4f23 100644 Binary files a/src/assets/music/salondowntime.mp3 and b/src/assets/music/salondowntime.mp3 differ diff --git a/src/components/Employee.ts b/src/components/Employee.ts index a03d89f..ccad420 100644 --- a/src/components/Employee.ts +++ b/src/components/Employee.ts @@ -24,6 +24,9 @@ export class Employee extends Button { public startX: number; public startY: number; + /** Uses alt. idle sprite. To be toggled externally */ + public isSinging: boolean; + constructor( scene: GameScene, x: number, @@ -38,6 +41,7 @@ export class Employee extends Button { this.cellSize = cellSize; this.currentCustomer = null; this.isWorking = false; + this.isSinging = false; this.startX = x; this.startY = y; @@ -66,6 +70,13 @@ export class Employee extends Button { const squish = 1.0 + factor * Math.sin((6 * time) / 1000); this.spriteCont.setScale(1.0, squish - 0.2 * this.holdSmooth); + if (this.hasBeenPurchased) { + const currentKey = this.sprite.frame.source.texture.key; + if (currentKey == this.spriteKeys.idle || currentKey == this.spriteKeys.sing) { + this.sprite.setTexture(this.idleFrame()); + } + } + if (this.isWorking) { const count = this.spriteKeys.work.length; const index = Math.floor(time / 200) % count; @@ -114,7 +125,7 @@ export class Employee extends Button { this.setPosition(pos.x, pos.y); // this.graphics.clear(); - this.sprite.setTexture(this.spriteKeys.idle); + this.sprite.setTexture(this.idleFrame()); this.emit("walkend"); }, }); @@ -123,7 +134,7 @@ export class Employee extends Button { setAction(isWorking: boolean) { this.isWorking = isWorking; if (!isWorking) { - this.sprite.setTexture(this.spriteKeys.idle); + this.sprite.setTexture(this.idleFrame()); } } @@ -139,7 +150,7 @@ export class Employee extends Button { this.setAlpha(1.0); } else if (this.upgradeTo) { this.employeeId = this.upgradeTo!; - this.sprite.setTexture(this.spriteKeys.idle); + this.sprite.setTexture(this.idleFrame()); } } @@ -164,7 +175,11 @@ export class Employee extends Button { this.hasBeenPurchased = true; this.setAlpha(1.0); this.employeeId = id; - this.sprite.setTexture(this.spriteKeys.idle); + this.sprite.setTexture(this.idleFrame()); + } + + idleFrame() { + return this.isSinging ? this.spriteKeys.sing : this.spriteKeys.idle; } /* Getters */ diff --git a/src/components/EmployeeData.ts b/src/components/EmployeeData.ts index f630749..0423158 100644 --- a/src/components/EmployeeData.ts +++ b/src/components/EmployeeData.ts @@ -12,6 +12,7 @@ export enum EmployeeType { export interface EmployeeTypeInterface { spriteKeys: { idle: string; + sing: string; walk: string[]; work: string[]; }; @@ -23,6 +24,7 @@ export const EmployeeTypeData: { [EmployeeType.RaccoonGray]: { spriteKeys: { idle: "worker", + sing: "workerSing", walk: ["workerWalk1", "workerWalk2", "workerWalk3", "workerWalk2"], work: ["workerWork1", "workerWork2"], }, @@ -30,6 +32,7 @@ export const EmployeeTypeData: { [EmployeeType.RaccoonBrown]: { spriteKeys: { idle: "workerAlt1", + sing: "workerAlt1Sing", walk: [ "workerAlt1Walk1", "workerAlt1Walk2", @@ -42,6 +45,7 @@ export const EmployeeTypeData: { [EmployeeType.RaccoonYellow]: { spriteKeys: { idle: "workerAlt2", + sing: "workerAlt2Sing", walk: [ "workerAlt2Walk1", "workerAlt2Walk2", @@ -54,6 +58,7 @@ export const EmployeeTypeData: { [EmployeeType.RaccoonPurple]: { spriteKeys: { idle: "workerAlt3", + sing: "workerAlt3Sing", walk: [ "workerAlt3Walk1", "workerAlt3Walk2", @@ -66,6 +71,7 @@ export const EmployeeTypeData: { [EmployeeType.RaccoonGreen]: { spriteKeys: { idle: "workerAlt4", + sing: "workerAlt4Sing", walk: [ "workerAlt4Walk1", "workerAlt4Walk2", @@ -78,6 +84,7 @@ export const EmployeeTypeData: { [EmployeeType.Human]: { spriteKeys: { idle: "player", + sing: "player", walk: ["player"], work: ["player"], }, diff --git a/src/scenes/GameScene.ts b/src/scenes/GameScene.ts index 7f25b07..2874d6e 100644 --- a/src/scenes/GameScene.ts +++ b/src/scenes/GameScene.ts @@ -58,9 +58,9 @@ export class GameScene extends BaseScene { public tArray: number[]; - public musicBase: Phaser.Sound.WebAudioSound; - public musicCutscene: Phaser.Sound.WebAudioSound; - public musicDowntime: Phaser.Sound.WebAudioSound; + public musicBase: Music; + public musicCutscene: Music; + public musicDowntime: Music; private shopClicker: Button; private ownerImage: Phaser.GameObjects.Sprite; @@ -1450,5 +1450,17 @@ export class GameScene extends BaseScene { this.musicBase.setVolume( clamp(intendedVolume.base, 0, 1) * volumeModifier); this.musicDowntime.setVolume(clamp(intendedVolume.downtime, 0, 1) * volumeModifier); this.musicCutscene.setVolume(clamp(intendedVolume.cutscene, 0, 1) * volumeModifier); + + // Singing animation + + if (this.game.hasFocus) { + + const sing = this.musicDowntime.volume > 0.1 + ? this.musicDowntime.noteActive + : false; + + this.employees.forEach(e => e.isSinging = sing); + } + } } diff --git a/src/utils/Music.ts b/src/utils/Music.ts index f8992f6..ba27bb8 100644 --- a/src/utils/Music.ts +++ b/src/utils/Music.ts @@ -11,6 +11,7 @@ export class Music extends Phaser.Sound.WebAudioSound { public speed: number; public start: number; public loopSum: number; + public notes: [number, number][]; constructor(scene: any, myKey: MusicKey, config = {}) { super(scene.sound, myKey, config); @@ -39,6 +40,7 @@ export class Music extends Phaser.Sound.WebAudioSound { this.speed = 60 / this.bpm; this.maxBar = Math.round((this.end - this.start) / this.speed); this.loopSum = 0; + this.notes = custom.notes ?? []; } update() { @@ -83,4 +85,11 @@ export class Music extends Phaser.Sound.WebAudioSound { get barTime() { return (this.totalTime - this.offset) / this.speed; } + + get noteActive() { + const possibleNotes = this.notes + .filter( ([start, end]) => start < this.seek && end > this.seek ) + + return possibleNotes.length != 0; + } } diff --git a/src/utils/MusicData.ts b/src/utils/MusicData.ts index 053e659..708fb59 100644 --- a/src/utils/MusicData.ts +++ b/src/utils/MusicData.ts @@ -25,6 +25,15 @@ const Data = { loop: true, start: 0 + overlap, end: 2690801 / 48000 + overlap, + notes: [ + [28.02,29.41], [29.78,30.36], [30.65,31.23], [31.53,32.91], + [33.28,33.46], [33.57,33.68], [33.72,33.83], [34.01,34.51], + [34.59,34.82], [35.03,36.05], [36.78,37.44], [37.59,38.39], + [38.54,38.68], [38.83,39.99], [40.29,40.82], [40.99,41.52], + [41.64,41.75], [42.04,44.22], [44.67,45.39], [45.54,46.78], + [47.29,48.82], [49.05,49.16], [49.48,49.60], [51.46,51.55], + [51.89,52.01], [52.33,52.45], [52.62,54.08] + ], }, m_first: { offset: 0, @@ -62,6 +71,7 @@ export type MusicDataType = { loop: boolean; start: number; end: number; + notes: [number, number][]; }; };