当前位置: 首页>>代码示例>>Golang>>正文


Golang Vec2.Y方法代码示例

本文整理汇总了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)
		}
	}
}
开发者ID:runningwild,项目名称:magnus,代码行数:30,代码来源:local.go

示例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
}
开发者ID:runningwild,项目名称:jota,代码行数:13,代码来源:editor_graphics.go

示例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()
}
开发者ID:runningwild,项目名称:jota,代码行数:40,代码来源:game_graphics.go

示例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))
	}
}
开发者ID:runningwild,项目名称:magnus,代码行数:72,代码来源:local.go


注:本文中的github.com/runningwild/linear.Vec2.Y方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。