examples/runes: Refactoring

This commit is contained in:
Hajime Hoshi 2017-08-16 00:09:20 +09:00
parent 78ed445111
commit 3f52fb951b

View File

@ -18,22 +18,21 @@ package main
import ( import (
"log" "log"
"strings"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil" "github.com/hajimehoshi/ebiten/ebitenutil"
) )
var ( var (
runes = append(make([]rune, 0, 1024), []rune("Type on the keyboard:\n")...) text = "Type on the keyboard:\n"
counter = 0 counter = 0
) )
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
runes = append(runes, ebiten.InputChars()...) text += string(ebiten.InputChars())
if ebiten.IsKeyPressed(ebiten.KeyEnter) { if ebiten.IsKeyPressed(ebiten.KeyEnter) && !strings.HasSuffix(text, "\n") {
if len(runes) > 0 && runes[len(runes)-1] != '\n' { text += "\n"
runes = append(runes, '\n')
}
} }
counter++ counter++
@ -41,10 +40,12 @@ func update(screen *ebiten.Image) error {
return nil return nil
} }
t := text
if counter%60 < 30 { if counter%60 < 30 {
return ebitenutil.DebugPrint(screen, string(append(runes, '_'))) t += "_"
} }
return ebitenutil.DebugPrint(screen, string(runes)) ebitenutil.DebugPrint(screen, t)
return nil
} }
func main() { func main() {