-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sounds): add multiple spectators sounds for ambiance
- Loading branch information
1 parent
3f038de
commit 64133e8
Showing
13 changed files
with
713 additions
and
652 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,48 @@ | ||
import { Actor, CollisionType, Vector, toRadians, vec, CollisionStartEvent } from 'excalibur'; | ||
import { Actor, CollisionType, Vector, toRadians, vec, CollisionStartEvent, Sound } from 'excalibur'; | ||
import { Config } from '../config'; | ||
import { Skier } from './skier'; | ||
import { Game } from '../game'; | ||
import { Resources } from '../resources'; | ||
|
||
export class Spectator extends Actor { | ||
constructor(position: Vector, rotation: number) { | ||
super({ | ||
anchor: vec(0, 1), | ||
pos: position, | ||
width: Config.SPECTATOR_WIDTH, | ||
height: Config.SPECTATOR_HEIGHT, | ||
rotation: toRadians(rotation), | ||
collisionType: CollisionType.Active, | ||
}); | ||
private hitSound!: Sound; | ||
|
||
this.useRandomSpectatorGraphic(); | ||
constructor(position: Vector, rotation: number) { | ||
super({ | ||
anchor: vec(0, 1), | ||
pos: position, | ||
width: Config.SPECTATOR_WIDTH, | ||
height: Config.SPECTATOR_HEIGHT, | ||
rotation: toRadians(rotation), | ||
collisionType: CollisionType.Active, | ||
}); | ||
|
||
const randomizer = Math.random(); | ||
this.useRandomSpectatorGraphic(randomizer); | ||
this.useRandomHitSound(randomizer); | ||
} | ||
|
||
} | ||
onInitialize() { | ||
this.on('collisionstart', evt => this.onPreCollision(evt)); | ||
} | ||
|
||
onInitialize() { | ||
this.on('collisionstart', evt => this.onPreCollision(evt)); | ||
} | ||
private useRandomSpectatorGraphic(randomizer: number): void { | ||
const spriteNumber = ~~(randomizer * Config.SPECTATOR_SPRITES.length); | ||
this.graphics.use(Config.SPECTATOR_SPRITES[spriteNumber]); | ||
} | ||
|
||
private useRandomSpectatorGraphic(): void { | ||
const spriteNumber = Math.floor(Math.random() * (Config.SPECTATOR_SPRITES.length - 1)); | ||
this.graphics.use(Config.SPECTATOR_SPRITES[spriteNumber]); | ||
} | ||
private useRandomHitSound(randomizer: number): void { | ||
const soundNumber = ~~(randomizer * Config.SPECTATOR_HIT_SOUNDS.length); | ||
this.hitSound = Config.SPECTATOR_HIT_SOUNDS[soundNumber]; | ||
} | ||
|
||
private onPreCollision(evt: CollisionStartEvent): void { | ||
if (evt.other instanceof Skier) { | ||
(this.scene.engine as Game).soundPlayer.playSound( | ||
Resources.SpectatorHitSound, | ||
0.5, | ||
false, | ||
true | ||
); | ||
} | ||
} | ||
private onPreCollision(evt: CollisionStartEvent): void { | ||
if (evt.other instanceof Skier) { | ||
(this.scene.engine as Game).soundPlayer.playSound( | ||
this.hitSound, | ||
Config.SPECTATOR_HIT_SOUND_INTENSITY, | ||
false, | ||
true, | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.