From 81ef20ddd030c903266b17a009be088db0123c12 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 18 Apr 2021 01:13:17 +0900 Subject: [PATCH] examples: Use the new keys Updates #1394 --- examples/2048/2048/input.go | 8 ++++---- examples/airship/main.go | 4 ++-- examples/blocks/blocks/input.go | 6 +++--- examples/camera/main.go | 8 ++++---- examples/platformer/main.go | 4 ++-- examples/polygons/main.go | 4 ++-- examples/raycasting/main.go | 8 ++++---- examples/shader/main.go | 4 ++-- examples/snake/main.go | 8 ++++---- examples/sprites/main.go | 4 ++-- examples/spriteshd/main.go | 4 ++-- examples/typewriter/main.go | 2 +- examples/windowsize/main.go | 16 ++++++++-------- 13 files changed, 40 insertions(+), 40 deletions(-) diff --git a/examples/2048/2048/input.go b/examples/2048/2048/input.go index 5e23ab523..0473c1a47 100644 --- a/examples/2048/2048/input.go +++ b/examples/2048/2048/input.go @@ -197,16 +197,16 @@ func (i *Input) Update() { // Dir returns a currently pressed direction. // Dir returns false if no direction key is pressed. func (i *Input) Dir() (Dir, bool) { - if inpututil.IsKeyJustPressed(ebiten.KeyUp) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowUp) { return DirUp, true } - if inpututil.IsKeyJustPressed(ebiten.KeyLeft) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowLeft) { return DirLeft, true } - if inpututil.IsKeyJustPressed(ebiten.KeyRight) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowRight) { return DirRight, true } - if inpututil.IsKeyJustPressed(ebiten.KeyDown) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowDown) { return DirDown, true } if i.mouseState == mouseStateSettled { diff --git a/examples/airship/main.go b/examples/airship/main.go index 02387b8f4..ea9f24221 100644 --- a/examples/airship/main.go +++ b/examples/airship/main.go @@ -247,11 +247,11 @@ func (g *Game) Update() error { g.player.MoveForward() } rotated := false - if ebiten.IsKeyPressed(ebiten.KeyRight) { + if ebiten.IsKeyPressed(ebiten.KeyArrowRight) { g.player.RotateRight() rotated = true } - if ebiten.IsKeyPressed(ebiten.KeyLeft) { + if ebiten.IsKeyPressed(ebiten.KeyArrowLeft) { g.player.RotateLeft() rotated = true } diff --git a/examples/blocks/blocks/input.go b/examples/blocks/blocks/input.go index dc2e313c6..40c0dba1c 100644 --- a/examples/blocks/blocks/input.go +++ b/examples/blocks/blocks/input.go @@ -77,21 +77,21 @@ func (i *Input) IsRotateLeftJustPressed() bool { } func (i *Input) StateForLeft() int { - if v := inpututil.KeyPressDuration(ebiten.KeyLeft); 0 < v { + if v := inpututil.KeyPressDuration(ebiten.KeyArrowLeft); 0 < v { return v } return i.stateForVirtualGamepadButton(virtualGamepadButtonLeft) } func (i *Input) StateForRight() int { - if v := inpututil.KeyPressDuration(ebiten.KeyRight); 0 < v { + if v := inpututil.KeyPressDuration(ebiten.KeyArrowRight); 0 < v { return v } return i.stateForVirtualGamepadButton(virtualGamepadButtonRight) } func (i *Input) StateForDown() int { - if v := inpututil.KeyPressDuration(ebiten.KeyDown); 0 < v { + if v := inpututil.KeyPressDuration(ebiten.KeyArrowDown); 0 < v { return v } return i.stateForVirtualGamepadButton(virtualGamepadButtonDown) diff --git a/examples/camera/main.go b/examples/camera/main.go index 6f4bf9412..c1e748925 100644 --- a/examples/camera/main.go +++ b/examples/camera/main.go @@ -134,16 +134,16 @@ type Game struct { } func (g *Game) Update() error { - if ebiten.IsKeyPressed(ebiten.KeyA) || ebiten.IsKeyPressed(ebiten.KeyLeft) { + if ebiten.IsKeyPressed(ebiten.KeyA) || ebiten.IsKeyPressed(ebiten.KeyArrowLeft) { g.camera.Position[0] -= 1 } - if ebiten.IsKeyPressed(ebiten.KeyD) || ebiten.IsKeyPressed(ebiten.KeyRight) { + if ebiten.IsKeyPressed(ebiten.KeyD) || ebiten.IsKeyPressed(ebiten.KeyArrowRight) { g.camera.Position[0] += 1 } - if ebiten.IsKeyPressed(ebiten.KeyW) || ebiten.IsKeyPressed(ebiten.KeyUp) { + if ebiten.IsKeyPressed(ebiten.KeyW) || ebiten.IsKeyPressed(ebiten.KeyArrowUp) { g.camera.Position[1] -= 1 } - if ebiten.IsKeyPressed(ebiten.KeyS) || ebiten.IsKeyPressed(ebiten.KeyDown) { + if ebiten.IsKeyPressed(ebiten.KeyS) || ebiten.IsKeyPressed(ebiten.KeyArrowDown) { g.camera.Position[1] += 1 } diff --git a/examples/platformer/main.go b/examples/platformer/main.go index 377a96d41..7879e8573 100644 --- a/examples/platformer/main.go +++ b/examples/platformer/main.go @@ -130,9 +130,9 @@ func (g *Game) Update() error { } // Controls - if ebiten.IsKeyPressed(ebiten.KeyA) || ebiten.IsKeyPressed(ebiten.KeyLeft) { + if ebiten.IsKeyPressed(ebiten.KeyA) || ebiten.IsKeyPressed(ebiten.KeyArrowLeft) { g.gopher.vx = -4 * unit - } else if ebiten.IsKeyPressed(ebiten.KeyD) || ebiten.IsKeyPressed(ebiten.KeyRight) { + } else if ebiten.IsKeyPressed(ebiten.KeyD) || ebiten.IsKeyPressed(ebiten.KeyArrowRight) { g.gopher.vx = 4 * unit } if inpututil.IsKeyJustPressed(ebiten.KeySpace) { diff --git a/examples/polygons/main.go b/examples/polygons/main.go index 9d7dc3e48..d635e8829 100644 --- a/examples/polygons/main.go +++ b/examples/polygons/main.go @@ -100,13 +100,13 @@ type Game struct { } func (g *Game) Update() error { - if inpututil.IsKeyJustPressed(ebiten.KeyLeft) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowLeft) { g.ngon-- if g.ngon < 1 { g.ngon = 1 } } - if inpututil.IsKeyJustPressed(ebiten.KeyRight) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowRight) { g.ngon++ if g.ngon > 120 { g.ngon = 120 diff --git a/examples/raycasting/main.go b/examples/raycasting/main.go index 119fc35ae..36fcc943d 100644 --- a/examples/raycasting/main.go +++ b/examples/raycasting/main.go @@ -171,19 +171,19 @@ func rayCasting(cx, cy float64, objects []object) []line { } func (g *Game) handleMovement() { - if ebiten.IsKeyPressed(ebiten.KeyD) || ebiten.IsKeyPressed(ebiten.KeyRight) { + if ebiten.IsKeyPressed(ebiten.KeyD) || ebiten.IsKeyPressed(ebiten.KeyArrowRight) { g.px += 4 } - if ebiten.IsKeyPressed(ebiten.KeyS) || ebiten.IsKeyPressed(ebiten.KeyDown) { + if ebiten.IsKeyPressed(ebiten.KeyS) || ebiten.IsKeyPressed(ebiten.KeyArrowDown) { g.py += 4 } - if ebiten.IsKeyPressed(ebiten.KeyA) || ebiten.IsKeyPressed(ebiten.KeyLeft) { + if ebiten.IsKeyPressed(ebiten.KeyA) || ebiten.IsKeyPressed(ebiten.KeyArrowLeft) { g.px -= 4 } - if ebiten.IsKeyPressed(ebiten.KeyW) || ebiten.IsKeyPressed(ebiten.KeyUp) { + if ebiten.IsKeyPressed(ebiten.KeyW) || ebiten.IsKeyPressed(ebiten.KeyArrowUp) { g.py -= 4 } diff --git a/examples/shader/main.go b/examples/shader/main.go index 23ec41317..53a5f21fe 100644 --- a/examples/shader/main.go +++ b/examples/shader/main.go @@ -99,11 +99,11 @@ type Game struct { func (g *Game) Update() error { g.time++ - if inpututil.IsKeyJustPressed(ebiten.KeyDown) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowDown) { g.idx++ g.idx %= len(shaderSrcs) } - if inpututil.IsKeyJustPressed(ebiten.KeyUp) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowUp) { g.idx += len(shaderSrcs) - 1 g.idx %= len(shaderSrcs) } diff --git a/examples/snake/main.go b/examples/snake/main.go index 67c75a4e9..e8659029c 100644 --- a/examples/snake/main.go +++ b/examples/snake/main.go @@ -103,19 +103,19 @@ func (g *Game) reset() { } func (g *Game) Update() error { - if inpututil.IsKeyJustPressed(ebiten.KeyLeft) || inpututil.IsKeyJustPressed(ebiten.KeyA) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowLeft) || inpututil.IsKeyJustPressed(ebiten.KeyA) { if g.moveDirection != dirRight { g.moveDirection = dirLeft } - } else if inpututil.IsKeyJustPressed(ebiten.KeyRight) || inpututil.IsKeyJustPressed(ebiten.KeyD) { + } else if inpututil.IsKeyJustPressed(ebiten.KeyArrowRight) || inpututil.IsKeyJustPressed(ebiten.KeyD) { if g.moveDirection != dirLeft { g.moveDirection = dirRight } - } else if inpututil.IsKeyJustPressed(ebiten.KeyDown) || inpututil.IsKeyJustPressed(ebiten.KeyS) { + } else if inpututil.IsKeyJustPressed(ebiten.KeyArrowDown) || inpututil.IsKeyJustPressed(ebiten.KeyS) { if g.moveDirection != dirUp { g.moveDirection = dirDown } - } else if inpututil.IsKeyJustPressed(ebiten.KeyUp) || inpututil.IsKeyJustPressed(ebiten.KeyW) { + } else if inpututil.IsKeyJustPressed(ebiten.KeyArrowUp) || inpututil.IsKeyJustPressed(ebiten.KeyW) { if g.moveDirection != dirDown { g.moveDirection = dirUp } diff --git a/examples/sprites/main.go b/examples/sprites/main.go index c057ce931..66dd95e7a 100644 --- a/examples/sprites/main.go +++ b/examples/sprites/main.go @@ -169,7 +169,7 @@ func (g *Game) Update() error { } // Decrease the number of the sprites. - if ebiten.IsKeyPressed(ebiten.KeyLeft) || leftTouched() { + if ebiten.IsKeyPressed(ebiten.KeyArrowLeft) || leftTouched() { g.sprites.num -= 20 if g.sprites.num < MinSprites { g.sprites.num = MinSprites @@ -177,7 +177,7 @@ func (g *Game) Update() error { } // Increase the number of the sprites. - if ebiten.IsKeyPressed(ebiten.KeyRight) || rightTouched() { + if ebiten.IsKeyPressed(ebiten.KeyArrowRight) || rightTouched() { g.sprites.num += 20 if MaxSprites < g.sprites.num { g.sprites.num = MaxSprites diff --git a/examples/spriteshd/main.go b/examples/spriteshd/main.go index 5b4e6df40..0a1d0716d 100644 --- a/examples/spriteshd/main.go +++ b/examples/spriteshd/main.go @@ -155,7 +155,7 @@ func (g *Game) Update() error { } // Decrease the number of the sprites. - if ebiten.IsKeyPressed(ebiten.KeyLeft) { + if ebiten.IsKeyPressed(ebiten.KeyArrowLeft) { g.sprites.num -= 20 if g.sprites.num < MinSprites { g.sprites.num = MinSprites @@ -163,7 +163,7 @@ func (g *Game) Update() error { } // Increase the number of the sprites. - if ebiten.IsKeyPressed(ebiten.KeyRight) { + if ebiten.IsKeyPressed(ebiten.KeyArrowRight) { g.sprites.num += 20 if MaxSprites < g.sprites.num { g.sprites.num = MaxSprites diff --git a/examples/typewriter/main.go b/examples/typewriter/main.go index 263622d8d..358a9e4df 100644 --- a/examples/typewriter/main.go +++ b/examples/typewriter/main.go @@ -64,7 +64,7 @@ func (g *Game) Update() error { } // If the enter key is pressed, add a line break. - if repeatingKeyPressed(ebiten.KeyEnter) || repeatingKeyPressed(ebiten.KeyKPEnter) { + if repeatingKeyPressed(ebiten.KeyEnter) || repeatingKeyPressed(ebiten.KeyNumpadEnter) { g.text += "\n" } diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index c70d86189..5d0475205 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -135,37 +135,37 @@ func (g *game) Update() error { const d = 16 toUpdateWindowSize := false if ebiten.IsKeyPressed(ebiten.KeyShift) { - if inpututil.IsKeyJustPressed(ebiten.KeyDown) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowDown) { screenHeight += d toUpdateWindowSize = true } - if inpututil.IsKeyJustPressed(ebiten.KeyUp) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowUp) { if 16 < screenHeight && d < screenHeight { screenHeight -= d toUpdateWindowSize = true } } - if inpututil.IsKeyJustPressed(ebiten.KeyLeft) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowLeft) { if 16 < screenWidth && d < screenWidth { screenWidth -= d toUpdateWindowSize = true } } - if inpututil.IsKeyJustPressed(ebiten.KeyRight) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowRight) { screenWidth += d toUpdateWindowSize = true } } else { - if inpututil.IsKeyJustPressed(ebiten.KeyUp) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowUp) { positionY -= d } - if inpututil.IsKeyJustPressed(ebiten.KeyDown) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowDown) { positionY += d } - if inpututil.IsKeyJustPressed(ebiten.KeyLeft) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowLeft) { positionX -= d } - if inpututil.IsKeyJustPressed(ebiten.KeyRight) { + if inpututil.IsKeyJustPressed(ebiten.KeyArrowRight) { positionX += d } }