Skip to content

Commit

Permalink
Trigger collision sound when player and buzzard collide
Browse files Browse the repository at this point in the history
  • Loading branch information
depsypher committed Jun 24, 2024
1 parent f8bc64d commit 5a93e1f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ Once it's complete enough I'd like to add a scrolling mode. I'm curious what the


Controls are left, right and space to flap.

https://depsypher.github.io/gojoust/

* Press `S` key to toggle sound
* Press `P` key to toggle pause
* Press `G` key to toggle god/debug mode
31 changes: 19 additions & 12 deletions assets/audio/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const (
FlapDnSound Sound = 3
FlapUpSound Sound = 4
HitSound Sound = 5
JoustFreSound Sound = 6
JoustLavSound Sound = 7
OneUpSound Sound = 6
LavaSound Sound = 7
PteroSound Sound = 8
SkidSound Sound = 9
SpawnSound Sound = 10
Expand Down Expand Up @@ -47,10 +47,10 @@ var (
Hit []byte

//go:embed joustfre.ogg
JoustFre []byte
OneUp []byte

//go:embed joustlav.ogg
JoustLav []byte
Lava []byte

//go:embed ptero.ogg
Ptero []byte
Expand All @@ -74,14 +74,21 @@ var (
Whomp []byte

soundFiles = map[Sound][]byte{
BumpSound: Bump,
EggSound: Egg,
EnergizeSound: Energize,
FlapDnSound: FlapDn,
FlapUpSound: FlapUp,
Walk1Sound: Walk1,
Walk2Sound: Walk2,
HitSound: Hit,
BumpSound: Bump,
EggSound: Egg,
EnergizeSound: Energize,
FlapDnSound: FlapDn,
FlapUpSound: FlapUp,
OneUpSound: OneUp,
LavaSound: Lava,
PteroSound: Ptero,
SkidSound: Skid,
SpawnSound: Spawn,
SpawnEnemySound: SpawnEnemy,
Walk1Sound: Walk1,
Walk2Sound: Walk2,
HitSound: Hit,
WhompSound: Whomp,
}
audioContext = audio.NewContext(44100)
)
Expand Down
6 changes: 6 additions & 0 deletions entity/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,14 @@ func buzzardCollision(gs *GameState, p *Player) {
p.Vy = -0.5
p.Y = enemy.Y - float64(enemy.Height)*0.6
enemy.state = UNMOUNTED
if err := gs.Sounds[audio.HitSound].Play(gs.SoundOn); err != nil {
log.Fatal("Error playing sound", err)
}
} else if py > by {
p.state = UNMOUNTED
if err := gs.Sounds[audio.HitSound].Play(gs.SoundOn); err != nil {
log.Fatal("Error playing sound", err)
}
} else {
p.bounce(gs, enemy.Sprite)
enemy.bounce(gs, p.Sprite)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (g *Game) init() {
g.state = &entity.GameState{
Keys: make(map[app.Control]bool),
GodMode: false,
SoundOn: true,
WaveStart: time.Now(),
}

Expand Down

0 comments on commit 5a93e1f

Please sign in to comment.