本文整理汇总了Golang中github.com/runningwild/mathgl.Vec2.Assign方法的典型用法代码示例。如果您正苦于以下问题:Golang Vec2.Assign方法的具体用法?Golang Vec2.Assign怎么用?Golang Vec2.Assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/runningwild/mathgl.Vec2
的用法示例。
在下文中一共展示了Vec2.Assign方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DoAdvance
// Advances ent up to dist towards the target cell. Returns the distance
// traveled.
func (e *Entity) DoAdvance(dist float32, x, y int) float32 {
if dist <= 0 {
e.sprite.sp.Command("stop")
return 0
}
e.sprite.sp.Command("move")
source := mathgl.Vec2{float32(e.X), float32(e.Y)}
target := mathgl.Vec2{float32(x), float32(y)}
var seg mathgl.Vec2
seg.Assign(&target)
seg.Subtract(&source)
e.TurnToFace(x, y)
var traveled float32
if seg.Length() > dist {
seg.Scale(dist / seg.Length())
traveled = dist
} else {
traveled = seg.Length()
}
seg.Add(&source)
e.X = float64(seg.X)
e.Y = float64(seg.Y)
return dist - traveled
}
示例2: TurnToFace
func (e *Entity) TurnToFace(x, y int) {
target := mathgl.Vec2{float32(x), float32(y)}
source := mathgl.Vec2{float32(e.X), float32(e.Y)}
var seg mathgl.Vec2
seg.Assign(&target)
seg.Subtract(&source)
target_facing := facing(seg)
f_diff := target_facing - e.sprite.sp.StateFacing()
if f_diff != 0 {
f_diff = (f_diff + 6) % 6
if f_diff > 3 {
f_diff -= 6
}
for f_diff < 0 {
e.sprite.sp.Command("turn_left")
f_diff++
}
for f_diff > 0 {
e.sprite.sp.Command("turn_right")
f_diff--
}
}
}