X Tutup
Skip to content

Commit 7889f05

Browse files
committed
Add waves (The most important commit!).
1 parent 48839ed commit 7889f05

File tree

7 files changed

+34
-5
lines changed

7 files changed

+34
-5
lines changed

files/waves.tiled-session

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@
119119
"scale": 8,
120120
"selectedLayer": 1,
121121
"viewCenter": {
122-
"x": 256,
123-
"y": 256
122+
"x": 397.875,
123+
"y": 268.75
124124
}
125125
},
126126
"spring_again_jetty_area.tmx#snow": {

public/assets/audio/waves.mp3

200 KB
Binary file not shown.

src/common/objects/jetty.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { rect } from 'common/factories/phaser';
2-
import { Animation, Depth, Sprite } from 'constants';
1+
import { rect, vec2 } from 'common/factories/phaser';
2+
import { Animation, Depth, Sound, Sprite } from 'constants';
3+
import { spatialAudio, SpatialAudio } from 'systems/audio';
34
import { Collision, collision } from 'systems/collision';
45

56
export class Jetty extends Phaser.GameObjects.Container {
@@ -11,11 +12,28 @@ export class Jetty extends Phaser.GameObjects.Container {
1112

1213
private collisions: Collision[];
1314

15+
private wavesAudio: SpatialAudio;
16+
1417
constructor(scene: Phaser.Scene) {
1518
const tiledSprite = scene.add.tileSprite(120, 0, 320, 480, Sprite.Waves).setDepth(Depth.Background - 1);
1619

1720
super(scene);
1821

22+
this.wavesAudio = spatialAudio(scene, Sound.Waves).setDistance(200).setPosition(vec2(32, 0)).loop().play();
23+
24+
scene.tweens
25+
.add({
26+
targets: this.wavesAudio,
27+
props: {
28+
volume: { from: 0, to: 1 },
29+
},
30+
duration: 3000,
31+
onUpdate: (_tween, _target, _key, current) => {
32+
this.wavesAudio.setVolume(current);
33+
},
34+
})
35+
.play();
36+
1937
this.sprite = scene.add.sprite(-2, 0, Sprite.Jetty);
2038

2139
this.sprite.anims.play(Animation.Jetty);
@@ -47,6 +65,7 @@ export class Jetty extends Phaser.GameObjects.Container {
4765
c4.toGameObject(),
4866
c5.toGameObject(),
4967
this.waves,
68+
this.wavesAudio.toGameObject(),
5069
]).setDepth(Depth.Main - 1);
5170

5271
this.addToUpdateList();

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ export const Sound = {
311311
IceCrack: 'audio/ice_crack.mp3',
312312
Watering: 'audio/watering.mp3',
313313
Splash: 'audio/splash.mp3',
314+
Waves: 'audio/waves.mp3',
314315
} as const;
315316
export type KeyOfSound = keyof typeof Sound;
316317
export type TypeOfSound = (typeof Sound)[KeyOfSound];

src/scenes/preloader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export class Preloader extends Phaser.Scene {
287287
this.load.audio(Sound.IceCrack, Sound.IceCrack);
288288
this.load.audio(Sound.Watering, Sound.Watering);
289289
this.load.audio(Sound.Splash, Sound.Splash);
290+
this.load.audio(Sound.Waves, Sound.Waves);
290291
}
291292

292293
create() {

src/systems/audio/decorators/spatial_audio.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,12 @@ export class SpatialAudio {
7272

7373
return this;
7474
}
75+
76+
public toGameObject() {
77+
return this.audio;
78+
}
79+
80+
public toSound() {
81+
return this.audio.sound;
82+
}
7583
}

src/systems/audio/objects/spatial_audio.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { clamp, normalize } from 'common/utils/math';
22
import { debugDepth, isDebug } from 'systems/flags';
33

44
export class SpatialAudio extends Phaser.GameObjects.Container {
5-
private sound: Phaser.Sound.WebAudioSound | Phaser.Sound.HTML5AudioSound | Phaser.Sound.NoAudioSound;
5+
public sound: Phaser.Sound.WebAudioSound | Phaser.Sound.HTML5AudioSound | Phaser.Sound.NoAudioSound;
66

77
private graphics: Phaser.GameObjects.Graphics;
88

0 commit comments

Comments
 (0)
X Tutup