-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.go
57 lines (52 loc) · 1.28 KB
/
move.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
55
56
57
package main
import (
"math"
"github.com/hajimehoshi/ebiten"
)
func checkKey() {
var newPos floatPosition
if ebiten.IsKeyPressed(ebiten.KeyW) {
newPos = myData.player.pos
newPos.y = myData.player.pos.y + math.Sin(myData.player.angle*(math.Pi/180))/30
if checkPos(newPos) {
myData.player.pos = newPos
}
newPos = myData.player.pos
newPos.x = myData.player.pos.x + math.Cos(myData.player.angle*(math.Pi/180))/30
if checkPos(newPos) {
myData.player.pos = newPos
}
}
if ebiten.IsKeyPressed(ebiten.KeyS) {
newPos = myData.player.pos
newPos.y = myData.player.pos.y - math.Sin(myData.player.angle*(math.Pi/180))/30
if checkPos(newPos) {
myData.player.pos = newPos
}
newPos = myData.player.pos
newPos.x = myData.player.pos.x - math.Cos(myData.player.angle*(math.Pi/180))/30
if checkPos(newPos) {
myData.player.pos = newPos
}
}
if ebiten.IsKeyPressed(ebiten.KeyA) {
myData.player.angle -= 3
// myData.miniMap.pix.rotate -= 3
}
if ebiten.IsKeyPressed(ebiten.KeyD) {
myData.player.angle += 3
// myData.miniMap.pix.rotate += 3
}
if myData.player.angle > 360 {
myData.player.angle = 0
}
if myData.player.angle < 0 {
myData.player.angle = 360
}
}
func checkPos(pos floatPosition) bool {
if isThereWall(pos.toIntPos()) {
return false
}
return true
}