]> git.lizzy.rs Git - mt.git/blob - playerpos.go
Add WaitGroup to SerializePkt
[mt.git] / playerpos.go
1 package mt
2
3 type Keys uint32
4
5 const (
6         ForwardKey Keys = 1 << iota
7         BackwardKey
8         LeftKey
9         RightKey
10         JumpKey
11         SpecialKey
12         SneakKey
13         DigKey
14         PlaceKey
15         ZoomKey
16 )
17
18 type PlayerPos struct {
19         Pos100, Vel100   [3]int32
20         Pitch100, Yaw100 int32
21         Keys             Keys
22         FOV80            uint8
23         WantedRange      uint8 // in MapBlks.
24 }
25
26 func (p PlayerPos) Pos() (pos Pos) {
27         for i := range pos {
28                 pos[i] = float32(p.Pos100[i]) / 100
29         }
30         return
31 }
32
33 func (p *PlayerPos) SetPos(pos Pos) {
34         for i, x := range pos {
35                 p.Pos100[i] = int32(x * 100)
36         }
37 }
38
39 func (p PlayerPos) Vel() (vel Vec) {
40         for i := range vel {
41                 vel[i] = float32(p.Vel100[i]) / 100
42         }
43         return
44 }
45
46 func (p *PlayerPos) SetVel(vel Vec) {
47         for i, x := range vel {
48                 p.Vel100[i] = int32(x * 100)
49         }
50 }
51
52 func (p PlayerPos) Pitch() float32 {
53         return float32(p.Pitch100) / 100
54 }
55
56 func (p *PlayerPos) SetPitch(pitch float32) {
57         p.Pitch100 = int32(pitch * 100)
58 }
59
60 func (p PlayerPos) Yaw() float32 {
61         return float32(p.Yaw100) / 100
62 }
63
64 func (p *PlayerPos) SetYaw(yaw float32) {
65         p.Yaw100 = int32(yaw * 100)
66 }
67
68 func (p PlayerPos) FOV() float32 {
69         return float32(p.FOV80) / 80
70 }
71
72 func (p *PlayerPos) SetFOV(fov float32) {
73         p.FOV80 = uint8(fov * 80)
74 }
75
76 func (p PlayerPos) StoodOn() [3]int16 {
77         return p.Pos().Sub(Vec{1: 5}).Int()
78 }