added mouse menu to player hud (events in level_scene), fix level 4

This commit is contained in:
2024-03-18 19:34:57 +01:00
parent daa5e41551
commit ae0e3a0676
9 changed files with 77 additions and 28 deletions

View File

@@ -82,6 +82,7 @@ func (game *Game) Update() error {
}
next := scene.GetNext()
if next != game.CurrentScene {
if next == Play && game.CurrentScene == Nextlevel {
// switched from nextlevel (lost or won) popup to play (either retry or next level)

View File

@@ -1,10 +1,13 @@
package game
import (
"image"
"log/slog"
"openquell/assets"
"openquell/config"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type LevelScene struct {
@@ -14,6 +17,7 @@ type LevelScene struct {
Next SceneName
Whoami SceneName
UseCache bool
MenuRect image.Rectangle
}
// Implements the actual playing Scene
@@ -22,6 +26,9 @@ func NewLevelScene(game *Game, startlevel int) Scene {
scene.GenerateLevels(game)
scene.SetLevel(startlevel)
scene.MenuRect = image.Rect(config.MenuRectX, config.MenuRectY,
config.MenuRectX+config.MenuRectCellsize,
config.MenuRectY+config.MenuRectCellsize)
return scene
}
@@ -66,8 +73,15 @@ func (scene *LevelScene) Update() error {
scene.Levels[scene.CurrentLevel].Update()
switch {
case ebiten.IsKeyPressed(ebiten.KeyEscape):
case inpututil.IsKeyJustPressed(ebiten.KeyEscape):
scene.SetNext(Popup)
case inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft):
// ok we're checking the menu button here, but drawing it in hud_system,
// because systems can't switch scenes
if image.Pt(ebiten.CursorPosition()).In(scene.MenuRect) {
scene.SetNext(Popup)
}
}
return nil

View File

@@ -10,6 +10,7 @@ import (
"github.com/ebitenui/ebitenui/widget"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type PopupScene struct {
@@ -50,6 +51,11 @@ func (scene *PopupScene) Clearscreen() bool {
func (scene *PopupScene) Update() error {
scene.Ui.Update()
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
scene.SetNext(Play)
}
return nil
}

View File

@@ -13,6 +13,7 @@ import (
"github.com/ebitenui/ebitenui/widget"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type SelectScene struct {
@@ -53,6 +54,11 @@ func (scene *SelectScene) Clearscreen() bool {
func (scene *SelectScene) Update() error {
scene.Ui.Update()
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
scene.SetNext(Menu)
}
return nil
}