Browse Source

Add music

main
Trevor Slocum 2 months ago
parent
commit
1e1896cab2
  1. 9
      asset/asset.go
  2. BIN
      asset/sound/suirad.ogg
  3. 1
      flags.go
  4. 2
      level/fish.go
  5. 11
      system/input_move.go
  6. 2
      system/movement.go
  7. 8
      system/renderhud.go
  8. 26
      world/world.go

9
asset/asset.go

@ -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

Binary file not shown.

1
flags.go

@ -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")

2
level/fish.go

@ -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),

11
system/input_move.go

@ -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()

2
system/movement.go

@ -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()
}

8
system/renderhud.go

@ -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}

26
world/world.go

@ -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
}

Loading…
Cancel
Save