Skip to content

Commit

Permalink
audio
Browse files Browse the repository at this point in the history
  • Loading branch information
eguneys committed Dec 8, 2022
1 parent 8b98743 commit 810b1f0
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 2 deletions.
Binary file removed content/fx.ase
Binary file not shown.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/svg+xml" href="#" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>lisotaire.com</title>
<style>
Expand Down
Binary file added public/audio/ding.wav
Binary file not shown.
Binary file added public/audio/drag.wav
Binary file not shown.
1 change: 0 additions & 1 deletion public/vite.svg

This file was deleted.

6 changes: 6 additions & 0 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { SolitairePlay } from './solitaire'

import { CardShowcase } from './showcase'

import Sound from './sound'

type RectData = {
w: number,
h: number,
Expand Down Expand Up @@ -1355,6 +1357,10 @@ export default class Game extends Play {

this.objects = []

Sound.load().then(() => {
console.log(Sound)
})

Content.load().then(() => {
scene_transition = this.make(SceneTransition, Vec2.zero, {})
})
Expand Down
12 changes: 12 additions & 0 deletions src/solitaire_game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { DragSource, DragSources } from 'lsolitaire'

import { Card, Stack, DragStack, Tableu, Cards } from './showcase'

import Sound from './sound'


const reverse_forEach = <A>(a: Array<A>, f: (_: A) => void) => {
for (let i = a.length - 1; i >= 0; i--) {
Expand Down Expand Up @@ -165,6 +167,10 @@ export class SolitaireGame extends Play {

self.dragging.dispose()
self.dragging = undefined
Sound.play('ding')
cards[0].after_ease(() => {
self.cards.shadow_group = undefined
})
}
}
})
Expand Down Expand Up @@ -261,9 +267,12 @@ export class SolitaireGame extends Play {
drag_tableu(tableu: number, i: number) {
let cards = this.tableus[tableu].remove_fronts(i)

Sound.play('drag')
this.dragging = this.make(DragStack, Vec2.zero, {})
this.drag_source = DragSources.tableu(tableu, i)
this.dragging.cards = cards

this.cards.shadow_group = cards
}

flip_front(tableu: number, front: OCard) {
Expand All @@ -274,6 +283,9 @@ export class SolitaireGame extends Play {
let cards = this.dragging!.release()
this.dragging = undefined
this.tableus[tableu].add_fronts(cards)
cards[0].after_ease(() => {
this.cards.shadow_group = undefined
})
}

wait_drop_tableu(tableu: number) {
Expand Down
37 changes: 37 additions & 0 deletions src/sound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@


function load_audio(path: string): HTMLMediaElement {
let res = new Audio(path)
return res
}

let names = ['ding', 'drag']


class Sound {

audios!: Record<string, Array<HTMLMediaElement>>

load = async () => {


this.audios = {}
names.forEach(name => this.audios[name] = [...Array(4).keys()].map(() =>
load_audio(`./audio/${name}.wav`))
)

}

play(name: string) {
let audios = this.audios[name]

let audio = audios.pop()!
audios.unshift(audio)

audio.play()
}

}


export default new Sound()

0 comments on commit 810b1f0

Please sign in to comment.