Add music

This commit is contained in:
Trevor Slocum 2022-06-12 20:05:43 -07:00
parent e34cc91c28
commit 1e1896cab2
8 changed files with 43 additions and 16 deletions

View File

@ -17,7 +17,7 @@ import (
const sampleRate = 44100
//go:embed image
//go:embed image sound
var FS embed.FS
var ColorWater = color.RGBA{96, 160, 168, 255}
@ -37,6 +37,10 @@ var (
ImgPeepClothesPants = LoadImage("image/cozy-people/clothes/pants.png")
)
var (
SoundMusic *audio.Player
)
func init() {
ImgWhiteSquare.Fill(color.White)
ImgBlackSquare.Fill(color.Black)
@ -49,7 +53,8 @@ func newFilledImage(w int, h int, c color.Color) *ebiten.Image {
}
func LoadSounds(ctx *audio.Context) {
// TODO
SoundMusic = LoadOGG(ctx, "sound/suirad.ogg", true)
SoundMusic.SetVolume(0.6)
}
func LoadImage(p string) *ebiten.Image {

BIN
asset/sound/suirad.ogg Normal file

Binary file not shown.

View File

@ -16,6 +16,7 @@ func parseFlags() {
noSplash bool
)
flag.BoolVar(&fullscreen, "fullscreen", false, "run in fullscreen mode")
flag.BoolVar(&world.World.StartMuted, "mute", false, "mute music")
flag.Int64Var(&world.World.ForceSeed, "seed", 0, "seed for random level generation")
flag.BoolVar(&noSplash, "no-splash", false, "skip splash screen")
flag.BoolVar(&world.World.GodMode, "god", false, "enable god mode")

View File

@ -257,7 +257,7 @@ var AllFish = map[FishType]*FishInfo{
FireRate: baseFireRate - (fireRateIncrement * 10),
BulletSpeed: 2 - (bulletSpeedIncrement * 23),
},
FishAnglerfish: {
FishAngler: {
Name: "ANGLER",
Damage: 1,
FireRate: baseFireRate - (fireRateIncrement * 10),

View File

@ -4,6 +4,8 @@ import (
"math"
"os"
"code.rocketnine.space/tslocum/fishfightback/asset"
"code.rocketnine.space/tslocum/fishfightback/component"
"code.rocketnine.space/tslocum/fishfightback/world"
"code.rocketnine.space/tslocum/gohan"
@ -62,6 +64,15 @@ func (s *playerMoveSystem) Update(e gohan.Entity) error {
return nil
}
if inpututil.IsKeyJustPressed(ebiten.KeyM) {
if asset.SoundMusic.IsPlaying() {
asset.SoundMusic.Pause()
} else {
asset.SoundMusic.Play()
}
return nil
}
if !world.World.GameStarted {
if ebiten.IsKeyPressed(ebiten.KeyEnter) || ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
world.StartGame()

View File

@ -164,6 +164,8 @@ func (s *MovementSystem) Update(e gohan.Entity) error {
creep.DamageTicks = 6
world.World.Kills++
world.World.Score += 25
world.World.ScoreUpdated = true
if world.World.Kills == world.World.NeedKills {
world.LevelUp()
}

View File

@ -25,8 +25,6 @@ type RenderHUDSystem struct {
killInfoWidth float64
lastScore int
padding float64
}
@ -36,7 +34,6 @@ func NewRenderHUDSystem() *RenderHUDSystem {
msgImg: ebiten.NewImage(200, 200),
tmpImg: ebiten.NewImage(200, 200),
levelUpImg: ebiten.NewImage(200, 200),
lastScore: -1,
padding: 4,
}
@ -58,8 +55,9 @@ func (s *RenderHUDSystem) Draw(_ gohan.Entity, screen *ebiten.Image) error {
return nil
}
if world.World.Score != s.lastScore {
if world.World.ScoreUpdated {
s.drawScore()
world.World.ScoreUpdated = false
}
if world.World.KillInfoUpdated {
@ -86,7 +84,7 @@ func (s *RenderHUDSystem) drawLevelUp() {
} else if world.World.LevelUpTicks != 0 {
message = fmt.Sprintf("YOU EVOLVED INTO A %s!", level.AllFish[world.World.Fish].Name)
} else {
message = world.NumberPrinter.Sprintf("%d TO EVOLVE", world.World.NeedKills-world.World.Kills)
message = world.NumberPrinter.Sprintf("%d TO GO!", world.World.NeedKills-world.World.Kills)
}
split := []string{message}

View File

@ -45,9 +45,10 @@ type GameWorld struct {
DisableEsc bool
Debug int
NoClip bool
GodMode bool
Debug int
StartMuted bool
NoClip bool
GodMode bool
GameStarted bool
GameStartedTicks int
@ -80,7 +81,8 @@ type GameWorld struct {
SectionB *Section
FirstSectionB bool
Score int
Score int
ScoreUpdated bool
Fish level.FishType
Kills int
@ -99,6 +101,7 @@ func Reset() {
World.FirstSectionB = false
World.Player = 0
World.Score = 0
World.ScoreUpdated = true
World.SectionA.ShoreDepth = 0
World.SectionB.ShoreDepth = 0
@ -149,6 +152,10 @@ func StartGame() {
return
}
World.GameStarted = true
if !World.StartMuted {
asset.SoundMusic.Play()
}
}
func SetMessage(message string, duration int) {
@ -191,17 +198,20 @@ func MaxCreeps() int {
}
func NeededKills() int {
const minCreeps = 2
const minCreeps = 7
level := int(World.Fish)
maxCreeps := minCreeps + math.Pow(2, float64(level))
maxCreeps := minCreeps + level*7
log.Println("need creep", level, maxCreeps)
return int(maxCreeps * 2)
return int(maxCreeps)
}
func LevelUp() {
SetFish(World.Fish + 1)
World.Kills = 0
World.LevelUpTicks = 144 * 3
World.LevelUpTicks = 144 * 2
World.Score += int(World.Fish) * 1000
World.ScoreUpdated = true
}