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


Golang Vector.X方法代码示例

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


在下文中一共展示了Vector.X方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: VectorFmt

func VectorFmt(v engine.Vector, arr []float32, s string) engine.Vector {
	if len(s) == 0 {
		if len(arr) > 2 {
			v.X = arr[0]
			v.Y = arr[1]
			v.Z = arr[2]
		} else if len(arr) > 1 {
			v.X = arr[0]
			v.Y = arr[1]
		} else {
			v.X = arr[0]
		}
		return v
	}
	if (len(s) <= 3 && len(s) >= 1) && len(arr) == 1 {
		for _, r := range s {
			switch r {
			case 'x', 'X':
				v.X = arr[0]
			case 'y', 'Y':
				v.Y = arr[0]
			case 'z', 'Z':
				v.Z = arr[0]
			}
		}
		return v
	}
	for i, r := range s {
		if i >= len(arr) {
			break
		}
		switch r {
		case 'x', 'X':
			v.X = arr[i]
		case 'y', 'Y':
			v.Y = arr[i]
		case 'z', 'Z':
			v.Z = arr[i]
		}
	}
	return v
}
开发者ID:skarr,项目名称:GarageEngine,代码行数:42,代码来源:Type.go

示例2: FixedUpdate

func (this *PlayerController) FixedUpdate() {
	this.GameObject().Physics.Shape.Layer = chipmunk.Layer(this.Player.Map.Layer)
	t := this.JointGameObject.Transform()

	var move engine.Vector = this.Transform().WorldPosition()

	if input.KeyDown('W') {
		move.Y += 100
	}
	if input.KeyDown('S') {
		move.Y += -100
	}
	if input.KeyDown('A') {
		move.X += -100
	}
	if input.KeyDown('D') {
		move.X += 100
	}

	t.SetWorldPosition(move)
}
开发者ID:skarr,项目名称:GarageEngine,代码行数:21,代码来源:PlayerController.go

示例3: PositionToTile

func (m *Map) PositionToTile(worldPosition engine.Vector) (tile Tile, x, y int) {

	mapPos := m.Transform().WorldPosition()
	//Calculate center of map
	mapPos.X -= (m.TileSize * float32(m.Width) / 2)
	mapPos.Y -= (m.TileSize * float32(m.Height) / 2)

	//World to Local position
	worldPosition.X -= mapPos.X
	worldPosition.Y -= mapPos.Y

	//Turn upside down
	worldPosition.Y = (float32(m.Height) * m.TileSize) - worldPosition.Y

	//Calculate tile position in array
	xx := (worldPosition.X / m.TileSize)
	yy := (worldPosition.Y / m.TileSize)
	if xx < 0 {
		x = -1
	} else {
		x = int(xx)
	}
	if yy < 0 {
		y = -1
	} else {
		y = int(yy)
	}

	//Check if outside of map
	if xx < 0 || yy < 0 || xx >= float32(m.Width) || yy >= float32(m.Height) {
		return 0, x, y
	}

	//return the tile
	return m.Tiles[x+(y*m.Width)], int(x), int(y)
}
开发者ID:skarr,项目名称:GarageEngine,代码行数:36,代码来源:Map.go

示例4: Draw

