examples/blocks: Improve gameover message

This commit is contained in:
Hajime Hoshi 2018-10-13 16:59:13 +09:00
parent 244e078810
commit 8ed02efd28
2 changed files with 10 additions and 3 deletions

View File

@ -56,8 +56,15 @@ func getArcadeFonts(scale int) font.Face {
}
func textWidth(str string) int {
b, _ := font.BoundString(getArcadeFonts(1), str)
return (b.Max.X - b.Min.X).Ceil()
maxW := 0
for _, line := range strings.Split(str, "\n") {
b, _ := font.BoundString(getArcadeFonts(1), line)
w := (b.Max.X - b.Min.X).Ceil()
if maxW < w {
maxW = w
}
}
return maxW
}
var (

View File

@ -107,7 +107,7 @@ func init() {
imageGameover, _ = ebiten.NewImage(ScreenWidth, ScreenHeight, ebiten.FilterDefault)
imageGameover.Fill(color.NRGBA{0x00, 0x00, 0x00, 0x80})
y = (ScreenHeight - blockHeight) / 2
drawTextWithShadowCenter(imageGameover, "GAME OVER", 0, y, 1, color.White, ScreenWidth)
drawTextWithShadowCenter(imageGameover, "GAME OVER\n\nPRESS START", 0, y, 1, color.White, ScreenWidth)
}
func drawWindow(r *ebiten.Image, x, y, width, height int) {