rts-sim-module/sys/common_sys/two_position_movement.go
walker 0bba8f0934 删除donburi包引用
修改filter导入为从ecs项目导入
整理包结构,将弃用的包放入deprecated文件中
2023-10-09 11:17:25 +08:00

36 lines
823 B
Go

package common_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"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 {
pos := position.Pos + position.Speed
if pos < consts.TwoPosMin {
position.Pos = consts.TwoPosMin
} else if pos > consts.TwoPosMax {
position.Pos = consts.TwoPosMax
} else {
position.Pos = pos
}
}
})
}