From cd2c3612e099f5a14750de132399dc8e899f16d5 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Sun, 2 Jun 2024 15:43:49 +0300 Subject: [PATCH] BUGFIX: Fixed level progression check --- src/main.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main.go b/src/main.go index 901d06d..99a862b 100644 --- a/src/main.go +++ b/src/main.go @@ -133,6 +133,10 @@ func (g *Game) SaveData() error { return nil } +func getPointsForLevel(level uint32) uint64 { + return 100 * uint64(level) +} + func (g *Game) Update() error { if ebiten.IsWindowBeingClosed() { return ebiten.Termination @@ -187,16 +191,6 @@ func (g *Game) Update() error { g.PlaySound("boop") } - /////////// TODO - if g.Save.Points > 0 && g.Save.Points%100 < uint64(g.Save.Level) { - // Level progression - g.Save.Level++ - 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 if g.AnimationData.Theta >= 0.03 { g.AnimationData.BounceDirectionFlag = false @@ -216,6 +210,13 @@ func (g *Game) Update() error { g.PassiveIncomeTicker++ } + if g.Save.Points > 0 && g.Save.Points >= getPointsForLevel(g.Save.Level) { + // Level progression + g.Save.Level++ + g.Save.PassiveIncome++ + g.PlaySound("levelup") + } + return nil }