-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.go
54 lines (45 loc) · 1.1 KB
/
input.go
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
package astar
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type Input struct {
LeftMousePressed bool
RightMousePressed bool
MouseX int
MouseY int
EnterPressed bool
ResetPressed bool
}
func (i *Input) Update() {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
i.RightMousePressed = true
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
i.LeftMousePressed = true
i.MouseX, i.MouseY = ebiten.CursorPosition()
}
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
i.EnterPressed = true
}
if inpututil.IsKeyJustPressed(ebiten.KeyR) {
i.ResetPressed = true
}
}
func (i *Input) CopyAndReset() *Input {
result := &Input{
RightMousePressed: i.RightMousePressed,
LeftMousePressed: i.LeftMousePressed,
MouseX: i.MouseX,
MouseY: i.MouseY,
EnterPressed: i.EnterPressed,
ResetPressed: i.ResetPressed,
}
i.RightMousePressed = false
i.LeftMousePressed = false
i.MouseX = 0
i.MouseY = 0
i.EnterPressed = false
i.ResetPressed = false
return result
}