Skip to content

Commit

Permalink
fix clock hand frustum culling, per-message triggers, sfx for adding …
Browse files Browse the repository at this point in the history
…gears to clock
  • Loading branch information
amcolash committed Jan 13, 2025
1 parent e2277df commit 59cfffc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
Binary file added public/assets/sounds/sfx/clunk.mp3
Binary file not shown.
18 changes: 12 additions & 6 deletions src/classes/Environment/ClockHands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GameObjects, Scene } from 'phaser';
import { GameObjects, Geom, Scene } from 'phaser';

import { Config } from '../../config';
import { Layer } from '../../data/layers';
import { JournalEntry } from '../../data/types';
import { Colors, getColorNumber } from '../../utils/colors';
Expand All @@ -10,7 +11,7 @@ const radius1 = 50;
const radius2 = 40;
const radius3 = 25;

const speed = 35;
const speed = 45;
const PI2 = Math.PI * 2;

const sec = 1000 * 60;
Expand All @@ -28,6 +29,8 @@ export class ClockHands extends GameObjects.Graphics {
update2: boolean = false;
update3: boolean = false;

cameraBounds: Geom.Rectangle = new Geom.Rectangle(0, 0, Config.width + 300, Config.height + 300);

constructor(scene: Scene, player: Player) {
super(scene);
this.name = 'ClockHands';
Expand All @@ -43,7 +46,10 @@ export class ClockHands extends GameObjects.Graphics {
}

update(time: number): void {
if (this.scene.cameras.main.worldView.contains(this.x, this.y)) {
this.cameraBounds.x = this.scene.cameras.main.scrollX - 150;
this.cameraBounds.y = this.scene.cameras.main.scrollY - 150;

if (!this.cameraBounds.contains(this.x, this.y)) {
this.setVisible(false);
return;
}
Expand All @@ -57,10 +63,10 @@ export class ClockHands extends GameObjects.Graphics {
this.clear();

this.fillStyle(getColorNumber('#224477'));
this.fillCircle(0, 0, 6);
this.fillCircle(0, 0, 5);

[8, 6].forEach((width) => {
this.lineStyle(width, getColorNumber(width === 6 ? '#224477' : Colors.Black));
[6, 2].forEach((width) => {
this.lineStyle(width, getColorNumber(width === 2 ? '#4477aa' : Colors.Black));
this.lineBetween(0, 0, Math.cos(this.angle1) * radius1, Math.sin(this.angle1) * radius1);
this.lineBetween(0, 0, Math.cos(this.angle2) * radius2, Math.sin(this.angle2) * radius2);
this.lineBetween(0, 0, Math.cos(this.angle3) * radius3, Math.sin(this.angle3) * radius3);
Expand Down
3 changes: 3 additions & 0 deletions src/classes/UI/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ export class Message extends GameObjects.Container {
}

this.messageIndex++;

if (this.dialog.onMessageShown) this.dialog.onMessageShown(this.player, this.messageIndex, this.target);

if (this.messageIndex >= messages.length) {
if (this.dialog.onCompleted) {
this.dialog.onCompleted(this.player, this.target);
Expand Down
11 changes: 9 additions & 2 deletions src/data/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface Dialog<T> {
options?: string[] | ((player: Player) => string[]);

onCompleted?: (player: Player, target?: T) => void;
onMessageShown?(player: Player, index: number, target?: T): void;
onSelected?: (option: string, player: Player, target?: T) => void;
}

Expand Down Expand Up @@ -295,12 +296,15 @@ export const NPCDialogs: Record<NPCType, Dialog<NPC>[]> = {
{
messages: [
'Slowly, you align and tighten the second gear into place.',
'[CREAKING NOISE]',
'[CLUNKING NOISE]',
'Now two of the hands of the clock are moving again.',
],
conditions: {
hasItem: ItemType.Gear2,
},
onMessageShown: (player, index) => {
if (index === 1) player.scene.sound.play('clunk');
},
onCompleted: (player) => {
player.inventory.removeItem(ItemType.Gear2);
player.journal.addEntry(JournalEntry.ClockSecondGear);
Expand All @@ -316,12 +320,15 @@ export const NPCDialogs: Record<NPCType, Dialog<NPC>[]> = {
messages: [
"This dusty clock tower hasn't told the correct time in many years. It appears to be missing some gears.",
'Let’s see what happens when we add the first gear. You tighten the gear into place.',
'[CREAKING NOISE]',
'[CLUNKING NOISE]',
'The clock tower is starting to partially move again. It looks like it’s missing two more gears.',
],
conditions: {
hasItem: ItemType.Gear1,
},
onMessageShown: (player, index) => {
if (index === 2) player.scene.sound.play('clunk');
},
onCompleted: (player) => {
player.inventory.removeItem(ItemType.Gear1);
player.journal.addEntry(JournalEntry.ClockFirstGear);
Expand Down
1 change: 1 addition & 0 deletions src/scenes/Preloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export class Preloader extends Scene {
this.load.audio('warp', 'sounds/sfx/warp.mp3');
this.load.audio('ladder', 'sounds/sfx/ladder.mp3');
this.load.audio('door', 'sounds/sfx/door.mp3');
this.load.audio('clunk', 'sounds/sfx/clunk.mp3');

// music
this.load.audio(MusicType.Town, 'sounds/music/Unknown.m4a');
Expand Down

0 comments on commit 59cfffc

Please sign in to comment.