Browse Source

Feature: Squish on click; BUGFIX: Fixed sound not playing every second click

master
parent
commit
371086cf63
  1. 39
      src/main.go

39
src/main.go

@ -20,8 +20,6 @@ import (
"github.com/hajimehoshi/ebiten/v2/text" "github.com/hajimehoshi/ebiten/v2/text"
"golang.org/x/image/font" "golang.org/x/image/font"
"golang.org/x/image/font/opentype" "golang.org/x/image/font/opentype"
_ "net/http/pprof"
) )
const Version string = "v0.1" const Version string = "v0.1"
@ -37,6 +35,12 @@ const (
SaveFileName string = "capyclickSave.json" SaveFileName string = "capyclickSave.json"
) )
type AnimationData struct {
Squish float64
Theta float64
BounceDirectionFlag bool
}
type Game struct { type Game struct {
WorkingDir string WorkingDir string
Config conf.Configuration Config conf.Configuration
@ -45,6 +49,7 @@ type Game struct {
AudioPlayers map[string]*audio.Player AudioPlayers map[string]*audio.Player
ImageResources map[string]*ebiten.Image ImageResources map[string]*ebiten.Image
Font font.Face Font font.Face
AnimationData AnimationData
} }
func NewGame() *Game { func NewGame() *Game {
@ -72,14 +77,19 @@ func NewGame() *Game {
DPI: 72, DPI: 72,
Hinting: font.HintingVertical, Hinting: font.HintingVertical,
}), }),
AnimationData: AnimationData{
Theta: 0.0,
BounceDirectionFlag: true,
Squish: 0,
},
} }
} }
// Plays sound and rewinds the player // Plays sound and rewinds the player
func (g *Game) PlaySound(soundKey string) { func (g *Game) PlaySound(soundKey string) {
if strings.TrimSpace(soundKey) != "" { if strings.TrimSpace(soundKey) != "" {
g.AudioPlayers[soundKey].Play()
g.AudioPlayers[soundKey].Rewind() g.AudioPlayers[soundKey].Rewind()
g.AudioPlayers[soundKey].Play()
} }
} }
@ -150,6 +160,7 @@ func (g *Game) Update() error {
// Click! // Click!
g.Save.TimesClicked++ g.Save.TimesClicked++
g.Save.Points++ g.Save.Points++
g.AnimationData.Squish += 0.5
go g.PlaySound("boop") go g.PlaySound("boop")
} }
@ -161,6 +172,17 @@ func (g *Game) Update() error {
go g.PlaySound("levelup") go g.PlaySound("levelup")
} }
// Capybara Animation
if g.AnimationData.Theta >= 0.03 {
g.AnimationData.BounceDirectionFlag = false
} else if g.AnimationData.Theta <= -0.03 {
g.AnimationData.BounceDirectionFlag = true
}
if g.AnimationData.Squish >= 0 {
g.AnimationData.Squish -= 0.05
}
return nil return nil
} }
@ -183,7 +205,16 @@ func (g *Game) Draw(screen *ebiten.Image) {
scale := 10.0 scale := 10.0
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Scale(scale, scale) if g.AnimationData.BounceDirectionFlag {
g.AnimationData.Theta += 0.001
} else {
g.AnimationData.Theta -= 0.001
}
op.GeoM.Scale(scale+g.AnimationData.Squish, scale-g.AnimationData.Squish)
op.GeoM.Rotate(g.AnimationData.Theta)
width := g.ImageResources[capybaraKey].Bounds().Dx() * int(scale) width := g.ImageResources[capybaraKey].Bounds().Dx() * int(scale)
height := g.ImageResources[capybaraKey].Bounds().Dy() * int(scale) height := g.ImageResources[capybaraKey].Bounds().Dy() * int(scale)
op.GeoM.Translate( op.GeoM.Translate(

Loading…
Cancel
Save