-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinput.go
More file actions
67 lines (59 loc) · 1.11 KB
/
Copy pathinput.go
File metadata and controls
67 lines (59 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/setanarut/v"
)
var timerR int
var timerL int
func getAxisX() float64 {
x := 0.0
if ebiten.IsKeyPressed(ebiten.KeyD) {
timerR++
x = 1.0
}
if ebiten.IsKeyPressed(ebiten.KeyA) {
timerL++
x = -1.0
}
if inpututil.IsKeyJustReleased(ebiten.KeyD) {
timerR = 0
}
if inpututil.IsKeyJustReleased(ebiten.KeyA) {
timerL = 0
}
if ebiten.IsKeyPressed(ebiten.KeyA) && ebiten.IsKeyPressed(ebiten.KeyD) {
if timerL > timerR {
x = -1.0
}
if timerR > timerL {
x = 1.0
}
}
return x
}
// var lastAxis v.Vec
func Axis() (axis v.Vec) {
if ebiten.IsKeyPressed(ebiten.KeyW) {
axis.Y -= 1
}
if ebiten.IsKeyPressed(ebiten.KeyS) {
axis.Y += 1
}
if ebiten.IsKeyPressed(ebiten.KeyA) {
axis.X -= 1
}
if ebiten.IsKeyPressed(ebiten.KeyD) {
axis.X += 1
}
return
}
func IsAxisHorizontal(axis v.Vec) bool {
return axis.X != 0 && axis.Y == 0
}
func IsAxisDiagonal(axis v.Vec) bool {
return axis.X != 0 && axis.Y != 0
}
func IsVertical(axis v.Vec) bool {
return axis.X == 0 && axis.Y != 0
}