You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.4 KiB
Go
74 lines
1.4 KiB
Go
package game
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"code.rocketnine.space/tslocum/etk"
|
|
"code.rocketnine.space/tslocum/gohan"
|
|
"code.rocketnine.space/tslocum/hot-cocoa-tycoon/entity"
|
|
"code.rocketnine.space/tslocum/hot-cocoa-tycoon/system"
|
|
"code.rocketnine.space/tslocum/hot-cocoa-tycoon/world"
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
)
|
|
|
|
type Game struct{}
|
|
|
|
func NewGame() (*Game, error) {
|
|
g := &Game{}
|
|
|
|
// Input demo.
|
|
{
|
|
buffer := etk.NewText("Are you a bad enough dude to create the greatest hot cocoa stand empire?")
|
|
|
|
onselected := func(text string) (handled bool) {
|
|
buffer.Write([]byte("\nInput: " + text))
|
|
return true
|
|
}
|
|
|
|
input := etk.NewInput(">", "", onselected)
|
|
|
|
inputDemo := etk.NewFlex()
|
|
inputDemo.SetVertical(true)
|
|
|
|
t := etk.NewText("Welcome to Hot Cocoa Tycoon")
|
|
inputDemo.AddChild(t, buffer, input)
|
|
|
|
etk.SetRoot(inputDemo)
|
|
|
|
log.Println(inputDemo)
|
|
}
|
|
|
|
etk.Layout(world.ScreenWidth, world.ScreenHeight)
|
|
|
|
entity.NewOnceEntity()
|
|
|
|
gohan.AddSystem(&system.UISystem{})
|
|
|
|
return g, nil
|
|
}
|
|
|
|
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
|
|
return world.ScreenWidth, world.ScreenHeight
|
|
}
|
|
|
|
func (g *Game) Update() error {
|
|
if ebiten.IsWindowBeingClosed() {
|
|
g.Exit()
|
|
return nil
|
|
}
|
|
|
|
return gohan.Update()
|
|
}
|
|
|
|
func (g *Game) Draw(screen *ebiten.Image) {
|
|
err := gohan.Draw(screen)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func (g *Game) Exit() {
|
|
os.Exit(0)
|
|
}
|