examples: Use the new keys

Updates #1394
This commit is contained in:
Hajime Hoshi 2021-04-18 01:13:17 +09:00
parent 1b70901659
commit 81ef20ddd0
13 changed files with 40 additions and 40 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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)

View File

@ -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
}

View File

@ -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) {

View File

@ -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

View File

@ -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
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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"
}

View File

@ -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
}
}