examples/2048: Use RunGame

Updates #1111
This commit is contained in:
Hajime Hoshi 2020-04-01 15:50:30 +09:00
parent 41213108ba
commit a70d6a314e
2 changed files with 10 additions and 19 deletions

View File

@ -51,8 +51,13 @@ func NewGame() (*Game, error) {
return g, nil return g, nil
} }
// Layout implements ebiten.Game's Layout.
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
return ScreenWidth, ScreenHeight
}
// Update updates the current game state. // Update updates the current game state.
func (g *Game) Update() error { func (g *Game) Update(*ebiten.Image) error {
g.input.Update() g.input.Update()
if err := g.board.Update(g.input); err != nil { if err := g.board.Update(g.input); err != nil {
return err return err

View File

@ -23,28 +23,14 @@ import (
"github.com/hajimehoshi/ebiten/examples/2048/2048" "github.com/hajimehoshi/ebiten/examples/2048/2048"
) )
var (
game *twenty48.Game
)
func update(screen *ebiten.Image) error {
if err := game.Update(); err != nil {
return err
}
if ebiten.IsDrawingSkipped() {
return nil
}
game.Draw(screen)
return nil
}
func main() { func main() {
var err error game, err := twenty48.NewGame()
game, err = twenty48.NewGame()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
if err := ebiten.Run(update, twenty48.ScreenWidth, twenty48.ScreenHeight, 1, "2048 (Ebiten Demo)"); err != nil { ebiten.SetWindowSize(twenty48.ScreenWidth, twenty48.ScreenHeight)
ebiten.SetWindowTitle("2048 (Ebiten Demo)")
if err := ebiten.RunGame(game); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }