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


Golang Vec2.X方法代码示例

本文整理汇总了Golang中github.com/runningwild/linear.Vec2.X方法的典型用法代码示例。如果您正苦于以下问题:Golang Vec2.X方法的具体用法?Golang Vec2.X怎么用?Golang Vec2.X使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/runningwild/linear.Vec2的用法示例。


在下文中一共展示了Vec2.X方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Draw

func (tm *ThunderMenu) Draw(region Region, style StyleStack) {
	// Set clip planes
	gl.PushAttrib(gl.TRANSFORM_BIT)
	defer gl.PopAttrib()
	var eqs [4][4]gl.Double
	eqs[0][0], eqs[0][1], eqs[0][2], eqs[0][3] = 1, 0, 0, -gl.Double(region.X)
	eqs[1][0], eqs[1][1], eqs[1][2], eqs[1][3] = -1, 0, 0, gl.Double(region.X+region.Dx)
	eqs[2][0], eqs[2][1], eqs[2][2], eqs[2][3] = 0, 1, 0, -gl.Double(region.Y)
	eqs[3][0], eqs[3][1], eqs[3][2], eqs[3][3] = 0, -1, 0, gl.Double(region.Y+region.Dy)
	gl.Enable(gl.CLIP_PLANE0)
	gl.Enable(gl.CLIP_PLANE1)
	gl.Enable(gl.CLIP_PLANE2)
	gl.Enable(gl.CLIP_PLANE3)
	gl.ClipPlane(gl.CLIP_PLANE0, &eqs[0][0])
	gl.ClipPlane(gl.CLIP_PLANE1, &eqs[1][0])
	gl.ClipPlane(gl.CLIP_PLANE2, &eqs[2][0])
	gl.ClipPlane(gl.CLIP_PLANE3, &eqs[3][0])

	var start, end int
	if tm.delta <= 0 {
		start = tm.current + int(math.Floor(tm.delta))
		end = tm.current
		region.X += int(float64(region.Dx) * (float64(start-tm.current) - tm.delta))
	} else {
		start = tm.current
		end = tm.current + int(math.Ceil(tm.delta))
		region.X += int(float64(region.Dx) * (float64(end-tm.current) - tm.delta - math.Floor(tm.delta) - 1))
	}
	var offset linear.Vec2
	offset.X = (float64(tm.current) + tm.delta) * float64(region.Dx)
	for i := start; i <= end; i++ {
		style.PushStyle(map[string]interface{}{"offset": offset})
		tm.Subs[tm.menuStack[i]].Draw(region, style)
		style.Pop()
		region.X += region.Dx
	}
}
开发者ID:runningwild,项目名称:magnus,代码行数:37,代码来源:thunder_menu.go

示例4: 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

示例5: 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.X方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。