本文整理匯總了Golang中github.com/runningwild/linear.Vec2.Y方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vec2.Y方法的具體用法?Golang Vec2.Y怎麽用?Golang Vec2.Y使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/runningwild/linear.Vec2
的用法示例。
在下文中一共展示了Vec2.Y方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: thinkAbility
func (l *LocalData) thinkAbility(g *Game, abs *personalAbilities, gid Gid) {
if abs.activeAbility == nil {
return
}
var mouse linear.Vec2
if l.mode == LocalModeArchitect {
mx, my := l.sys.GetCursorPos()
mouse.X = float64(mx)
mouse.Y = float64(my)
mouse = mouse.Sub(l.architect.camera.regionPos)
mouse.X /= l.architect.camera.regionDims.X
mouse.Y /= l.architect.camera.regionDims.Y
mouse.X *= l.architect.camera.current.dims.X
mouse.Y *= l.architect.camera.current.dims.Y
mouse = mouse.Sub(l.architect.camera.current.dims.Scale(0.5))
mouse = mouse.Add(l.architect.camera.current.mid)
}
events, die := abs.activeAbility.Think(gid, g, mouse)
for _, event := range events {
l.engine.ApplyEvent(event)
}
if die {
base.Log().Printf("Deactivate on die")
more_events := abs.activeAbility.Deactivate(gid)
abs.activeAbility = nil
for _, event := range more_events {
l.engine.ApplyEvent(event)
}
}
}
示例2: getPoly
func (editor *editorData) getPoly(g *Game) linear.Poly {
pos := editor.cursorPosInGameCoords(&g.Level.Room)
var offset linear.Vec2
offset.X = pos.X - editor.placeBlock.offset.X
offset.X = math.Floor(offset.X/editor.placeBlock.grid+0.5) * editor.placeBlock.grid
offset.Y = pos.Y - editor.placeBlock.offset.Y
offset.Y = math.Floor(offset.Y/editor.placeBlock.grid+0.5) * editor.placeBlock.grid
block := make(linear.Poly, len(editor.placeBlock.block))
for i := range editor.placeBlock.block {
block[i] = editor.placeBlock.block[i].Add(offset)
}
return block
}
示例3: FocusRegion
func (camera *cameraInfo) FocusRegion(g *Game, side int) {
min := linear.Vec2{1e9, 1e9}
max := linear.Vec2{-1e9, -1e9}
player := g.Ents[g.local.Gid]
if player == nil {
min.X = 0
min.Y = 0
max.X = float64(g.Level.Room.Dx)
max.Y = float64(g.Level.Room.Dy)
} else {
min.X = player.Pos().X - player.Stats().Vision()
min.Y = player.Pos().Y - player.Stats().Vision()
if min.X < 0 {
min.X = 0
}
if min.Y < 0 {
min.Y = 0
}
max.X = player.Pos().X + player.Stats().Vision()
max.Y = player.Pos().Y + player.Stats().Vision()
if max.X > float64(g.Level.Room.Dx) {
max.X = float64(g.Level.Room.Dx)
}
if max.Y > float64(g.Level.Room.Dy) {
max.Y = float64(g.Level.Room.Dy)
}
}
mid := min.Add(max).Scale(0.5)
dims := max.Sub(min)
if dims.X/dims.Y < camera.regionDims.X/camera.regionDims.Y {
dims.X = dims.Y * camera.regionDims.X / camera.regionDims.Y
} else {
dims.Y = dims.X * camera.regionDims.Y / camera.regionDims.X
}
camera.target.dims = dims
camera.target.mid = mid
camera.approachTarget()
}
示例4: doInvadersFocusRegion
func (camera *cameraInfo) doInvadersFocusRegion(g *Game, side int) {
min := linear.Vec2{1e9, 1e9}
max := linear.Vec2{-1e9, -1e9}
hits := 0
for _, ent := range g.temp.AllEnts {
if ent.Side() != side {
continue
}
if player, ok := ent.(*PlayerEnt); ok {
hits++
pos := player.Pos()
if pos.X < min.X {
min.X = pos.X
}
if pos.Y < min.Y {
min.Y = pos.Y
}
if pos.X > max.X {
max.X = pos.X
}
if pos.Y > max.Y {
max.Y = pos.Y
}
}
}
if hits == 0 {
min.X = 0
min.Y = 0
max.X = float64(g.Levels[GidInvadersStart].Room.Dx)
max.Y = float64(g.Levels[GidInvadersStart].Room.Dy)
} else {
min.X -= stats.LosPlayerHorizon + 50
min.Y -= stats.LosPlayerHorizon + 50
if min.X < 0 {
min.X = 0
}
if min.Y < 0 {
min.Y = 0
}
max.X += stats.LosPlayerHorizon + 50
max.Y += stats.LosPlayerHorizon + 50
if max.X > float64(g.Levels[GidInvadersStart].Room.Dx) {
max.X = float64(g.Levels[GidInvadersStart].Room.Dx)
}
if max.Y > float64(g.Levels[GidInvadersStart].Room.Dy) {
max.Y = float64(g.Levels[GidInvadersStart].Room.Dy)
}
}
mid := min.Add(max).Scale(0.5)
dims := max.Sub(min)
if dims.X/dims.Y < camera.regionDims.X/camera.regionDims.Y {
dims.X = dims.Y * camera.regionDims.X / camera.regionDims.Y
} else {
dims.Y = dims.X * camera.regionDims.Y / camera.regionDims.X
}
camera.target.dims = dims
camera.target.mid = mid
if camera.current.mid.X == 0 && camera.current.mid.Y == 0 {
// On the very first frame the current midpoint will be (0,0), which should
// never happen after the game begins. In this one case we'll immediately
// set current to target so we don't start off by approaching it from the
// origin.
camera.current = camera.target
} else {
// speed is in (0, 1), the higher it is, the faster current approaches target.
speed := 0.1
camera.current.dims = camera.current.dims.Scale(1 - speed).Add(camera.target.dims.Scale(speed))
camera.current.mid = camera.current.mid.Scale(1 - speed).Add(camera.target.mid.Scale(speed))
}
}