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


Golang Vec2.Add方法代码示例

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


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

func fireDoLine(c *cmwc.Cmwc, pos linear.Vec2, angle, stored float64, speed int, level *game.Level) fireExplosion {
	rng := rand.New(c)
	ray := (linear.Vec2{1, 0})
	// ray.Scale(math.Abs(rng.NormFloat64()/10) + 50)
	scale := (stored/5 + 50) * (1 + rng.Float64()*(0.2+stored/2000))
	ray = ray.Rotate(angle).Rotate(rng.NormFloat64() * (0.2 + stored/7500)).Scale(scale)
	seg := linear.Seg2{pos, pos.Add(ray)}
	base.DoOrdered(level.Room.Walls, func(a, b string) bool { return a < b }, func(_ string, poly linear.Poly) {
		for i := range poly {
			if seg.DoesIsect(poly.Seg(i)) {
				isect := seg.Isect(poly.Seg(i))
				seg.Q = isect
			}
		}
	})
	p1 := rng.Intn(speed)
	p2 := rng.Intn(speed)
	p3 := rng.Intn(speed)
	return fireExplosion{
		Pos:    seg.Q,
		Radius: rng.Float64()*40 + 30,
		Timer:  0,
		Start:  1*speed + p1,
		Peak:   4*speed + p1 + p2,
		End:    5*speed + p1 + p2 + p3,
	}
}
开发者ID:runningwild,项目名称:magnus,代码行数:27,代码来源:fire.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: AddCreeps

func (g *Game) AddCreeps(pos linear.Vec2, count, side int, params map[string]interface{}) {
	if side < 0 || side >= len(g.Level.Room.SideData) {
		base.Error().Fatalf("Got side %d, but this level only supports sides from 0 to %d.", side, len(g.Level.Room.SideData)-1)
		return
	}
	for i := 0; i < count; i++ {
		var c CreepEnt
		c.StatsInst = stats.Make(stats.Base{
			Health: 100,
			Mass:   250,
			Acc:    50.0,
			Rate:   0.0,
			Size:   8,
			Vision: 400,
		})

		// Evenly space the players on a circle around the starting position.
		randAngle := rand.New(g.Rng).Float64() * math.Pi
		rot := (linear.Vec2{15, 0}).Rotate(randAngle + float64(i)*2*3.1415926535/float64(count))
		c.Position = pos.Add(rot)

		c.Side_ = side
		c.Gid = g.NextGid()

		c.Abilities_ = append(
			c.Abilities_,
			ability_makers["asplode"](map[string]float64{"startRadius": 40, "endRadius": 70, "durationThinks": 50, "dps": 5}))

		// if playerData.gid[0:2] == "Ai" {
		//  c.BindAi("simple", g.local.Engine)
		// }

		g.AddEnt(&c)
		c.BindAi("creep", g.local.Engine)
		for name, value := range params {
			c.ai.SetParam(name, value)
		}
	}
}
开发者ID:runningwild,项目名称:jota,代码行数:39,代码来源:creep.go

示例5: BasicOperationsSpec

func BasicOperationsSpec(c gospec.Context) {
	a := linear.Vec2{3, 4}
	b := linear.Vec2{5, 6}
	c.Specify("Make sure adding vectors works.", func() {
		VecExpect(c, a.Add(b), Equals, linear.Vec2{8, 10})
	})
	c.Specify("Make sure subtracting vectors works.", func() {
		VecExpect(c, a.Sub(b), Equals, linear.Vec2{-2, -2})
	})
	c.Specify("Make sure dotting vectors works.", func() {
		c.Expect(a.Dot(b), IsWithin(1e-9), 39.0)
	})
	c.Specify("Make sure crossing vectors works.", func() {
		VecExpect(c, a.Cross(), Equals, linear.Vec2{-4, 3})
	})
	c.Specify("Make sure taking the magnitude of vectors works.", func() {
		c.Expect(a.Mag(), IsWithin(1e-9), 5.0)
		c.Expect(a.Mag2(), IsWithin(1e-9), 25.0)
	})
	c.Specify("Make sure scaling vectors works.", func() {
		VecExpect(c, a.Scale(3), Equals, linear.Vec2{9, 12})
	})
}
开发者ID:runningwild,项目名称:linear,代码行数:23,代码来源:linear_test.go

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