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 (
"log"
"strings"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
)
var (
runes = append(make([]rune, 0, 1024), []rune("Type on the keyboard:\n")...)
text = "Type on the keyboard:\n"
counter = 0
)
func update(screen *ebiten.Image) error {
runes = append(runes, ebiten.InputChars()...)
if ebiten.IsKeyPressed(ebiten.KeyEnter) {
if len(runes) > 0 && runes[len(runes)-1] != '\n' {
runes = append(runes, '\n')
}
text += string(ebiten.InputChars())
if ebiten.IsKeyPressed(ebiten.KeyEnter) && !strings.HasSuffix(text, "\n") {
text += "\n"
}
counter++
@ -41,10 +40,12 @@ func update(screen *ebiten.Image) error {
return nil
}
t := text
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() {