添加基本游戏内容

This commit is contained in:
kercylan98 2023-04-24 13:25:57 +08:00
parent a7b603740f
commit 8418ad4979
7 changed files with 255 additions and 0 deletions

7
game/actor.go Normal file
View File

@ -0,0 +1,7 @@
package game
// Actor 表示游戏中的对象,具有唯一标识符
type Actor interface {
// GetGuid 获取对象的唯一标识符
GetGuid() int64
}

15
game/actor_follow.go Normal file
View File

@ -0,0 +1,15 @@
package game
// ActorFollow 是一个将ActorMove和Position结合的接口表示可以跟随目标移动的游戏对象。
// 通过实现此接口,游戏对象可以跟随指定的目标进行移动和操作。
type ActorFollow interface {
ActorMove
// FollowTarget2D 让游戏对象跟随目标在2D平面上移动。
// 该方法将对象的位置设置为目标的位置加上指定的偏移量,即相对移动。
// 参数target表示要跟随的目标位置dx、dy表示对象在X、Y轴上的偏移量。
FollowTarget2D(target Position, dx, dy float64)
// FollowTarget3D 让游戏对象跟随目标在3D空间中移动。
// 该方法将对象的位置设置为目标的位置加上指定的偏移量,即相对移动。
// 参数target表示要跟随的目标位置dx、dy、dz表示对象在X、Y、Z轴上的偏移量。
FollowTarget3D(target Position, dx, dy, dz float64)
}

52
game/actor_move.go Normal file
View File

@ -0,0 +1,52 @@
package game
// ActorMove 是一个将Actor和Position结合的接口表示可以移动的游戏对象。
// 通过实现此接口,游戏对象可以在游戏世界中进行移动和操作。
type ActorMove interface {
Actor
Position
// MoveTo2D 将游戏对象移动到指定的位置。
// 该方法将对象的位置设置为指定的坐标,即绝对移动。
// 参数x、y分别表示对象在X、Y轴上的目标位置。
MoveTo2D(x, y float64)
// MoveBy2D 在当前位置基础上移动游戏对象。
// 该方法将对象的位置增加指定的偏移量,即相对移动。
// 参数dx、dy分别表示对象在X、Y轴上的偏移量。
MoveBy2D(dx, dy float64)
// MoveTo3D 将游戏对象移动到指定的位置。
// 该方法将对象的位置设置为指定的坐标,即绝对移动。
// 参数x、y和z分别表示对象在X、Y和Z轴上的目标位置。
MoveTo3D(x, y, z float64)
// MoveBy3D 在当前位置基础上移动游戏对象。
// 该方法将对象的位置增加指定的偏移量,即相对移动。
// 参数dx、dy和dz分别表示对象在X、Y和Z轴上的偏移量。
MoveBy3D(dx, dy, dz float64)
// MoveToX 将游戏对象在X轴上移动到指定位置。
// 该方法将对象的X坐标设置为指定的位置即绝对移动。
// 参数x表示对象在X轴上的目标位置。
MoveToX(x float64)
// MoveByX 在当前位置基础上移动游戏对象在X轴上的位置。
// 该方法将对象的X坐标增加指定的偏移量即相对移动。
// 参数dx表示对象在X轴上的偏移量。
MoveByX(dx float64)
// MoveToY 将游戏对象在Y轴上移动到指定位置。
// 该方法将对象的Y坐标设置为指定的位置即绝对移动。
// 参数y表示对象在Y轴上的目标位置。
MoveToY(y float64)
// MoveByY 在当前位置基础上移动游戏对象在Y轴上的位置。
// 该方法将对象的Y坐标增加指定的偏移量即相对移动。
// 参数dy表示对象在Y轴上的偏移量。
MoveByY(dy float64)
// MoveToZ 将游戏对象在Z轴上移动到指定位置。
// 该方法将对象的Z坐标设置为指定的位置即绝对移动。
// 参数z表示对象在Z轴上的目标位置。
MoveToZ(z float64)
// MoveByZ 在当前位置基础上移动游戏对象在Z轴上的位置。
// 该方法将对象的Z坐标增加指定的偏移量即相对移动。
// 参数dz表示对象在Z轴上的偏移量。
MoveByZ(dz float64)
// GetSpeed 获取对象的移动速度
GetSpeed() float64
// SetSpeed 设置对象的移动速度
SetSpeed(speed float64)
}

