16 Star 63 Fork 47

ShirDon-廖显东 / Go语言高级开发与实战-随书代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 782 Bytes
一键复制 编辑 原始数据 按行查看 历史
ShirDon-廖显东 提交于 2021-12-02 15:19 . commit
package main
import (
"fmt"
"gitee.com/shirdonl/goAdvanced/chapter1/struct/game/pkg"
"time"
)
func main() {
// 创建玩家,设置玩家速度
var p = pkg.NewPlayer(0.6)
fmt.Println(p.Speed)
// 设置玩家目标位置
p.MoveTo(pkg.Vector{6, 8})
p.CurrentVector = pkg.Vector{9, 13}
fmt.Println(p.TargetVector)
for !p.IsArrived() {
// 更新玩家坐标位置
p.Update()
// 打印玩家位置
fmt.Println(p.Position())
// 一秒更新一次
time.Sleep(time.Second)
}
fmt.Println("到达目的地了~")
}
//0.6
//{6 8}
//{8.691302 12.485504}
//{8.382605 11.971008}
//{8.073907 11.456512}
//{7.7652097 10.942017}
//{7.4565125 10.427521}
//{7.1478148 9.913025}
//{6.8391175 9.398529}
//{6.53042 8.884033}
//{6.2217226 8.369537}
//到达目的地了~
Go
1
https://gitee.com/shirdonl/goAdvanced.git
git@gitee.com:shirdonl/goAdvanced.git
shirdonl
goAdvanced
Go语言高级开发与实战-随书代码
0f051d9f4e35

搜索帮助

53164aa7 5694891 3bd8fe86 5694891