rts-sim-module/system/movable_system.go
2023-08-25 10:50:39 +08:00

32 lines
760 B
Go

package system
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
)
// 按速度移动的设备系统
// 只负责按速度移动位置,由该组件的观察者负责解释位置
type MovableDeviceSystem struct {
query *ecs.Query
}
func NewMovableDeviceSystem() *MovableDeviceSystem {
return &MovableDeviceSystem{query: ecs.NewQuery(filter.Contains(components.MovableDeviceStateComponent))}
}
// world 执行
func (me *MovableDeviceSystem) Update(world ecs.World) {
me.query.Each(world, func(e *ecs.Entry) {
md := components.MovableDeviceStateComponent.Get(e)
if md.Speed > 0 {
if md.ToH {
md.Position += int64(md.Speed)
} else {
md.Position -= int64(md.Speed)
}
}
})
}