added select menu scene (transparency fails)
This commit is contained in:
parent
4f5bbdc56a
commit
3069d77189
@ -3,7 +3,9 @@ package assets
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/tinne26/etxt"
|
||||
"golang.org/x/image/font"
|
||||
)
|
||||
|
||||
var FontRenderer = LoadFonts("fonts")
|
||||
@ -15,11 +17,28 @@ const (
|
||||
|
||||
type Texter struct {
|
||||
Renderer *etxt.Renderer
|
||||
Font *font.Face
|
||||
}
|
||||
|
||||
func LoadFonts(dir string) *Texter {
|
||||
fontbytes, err := assetfs.ReadFile(dir + "/" + GameFont + ".ttf")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
gamefont, err := truetype.Parse(fontbytes)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
gameface := truetype.NewFace(gamefont, &truetype.Options{
|
||||
Size: float64(FontSize),
|
||||
DPI: 72,
|
||||
Hinting: font.HintingFull,
|
||||
})
|
||||
|
||||
fontlib := etxt.NewFontLibrary()
|
||||
_, _, err := fontlib.ParseEmbedDirFonts(dir, assetfs)
|
||||
_, _, err = fontlib.ParseEmbedDirFonts(dir, assetfs)
|
||||
if err != nil {
|
||||
log.Fatalf("Error while loading fonts: %s", err.Error())
|
||||
}
|
||||
@ -39,7 +58,7 @@ func LoadFonts(dir string) *Texter {
|
||||
renderer.SetCacheHandler(glyphsCache.NewHandler())
|
||||
renderer.SetFont(fontlib.GetFont(GameFont))
|
||||
|
||||
return &Texter{renderer}
|
||||
return &Texter{Renderer: renderer, Font: &gameface}
|
||||
}
|
||||
|
||||
// helper function used with FontLibrary.EachFont to make sure
|
||||
|
||||
@ -110,7 +110,12 @@ func InitTiles() TileRegistry {
|
||||
'S': NewTilePlayer(),
|
||||
'o': NewTileCollectible("collectible-orange"),
|
||||
'*': NewTileParticle([]string{
|
||||
"particle-ring-1", "particle-ring-2", "particle-ring-3", "particle-ring-4", "particle-ring-5", "particle-ring-6",
|
||||
//"particle-ring-1",
|
||||
"particle-ring-2",
|
||||
"particle-ring-3",
|
||||
"particle-ring-4",
|
||||
"particle-ring-5",
|
||||
"particle-ring-6",
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
BIN
assets/sprites/background-transparent.png
Normal file
BIN
assets/sprites/background-transparent.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@ -18,7 +18,7 @@ type Game struct {
|
||||
Observer *observers.GameObserver
|
||||
}
|
||||
|
||||
func NewGame(width, height, cellsize, startlevel int, startscene int) *Game {
|
||||
func NewGame(width, height, cellsize, startlevel int, startscene SceneName) *Game {
|
||||
world := ecs.NewWorld()
|
||||
|
||||
game := &Game{
|
||||
@ -34,8 +34,9 @@ func NewGame(width, height, cellsize, startlevel int, startscene int) *Game {
|
||||
game.Observer = observers.NewGameObserver(&world, startlevel, width, height, cellsize)
|
||||
|
||||
game.Scenes[Welcome] = NewWelcomeScene(game)
|
||||
game.Scenes[Select] = NewSelectScene(game)
|
||||
game.Scenes[Play] = NewLevelScene(game, startlevel)
|
||||
game.CurrentScene = Welcome
|
||||
game.CurrentScene = startscene
|
||||
|
||||
fmt.Println(game.World.Stats().String())
|
||||
|
||||
|
||||
113
game/select_scene.go
Normal file
113
game/select_scene.go
Normal file
@ -0,0 +1,113 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"openquell/assets"
|
||||
|
||||
"github.com/ebitenui/ebitenui"
|
||||
"github.com/ebitenui/ebitenui/image"
|
||||
"github.com/ebitenui/ebitenui/widget"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type SelectScene struct {
|
||||
Game *Game
|
||||
Next SceneName
|
||||
Whoami SceneName
|
||||
UseCache bool
|
||||
Ui *ebitenui.UI
|
||||
}
|
||||
|
||||
func NewSelectScene(game *Game) Scene {
|
||||
scene := &SelectScene{Whoami: Select, Game: game, Next: Select}
|
||||
|
||||
scene.SetupUI()
|
||||
|
||||
return scene
|
||||
}
|
||||
|
||||
func (scene *SelectScene) GetNext() SceneName {
|
||||
return scene.Next
|
||||
}
|
||||
|
||||
func (scene *SelectScene) SetNext(next SceneName) {
|
||||
scene.Next = next
|
||||
}
|
||||
|
||||
func (scene *SelectScene) Update() error {
|
||||
scene.Ui.Update()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (scene *SelectScene) Draw(screen *ebiten.Image) {
|
||||
scene.Ui.Draw(screen)
|
||||
}
|
||||
|
||||
func (scene *SelectScene) SetupUI() {
|
||||
buttonImage, _ := loadButtonImage()
|
||||
|
||||
btnContainer := widget.NewContainer(
|
||||
widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
|
||||
)
|
||||
|
||||
button := widget.NewButton(
|
||||
widget.ButtonOpts.WidgetOpts(
|
||||
widget.WidgetOpts.LayoutData(widget.AnchorLayoutData{
|
||||
HorizontalPosition: widget.AnchorLayoutPositionCenter,
|
||||
VerticalPosition: widget.AnchorLayoutPositionCenter,
|
||||
}),
|
||||
),
|
||||
|
||||
widget.ButtonOpts.Image(buttonImage),
|
||||
|
||||
widget.ButtonOpts.Text("Start new Game", *assets.FontRenderer.Font, &widget.ButtonTextColor{
|
||||
Idle: color.NRGBA{0xdf, 0xf4, 0xff, 0xff},
|
||||
}),
|
||||
|
||||
widget.ButtonOpts.TextPadding(widget.Insets{
|
||||
Left: 30,
|
||||
Right: 30,
|
||||
Top: 5,
|
||||
Bottom: 5,
|
||||
}),
|
||||
|
||||
widget.ButtonOpts.ClickedHandler(func(args *widget.ButtonClickedEventArgs) {
|
||||
scene.SetNext(Play)
|
||||
}),
|
||||
)
|
||||
|
||||
btnContainer.AddChild(button)
|
||||
|
||||
rootContainer := widget.NewContainer(
|
||||
widget.ContainerOpts.BackgroundImage(
|
||||
// FIXME: see https://github.com/ebitenui/ebitenui/issues/118
|
||||
image.NewNineSlice(assets.Assets["background-transparent"], [3]int{0, 1, 639}, [3]int{0, 1, 479})),
|
||||
//widget.ContainerOpts.BackgroundImage(image.NewNineSliceColor(color.NRGBA{0x13, 0x1a, 0x22, 0xff})),
|
||||
//widget.ContainerOpts.BackgroundImage(image.NewNineSliceColor(color.NRGBA{0xff, 0x80, 0x00, 0x00})),
|
||||
widget.ContainerOpts.Layout(
|
||||
widget.NewStackedLayout(
|
||||
widget.StackedLayoutOpts.Padding(
|
||||
widget.NewInsetsSimple(25)))),
|
||||
)
|
||||
|
||||
rootContainer.AddChild(btnContainer)
|
||||
|
||||
scene.Ui = &ebitenui.UI{
|
||||
Container: rootContainer,
|
||||
}
|
||||
}
|
||||
|
||||
func loadButtonImage() (*widget.ButtonImage, error) {
|
||||
idle := image.NewNineSliceColor(color.NRGBA{R: 170, G: 170, B: 180, A: 255})
|
||||
|
||||
hover := image.NewNineSliceColor(color.NRGBA{R: 130, G: 130, B: 150, A: 255})
|
||||
|
||||
pressed := image.NewNineSliceColor(color.NRGBA{R: 100, G: 100, B: 120, A: 255})
|
||||
|
||||
return &widget.ButtonImage{
|
||||
Idle: idle,
|
||||
Hover: hover,
|
||||
Pressed: pressed,
|
||||
}, nil
|
||||
}
|
||||
@ -33,7 +33,7 @@ func (scene *WelcomeScene) Update() error {
|
||||
switch {
|
||||
case ebiten.IsKeyPressed(ebiten.KeyEnter):
|
||||
slog.Debug("welcome.Update() next")
|
||||
scene.SetNext(Play)
|
||||
scene.SetNext(Select)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
3
go.mod
3
go.mod
@ -10,12 +10,15 @@ require (
|
||||
require (
|
||||
github.com/alecthomas/repr v0.3.0 // indirect
|
||||
github.com/ebitengine/purego v0.5.0 // indirect
|
||||
github.com/ebitenui/ebitenui v0.5.5 // indirect
|
||||
github.com/fatih/color v1.16.0 // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/jezek/xgb v1.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/tinne26/etxt v0.0.8 // indirect
|
||||
github.com/tlinden/yadu v0.1.3 // indirect
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
|
||||
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 // indirect
|
||||
golang.org/x/image v0.12.0 // indirect
|
||||
golang.org/x/mobile v0.0.0-20230922142353-e2f452493d57 // indirect
|
||||
|
||||
6
go.sum
6
go.sum
@ -2,8 +2,12 @@ github.com/alecthomas/repr v0.3.0 h1:NeYzUPfjjlqHY4KtzgKJiWd6sVq2eNUPTi34PiFGjY8
|
||||
github.com/alecthomas/repr v0.3.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
|
||||
github.com/ebitengine/purego v0.5.0 h1:JrMGKfRIAM4/QVKaesIIT7m/UVjTj5GYhRSQYwfVdpo=
|
||||
github.com/ebitengine/purego v0.5.0/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
|
||||
github.com/ebitenui/ebitenui v0.5.5 h1:L9UCWmiMlo4sG5TavQKmjfsnwMmYqkld2tXWZMmKkSA=
|
||||
github.com/ebitenui/ebitenui v0.5.5/go.mod h1:CkzAwu9Ks32P+NC/7+iypdLA85Wqnn93UztPFE+kAH4=
|
||||
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/hajimehoshi/ebiten/v2 v2.6.5 h1:lALv+qhEK3CBWViyiGpz4YcR6slVJEjCiS7sExKZ9OE=
|
||||
github.com/hajimehoshi/ebiten/v2 v2.6.5/go.mod h1:TZtorL713an00UW4LyvMeKD8uXWnuIuCPtlH11b0pgI=
|
||||
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk=
|
||||
@ -24,6 +28,8 @@ github.com/tlinden/yadu v0.1.3/go.mod h1:l3bRmHKL9zGAR6pnBHY2HRPxBecf7L74BoBgOOp
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
|
||||
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 h1:3AGKexOYqL+ztdWdkB1bDwXgPBuTS/S8A4WzuTvJ8Cg=
|
||||
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0=
|
||||
golang.org/x/image v0.12.0 h1:w13vZbU4o5rKOFFR8y7M+c4A5jXDC0uXTdHYRP8X2DQ=
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user