目录结构调整

This commit is contained in:
kercylan98 2023-06-03 16:22:03 +08:00
parent e7607cdff5
commit bec0561d30
5 changed files with 22 additions and 20 deletions

View File

@ -1,7 +1,7 @@
package builtin
package components
import (
"github.com/kercylan98/minotaur/game"
"github.com/kercylan98/minotaur/component"
"github.com/kercylan98/minotaur/utils/g2d"
"sync"
"time"
@ -35,12 +35,12 @@ type Moving2D struct {
event chan func()
close bool
position2DChangeEventHandles []game.Position2DChangeEventHandle
position2DDestinationEventHandles []game.Position2DDestinationEventHandle
position2DChangeEventHandles []component.Position2DChangeEventHandle
position2DDestinationEventHandles []component.Position2DDestinationEventHandle
}
// MoveTo 设置对象移动到特定位置
func (slf *Moving2D) MoveTo(entity game.Moving2DEntity, x float64, y float64) {
func (slf *Moving2D) MoveTo(entity component.Moving2DEntity, x float64, y float64) {
guid := entity.GetGuid()
current := time.Now().UnixMilli()
slf.rw.Lock()
@ -72,29 +72,29 @@ func (slf *Moving2D) StopMove(guid int64) {
}
// RegPosition2DChangeEvent 在对象位置改变时将执行注册的事件处理函数
func (slf *Moving2D) RegPosition2DChangeEvent(handle game.Position2DChangeEventHandle) {
func (slf *Moving2D) RegPosition2DChangeEvent(handle component.Position2DChangeEventHandle) {
slf.position2DChangeEventHandles = append(slf.position2DChangeEventHandles, handle)
}
func (slf *Moving2D) OnPosition2DChangeEvent(entity game.Moving2DEntity, oldX, oldY float64) {
func (slf *Moving2D) OnPosition2DChangeEvent(entity component.Moving2DEntity, oldX, oldY float64) {
for _, handle := range slf.position2DChangeEventHandles {
handle(slf, entity, oldX, oldY)
}
}
// RegPosition2DDestinationEvent 在对象到达终点时将执行被注册的事件处理函数
func (slf *Moving2D) RegPosition2DDestinationEvent(handle game.Position2DDestinationEventHandle) {
func (slf *Moving2D) RegPosition2DDestinationEvent(handle component.Position2DDestinationEventHandle) {
slf.position2DDestinationEventHandles = append(slf.position2DDestinationEventHandles, handle)
}
func (slf *Moving2D) OnPosition2DDestinationEvent(entity game.Moving2DEntity) {
func (slf *Moving2D) OnPosition2DDestinationEvent(entity component.Moving2DEntity) {
for _, handle := range slf.position2DDestinationEventHandles {
handle(slf, entity)
}
}
type moving2DTarget struct {
game.Moving2DEntity
component.Moving2DEntity
x, y float64
lastMoveTime int64
}

View File

@ -1,4 +1,4 @@
package builtin
package components
import (
"errors"

View File

@ -1,8 +1,8 @@
package builtin
package components
import (
"fmt"
"github.com/kercylan98/minotaur/game"
"github.com/kercylan98/minotaur/component"
"sync"
"testing"
"time"
@ -43,11 +43,11 @@ func NewEntity(guid int64, speed float64) *MoveEntity {
func TestMoving2D_MoveTo(t *testing.T) {
moving := NewMoving2D(WithMoving2DTimeUnit(time.Second))
var wait sync.WaitGroup
moving.RegPosition2DDestinationEvent(func(moving game.Moving2D, entity game.Moving2DEntity) {
moving.RegPosition2DDestinationEvent(func(moving component.Moving2D, entity component.Moving2DEntity) {
wait.Done()
})
var res []string
moving.RegPosition2DChangeEvent(func(moving game.Moving2D, entity game.Moving2DEntity, oldX, oldY float64) {
moving.RegPosition2DChangeEvent(func(moving component.Moving2D, entity component.Moving2DEntity, oldX, oldY float64) {
x, y := entity.GetPosition()
res = append(res, fmt.Sprintf("%d : %d | %f, %f > %f, %f", entity.GetGuid(), time.Now().UnixMilli(), oldX, oldY, x, y))
})

View File

@ -1,4 +1,4 @@
package game
package component
// Moving2D 2D移动功能接口定义
type Moving2D interface {

View File

@ -1,10 +1,12 @@
package game
package component
import "github.com/kercylan98/minotaur/game"
// Moving2DEntity 2D移动对象接口定义
type Moving2DEntity interface {
Actor
Position2D
Position2DSet
game.Actor
game.Position2D
game.Position2DSet
// GetSpeed 获取移动速度
GetSpeed() float64