2023-09-22 18:33:01 +08:00
|
|
|
package physics_sys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/yohamta/donburi/filter"
|
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TwoPositionMovementSys struct {
|
|
|
|
query *ecs.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTwoPositionMovementSys() *TwoPositionMovementSys {
|
|
|
|
return &TwoPositionMovementSys{
|
|
|
|
query: ecs.NewQuery(filter.Contains(component.TwoPositionTransformType)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新位置
|
|
|
|
func (tp *TwoPositionMovementSys) Update(w ecs.World) {
|
|
|
|
tp.query.Each(w, func(entry *ecs.Entry) {
|
|
|
|
position := component.TwoPositionTransformType.Get(entry)
|
|
|
|
if position.Speed != 0 {
|
2023-09-26 18:06:15 +08:00
|
|
|
pos := position.Pos + position.Speed
|
|
|
|
if pos < consts.TwoPosMin {
|
|
|
|
position.Pos = consts.TwoPosMin
|
|
|
|
position.Speed = 0
|
|
|
|
} else if pos > consts.TwoPosMax {
|
|
|
|
position.Pos = consts.TwoPosMax
|
|
|
|
position.Speed = 0
|
|
|
|
} else {
|
|
|
|
position.Pos = pos
|
2023-09-22 18:33:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|