func (m *Map) Draw() {
	if m.Layer < MainPlayer.Map.Layer {
		return
	}
	camera := engine.GetScene().SceneBase().Camera
	cameraPos := camera.Transform().WorldPosition()
	w, h := camera.ScreenSize()
	cameraPos.X -= w / 2
	cameraPos.Y -= h / 2

	//calculate max tiles on screen
	width := int(float32(engine.Width)/(m.TileSize-1)) + 2
	height := int(float32(engine.Height)/(m.TileSize-1)) + 2

	index := 0
	for x := -1; x < width; x++ {
		for y := -1; y < height; y++ {
			var tilePos engine.Vector

			//Try to find tiles on screen
			tilePos.X = cameraPos.X + float32((x * int(m.TileSize-1)))
			tilePos.Y = cameraPos.Y + float32((y * int(m.TileSize-1)))

			//Get tile
			tileType, tx, ty := m.PositionToTile(tilePos)

			//Check if visible/exists
			if tileType.Type() != 0 {
				//Add to draw list
				m.uvs[index] = m.Sprite.UVs[tileType.Type()-1]
				pos, e := m.GetTilePos(tx, ty)
				if !e {
					panic("Does not exists")
				}
				m.positions[index] = pos
				m.rotations[index] = tileType.Angle() + m.Disco
				m.scales[index] = engine.NewVector2(m.TileSize+float32(int(m.Disco)%52), m.TileSize+float32(int(m.Disco)%52))
				index++
				//engine.DrawSprite(m.Sprite.Texture, m.Sprite.UVs[int(m.Tiles[tileIndex])], tilePos, engine.NewVector2(m.TileSize, m.TileSize), 0, engine.AlignCenter, engine.One)
			}
			if tileType.Type2() != 0 {
				//Add to draw list
				m.uvs[index] = m.Sprite.UVs[tileType.Type2()-1]
				pos, e := m.GetTilePos(tx, ty)
				if !e {
					panic("Does not exists")
				}
				m.positions[index] = pos
				m.rotations[index] = tileType.Angle2() + m.Disco
				m.scales[index] = engine.NewVector2(m.TileSize+float32(int(m.Disco)%52), m.TileSize+float32(int(m.Disco)%52))
				index++
				//engine.DrawSprite(m.Sprite.Texture, m.Sprite.UVs[int(m.Tiles[tileIndex])], tilePos, engine.NewVector2(m.TileSize, m.TileSize), 0, engine.AlignCenter, engine.One)
			}
		}
	}

	if m.EnableDisco {
		if m.DiscoStyle == 1 {
			m.Disco++
		} else {
			m.Disco--
		}
		if m.Disco > 50 {
			m.DiscoStyle = 0
		}
		if m.Disco < 0 {
			m.DiscoStyle = 1
		}
	}

	if index > 0 {
		engine.DrawSprites(m.Sprite.Texture, m.uvs[:index], m.positions[:index], m.scales[:index], m.rotations[:index], m.alings[:index], m.colors[:index])
	}

}
开发者ID:skarr,项目名称:GarageEngine,代码行数:75,代码来源:Map.go

示例5: OldLoad

