examples/flappy: Use RunGame

Updates #1111
This commit is contained in:
Hajime Hoshi 2020-04-01 15:59:45 +09:00
parent 01a1334639
commit 9302160486

View File

@ -193,6 +193,10 @@ func jump() bool {
return false return false
} }
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return screenWidth, screenHeight
}
func (g *Game) Update(screen *ebiten.Image) error { func (g *Game) Update(screen *ebiten.Image) error {
switch g.mode { switch g.mode {
case ModeTitle: case ModeTitle:
@ -230,11 +234,10 @@ func (g *Game) Update(screen *ebiten.Image) error {
g.mode = ModeTitle g.mode = ModeTitle
} }
} }
if ebiten.IsDrawingSkipped() {
return nil return nil
} }
func (g *Game) Draw(screen *ebiten.Image) {
screen.Fill(color.RGBA{0x80, 0xa0, 0xc0, 0xff}) screen.Fill(color.RGBA{0x80, 0xa0, 0xc0, 0xff})
g.drawTiles(screen) g.drawTiles(screen)
if g.mode != ModeTitle { if g.mode != ModeTitle {
@ -266,7 +269,6 @@ func (g *Game) Update(screen *ebiten.Image) error {
scoreStr := fmt.Sprintf("%04d", g.score()) scoreStr := fmt.Sprintf("%04d", g.score())
text.Draw(screen, scoreStr, arcadeFont, screenWidth-len(scoreStr)*fontSize, fontSize, color.White) text.Draw(screen, scoreStr, arcadeFont, screenWidth-len(scoreStr)*fontSize, fontSize, color.White)
ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f", ebiten.CurrentTPS())) ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f", ebiten.CurrentTPS()))
return nil
} }
func (g *Game) pipeAt(tileX int) (tileY int, ok bool) { func (g *Game) pipeAt(tileX int) (tileY int, ok bool) {
@ -390,8 +392,9 @@ func (g *Game) drawGopher(screen *ebiten.Image) {
} }
func main() { func main() {
g := NewGame() ebiten.SetWindowSize(screenWidth, screenHeight)
if err := ebiten.Run(g.Update, screenWidth, screenHeight, 1, "Flappy Gopher (Ebiten Demo)"); err != nil { ebiten.SetWindowTitle("Flappy Gopher (Ebiten Demo)")
if err := ebiten.RunGame(NewGame()); err != nil {
panic(err) panic(err)
} }
} }