-
Notifications
You must be signed in to change notification settings - Fork 7
/
chassis.go
63 lines (53 loc) · 1.5 KB
/
chassis.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
58
59
60
61
62
63
package systems
import (
"github.com/EngoEngine/ecs"
"github.com/EngoEngine/engo"
"github.com/brunoga/robomaster/sdk"
"github.com/brunoga/robomaster/sdk/examples/robotcontrol/components"
"github.com/brunoga/robomaster/sdk/modules/chassis"
)
type systemChassisEntity struct {
ecs.BasicEntity
*components.Speed
}
type Chassis struct {
entity *systemChassisEntity
client *sdk.Client
mirrorClients []*sdk.Client
}
func NewChassis(client *sdk.Client, mirrorClients []*sdk.Client) *Chassis {
return &Chassis{
&systemChassisEntity{
ecs.NewBasic(),
&components.Speed{},
},
client,
mirrorClients,
}
}
func (c *Chassis) New(world *ecs.World) {
// Do nothing.
}
func (c *Chassis) Update(dt float32) {
currentLeftRight := engo.Input.Axis("Left/Right").Value()
currentForwardBackward := -engo.Input.Axis("Forward/Backward").Value()
if c.entity.SpeedX != float64(currentForwardBackward) ||
c.entity.SpeedY != float64(currentLeftRight) {
c.client.ChassisModule().SetSpeed(chassis.NewSpeed(
float64(currentForwardBackward)/2.0, float64(currentLeftRight)/2.0,
0.0), true)
for _, mirrorClient := range c.mirrorClients {
mirrorClient.ChassisModule().SetSpeed(chassis.NewSpeed(
float64(currentForwardBackward)/2.0,
float64(currentLeftRight)/2.0, 0.0), true)
}
c.entity.SpeedX = float64(currentForwardBackward)
c.entity.SpeedY = float64(currentLeftRight)
}
}
func (c *Chassis) Remove(e ecs.BasicEntity) {
// Do nothing.
}
func (c *Chassis) Priority() int {
return 9
}