From 80605f6c838991f7b7cf2127483ed81ddf07c513 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Sat, 1 Jun 2024 17:05:46 +0300 Subject: [PATCH] FEATURE: Added passive income on level up --- src/main.go | 49 ++++++++++++++++++++++++++++++------------------ src/save/save.go | 2 ++ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/main.go b/src/main.go index 8da1b2b..0d4f31f 100644 --- a/src/main.go +++ b/src/main.go @@ -42,14 +42,15 @@ type AnimationData struct { } type Game struct { - WorkingDir string - Config conf.Configuration - Save save.Save - AudioContext *audio.Context - AudioPlayers map[string]*audio.Player - ImageResources map[string]*ebiten.Image - Font font.Face - AnimationData AnimationData + WorkingDir string + Config conf.Configuration + Save save.Save + AudioContext *audio.Context + AudioPlayers map[string]*audio.Player + ImageResources map[string]*ebiten.Image + Font font.Face + AnimationData AnimationData + PassiveIncomeTicker int } func NewGame() *Game { @@ -84,6 +85,7 @@ func NewGame() *Game { BounceDirectionFlag: true, Squish: 0, }, + PassiveIncomeTicker: 0, } } @@ -163,15 +165,16 @@ func (g *Game) Update() error { g.Save.TimesClicked++ g.Save.Points++ g.AnimationData.Squish += 0.5 - go g.PlaySound("boop") + g.PlaySound("boop") } - if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) && - g.Save.Points > 0 && - g.Save.Points%100 == 0 { + if g.Save.Points > 0 && g.Save.Points%100 == 0 { // Level progression g.Save.Level++ - go g.PlaySound("levelup") + g.Save.PassiveIncome++ + // Bump points number immediately in order to not mistakengly level up on the next update + g.Save.Points++ + g.PlaySound("levelup") } // Capybara Animation @@ -185,6 +188,14 @@ func (g *Game) Update() error { g.AnimationData.Squish -= 0.05 } + // Passive points income + if g.PassiveIncomeTicker == ebiten.TPS() { + g.PassiveIncomeTicker = 0 + g.Save.Points += g.Save.PassiveIncome + } else { + g.PassiveIncomeTicker++ + } + return nil } @@ -250,7 +261,7 @@ func (g *Game) Draw(screen *ebiten.Image) { screen, msg, g.Font, - screen.Bounds().Dx()-len(msg)*24, + screen.Bounds().Dx()-len(msg)*19, 30, color.White, ) @@ -262,7 +273,8 @@ func (g *Game) Draw(screen *ebiten.Image) { msg, g.Font, 10, - screen.Bounds().Dy()-30, + // screen.Bounds().Dy()-30, + screen.Bounds().Dy()-24*2, color.White, ) @@ -272,8 +284,9 @@ func (g *Game) Draw(screen *ebiten.Image) { screen, msg, g.Font, - screen.Bounds().Dx()-len(msg)*19, - screen.Bounds().Dy()-30, + // screen.Bounds().Dx()-len(msg)*17, + 10, + screen.Bounds().Dy()-24, color.White, ) } @@ -342,7 +355,7 @@ func main() { ebiten.SetWindowClosingHandled(true) // So we can save data ebiten.SetRunnableOnUnfocused(true) ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled) - ebiten.SetWindowSizeLimits(480, 320, -1, -1) + ebiten.SetWindowSizeLimits(380, 576, -1, -1) ebiten.SetTPS(60) ebiten.SetWindowSize(game.Config.WindowSize[0], game.Config.WindowSize[1]) ebiten.SetWindowPosition(game.Config.LastWindowPosition[0], game.Config.LastWindowPosition[1]) diff --git a/src/save/save.go b/src/save/save.go index 410ac9c..2738bfd 100644 --- a/src/save/save.go +++ b/src/save/save.go @@ -16,6 +16,7 @@ type Save struct { CreatedUnix uint64 `json:"createdUnix"` LastOpenedUnix uint64 `json:"lastOpenedUnix"` TimesClicked uint64 `json:"timesClicked"` + PassiveIncome uint64 `json:"passiveIncome"` } // Returns a blank save file structure @@ -27,6 +28,7 @@ func Default() Save { CreatedUnix: uint64(time.Now().Unix()), LastOpenedUnix: uint64(time.Now().Unix()), TimesClicked: 0, + PassiveIncome: 0, } }