Browse Source

Sound effects!

master
Rei 1 year ago
parent
commit
d9328d2ed3
7 changed files with 30 additions and 6 deletions
  1. +10
    -3
      game/Game.go
  2. +11
    -2
      game/Player.go
  3. +8
    -0
      game/ResourceLoader.go
  4. +1
    -1
      main.go
  5. BIN
      res/snd/hurt.ogg
  6. BIN
      res/snd/jump.ogg
  7. BIN
      res/snd/swap.ogg

+ 10
- 3
game/Game.go View File

@@ -9,24 +9,31 @@ type Updateable interface {
}

type Game struct {
ResourceLoader ResourceLoader
}

func (g *Game) Run() {

loader = CreateResourceLoader()

rl.SetConfigFlags(rl.FlagWindowResizable)
rl.InitWindow(1600, 900, "Achromata")
defer rl.CloseWindow()
rl.InitAudioDevice()
defer rl.CloseAudioDevice()

background := g.ResourceLoader.LoadMusic("res/snd/bgtheme.ogg") // Chris_Zabriskie_-_01_-_The_Temperature_of_the_Air_on_the_Bow_of_the_Kaleetan
background := loader.LoadMusic("res/snd/bgtheme.ogg") // Chris_Zabriskie_-_01_-_The_Temperature_of_the_Air_on_the_Bow_of_the_Kaleetan
rl.PlayMusicStream(*background)

loader.LoadSound(JUMPSOUND)
loader.LoadSound(SWAPSOUND)
loader.LoadSound(HURTSOUND)

rl.SetTargetFPS(60)

renderTarget := rl.LoadRenderTexture(320, 180)
rl.SetTextureFilter(renderTarget.Texture, rl.FilterPoint)

texture, err := g.ResourceLoader.LoadPicture("res/img/player.png")
texture, err := loader.LoadPicture("res/img/player.png")
if err != nil {
panic(err)
}

+ 11
- 2
game/Player.go View File

@@ -115,6 +115,12 @@ func (p *Player) Update(level *Level) {
}
}

func (p *Player) Hurt(level *Level) {
p.X = 0
p.Y = 0
rl.PlaySound(*(loader.sounds[HURTSOUND]))
}

func (p *Player) UpdateDashing(level *Level) {
if p.dashLeftX > 0 {
p.dashLeftX -= dashSpeed
@@ -151,6 +157,7 @@ func (p *Player) UpdateDashing(level *Level) {
}
p.UpdateCollission(level)
if p.dashLeftX == 0 && p.dashLeftY == 0 {
rl.PlaySound(*(loader.sounds[JUMPSOUND]))
p.state = PLAYERSTATE_NORMAL
}
}
@@ -183,6 +190,7 @@ func (p *Player) UpdateNormal(level *Level) {
if rl.IsKeyPressed(rl.KeySpace) && p.canJump && p.vsp <= 0 {
p.vsp = jumpPower
p.canJump = false
rl.PlaySound(*(loader.sounds[JUMPSOUND]))
}

if rl.IsKeyPressed(rl.KeyE) && p.canSwitch {
@@ -197,6 +205,8 @@ func (p *Player) UpdateNormal(level *Level) {
p.dashLeftY = int32(vDir * dashStrength)
}
p.state = PLAYERSTATE_DASHING
rl.PlaySound(*(loader.sounds[SWAPSOUND]))

return
}

@@ -228,8 +238,7 @@ func (p *Player) UpdateCollission(level *Level) {

// Before we do anything we check if we landed in some spikes
if PlayerUpdateCollides(p.X+p.hsp, p.Y+p.vsp, p.GetWidth(), p.GetHeight(), level) == COLLISSIONTYPE_SPIKES {
p.X = 0
p.Y = 0
p.Hurt(level)
return
}


+ 8
- 0
game/ResourceLoader.go View File

@@ -6,6 +6,14 @@ import (
"github.com/gen2brain/raylib-go/raylib"
)

var loader ResourceLoader

const (
JUMPSOUND = "res/snd/jump.ogg"
HURTSOUND = "res/snd/hurt.ogg"
SWAPSOUND = "res/snd/swap.ogg"
)

type ResourceLoader struct {
images map[string]*rl.Texture2D
sounds map[string]*rl.Sound

+ 1
- 1
main.go View File

@@ -5,6 +5,6 @@ import (
)

func main() {
game := game.Game{ResourceLoader: game.CreateResourceLoader()}
game := game.Game{}
game.Run()
}

BIN
res/snd/hurt.ogg View File


BIN
res/snd/jump.ogg View File


BIN
res/snd/swap.ogg View File


Loading…
Cancel
Save