func (s *GameScene) OldLoad() {

	LoadTextures()

	queenDead = false

	rand.Seed(time.Now().UnixNano())

	GameSceneGeneral = s

	s.Camera = engine.NewCamera()

	cam := engine.NewGameObject("Camera")
	cam.AddComponent(s.Camera)

	cam.Transform().SetScalef(1, 1)

	gui := engine.NewGameObject("GUI")

	Layer1 := engine.NewGameObject("Layer1")
	Layer2 := engine.NewGameObject("Layer2")
	Layer3 := engine.NewGameObject("Layer3")
	Layer4 := engine.NewGameObject("Layer3")

	s.Layer1 = Layer1
	s.Layer2 = Layer2
	s.Layer3 = Layer3
	s.Layer4 = Layer4

	mouse := engine.NewGameObject("Mouse")
	mouse.AddComponent(engine.NewMouse())
	mouse.AddComponent(NewMouseDebugger())
	mouse.Transform().SetParent2(cam)

	FPSDrawer := engine.NewGameObject("FPS")
	FPSDrawer.Transform().SetParent2(cam)
	txt := FPSDrawer.AddComponent(components.NewUIText(ArialFont2, "")).(*components.UIText)
	fps := FPSDrawer.AddComponent(engine.NewFPS()).(*engine.FPS)
	fps.SetAction(func(fps float64) {
		txt.SetString("FPS: " + strconv.FormatFloat(fps, 'f', 2, 32))
	})
	txt.SetAlign(engine.AlignLeft)

	FPSDrawer.Transform().SetPositionf(20, float32(engine.Height)-20)
	FPSDrawer.Transform().SetScalef(20, 20)

	label := engine.NewGameObject("Label")
	label.Transform().SetParent2(cam)
	label.Transform().SetPositionf(20, float32(engine.Height)-40)
	label.Transform().SetScalef(20, 20)

	txt2 := label.AddComponent(components.NewUIText(ArialFont2, "Input: ")).(*components.UIText)
	txt2.SetFocus(true)
	txt2.SetWritable(true)
	txt2.SetAlign(engine.AlignLeft)

	//SPACCCEEEEE
	engine.Space.Gravity.Y = 0
	engine.Space.Iterations = 10

	Health := engine.NewGameObject("HP")
	Health.Transform().SetParent2(cam)
	Health.Transform().SetPositionf(150, 50)

	HealthGUI := engine.NewGameObject("HPGUI")
	HealthGUI.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, HPGUI_A)))
	HealthGUI.Transform().SetParent2(Health)
	HealthGUI.Transform().SetScalef(50, 50)

	HealthBar := engine.NewGameObject("HealthBar")
	HealthBar.Transform().SetParent2(Health)
	HealthBar.Transform().SetPositionf(-82, 0)
	HealthBar.Transform().SetScalef(100, 50)

	uvHP := engine.IndexUV(atlas, HP_A)

	HealthBarGUI := engine.NewGameObject("HealthBarGUI")
	HealthBarGUI.Transform().SetParent2(HealthBar)
	HealthBarGUI.AddComponent(engine.NewSprite2(atlas.Texture, uvHP))
	HealthBarGUI.Transform().SetScalef(0.52, 1)
	HealthBarGUI.Transform().SetPositionf((uvHP.Ratio/2)*HealthBarGUI.Transform().Scale().X, 0)

	JetFire := engine.NewGameObject("Jet")
	JetFire.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, Jet_A)))

	ship := engine.NewGameObject("Ship")
	Player = ship
	ship.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, SpaceShip_A)))
	PlayerShip = ship.AddComponent(NewShipController()).(*ShipController)
	ship.AddComponent(components.NewSmoothFollow(nil, 0, 50))
	ship.Transform().SetParent2(Layer2)
	ship.Transform().SetPositionf(400, 200)
	ship.Transform().SetScalef(100, 100)
	shipHP := float32(1000)
	PlayerShip.HPBar = HealthBar
	PlayerShip.JetFire = JetFire

	settings := struct {
		Ship                *ShipController
		PowerUpChance       *int
//.........这里部分代码省略.........
开发者ID:skarr,项目名称:GarageEngine,代码行数:101,代码来源:SpaceScene.go

示例6: Load


//.........这里部分代码省略.........
	missleGameObject.Physics.Shape.IsSensor = true
	missle = NewMissle(30000)
	missleGameObject.AddComponent(missle)
	missle.Explosion = Explosion
	ds := NewDestoyable(0, 1)
	ds.SetDestroyTime(1)
	missleGameObject.AddComponent(ds)

	ship := engine.NewGameObject("Ship")
	Player = ship
	Player.Transform().SetParent2(Layer2)
	Player.AddComponent(MyClient)
	/*
		Health := engine.NewGameObject("HP")
		Health.Transform().SetParent2(cam)
		Health.Transform().SetPositionf(150, 50)

		HealthGUI := engine.NewGameObject("HPGUI")
		HealthGUI.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, HPGUI_A)))
		HealthGUI.Transform().SetParent2(Health)
		HealthGUI.Transform().SetScalef(50, 50)

		HealthBar := engine.NewGameObject("HealthBar")
		HealthBar.Transform().SetParent2(Health)
		HealthBar.Transform().SetPositionf(-82, 0)
		HealthBar.Transform().SetScalef(100, 50)

		uvHP := engine.IndexUV(atlas, HP_A)

		HealthBarGUI := engine.NewGameObject("HealthBarGUI")
		HealthBarGUI.Transform().SetParent2(HealthBar)
		HealthBarGUI.AddComponent(engine.NewSprite2(atlas.Texture, uvHP))
		HealthBarGUI.Transform().SetScalef(0.52, 1)
		HealthBarGUI.Transform().SetPositionf((uvHP.Ratio/2)*HealthBarGUI.Transform().Scale().X, 0)

		JetFire := engine.NewGameObject("Jet")
		JetFire.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, Jet_A)))

		ship.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, SpaceShip_A)))
		PlayerShip = ship.AddComponent(NewShipController()).(*ShipController)
		ship.Transform().SetParent2(Layer2)
		ship.Transform().SetPositionf(400, 200)
		ship.Transform().SetScalef(100, 100)
		shipHP := float32(1000)
		PlayerShip.HPBar = HealthBar
		PlayerShip.JetFire = JetFire
		PlayerShip.Missle = missle
		ship.AddComponent(NewDestoyable(shipHP, 1))
	*/

	cookie = engine.NewGameObject("Cookie")
	cookie.AddComponent(engine.NewSprite(cir))
	cookie.AddComponent(NewDestoyable(100, 2))
	cookie.AddComponent(NewDamageDealer(20))
	cookie.AddComponent(NewEnemeyAI(Player, Enemey_Cookie))
	cookie.Transform().SetScalef(50, 50)
	cookie.Transform().SetPositionf(400, 400)
	cookie.AddComponent(engine.NewPhysicsShape(false, chipmunk.NewCircle(vect.Vect{0, 0}, 25)))
	cookie.Tag = CookieTag

	defender = engine.NewGameObject("Box")
	ds = NewDestoyable(30, 3)
	ds.SetDestroyTime(5)
	defender.AddComponent(ds)
	defender.AddComponent(engine.NewSprite(boxt))
	defender.Tag = CookieTag
开发者ID:skarr,项目名称:GarageEngine,代码行数:67,代码来源:SpaceScene.go


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