Skip to content

Commit

Permalink
Add station front masking, hiding customers inside the baths
Browse files Browse the repository at this point in the history
  • Loading branch information
Golen87 committed Aug 31, 2024
1 parent d35878d commit 91d45fd
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 14 deletions.
Binary file modified src/assets/images/characters/largeCSit1.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/images/characters/largeCSit1_aqua.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/images/characters/largeCSit1_green.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/images/characters/largeCSit1_red.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/images/characters/medCSit1.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/images/characters/medCSit1_aqua.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/images/characters/medCSit1_green.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/images/characters/medCSit1_red.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/images/items/bath1f.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/images/items/bath2f.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/images/items/bath3f.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/components/Customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,27 @@ export class Customer extends Button {
});
}

applyMask(station: Station) {
if (station.foregroundMask) {
this.scene.tweens.addCounter({
from: 0,
to: 1,
yoyo: true,
duration: 200,
ease: "Sine.easeInOut",
onUpdate: (tween, target, key, current) => {
this.spriteCont.y = this.spriteOffset - 0.3 * this.cellSize * current;
},
onYoyo: () => {
this.setMask(station.foregroundMask);
},
});
}
}

setStation(station: Station | null) {
this.currentStation = station;
this.clearMask();

if (station) {
this.lastX = station.x;
Expand Down
41 changes: 36 additions & 5 deletions src/components/Station.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export class Station extends Button {
private spriteCont: Phaser.GameObjects.Container;
private sprite: Phaser.GameObjects.Image;

private maskImage: Phaser.GameObjects.Image;
public foregroundMask: Phaser.Display.Masks.BitmapMask;

private progressTimer: Timer;
private upgradeIcon: UpgradeIcon;

Expand Down Expand Up @@ -73,6 +76,19 @@ export class Station extends Button {
this.sprite.setTint(interpolateColor(0xffffff, this.stationTypeColor, 0.2));
this.spriteCont.add(this.sprite);

const frontKey = this.spriteKey + "_front";
if (scene.textures.exists(frontKey)) {
this.maskImage = this.scene.make
.image({
key: frontKey,
add: false,
})
.setOrigin(0.5, 1);

this.foregroundMask = this.maskImage.createBitmapMask();
this.foregroundMask.invertAlpha = true;
}

this.upgradeIcon = new UpgradeIcon(
scene,
x + 0.3 * cellSize,
Expand Down Expand Up @@ -123,6 +139,11 @@ export class Station extends Button {
const squish = 1.0 + amount * Math.sin((6 * time) / 1000);
this.spriteCont.setScale(1.0, squish - 0.2 * this.holdSmooth);

if (this.maskImage) {
const scale = this.spriteSize / this.maskImage.width;
this.maskImage.setScale(scale, scale * (squish - 0.2 * this.holdSmooth));
}

this.upgradeIcon.update(time, delta);
}

Expand Down Expand Up @@ -265,10 +286,7 @@ export class Station extends Button {
this.upgradeIcon.setPurchased(true);
} else if (this.upgradeTo) {
this.stationId = this.upgradeTo!;
this.sprite.setTexture(this.spriteKey);
this.spriteCont.x = this.spriteOffsetX;
this.spriteCont.y = this.spriteOffsetY;
this.sprite.setScale(this.spriteSize / this.sprite.width);
this.updateTexture();
}

if (this.upgradeTo === undefined) {
Expand All @@ -281,11 +299,24 @@ export class Station extends Button {
this.hasBeenPurchased = true;
this.setAlpha(1.0);
this.stationId = id;
this.updateTexture();
this.upgradeIcon.setPurchased(true);
}

updateTexture() {
this.sprite.setTexture(this.spriteKey);
this.spriteCont.x = this.spriteOffsetX;
this.spriteCont.y = this.spriteOffsetY;
this.sprite.setScale(this.spriteSize / this.sprite.width);
this.upgradeIcon.setPurchased(true);

if (this.maskImage) {
this.maskImage.setTexture(this.spriteKey + "_front");
this.maskImage.setPosition(
this.x + this.spriteCont.x,
this.y + this.spriteCont.y
);
this.maskImage.setScale(this.spriteSize / this.maskImage.width);
}
}

applyItem(id: number, sp: string) {
Expand Down
19 changes: 10 additions & 9 deletions src/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,6 @@ export class GameScene extends BaseScene {
if (employeeId !== undefined) {
this.addEmployee(gridX, gridY, employeeId);
}

console.log(blockType, stationId, employeeId);
}
}

Expand Down Expand Up @@ -744,8 +742,7 @@ export class GameScene extends BaseScene {
// Picking up a customer
customer.on("pickup", () => {
if (customer.currentStation) {
// customer.currentStation.setCustomer(null);
// customer.setStation(null);
customer.clearMask();
}
});

Expand All @@ -769,8 +766,10 @@ export class GameScene extends BaseScene {

station.setCustomer(customer);
customer.setStation(station);
customer.applyMask(station);
} else if (customer.currentStation) {
customer.snapTo(customer.currentStation.x, customer.currentStation.y);
customer.applyMask(customer.currentStation);
} else {
customer.snapTo(customer.lastX, customer.lastY);
}
Expand Down Expand Up @@ -819,11 +818,13 @@ export class GameScene extends BaseScene {
// Get available seat for new customers to go to
getAvailableWaitingSeat(id: CustomerId) {
// TODO: Use id to ensure seat and stations are available for tier
return this.stations.find(
(s) =>
s.stationType === StationType.Waiting &&
s.hasBeenPurchased &&
!s.currentCustomer
return Phaser.Math.RND.pick(
this.stations.filter(
(s) =>
s.stationType === StationType.Waiting &&
s.hasBeenPurchased &&
!s.currentCustomer
)
);
}

Expand Down

0 comments on commit 91d45fd

Please sign in to comment.