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 } } }) }