Play sound when bearing off checker
This commit is contained in:
parent
221711e089
commit
1f651d9c92
8 changed files with 68 additions and 15 deletions
|
@ -1,3 +1,6 @@
|
|||
1.3.8:
|
||||
- Play sound when bearing off checker
|
||||
|
||||
1.3.7:
|
||||
- Add /help command
|
||||
- Fix bots leaving matches due to inactivity when playing offline
|
||||
|
|
BIN
game/asset/audio/homemulti1.ogg
Normal file
BIN
game/asset/audio/homemulti1.ogg
Normal file
Binary file not shown.
BIN
game/asset/audio/homemulti2.ogg
Normal file
BIN
game/asset/audio/homemulti2.ogg
Normal file
Binary file not shown.
BIN
game/asset/audio/homesingle.ogg
Normal file
BIN
game/asset/audio/homesingle.ogg
Normal file
Binary file not shown.
|
@ -2666,6 +2666,14 @@ func (b *board) _movePiece(sprite *Sprite, from int8, to int8, speed int8, pause
|
|||
b.spaceSprites[to] = append(b.spaceSprites[to], sprite)
|
||||
b.moving = nil
|
||||
|
||||
if to == bgammon.SpaceHomePlayer || to == bgammon.SpaceHomeOpponent {
|
||||
if b.gameState.Board[to] == 0 {
|
||||
playSoundEffect(effectHomeSingle)
|
||||
} else {
|
||||
playSoundEffect(effectHomeMulti)
|
||||
}
|
||||
}
|
||||
|
||||
if pauseTime == 0 {
|
||||
return
|
||||
} else if pause {
|
||||
|
@ -2785,7 +2793,15 @@ func (b *board) finishDrag(x int, y int, click bool) {
|
|||
if space != index {
|
||||
ok, _ := b.gameState.AddMoves([][]int8{{space, index}}, true)
|
||||
if ok {
|
||||
playSoundEffect(effectMove)
|
||||
if index == bgammon.SpaceHomePlayer || index == bgammon.SpaceHomeOpponent {
|
||||
if b.gameState.Board[index] == 0 {
|
||||
playSoundEffect(effectHomeSingle)
|
||||
} else {
|
||||
playSoundEffect(effectHomeMulti)
|
||||
}
|
||||
} else {
|
||||
playSoundEffect(effectMove)
|
||||
}
|
||||
b.processState()
|
||||
scheduleFrame()
|
||||
processed = true
|
||||
|
@ -2797,6 +2813,11 @@ func (b *board) finishDrag(x int, y int, click bool) {
|
|||
homeStart, homeEnd = homeEnd, homeStart
|
||||
}
|
||||
if index >= homeStart && index <= homeEnd {
|
||||
if b.gameState.Board[index] == 0 {
|
||||
playSoundEffect(effectHomeSingle)
|
||||
} else {
|
||||
playSoundEffect(effectHomeMulti)
|
||||
}
|
||||
b.Client.Out <- []byte(fmt.Sprintf("mv %d/off", index))
|
||||
}
|
||||
} else if time.Since(b.lastDragClick) < 500*time.Millisecond && space == bgammon.SpaceHomePlayer && !b.gameState.Player1.Entered {
|
||||
|
|
45
game/game.go
45
game/game.go
|
@ -38,7 +38,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
version = "v1.3.7"
|
||||
version = "v1.3.7p2"
|
||||
baseButtonHeight = 54
|
||||
MaxDebug = 2
|
||||
DefaultServerAddress = "wss://ws.bgammon.org"
|
||||
|
@ -151,6 +151,8 @@ var (
|
|||
SoundDie1, SoundDie2, SoundDie3 []byte
|
||||
SoundDice1, SoundDice2, SoundDice3, SoundDice4 []byte
|
||||
SoundMove1, SoundMove2, SoundMove3 []byte
|
||||
SoundHomeSingle []byte
|
||||
SoundHomeMulti1, SoundHomeMulti2 []byte
|
||||
SoundJoinLeave []byte
|
||||
SoundSay []byte
|
||||
)
|
||||
|
@ -257,6 +259,11 @@ func loadAudioAssets() {
|
|||
SoundMove2 = LoadBytes(p + "move2.ogg")
|
||||
SoundMove3 = LoadBytes(p + "move3.ogg")
|
||||
|
||||
SoundHomeSingle = LoadBytes(p + "homesingle.ogg")
|
||||
|
||||
SoundHomeMulti1 = LoadBytes(p + "homemulti1.ogg")
|
||||
SoundHomeMulti2 = LoadBytes(p + "homemulti2.ogg")
|
||||
|
||||
SoundJoinLeave = LoadBytes(p + "joinleave.ogg")
|
||||
SoundSay = LoadBytes(p + "say.ogg")
|
||||
|
||||
|
@ -281,6 +288,12 @@ func loadAudioAssets() {
|
|||
SoundMove3,
|
||||
}
|
||||
randomizeByteSlice(moveSounds)
|
||||
|
||||
homeMultiSounds = [][]byte{
|
||||
SoundHomeMulti1,
|
||||
SoundHomeMulti2,
|
||||
}
|
||||
randomizeByteSlice(homeMultiSounds)
|
||||
}
|
||||
|
||||
func loadImage(assetPath string) image.Image {
|
||||
|
@ -2896,15 +2909,19 @@ const (
|
|||
effectDie
|
||||
effectDice
|
||||
effectMove
|
||||
effectHomeSingle
|
||||
effectHomeMulti
|
||||
)
|
||||
|
||||
var (
|
||||
dieSounds [][]byte
|
||||
dieSoundPlays int
|
||||
diceSounds [][]byte
|
||||
diceSoundPlays int
|
||||
moveSounds [][]byte
|
||||
moveSoundPlays int
|
||||
dieSounds [][]byte
|
||||
dieSoundPlays int
|
||||
diceSounds [][]byte
|
||||
diceSoundPlays int
|
||||
moveSounds [][]byte
|
||||
moveSoundPlays int
|
||||
homeMultiSounds [][]byte
|
||||
homeMultiSoundPlays int
|
||||
)
|
||||
|
||||
func playSoundEffect(effect SoundEffect) {
|
||||
|
@ -2942,6 +2959,16 @@ func playSoundEffect(effect SoundEffect) {
|
|||
randomizeByteSlice(moveSounds)
|
||||
moveSoundPlays = 0
|
||||
}
|
||||
case effectHomeSingle:
|
||||
b = SoundHomeSingle
|
||||
case effectHomeMulti:
|
||||
b = homeMultiSounds[homeMultiSoundPlays]
|
||||
|
||||
homeMultiSoundPlays++
|
||||
if homeMultiSoundPlays == len(homeMultiSounds)-1 {
|
||||
randomizeByteSlice(homeMultiSounds)
|
||||
homeMultiSoundPlays = 0
|
||||
}
|
||||
default:
|
||||
log.Panicf("unknown sound effect: %d", effect)
|
||||
return
|
||||
|
@ -2957,7 +2984,9 @@ func playSoundEffect(effect SoundEffect) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
if effect == effectSay {
|
||||
if effect == effectHomeSingle || effect == effectHomeMulti {
|
||||
player.SetVolume(game.volume / 6)
|
||||
} else if effect == effectSay {
|
||||
player.SetVolume(game.volume / 2)
|
||||
} else {
|
||||
player.SetVolume(game.volume)
|
||||
|
|
4
go.mod
4
go.mod
|
@ -8,7 +8,7 @@ require (
|
|||
code.rocket9labs.com/tslocum/etk v0.0.0-20240722093150-1d8a55632df0
|
||||
code.rocket9labs.com/tslocum/gotext v0.0.0-20240722063358-6067ad4d7a58
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240703054156-ce0b448f0999
|
||||
github.com/hajimehoshi/ebiten/v2 v2.7.7
|
||||
github.com/hajimehoshi/ebiten/v2 v2.7.8
|
||||
github.com/llgcode/draw2d v0.0.0-20240627062922-0ed1ff131195
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
golang.org/x/image v0.18.0
|
||||
|
@ -43,7 +43,7 @@ require (
|
|||
github.com/jfreymuth/vorbis v1.0.2 // indirect
|
||||
github.com/jlouis/glicko2 v1.0.0 // indirect
|
||||
github.com/matcornic/hermes/v2 v2.1.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
|
|
8
go.sum
8
go.sum
|
@ -52,8 +52,8 @@ github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A
|
|||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.0.0 h1:r2+6gYK38nfztS/et50gHAswb9hXgxXECYgE8Nczmi4=
|
||||
github.com/hajimehoshi/ebiten/v2 v2.7.7 h1:FyiuIOZqKU4aefYVws/lBDhTZu2WY2m/eWI3PtXZaHs=
|
||||
github.com/hajimehoshi/ebiten/v2 v2.7.7/go.mod h1:Ulbq5xDmdx47P24EJ+Mb31Zps7vQq+guieG9mghQUaA=
|
||||
github.com/hajimehoshi/ebiten/v2 v2.7.8 h1:QrlvF2byCzMuDsbxFReJkOCbM3O2z1H/NKQaGcA8PKk=
|
||||
github.com/hajimehoshi/ebiten/v2 v2.7.8/go.mod h1:Ulbq5xDmdx47P24EJ+Mb31Zps7vQq+guieG9mghQUaA=
|
||||
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
|
||||
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
|
||||
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
||||
|
@ -88,8 +88,8 @@ github.com/matcornic/hermes/v2 v2.1.0 h1:9TDYFBPFv6mcXanaDmRDEp/RTWj0dTTi+LpFnnn
|
|||
github.com/matcornic/hermes/v2 v2.1.0/go.mod h1:2+ziJeoyRfaLiATIL8VZ7f9hpzH4oDHqTmn0bhrsgVI=
|
||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
|
||||
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
|
||||
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
|
||||
|
|
Loading…
Reference in a new issue