本文整理汇总了Golang中github.com/runningwild/haunts/game.Game.ToVertex方法的典型用法代码示例。如果您正苦于以下问题:Golang Game.ToVertex方法的具体用法?Golang Game.ToVertex怎么用?Golang Game.ToVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/runningwild/haunts/game.Game
的用法示例。
在下文中一共展示了Game.ToVertex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Maintain
func (a *Move) Maintain(dt int64, g *game.Game, ae game.ActionExec) game.MaintenanceStatus {
if ae != nil {
exec := ae.(*moveExec)
a.ent = g.EntityById(ae.EntityId())
if len(exec.Path) == 0 {
base.Error().Printf("Got a move exec with a path length of 0: %v", exec)
return game.Complete
}
a.cost = exec.measureCost(a.ent, g)
if a.cost > a.ent.Stats.ApCur() {
base.Error().Printf("Got a move that required more ap than available: %v", exec)
base.Error().Printf("Path: %v", exec.Path)
return game.Complete
}
if a.cost == -1 {
base.Error().Printf("Got a move that followed an invalid path: %v", exec)
base.Error().Printf("Path: %v", exec.Path)
if a.ent == nil {
base.Error().Printf("ENT was Nil!")
} else {
x, y := a.ent.Pos()
v := g.ToVertex(x, y)
base.Error().Printf("Ent pos: (%d, %d) -> (%d)", x, y, v)
}
return game.Complete
}
algorithm.Map2(exec.Path, &a.path, func(v int) [2]int {
_, x, y := g.FromVertex(v)
return [2]int{x, y}
})
base.Log().Printf("Path Validated: %v", exec)
a.ent.Stats.ApplyDamage(-a.cost, 0, status.Unspecified)
src := g.ToVertex(a.ent.Pos())
graph := g.Graph(a.ent.Side(), true, nil)
a.drawPath(a.ent, g, graph, src)
}
// Do stuff
factor := float32(math.Pow(2, a.ent.Walking_speed))
dist := a.ent.DoAdvance(factor*float32(dt)/200, a.path[0][0], a.path[0][1])
for dist > 0 {
if len(a.path) == 1 {
a.ent.DoAdvance(0, 0, 0)
a.ent.Info.RoomsExplored[a.ent.CurrentRoom()] = true
a.ent = nil
return game.Complete
}
a.path = a.path[1:]
a.ent.Info.RoomsExplored[a.ent.CurrentRoom()] = true
dist = a.ent.DoAdvance(dist, a.path[0][0], a.path[0][1])
}
return game.InProgress
}
示例2: measureCost
func (exec *moveExec) measureCost(ent *game.Entity, g *game.Game) int {
if len(exec.Path) == 0 {
base.Error().Printf("Zero length path")
return -1
}
if g.ToVertex(ent.Pos()) != exec.Path[0] {
base.Error().Printf("Path doesn't begin at ent's position, %d != %d", g.ToVertex(ent.Pos()), exec.Path[0])
return -1
}
graph := g.Graph(ent.Side(), true, nil)
v := g.ToVertex(ent.Pos())
cost := 0
for _, step := range exec.Path[1:] {
dsts, costs := graph.Adjacent(v)
ok := false
prev := v
base.Log().Printf("Adj(%d):", v)
for j := range dsts {
base.Log().Printf("Node %d", dsts[j])
if dsts[j] == step {
cost += int(costs[j])
v = dsts[j]
ok = true
break
}
}
base.Log().Printf("%d -> %d: %t", prev, v, ok)
if !ok {
return -1
}
}
return cost
}
示例3: HandleInput
func (a *Move) HandleInput(group gui.EventGroup, g *game.Game) (bool, game.ActionExec) {
cursor := group.Events[0].Key.Cursor()
if cursor != nil {
fx, fy := g.GetViewer().WindowToBoard(cursor.Point())
a.findPath(a.ent, int(fx), int(fy))
}
if found, _ := group.FindEvent(gin.MouseLButton); found {
if len(a.path) > 0 {
if a.cost <= a.ent.Stats.ApCur() {
var exec moveExec
exec.SetBasicData(a.ent, a)
algorithm.Map2(a.path, &exec.Path, func(v [2]int) int {
return g.ToVertex(v[0], v[1])
})
return true, &exec
}
return true, nil
} else {
return false, nil
}
}
return false, nil
}
示例4: drawPath
func (a *Move) drawPath(ent *game.Entity, g *game.Game, graph algorithm.Graph, src int) {
if path_tex != nil {
pix := path_tex.Pix()
for i := range pix {
for j := range pix[i] {
pix[i][j] = 0
}
}
current := 0.0
for i := 1; i < len(a.path); i++ {
src := g.ToVertex(a.path[i-1][0], a.path[i-1][1])
dst := g.ToVertex(a.path[i][0], a.path[i][1])
v, cost := graph.Adjacent(src)
for j := range v {
if v[j] == dst {
current += cost[j]
break
}
}
pix[a.path[i][1]][a.path[i][0]] += byte(current)
}
path_tex.Remap()
}
}