diff --git a/TODO.md b/TODO.md index 7d4705a..fa55369 100644 --- a/TODO.md +++ b/TODO.md @@ -11,4 +11,4 @@ - [ ] Fix z-fighting of monsters. - [ ] Add exploding animation of monsters. - [ ] Add audio settings (music & sound volume). -- [ ] Hearts must be saved as well for resume. \ No newline at end of file +- [X] Hearts must be saved as well for resume. \ No newline at end of file diff --git a/cmd/tins2021/appcontext.go b/cmd/tins2021/appcontext.go index e51b68d..392bef4 100644 --- a/cmd/tins2021/appcontext.go +++ b/cmd/tins2021/appcontext.go @@ -54,7 +54,7 @@ func (app *appContext) Play(ctx ui.Context) { level := tins2021.NewLevel() level.Randomize(0, numberOfStars) - app.Score.Current = tins2021.Score{} + app.ResetCurrentScore() app.show(ctx, newLevelControl(app, ctx, level)) } @@ -74,11 +74,22 @@ func (app *appContext) PlayNext(ctx ui.Context, controller *levelController) { func (app *appContext) PlayResume(ctx ui.Context) { level := tins2021.NewLevel() level.Score = app.Score.Current.Score + level.Lives = app.Score.CurrentLives level.Randomize(app.Score.Current.Difficulty, numberOfStars) app.show(ctx, newLevelControl(app, ctx, level)) } +func (app *appContext) ResetCurrentScore() { + app.Score.Current = tins2021.Score{} + app.Score.CurrentLives = 0 +} + +func (app *appContext) SetCurrentScore(level *tins2021.Level) { + app.Score.Current = tins2021.NewScore(level.Score, level.Difficulty+1) + app.Score.CurrentLives = level.Lives +} + func (app *appContext) show(ctx ui.Context, control ui.Control) { app.setView(control) if _, ok := control.(*levelController); ok { diff --git a/cmd/tins2021/levelcontroller.go b/cmd/tins2021/levelcontroller.go index 5f74bed..124f246 100644 --- a/cmd/tins2021/levelcontroller.go +++ b/cmd/tins2021/levelcontroller.go @@ -91,7 +91,7 @@ func (r *levelController) updateHighscore() bool { if highscore { r.app.Score.Highscores = highscores } - r.app.Score.Current = tins2021.Score{} // reset score + r.app.ResetCurrentScore() return highscore } @@ -101,7 +101,7 @@ func (r *levelController) Handle(ctx ui.Context, e ui.Event) bool { switch e.Key { case ui.KeyEscape: if r.Level.StarsCollected == r.Level.Stars { - r.app.Score.Current = tins2021.NewScore(r.Level.Score, r.Level.Difficulty+1) + r.app.SetCurrentScore(r.Level) } r.app.ShowMainMenu(ctx) } @@ -116,7 +116,7 @@ func (r *levelController) Handle(ctx ui.Context, e ui.Event) bool { case *ui.KeyDownEvent: switch e.Key { case ui.KeyEnter: - r.app.Score.Current = tins2021.NewScore(r.Level.Score, r.Level.Difficulty+1) + r.app.SetCurrentScore(r.Level) r.app.PlayNext(ctx, r) } } diff --git a/score.go b/score.go index 6d2f83e..5d2ca83 100644 --- a/score.go +++ b/score.go @@ -57,8 +57,9 @@ func (s *Score) Validate() bool { } type ScoreState struct { - Current Score - Highscores Highscores + Current Score + CurrentLives int + Highscores Highscores } func LoadScores() (ScoreState, error) {