15
game/builtin/actor.go Normal file
View File

@ -0,0 +1,15 @@
package builtin
func NewActor(guid int64) *Actor {
return &Actor{
guid: guid,
}
}
type Actor struct {
guid int64
}
func (slf *Actor) GetGuid() int64 {
return slf.guid
}

View File

@ -0,0 +1,71 @@
package builtin
import (
"minotaur/game"
)
type ActorMove struct {
game.Actor
game.Position
speed float64 // 移动速度
}
func (slf *ActorMove) MoveTo2D(x, y float64) {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) MoveBy2D(dx, dy float64) {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) MoveTo3D(x, y, z float64) {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) MoveBy3D(dx, dy, dz float64) {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) MoveToX(x float64) {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) MoveByX(dx float64) {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) MoveToY(y float64) {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) MoveByY(dy float64) {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) MoveToZ(z float64) {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) MoveByZ(dz float64) {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) GetSpeed() float64 {
//TODO implement me
panic("implement me")
}
func (slf *ActorMove) SetSpeed(speed float64) {
//TODO implement me
panic("implement me")
}

68
game/builtin/position.go Normal file
View File

@ -0,0 +1,68 @@
package builtin
// NewPosition 创建一个新的Position对象。
func NewPosition(x, y, z float64) *Position {
return &Position{
x: x,
y: y,
z: z,
}
}
// Position 是一个具有位置信息的对象。
type Position struct {
x, y, z float64
}
// GetX 返回Position对象的X坐标。
func (p *Position) GetX() float64 {
return p.x
}
// GetY 返回Position对象的Y坐标。
func (p *Position) GetY() float64 {
return p.y
}
// GetZ 返回Position对象的Z坐标。
func (p *Position) GetZ() float64 {
return p.z
}
// GetXY 返回Position对象的X和Y坐标。
func (p *Position) GetXY() (float64, float64) {
return p.x, p.y
}
// GetXYZ 返回Position对象的X、Y和Z坐标。
func (p *Position) GetXYZ() (float64, float64, float64) {
return p.x, p.y, p.z
}
// SetX 设置Position对象的X坐标。
func (p *Position) SetX(x float64) {
p.x = x
}
// SetY 设置Position对象的Y坐标。
func (p *Position) SetY(y float64) {
p.y = y
}
// SetZ 设置Position对象的Z坐标。
func (p *Position) SetZ(z float64) {
p.z = z
}
// SetXY 设置Position对象的X和Y坐标。
func (p *Position) SetXY(x, y float64) {
p.x = x
p.y = y
}
// SetXYZ 设置Position对象的X、Y和Z坐标。
func (p *Position) SetXYZ(x, y, z float64) {
p.x = x
p.y = y
p.z = z
}

27
game/postion.go Normal file
View File

@ -0,0 +1,27 @@
package game
// Position 是一个兼容2D和3D的位置接口用于表示游戏中对象的空间位置。
// 该接口提供了获取和设置X、Y和Z轴坐标的方法以便在2D和3D环境中灵活使用。
// 通过实现此接口,游戏对象可以方便地在不同的坐标系中进行转换和操作。
type Position interface {
// GetX 获取X轴坐标
GetX() float64
// GetY 获取Y轴坐标
GetY() float64
// GetZ 获取Z轴坐标
GetZ() float64
// GetXY 获取X和Y轴坐标
GetXY() (x, y float64)
// GetXYZ 获取X、Y和Z轴坐标
GetXYZ() (x, y, z float64)
// SetX 设置X轴坐标
SetX(x float64)
// SetY 设置Y轴坐标
SetY(y float64)
// SetZ 设置Z轴坐标
SetZ(z float64)
// SetXY 设置X和Y轴坐标
SetXY(x, y float64)
// SetXYZ 设置X、Y和Z轴坐标
SetXYZ(x, y, z float64)
}