Browse Source

Sound effects!

master
Rei 10 months 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 {
9 9
 }
10 10
 
11 11
 type Game struct {
12
-	ResourceLoader ResourceLoader
13 12
 }
14 13
 
15 14
 func (g *Game) Run() {
15
+
16
+	loader = CreateResourceLoader()
17
+
16 18
 	rl.SetConfigFlags(rl.FlagWindowResizable)
17 19
 	rl.InitWindow(1600, 900, "Achromata")
18 20
 	defer rl.CloseWindow()
19 21
 	rl.InitAudioDevice()
20 22
 	defer rl.CloseAudioDevice()
21 23
 
22
-	background := g.ResourceLoader.LoadMusic("res/snd/bgtheme.ogg") // Chris_Zabriskie_-_01_-_The_Temperature_of_the_Air_on_the_Bow_of_the_Kaleetan
24
+	background := loader.LoadMusic("res/snd/bgtheme.ogg") // Chris_Zabriskie_-_01_-_The_Temperature_of_the_Air_on_the_Bow_of_the_Kaleetan
23 25
 	rl.PlayMusicStream(*background)
26
+
27
+	loader.LoadSound(JUMPSOUND)
28
+	loader.LoadSound(SWAPSOUND)
29
+	loader.LoadSound(HURTSOUND)
30
+
24 31
 	rl.SetTargetFPS(60)
25 32
 
26 33
 	renderTarget := rl.LoadRenderTexture(320, 180)
27 34
 	rl.SetTextureFilter(renderTarget.Texture, rl.FilterPoint)
28 35
 
29
-	texture, err := g.ResourceLoader.LoadPicture("res/img/player.png")
36
+	texture, err := loader.LoadPicture("res/img/player.png")
30 37
 	if err != nil {
31 38
 		panic(err)
32 39
 	}

+ 11
- 2
game/Player.go View File

@@ -115,6 +115,12 @@ func (p *Player) Update(level *Level) {
115 115
 	}
116 116
 }
117 117
 
118
+func (p *Player) Hurt(level *Level) {
119
+	p.X = 0
120
+	p.Y = 0
121
+	rl.PlaySound(*(loader.sounds[HURTSOUND]))
122
+}
123
+
118 124
 func (p *Player) UpdateDashing(level *Level) {
119 125
 	if p.dashLeftX > 0 {
120 126
 		p.dashLeftX -= dashSpeed
@@ -151,6 +157,7 @@ func (p *Player) UpdateDashing(level *Level) {
151 157
 	}
152 158
 	p.UpdateCollission(level)
153 159
 	if p.dashLeftX == 0 && p.dashLeftY == 0 {
160
+		rl.PlaySound(*(loader.sounds[JUMPSOUND]))
154 161
 		p.state = PLAYERSTATE_NORMAL
155 162
 	}
156 163
 }
@@ -183,6 +190,7 @@ func (p *Player) UpdateNormal(level *Level) {
183 190
 	if rl.IsKeyPressed(rl.KeySpace) && p.canJump && p.vsp <= 0 {
184 191
 		p.vsp = jumpPower
185 192
 		p.canJump = false
193
+		rl.PlaySound(*(loader.sounds[JUMPSOUND]))
186 194
 	}
187 195
 
188 196
 	if rl.IsKeyPressed(rl.KeyE) && p.canSwitch {
@@ -197,6 +205,8 @@ func (p *Player) UpdateNormal(level *Level) {
197 205
 			p.dashLeftY = int32(vDir * dashStrength)
198 206
 		}
199 207
 		p.state = PLAYERSTATE_DASHING
208
+		rl.PlaySound(*(loader.sounds[SWAPSOUND]))
209
+
200 210
 		return
201 211
 	}
202 212
 
@@ -228,8 +238,7 @@ func (p *Player) UpdateCollission(level *Level) {
228 238
 
229 239
 	// Before we do anything we check if we landed in some spikes
230 240
 	if PlayerUpdateCollides(p.X+p.hsp, p.Y+p.vsp, p.GetWidth(), p.GetHeight(), level) == COLLISSIONTYPE_SPIKES {
231
-		p.X = 0
232
-		p.Y = 0
241
+		p.Hurt(level)
233 242
 		return
234 243
 	}
235 244
 

+ 8
- 0
game/ResourceLoader.go View File

@@ -6,6 +6,14 @@ import (
6 6
 	"github.com/gen2brain/raylib-go/raylib"
7 7
 )
8 8
 
9
+var loader ResourceLoader
10
+
11
+const (
12
+	JUMPSOUND = "res/snd/jump.ogg"
13
+	HURTSOUND = "res/snd/hurt.ogg"
14
+	SWAPSOUND = "res/snd/swap.ogg"
15
+)
16
+
9 17
 type ResourceLoader struct {
10 18
 	images map[string]*rl.Texture2D
11 19
 	sounds map[string]*rl.Sound

+ 1
- 1
main.go View File

@@ -5,6 +5,6 @@ import (
5 5
 )
6 6
 
7 7
 func main() {
8
-	game := game.Game{ResourceLoader: game.CreateResourceLoader()}
8
+	game := game.Game{}
9 9
 	game.Run()
10 10
 }

BIN
res/snd/hurt.ogg View File


BIN
res/snd/jump.ogg View File


BIN
res/snd/swap.ogg View File


Loading…
Cancel
Save