Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cf4a0143d | ||
|
|
7af60685db |
BIN
assets/.DS_Store
vendored
BIN
assets/.DS_Store
vendored
Binary file not shown.
@@ -8,6 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/audio"
|
"github.com/hajimehoshi/ebiten/v2/audio"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/audio/mp3"
|
||||||
"github.com/hajimehoshi/ebiten/v2/audio/wav"
|
"github.com/hajimehoshi/ebiten/v2/audio/wav"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ func loadTracksForSong(sng int) map[int]*audio.Player {
|
|||||||
|
|
||||||
var SFXLibrary = map[string]*audio.Player{
|
var SFXLibrary = map[string]*audio.Player{
|
||||||
"newLevel": LoadWavAudioFile("audio/portal2.wav", false),
|
"newLevel": LoadWavAudioFile("audio/portal2.wav", false),
|
||||||
"colourMatch": LoadWavAudioFile("audio/portal.wav", false),
|
"colourMatch": LoadMP3AudioFile("audio/portal.mp3", false),
|
||||||
"gameOver": LoadWavAudioFile("audio/gameOver.wav", false),
|
"gameOver": LoadWavAudioFile("audio/gameOver.wav", false),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +65,36 @@ func LoadWavAudioFile(filePath string, loop bool) *audio.Player {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LoadMP3AudioFile(filePath string, loop bool) *audio.Player {
|
||||||
|
|
||||||
|
audioData, err := fs.ReadFile(embeddedFiles, filePath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
stream, err := mp3.DecodeWithSampleRate(sampleRate, bytes.NewReader(audioData))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to decode audio: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var player *audio.Player
|
||||||
|
|
||||||
|
if loop {
|
||||||
|
lengthOfAudioData := int64(len(audioData))
|
||||||
|
loopingStream := audio.NewInfiniteLoop(stream, lengthOfAudioData)
|
||||||
|
player, err = audioContext.NewPlayer(loopingStream)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
player, err = audioContext.NewPlayer(stream)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return player
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func SilenceSongTracks() {
|
func SilenceSongTracks() {
|
||||||
for _, song := range SongTracks {
|
for _, song := range SongTracks {
|
||||||
song.SetVolume(0)
|
song.SetVolume(0)
|
||||||
|
|||||||
BIN
assets/audio/.DS_Store
vendored
BIN
assets/audio/.DS_Store
vendored
Binary file not shown.
BIN
assets/audio/portal.mp3
Normal file
BIN
assets/audio/portal.mp3
Normal file
Binary file not shown.
@@ -12,12 +12,12 @@ var defaultSquareSpacing = 5
|
|||||||
var minBorder = 20
|
var minBorder = 20
|
||||||
var ScoreOffset = 50
|
var ScoreOffset = 50
|
||||||
var HighScoreOffset = 10
|
var HighScoreOffset = 10
|
||||||
var GameGrid Grid
|
var GameGrid *Grid
|
||||||
var MaxGridDimension = 20
|
var MaxGridDimension = 20
|
||||||
|
|
||||||
type Grid struct {
|
type Grid struct {
|
||||||
squareSpacing int
|
squareSpacing int
|
||||||
squares [][]Square
|
squares [][]*Square
|
||||||
startX int
|
startX int
|
||||||
startY int
|
startY int
|
||||||
squareSize int
|
squareSize int
|
||||||
@@ -77,14 +77,14 @@ func BuildGrid(numRows int, numColumns int) {
|
|||||||
grd.startY = currentY
|
grd.startY = currentY
|
||||||
grd.squareSize = sqSize
|
grd.squareSize = sqSize
|
||||||
|
|
||||||
table := make([][]Square, numRows)
|
table := make([][]*Square, numRows)
|
||||||
|
|
||||||
for i := 0; i < numRows; i++ {
|
for i := 0; i < numRows; i++ {
|
||||||
row := make([]Square, numColumns)
|
row := make([]*Square, numColumns)
|
||||||
for j := 0; j < numColumns; j++ {
|
for j := 0; j < numColumns; j++ {
|
||||||
sq := MakeSquare(sqSize)
|
sq := MakeSquare(sqSize)
|
||||||
sq.SetPosition(currentX, currentY)
|
sq.SetPosition(currentX, currentY)
|
||||||
row[j] = sq
|
row[j] = &sq
|
||||||
currentX += sqSize + grd.squareSpacing
|
currentX += sqSize + grd.squareSpacing
|
||||||
}
|
}
|
||||||
table[i] = row
|
table[i] = row
|
||||||
@@ -133,7 +133,7 @@ func BuildGrid(numRows int, numColumns int) {
|
|||||||
}
|
}
|
||||||
grd.coloredSquaresRemaining = squaresToColour
|
grd.coloredSquaresRemaining = squaresToColour
|
||||||
|
|
||||||
GameGrid = grd
|
GameGrid = &grd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (grd *Grid) Draw(screen *ebiten.Image) {
|
func (grd *Grid) Draw(screen *ebiten.Image) {
|
||||||
@@ -174,7 +174,7 @@ func (grd *Grid) ChangeColour(row int, column int, clr color.Color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (grd *Grid) GetSquareAt(row int, column int) *Square {
|
func (grd *Grid) GetSquareAt(row int, column int) *Square {
|
||||||
return &grd.squares[row-1][column-1]
|
return grd.squares[row-1][column-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (grd *Grid) ColouredSquaresRemaining() int {
|
func (grd *Grid) ColouredSquaresRemaining() int {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ var CurrentEnergy = defaultStartingEnergy
|
|||||||
var CurrentLevel = 1
|
var CurrentLevel = 1
|
||||||
|
|
||||||
type Player struct {
|
type Player struct {
|
||||||
square Square
|
square *Square
|
||||||
row int
|
row int
|
||||||
col int
|
col int
|
||||||
currColorIndex int
|
currColorIndex int
|
||||||
@@ -41,7 +41,7 @@ func SetupPlayer() {
|
|||||||
sq.SetPosition(gridSq.x, gridSq.y)
|
sq.SetPosition(gridSq.x, gridSq.y)
|
||||||
|
|
||||||
//setup struct for passing around
|
//setup struct for passing around
|
||||||
ply := Player{square: sq, row: rows, col: 1, currColorIndex: 0}
|
ply := Player{square: &sq, row: rows, col: 1, currColorIndex: 0}
|
||||||
MainPlayer = &ply
|
MainPlayer = &ply
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -2,7 +2,9 @@ module src.robn.tv/MrDonuts/RGB
|
|||||||
|
|
||||||
go 1.21.3
|
go 1.21.3
|
||||||
|
|
||||||
require github.com/hajimehoshi/ebiten/v2 v2.6.2
|
require github.com/hajimehoshi/ebiten/v2 v2.6.3
|
||||||
|
|
||||||
|
require github.com/hajimehoshi/go-mp3 v0.3.4 // indirect
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ebitengine/oto/v3 v3.1.0 // indirect
|
github.com/ebitengine/oto/v3 v3.1.0 // indirect
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -6,6 +6,11 @@ github.com/hajimehoshi/bitmapfont/v3 v3.0.0 h1:r2+6gYK38nfztS/et50gHAswb9hXgxXEC
|
|||||||
github.com/hajimehoshi/bitmapfont/v3 v3.0.0/go.mod h1:+CxxG+uMmgU4mI2poq944i3uZ6UYFfAkj9V6WqmuvZA=
|
github.com/hajimehoshi/bitmapfont/v3 v3.0.0/go.mod h1:+CxxG+uMmgU4mI2poq944i3uZ6UYFfAkj9V6WqmuvZA=
|
||||||
github.com/hajimehoshi/ebiten/v2 v2.6.2 h1:tVa3ZJbp4Uz/VSjmpgtQIOvwd7aQH290XehHBLr2iWk=
|
github.com/hajimehoshi/ebiten/v2 v2.6.2 h1:tVa3ZJbp4Uz/VSjmpgtQIOvwd7aQH290XehHBLr2iWk=
|
||||||
github.com/hajimehoshi/ebiten/v2 v2.6.2/go.mod h1:TZtorL713an00UW4LyvMeKD8uXWnuIuCPtlH11b0pgI=
|
github.com/hajimehoshi/ebiten/v2 v2.6.2/go.mod h1:TZtorL713an00UW4LyvMeKD8uXWnuIuCPtlH11b0pgI=
|
||||||
|
github.com/hajimehoshi/ebiten/v2 v2.6.3 h1:xJ5klESxhflZbPUx3GdIPoITzgPgamsyv8aZCVguXGI=
|
||||||
|
github.com/hajimehoshi/ebiten/v2 v2.6.3/go.mod h1:TZtorL713an00UW4LyvMeKD8uXWnuIuCPtlH11b0pgI=
|
||||||
|
github.com/hajimehoshi/go-mp3 v0.3.4 h1:NUP7pBYH8OguP4diaTZ9wJbUbk3tC0KlfzsEpWmYj68=
|
||||||
|
github.com/hajimehoshi/go-mp3 v0.3.4/go.mod h1:fRtZraRFcWb0pu7ok0LqyFhCUrPeMsGRSVop0eemFmo=
|
||||||
|
github.com/hajimehoshi/oto/v2 v2.3.1/go.mod h1:seWLbgHH7AyUMYKfKYT9pg7PhUu9/SisyJvNTT+ASQo=
|
||||||
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk=
|
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk=
|
||||||
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
|
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
|
||||||
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 h1:3AGKexOYqL+ztdWdkB1bDwXgPBuTS/S8A4WzuTvJ8Cg=
|
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 h1:3AGKexOYqL+ztdWdkB1bDwXgPBuTS/S8A4WzuTvJ8Cg=
|
||||||
@@ -16,6 +21,7 @@ golang.org/x/mobile v0.0.0-20230922142353-e2f452493d57 h1:Q6NT8ckDYNcwmi/bmxe+Xb
|
|||||||
golang.org/x/mobile v0.0.0-20230922142353-e2f452493d57/go.mod h1:wEyOn6VvNW7tcf+bW/wBz1sehi2s2BZ4TimyR7qZen4=
|
golang.org/x/mobile v0.0.0-20230922142353-e2f452493d57/go.mod h1:wEyOn6VvNW7tcf+bW/wBz1sehi2s2BZ4TimyR7qZen4=
|
||||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||||
|
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
|
|||||||
@@ -49,9 +49,7 @@ func (s *PlayLevelState) Update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
geom.MainPlayer.Update()
|
geom.MainPlayer.Update()
|
||||||
if geom.CurrentEnergy == 0 {
|
|
||||||
SM.Transition("game over")
|
|
||||||
}
|
|
||||||
if geom.GameGrid.ColouredSquaresRemaining() == 0 {
|
if geom.GameGrid.ColouredSquaresRemaining() == 0 {
|
||||||
//go to next level
|
//go to next level
|
||||||
newRowSize := min(rand.Intn(5+geom.CurrentLevel)+2, geom.MaxGridDimension)
|
newRowSize := min(rand.Intn(5+geom.CurrentLevel)+2, geom.MaxGridDimension)
|
||||||
@@ -60,6 +58,12 @@ func (s *PlayLevelState) Update() {
|
|||||||
SM.Transition("load")
|
SM.Transition("load")
|
||||||
assets.SFXLibrary["newLevel"].Rewind()
|
assets.SFXLibrary["newLevel"].Rewind()
|
||||||
assets.SFXLibrary["newLevel"].Play()
|
assets.SFXLibrary["newLevel"].Play()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if geom.CurrentEnergy == 0 {
|
||||||
|
SM.Transition("game over")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -67,5 +71,5 @@ func (s *PlayLevelState) Update() {
|
|||||||
func (s *PlayLevelState) Draw(screen *ebiten.Image) {
|
func (s *PlayLevelState) Draw(screen *ebiten.Image) {
|
||||||
geom.GameGrid.Draw(screen)
|
geom.GameGrid.Draw(screen)
|
||||||
geom.MainPlayer.Draw(screen)
|
geom.MainPlayer.Draw(screen)
|
||||||
score.ScoreMngr.Draw(screen)
|
score.ScoreMngr.Draw(screen) //something in here is causing big time CPU usage
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var ScoreMngr ScoreManager
|
var ScoreMngr ScoreManager
|
||||||
|
var smallFace = assets.LoadFontFace("fonts/robot.otf", 12)
|
||||||
|
var bigFace = assets.LoadFontFace("fonts/robot.otf", 20)
|
||||||
|
|
||||||
type ScoreManager struct{}
|
type ScoreManager struct{}
|
||||||
|
|
||||||
@@ -24,22 +26,14 @@ func (sm *ScoreManager) Draw(screen *ebiten.Image) {
|
|||||||
|
|
||||||
w, h := ebiten.WindowSize()
|
w, h := ebiten.WindowSize()
|
||||||
|
|
||||||
//highScoreStr := fmt.Sprintf("High Score: %v", highScore)
|
|
||||||
levelStr := fmt.Sprintf("Level: %v", geom.CurrentLevel)
|
levelStr := fmt.Sprintf("Level: %v", geom.CurrentLevel)
|
||||||
face := assets.LoadFontFace("fonts/robot.otf", 12)
|
|
||||||
|
|
||||||
//draw high score (i.e. best level)
|
|
||||||
//stringWidth := font.MeasureString(face, highScoreStr).Ceil()
|
|
||||||
//text.Draw(screen, highScoreStr, face, w-stringWidth-geom.HighScoreOffset, h-geom.HighScoreOffset, color.White)
|
|
||||||
|
|
||||||
//draw current level
|
//draw current level
|
||||||
//stringWidth = font.MeasureString(face, levelStr).Ceil()
|
text.Draw(screen, levelStr, smallFace, geom.HighScoreOffset, h-geom.HighScoreOffset, color.White)
|
||||||
text.Draw(screen, levelStr, face, geom.HighScoreOffset, h-geom.HighScoreOffset, color.White)
|
|
||||||
|
|
||||||
//draw energy at the top
|
//draw energy at the top
|
||||||
energyStr := fmt.Sprintf("Energy: %v", geom.CurrentEnergy)
|
energyStr := fmt.Sprintf("Energy: %v", geom.CurrentEnergy)
|
||||||
face = assets.LoadFontFace("fonts/robot.otf", 20)
|
stringWidth := font.MeasureString(bigFace, energyStr).Ceil()
|
||||||
stringWidth := font.MeasureString(face, energyStr).Ceil()
|
text.Draw(screen, energyStr, bigFace, w/2-stringWidth/2, geom.ScoreOffset, color.White)
|
||||||
text.Draw(screen, energyStr, face, w/2-stringWidth/2, geom.ScoreOffset, color.White)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user