examples/keyboard/keyboard: go generate

This commit is contained in:
Hajime Hoshi 2021-04-17 19:30:04 +09:00
parent 6df87a0383
commit c8ed6ec12e
2 changed files with 21 additions and 21 deletions

View File

@ -148,7 +148,7 @@ func keyDisplayNameToKey(name string) ebiten.Key {
func drawKey(t *ebiten.Image, name string, x, y, width int) {
const height = 16
width--
img, _ := ebiten.NewImage(width, height)
img := ebiten.NewImage(width, height)
p := make([]byte, width*height*4)
for j := 0; j < height; j++ {
for i := 0; i < width; i++ {
@ -196,7 +196,7 @@ func drawKey(t *ebiten.Image, name string, x, y, width int) {
func outputKeyboardImage() (map[ebiten.Key]image.Rectangle, error) {
keyMap := map[ebiten.Key]image.Rectangle{}
img, _ := ebiten.NewImage(320, 240)
img := ebiten.NewImage(320, 240)
x, y := 0, 0
for j, line := range keyboardKeys {
x = 0
@ -321,7 +321,7 @@ type game struct {
rects map[ebiten.Key]image.Rectangle
}
func (g *game) Update(_ *ebiten.Image) error {
func (g *game) Update() error {
var err error
g.rects, err = outputKeyboardImage()
if err != nil {

View File

@ -25,16 +25,6 @@ import (
var keyboardKeyRects = map[ebiten.Key]image.Rectangle{}
func init() {
keyboardKeyRects[ebiten.Key0] = image.Rect(176, 0, 192, 18)
keyboardKeyRects[ebiten.Key1] = image.Rect(32, 0, 48, 18)
keyboardKeyRects[ebiten.Key2] = image.Rect(48, 0, 64, 18)
keyboardKeyRects[ebiten.Key3] = image.Rect(64, 0, 80, 18)
keyboardKeyRects[ebiten.Key4] = image.Rect(80, 0, 96, 18)
keyboardKeyRects[ebiten.Key5] = image.Rect(96, 0, 112, 18)
keyboardKeyRects[ebiten.Key6] = image.Rect(112, 0, 128, 18)
keyboardKeyRects[ebiten.Key7] = image.Rect(128, 0, 144, 18)
keyboardKeyRects[ebiten.Key8] = image.Rect(144, 0, 160, 18)
keyboardKeyRects[ebiten.Key9] = image.Rect(160, 0, 176, 18)
keyboardKeyRects[ebiten.KeyA] = image.Rect(48, 36, 64, 54)
keyboardKeyRects[ebiten.KeyB] = image.Rect(120, 54, 136, 72)
keyboardKeyRects[ebiten.KeyC] = image.Rect(88, 54, 104, 72)
@ -61,26 +51,36 @@ func init() {
keyboardKeyRects[ebiten.KeyX] = image.Rect(72, 54, 88, 72)
keyboardKeyRects[ebiten.KeyY] = image.Rect(120, 18, 136, 36)
keyboardKeyRects[ebiten.KeyZ] = image.Rect(56, 54, 72, 72)
keyboardKeyRects[ebiten.KeyApostrophe] = image.Rect(208, 36, 224, 54)
keyboardKeyRects[ebiten.KeyArrowDown] = image.Rect(48, 126, 96, 144)
keyboardKeyRects[ebiten.KeyArrowLeft] = image.Rect(0, 126, 48, 144)
keyboardKeyRects[ebiten.KeyArrowRight] = image.Rect(96, 126, 144, 144)
keyboardKeyRects[ebiten.KeyArrowUp] = image.Rect(48, 108, 96, 126)
keyboardKeyRects[ebiten.KeyBackquote] = image.Rect(240, 0, 256, 18)
keyboardKeyRects[ebiten.KeyBackslash] = image.Rect(224, 0, 240, 18)
keyboardKeyRects[ebiten.KeyBackspace] = image.Rect(232, 18, 272, 36)
keyboardKeyRects[ebiten.KeyBracketLeft] = image.Rect(200, 18, 216, 36)
keyboardKeyRects[ebiten.KeyBracketRight] = image.Rect(216, 18, 232, 36)
keyboardKeyRects[ebiten.KeyComma] = image.Rect(168, 54, 184, 72)
keyboardKeyRects[ebiten.KeyDown] = image.Rect(48, 126, 96, 144)
keyboardKeyRects[ebiten.KeyDigit0] = image.Rect(176, 0, 192, 18)
keyboardKeyRects[ebiten.KeyDigit1] = image.Rect(32, 0, 48, 18)
keyboardKeyRects[ebiten.KeyDigit2] = image.Rect(48, 0, 64, 18)
keyboardKeyRects[ebiten.KeyDigit3] = image.Rect(64, 0, 80, 18)
keyboardKeyRects[ebiten.KeyDigit4] = image.Rect(80, 0, 96, 18)
keyboardKeyRects[ebiten.KeyDigit5] = image.Rect(96, 0, 112, 18)
keyboardKeyRects[ebiten.KeyDigit6] = image.Rect(112, 0, 128, 18)
keyboardKeyRects[ebiten.KeyDigit7] = image.Rect(128, 0, 144, 18)
keyboardKeyRects[ebiten.KeyDigit8] = image.Rect(144, 0, 160, 18)
keyboardKeyRects[ebiten.KeyDigit9] = image.Rect(160, 0, 176, 18)
keyboardKeyRects[ebiten.KeyEnter] = image.Rect(224, 36, 272, 54)
keyboardKeyRects[ebiten.KeyEqual] = image.Rect(208, 0, 224, 18)
keyboardKeyRects[ebiten.KeyEscape] = image.Rect(0, 0, 32, 18)
keyboardKeyRects[ebiten.KeyGraveAccent] = image.Rect(240, 0, 256, 18)
keyboardKeyRects[ebiten.KeyLeft] = image.Rect(0, 126, 48, 144)
keyboardKeyRects[ebiten.KeyLeftBracket] = image.Rect(200, 18, 216, 36)
keyboardKeyRects[ebiten.KeyMinus] = image.Rect(192, 0, 208, 18)
keyboardKeyRects[ebiten.KeyPeriod] = image.Rect(184, 54, 200, 72)
keyboardKeyRects[ebiten.KeyRight] = image.Rect(96, 126, 144, 144)
keyboardKeyRects[ebiten.KeyRightBracket] = image.Rect(216, 18, 232, 36)
keyboardKeyRects[ebiten.KeyQuote] = image.Rect(208, 36, 224, 54)
keyboardKeyRects[ebiten.KeySemicolon] = image.Rect(192, 36, 208, 54)
keyboardKeyRects[ebiten.KeySlash] = image.Rect(200, 54, 216, 72)
keyboardKeyRects[ebiten.KeySpace] = image.Rect(96, 72, 176, 90)
keyboardKeyRects[ebiten.KeyTab] = image.Rect(0, 18, 40, 36)
keyboardKeyRects[ebiten.KeyUp] = image.Rect(48, 108, 96, 126)
keyboardKeyRects[ebiten.KeyAlt] = image.Rect(64, 72, 96, 90)
keyboardKeyRects[ebiten.KeyControl] = image.Rect(0, 36, 48, 54)
keyboardKeyRects[ebiten.KeyShift] = image.Rect(0, 54, 56, 72)