Skip to content

Commit

Permalink
Update to use latest G3N
Browse files Browse the repository at this point in the history
  • Loading branch information
danaugrs committed Apr 2, 2022
1 parent 05d2e5f commit 2a90032
Show file tree
Hide file tree
Showing 15 changed files with 1,025 additions and 1,041 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Gokoban is a 3D puzzle game written in Go. You control the Go gopher, and your o

It was created using [G3N](https://github.com/g3n/engine) for the [2017 Gopher Game Jam](https://itch.io/jam/gopher-jam) on [itch.io](https://itch.io).

### [:white_check_mark: Download Windows 64-bit Precompiled Binary](https://github.com/danaugrs/gokoban/archive/win64-bin.zip)
### [ Download Windows 64-bit Precompiled Binary (v1.0)](https://github.com/danaugrs/gokoban/archive/win64-bin.zip)

![Gokoban Screenshots](img/screenshots.gif)

Expand Down
5 changes: 2 additions & 3 deletions animation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ func NewAnimation(node *core.Node, dest *math32.Vector3, cb func(interface{}), c
// and calls the callback with the previously provided args once finished
func (a *Animation) Update(timeDelta float64) bool {
pos := a.node.Position()
delta := math32.NewVector3(0, 0, 0)
delta.Add(a.dest)
delta := a.dest.Clone()
delta.Sub(&pos)
dist := delta.Length()
delta = delta.Normalize().MultiplyScalar(a.speed * float32(timeDelta))
delta = delta.Normalize().MultiplyScalar(-a.speed * float32(timeDelta))
if dist > delta.Length() {
a.node.SetPositionVec(pos.Sub(delta))
return true
Expand Down
156 changes: 156 additions & 0 deletions audio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Copyright 2017 Daniel Salvadori. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
"github.com/g3n/engine/audio"
)

// Audio contains all sounds and music used by the game
type Audio struct {
// Music
musicGame *audio.Player
musicMenu *audio.Player

// Gameplay sound effects
levelDone *audio.Player
levelRestart *audio.Player
levelFail *audio.Player
gameComplete *audio.Player

// User interface sound effects
click *audio.Player
hover *audio.Player

// Gopher sound effects
gopherWalk *audio.Player
gopherBump *audio.Player
gopherHurt *audio.Player
gopherFallStart *audio.Player
gopherFallEnd *audio.Player

// Box sound effects
boxPush *audio.Player
boxOnPad *audio.Player
boxOffPad *audio.Player
boxFallStart *audio.Player
boxFallEnd *audio.Player

// Elevator sound effects
elevatorUp *audio.Player
elevatorDown *audio.Player
}

// NewAudio creates and returns a new Audio instance with sounds and music ready to go
func NewAudio() *Audio {
a := new(Audio)

// Helper function to create player and handle errors
createPlayer := func(fileName string) *audio.Player {
log.Debug("Creating sound player for: " + fileName)
p, err := audio.NewPlayer(fileName)
if err != nil {
log.Error("Failed to create sound player: %v", err)
}
return p
}

// Music
a.musicGame = createPlayer("./audio/music/Lost-Jungle_Looping.ogg")
a.musicGame.SetLooping(true)
a.musicMenu = createPlayer("./audio/music/Spooky-Island.ogg")
a.musicMenu.SetLooping(true)

// Gameplay sound effects
a.levelDone = createPlayer("./audio/sfx/level_done.ogg")
a.levelDone.SetRolloffFactor(0)
a.levelRestart = createPlayer("./audio/sfx/level_restart.ogg")
a.levelRestart.SetRolloffFactor(0)
a.levelFail = createPlayer("./audio/sfx/level_fail.ogg")
a.levelFail.SetRolloffFactor(0)
a.gameComplete = createPlayer("./audio/sfx/game_complete.ogg")
a.gameComplete.SetRolloffFactor(0)

// User interface sound effects
a.click = createPlayer("./audio/sfx/button_click.ogg")
a.click.SetRolloffFactor(0)
a.hover = createPlayer("./audio/sfx/button_hover.ogg")
a.hover.SetRolloffFactor(0)

// Gopher sound effects
a.gopherWalk = createPlayer("./audio/sfx/gopher_walk.ogg")
a.gopherWalk.SetRolloffFactor(0)
a.gopherBump = createPlayer("./audio/sfx/gopher_bump.ogg")
a.gopherBump.SetRolloffFactor(0)
a.gopherHurt = createPlayer("./audio/sfx/gopher_hurt.ogg")
a.gopherHurt.SetRolloffFactor(0)
a.gopherFallStart = createPlayer("./audio/sfx/gopher_fall_start.ogg")
a.gopherFallStart.SetRolloffFactor(0)
a.gopherFallEnd = createPlayer("./audio/sfx/gopher_fall_end.ogg")
a.gopherFallEnd.SetRolloffFactor(0)

// Box sound effects
a.boxPush = createPlayer("./audio/sfx/box_push.ogg")
a.boxPush.SetRolloffFactor(0)
a.boxOnPad = createPlayer("./audio/sfx/box_on.ogg")
a.boxOnPad.SetRolloffFactor(0)
a.boxOffPad = createPlayer("./audio/sfx/box_off.ogg")
a.boxOffPad.SetRolloffFactor(0)
a.boxFallStart = createPlayer("./audio/sfx/box_fall_start.ogg")
a.boxFallStart.SetRolloffFactor(0)
a.boxFallEnd = createPlayer("./audio/sfx/box_fall_end.ogg")
a.boxFallEnd.SetRolloffFactor(0)

// Elevator sound effects
a.elevatorUp = createPlayer("./audio/sfx/elevator_up.ogg")
a.elevatorUp.SetLooping(true)
a.elevatorUp.SetRolloffFactor(0)
a.elevatorDown = createPlayer("./audio/sfx/elevator_down.ogg")
a.elevatorDown.SetLooping(true)
a.elevatorDown.SetRolloffFactor(0)

return a
}

// SetMusicVolume sets the volume of the music
func (a *Audio) SetMusicVolume(vol float32) {
log.Debug("Set Music Volume %v", vol)

a.musicGame.SetGain(vol)
a.musicMenu.SetGain(vol)
}

// SetSfxVolume sets the volume of all sound effects
func (a *Audio) SetSfxVolume(vol float32) {
log.Debug("Set Sfx Volume %v", vol)

// Gameplay sound effects
a.levelDone.SetGain(vol)
a.levelRestart.SetGain(vol)
a.levelFail.SetGain(vol)
a.gameComplete.SetGain(vol)

// User interface sound effects
a.click.SetGain(vol)
a.hover.SetGain(vol)

// Gopher sound effects
a.gopherWalk.SetGain(vol)
a.gopherBump.SetGain(vol)
a.gopherHurt.SetGain(vol)
a.gopherFallStart.SetGain(vol)
a.gopherFallEnd.SetGain(vol)

// Box sound effects
a.boxPush.SetGain(vol)
a.boxOnPad.SetGain(vol)
a.boxOffPad.SetGain(vol)
a.boxFallStart.SetGain(vol)
a.boxFallEnd.SetGain(vol)

// Elevator sound effects
a.elevatorUp.SetGain(vol)
a.elevatorDown.SetGain(vol)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.17
// To run with a local version of G3N uncomment the following line
// replace github.com/g3n/engine => ../g3n/engine

require github.com/g3n/engine v0.2.0
require github.com/g3n/engine v0.2.1-0.20220402201105-253be6caa10f

require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/g3n/engine v0.2.0 h1:7dmj4c+3xHcBnYrVmRuVf/oZ2JycxJU9Y+2FQj1Af2Y=
github.com/g3n/engine v0.2.0/go.mod h1:rnj8jiLdKEDI8VbveKhmdL4rovjjy+uxNP5YROg2x8g=
github.com/g3n/engine v0.2.1-0.20220402201105-253be6caa10f h1:VZq9J1pB5yzz81bKY7pB1SdSqVJoF3YiC9vhw90Byvw=
github.com/g3n/engine v0.2.1-0.20220402201105-253be6caa10f/go.mod h1:rnj8jiLdKEDI8VbveKhmdL4rovjjy+uxNP5YROg2x8g=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb h1:T6gaWBvRzJjuOrdCtg8fXXjKai2xSDqWTcKFUPuw8Tw=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
Expand Down
Loading

0 comments on commit 2a90032

Please sign in to comment.