Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NightLightLumie committed Aug 21, 2024
2 parents e7083af + 45a3356 commit e4efd00
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/assets/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'),
Expand All @@ -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'),
Expand All @@ -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'),
Expand All @@ -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'),
Expand Down
Binary file added src/assets/images/characters/workerAlt1Sing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/characters/workerAlt2Sing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/characters/workerAlt3Sing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/characters/workerSing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/music/salondowntime.mp3
Binary file not shown.
23 changes: 19 additions & 4 deletions src/components/Employee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
},
});
Expand All @@ -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());
}
}

Expand All @@ -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());
}
}

Expand All @@ -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 */
Expand Down
7 changes: 7 additions & 0 deletions src/components/EmployeeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum EmployeeType {
export interface EmployeeTypeInterface {
spriteKeys: {
idle: string;
sing: string;
walk: string[];
work: string[];
};
Expand All @@ -23,13 +24,15 @@ export const EmployeeTypeData: {
[EmployeeType.RaccoonGray]: {
spriteKeys: {
idle: "worker",
sing: "workerSing",
walk: ["workerWalk1", "workerWalk2", "workerWalk3", "workerWalk2"],
work: ["workerWork1", "workerWork2"],
},
},
[EmployeeType.RaccoonBrown]: {
spriteKeys: {
idle: "workerAlt1",
sing: "workerAlt1Sing",
walk: [
"workerAlt1Walk1",
"workerAlt1Walk2",
Expand All @@ -42,6 +45,7 @@ export const EmployeeTypeData: {
[EmployeeType.RaccoonYellow]: {
spriteKeys: {
idle: "workerAlt2",
sing: "workerAlt2Sing",
walk: [
"workerAlt2Walk1",
"workerAlt2Walk2",
Expand All @@ -54,6 +58,7 @@ export const EmployeeTypeData: {
[EmployeeType.RaccoonPurple]: {
spriteKeys: {
idle: "workerAlt3",
sing: "workerAlt3Sing",
walk: [
"workerAlt3Walk1",
"workerAlt3Walk2",
Expand All @@ -66,6 +71,7 @@ export const EmployeeTypeData: {
[EmployeeType.RaccoonGreen]: {
spriteKeys: {
idle: "workerAlt4",
sing: "workerAlt4Sing",
walk: [
"workerAlt4Walk1",
"workerAlt4Walk2",
Expand All @@ -78,6 +84,7 @@ export const EmployeeTypeData: {
[EmployeeType.Human]: {
spriteKeys: {
idle: "player",
sing: "player",
walk: ["player"],
work: ["player"],
},
Expand Down
18 changes: 15 additions & 3 deletions src/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

}
}
9 changes: 9 additions & 0 deletions src/utils/Music.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions src/utils/MusicData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -62,6 +71,7 @@ export type MusicDataType = {
loop: boolean;
start: number;
end: number;
notes: [number, number][];
};
};

Expand Down

0 comments on commit e4efd00

Please sign in to comment.