lotsa fixes:

- fixed obstacle collision and death on obstacle spike
- moved player move into separate loop after other collision checks
  are done
- fixed level setup, generation and selection
- added test levels for obstacles
This commit is contained in:
2024-02-21 12:50:17 +01:00
parent 646b227b8e
commit f696660ccd
17 changed files with 74 additions and 15 deletions

View File

@@ -50,6 +50,8 @@ func (scene *AboutScene) ResetNext() {
scene.Next = scene.Whoami
}
func (scene *AboutScene) SetLevel(level int) {}
func (scene *AboutScene) Clearscreen() bool {
return true
}

View File

@@ -39,7 +39,7 @@ func NewGame(width, height, cellsize, startlevel int, startscene SceneName) *Gam
game.Scenes[Menu] = NewMenuScene(game)
game.Scenes[About] = NewAboutScene(game)
game.Scenes[Popup] = NewPopupScene(game)
//game.Scenes[Play] = NewLevelScene(game, startlevel)
game.Scenes[Play] = NewLevelScene(game, startlevel)
game.Scenes[Select] = NewSelectScene(game)
game.CurrentScene = startscene
@@ -94,7 +94,8 @@ func (game *Game) Update() error {
if next == Play {
// fresh setup of actual level every time we enter the play scene
game.Scenes[Play] = NewLevelScene(game, gameobserver.CurrentLevel)
//game.Scenes[Play] = NewLevelScene(game, gameobserver.CurrentLevel)
game.Scenes[Play].SetLevel(gameobserver.CurrentLevel)
}
// make sure we stay on the selected scene

View File

@@ -18,10 +18,10 @@ type LevelScene struct {
// Implements the actual playing Scene
func NewLevelScene(game *Game, startlevel int) Scene {
scene := &LevelScene{CurrentLevel: startlevel, Whoami: Play, Next: Play, Game: game}
scene := &LevelScene{Whoami: Play, Next: Play, Game: game}
scene.GenerateLevels(game)
scene.Levels[scene.CurrentLevel].SetupGrid(game)
scene.SetLevel(startlevel)
return scene
}
@@ -34,6 +34,11 @@ func (scene *LevelScene) GenerateLevels(game *Game) {
scene.Game.Levels = scene.Levels
}
func (scene *LevelScene) SetLevel(level int) {
scene.CurrentLevel = level
scene.Levels[scene.CurrentLevel].SetupGrid(scene.Game)
}
// Interface methods
func (scene *LevelScene) SetNext(next SceneName) {
scene.Next = next
@@ -53,7 +58,6 @@ func (scene *LevelScene) Clearscreen() bool {
}
func (scene *LevelScene) Update() error {
scene.Levels[scene.CurrentLevel].Update()
switch {

View File

@@ -37,6 +37,8 @@ func (scene *MenuScene) ResetNext() {
scene.Next = scene.Whoami
}
func (scene *MenuScene) SetLevel(level int) {}
func (scene *MenuScene) SetNext(next SceneName) {
slog.Debug("select setnext", "next", next)
scene.Next = next

View File

@@ -58,6 +58,8 @@ func (scene *NextlevelScene) Update() error {
return nil
}
func (scene *NextlevelScene) SetLevel(level int) {}
func (scene *NextlevelScene) Draw(screen *ebiten.Image) {
background := assets.Assets["background-popup"]

View File

@@ -41,6 +41,8 @@ func (scene *PopupScene) SetNext(next SceneName) {
scene.Next = next
}
func (scene *PopupScene) SetLevel(level int) {}
func (scene *PopupScene) Clearscreen() bool {
// both level_scene AND the popup must not clear to get an actual popup
return false

View File

@@ -26,6 +26,7 @@ type Scene interface {
ResetNext()
Clearscreen() bool
Update() error
SetLevel(int)
Draw(screen *ebiten.Image)
}

View File

@@ -3,6 +3,7 @@ package game
import (
"fmt"
"image/color"
"log/slog"
"openquell/assets"
"openquell/gameui"
"openquell/observers"
@@ -31,6 +32,8 @@ func NewSelectScene(game *Game) Scene {
return scene
}
func (scene *SelectScene) SetLevel(level int) {}
func (scene *SelectScene) GetNext() SceneName {
return scene.Next
}
@@ -79,6 +82,7 @@ func (scene *SelectScene) SetupUI() {
levels = append(levels, LevelEntry{Id: id, Name: scene.Game.Levels[id].Name})
}
slog.Debug("levels", "levels", levels)
buttonImage, err := gameui.LoadButtonImage()
if err != nil {
panic(err)

View File

@@ -36,6 +36,8 @@ func (scene *WelcomeScene) ResetNext() {
scene.Next = scene.Whoami
}
func (scene *WelcomeScene) SetLevel(level int) {}
func (scene *WelcomeScene) Clearscreen() bool {
return true
}