本文整理汇总了Golang中github.com/skarr/GarageEngine/engine.Vector类的典型用法代码示例。如果您正苦于以下问题:Golang Vector类的具体用法?Golang Vector怎么用?Golang Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetCollisions2
func (m *Map) GetCollisions2(worldPosition engine.Vector, width, height float32, xCollisions, yCollisions []int) (x, y []int) {
_, x1, y1 := m.PositionToTile(worldPosition.Add(engine.Vector{width / 2, height / 2, 0}))
_, x2, y2 := m.PositionToTile(worldPosition.Add(engine.Vector{-width / 2, -height / 2, 0}))
if x1 > x2 {
x1, x2 = x2, x1
}
if y1 > y2 {
y1, y2 = y2, y1
}
for ; y1 <= y2; y1++ {
for x := x1; x <= x2; x++ {
if !m.IsTileWalkabke(x, y1) {
if xCollisions == nil {
xCollisions = make([]int, 0, 4)
}
if yCollisions == nil {
yCollisions = make([]int, 0, 4)
}
xCollisions = append(xCollisions, x)
yCollisions = append(yCollisions, y1)
}
}
}
return xCollisions, yCollisions
}
开发者ID:skarr,项目名称:GarageEngine,代码行数:26,代码来源:Map.go
示例2: VectorFmtRotation
func VectorFmtRotation(v engine.Vector, arr []float32, s string) engine.Vector {
if len(s) == 0 && len(arr) == 1 {
v.Z = arr[0]
return v
}
return VectorFmt(v, arr, s)
}
开发者ID:skarr,项目名称:GarageEngine,代码行数:7,代码来源:Type.go
示例3: CheckCollision
func (m *Map) CheckCollision(worldPosition engine.Vector, width, height float32) bool {
_, x1, y1 := m.PositionToTile(worldPosition.Add(engine.Vector{width / 2, height / 2, 0}))
_, x2, y2 := m.PositionToTile(worldPosition.Add(engine.Vector{-width / 2, -height / 2, 0}))
if x1 > x2 {
x1, x2 = x2, x1
}
if y1 > y2 {
y1, y2 = y2, y1
}
for ; y1 <= y2; y1++ {
for x := x1; x <= x2; x++ {
if !m.IsTileWalkabke(x, y1) {
return true
}
}
}
return false
}
开发者ID:skarr,项目名称:GarageEngine,代码行数:20,代码来源:Map.go
示例4: 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
示例5: 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
示例6: 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
示例7: OldLoad
//.........这里部分代码省略.........
Background.AddComponent(engine.NewSprite3(atlasSpace.Texture, uvs))
Background.Sprite.BindAnimations(ind)
Background.Sprite.SetAnimation("s")
Background.Sprite.AnimationSpeed = 0
Background.Transform().SetScalef(50, 50)
Background.Transform().SetPositionf(400, 400)
uvs, ind = engine.AnimatedGroupUVs(atlasPowerUp, PowerUps_ID)
PowerUpGO = engine.NewGameObject("Background")
//PowerUpGO.Transform().SetParent2(Layer2)
PowerUpGO.AddComponent(engine.NewSprite3(atlasPowerUp.Texture, uvs))
PowerUpGO.AddComponent(engine.NewPhysics(false))
PowerUpGO.Physics.Shape.IsSensor = true
PowerUpGO.Sprite.BindAnimations(ind)
PowerUpGO.Sprite.SetAnimation(PowerUps_ID)
PowerUpGO.Sprite.AnimationSpeed = 0
index := (rand.Int() % 6) + 6
PowerUpGO.Sprite.SetAnimationIndex(int(index))
PowerUpGO.Transform().SetScalef(61, 61)
PowerUpGO.Transform().SetPositionf(0, 0)
background := engine.NewGameObject("Background")
background.AddComponent(engine.NewSprite(backgroung))
background.AddComponent(NewBackground(background.Sprite))
background.Sprite.Render = false
//background.Transform().SetScalef(float32(backgroung.Height()), float32(backgroung.Height()), 1)
background.Transform().SetScalef(800, 800)
background.Transform().SetPositionf(0, 0)
for i := 0; i < 300; i++ {
c := Background.Clone()
c.Transform().SetParent2(Layer4)
size := 20 + rand.Float32()*50
p := engine.Vector{(rand.Float32() * 5000) - 1000, (rand.Float32() * 5000) - 1000, 1}
index := rand.Int() % 7
Background.Sprite.SetAnimationIndex(int(index))
c.Transform().SetRotationf(rand.Float32() * 360)
c.Transform().SetPosition(p)
c.Transform().SetScalef(size, size)
}
for i := 0; i < 600; i++ {
c := cookie.Clone()
//c.Tag = CookieTag
c.Transform().SetParent2(Layer2)
size := 40 + rand.Float32()*100
p := engine.Vector{(rand.Float32() * 4000), (rand.Float32() * 4000), 1}
if p.X < 1100 && p.Y < 800 {
p.X += 1100
p.Y += 800
}
c.Transform().SetPosition(p)
c.Transform().SetScalef(size, size)
}
Wall = engine.NewGameObject("Wall")
Wall.Transform().SetParent2(Layer2)
for i := 0; i < (4000/400)+2; i++ {
c := staticCookie.Clone()
开发者ID:skarr,项目名称:GarageEngine,代码行数:67,代码来源:SpaceScene.go
示例8: Load
//.........这里部分代码省略.........
Background.AddComponent(engine.NewSprite3(atlasSpace.Texture, uvs))
Background.Sprite.BindAnimations(ind)
Background.Sprite.SetAnimation("s")
Background.Sprite.AnimationSpeed = 0
Background.Transform().SetScalef(50, 50)
Background.Transform().SetPositionf(400, 400)
uvs, ind = engine.AnimatedGroupUVs(atlasPowerUp, PowerUps_ID)
PowerUpGO = engine.NewGameObject("Background")
//PowerUpGO.Transform().SetParent2(Layer2)
PowerUpGO.AddComponent(engine.NewSprite3(atlasPowerUp.Texture, uvs))
PowerUpGO.AddComponent(engine.NewPhysics(false))
PowerUpGO.Physics.Shape.IsSensor = true
PowerUpGO.Sprite.BindAnimations(ind)
PowerUpGO.Sprite.SetAnimation(PowerUps_ID)
PowerUpGO.Sprite.AnimationSpeed = 0
index := (rand.Int() % 6) + 6
PowerUpGO.Sprite.SetAnimationIndex(int(index))
PowerUpGO.Transform().SetScalef(61, 61)
PowerUpGO.Transform().SetPositionf(0, 0)
background := engine.NewGameObject("Background")
background.AddComponent(engine.NewSprite(backgroung))
background.Transform().SetScalef(800, 800)
background.Transform().SetPositionf(0, 0)
background.Transform().SetDepth(-6)
background.Transform().SetParent2(cam)
for i := 0; i < 300; i++ {
c := Background.Clone()
c.Transform().SetParent2(Layer4)
c.Transform().SetDepth(-5)
size := 20 + rand.Float32()*50
p := engine.Vector{(rand.Float32() * 5000) - 1000, (rand.Float32() * 5000) - 1000, 1}
index := rand.Int() % 7
Background.Sprite.SetAnimationIndex(int(index))
c.Transform().SetRotationf(rand.Float32() * 360)
c.Transform().SetPosition(p)
c.Transform().SetScalef(size, size)
}
for i := 0; i < 600; i++ {
c := cookie.Clone()
//c.Tag = CookieTag
c.Transform().SetParent2(Layer2)
size := 40 + rand.Float32()*100
p := engine.Vector{(rand.Float32() * 4000), (rand.Float32() * 4000), 1}
if p.X < 1100 && p.Y < 800 {
p.X += 1100
p.Y += 800
}
c.Transform().SetPosition(p)
c.Transform().SetScalef(size, size)
}
Wall = engine.NewGameObject("Wall")
Wall.Transform().SetParent2(Layer2)
for i := 0; i < (4000/400)+2; i++ {
c := staticCookie.Clone()
开发者ID:skarr,项目名称:GarageEngine,代码行数:67,代码来源:SpaceScene.go
示例9: 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
注:本文中的github.com/skarr/GarageEngine/engine.Vector类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论