Exemple #1
0
func (b *back) Update() {
	camera := engine.GetScene().SceneBase().Camera
	if camera != nil {
		myPos := engine.Vector{b.Transform().Position().X - float32(engine.Width/2), b.Transform().Position().Y - float32(engine.Height/2), 0}
		camPos := camera.Transform().Position()

		myPos = engine.Lerp(myPos, camPos, float32(engine.DeltaTime())*5)
		disX := myPos.X - camPos.X
		disY := myPos.Y - camPos.Y
		var MaxDis float32 = 300
		if float32(math.Abs(float64(disX))) > MaxDis {
			if disX < 0 {
				myPos.X = MaxDis - myPos.X
			} else {
				myPos.X = myPos.X + MaxDis
			}
		}
		if float32(math.Abs(float64(disY))) > MaxDis {
			if disY < 0 {
				myPos.Y = MaxDis - myPos.Y
			} else {
				myPos.Y = myPos.Y + MaxDis
			}
		}

		b.Transform().SetPosition(camPos)
	}
}
Exemple #2
0
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
}
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)
}
Exemple #4
0
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)
}
Exemple #5
0
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])
	}

}
Exemple #6
0
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
		PowerUpRepairChance *int
		ShipHP              *float32
		Debug               *bool
	}{
		PlayerShip,
		&PowerUpChance,
		&PowerUpRepairChance,
		&shipHP,
		&engine.Debug,
	}

	f, e := os.Open("./data/spaceCookies/game.dat")
	if e != nil {
		f, e = os.Create("./data/spaceCookies/game.dat")
		if e != nil {
			fmt.Println(e)
		}
		defer f.Close()
		encoder := json.NewEncoder(f)
		encoder.Encode(settings)
	} else {
		defer f.Close()
	}
	decoder := json.NewDecoder(f)
	e = decoder.Decode(&settings)
	if e != nil {
		fmt.Println(e)
	}
	ship.AddComponent(NewDestoyable(shipHP, 1))

	uvs, ind := engine.AnimatedGroupUVs(atlas, Explosion_ID)
	Explosion = engine.NewGameObject("Explosion")
	Explosion.AddComponent(engine.NewSprite3(atlas.Texture, uvs))
	Explosion.Sprite.BindAnimations(ind)
	Explosion.Sprite.AnimationSpeed = 25
	Explosion.Sprite.AnimationEndCallback = func(sprite *engine.Sprite) {
		sprite.GameObject().Destroy()
	}
	Explosion.Transform().SetScalef(30, 30)

	missle := engine.NewGameObject("Missle")
	missle.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, Missle_A)))
	missle.AddComponent(engine.NewPhysics(false))
	missle.Transform().SetScalef(20, 20)
	missle.AddComponent(NewDamageDealer(50))

	m := NewMissle(30000)
	missle.AddComponent(m)
	PlayerShip.Missle = m
	m.Explosion = Explosion
	ds := NewDestoyable(0, 1)
	ds.SetDestroyTime(1)
	missle.AddComponent(ds)

	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
	defender.Transform().SetScalef(50, 50)

	phx := defender.AddComponent(engine.NewPhysics(false)).(*engine.Physics)
	phx.Body.SetMass(2.5)
	phx.Body.SetMoment(phx.Shape.Moment(2.5))
	phx.Shape.SetFriction(0.5)
	//phx.Shape.Group = 2
	phx.Shape.SetElasticity(0.5)

	QueenCookie := engine.NewGameObject("Cookie")
	QueenCookie.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, Queen_A)))
	QueenCookie.AddComponent(NewDestoyable(5000, 2))
	QueenCookie.AddComponent(NewDamageDealer(200))
	QueenCookie.AddComponent(NewEnemeyAI(Player, Enemey_Boss))
	QueenCookie.Transform().SetParent2(Layer2)
	QueenCookie.Transform().SetScalef(300, 300)
	QueenCookie.Transform().SetPositionf(999999, 999999)
	QueenCookie.AddComponent(engine.NewPhysicsShape(false, chipmunk.NewCircle(vect.Vect{0, 0}, 25)))
	QueenCookie.Tag = CookieTag

	staticCookie := engine.NewGameObject("Cookie")
	staticCookie.AddComponent(engine.NewSprite(cir))
	staticCookie.Transform().SetScalef(400, 400)
	staticCookie.Transform().SetPositionf(400, 400)
	staticCookie.AddComponent(NewDestoyable(float32(engine.Inf), 2))
	staticCookie.AddComponent(engine.NewPhysicsShape(true, chipmunk.NewCircle(vect.Vect{0, 0}, 200)))

	staticCookie.Physics.Shape.SetElasticity(0)
	staticCookie.Physics.Body.SetMass(999999999999)
	staticCookie.Physics.Body.SetMoment(staticCookie.Physics.Shape.Moment(999999999999))
	staticCookie.Tag = CookieTag

	uvs, ind = engine.AnimatedGroupUVs(atlasSpace, "s")
	Background := engine.NewGameObject("Background")
	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()
		c.Transform().SetParent2(Wall)
		p := engine.Vector{float32(i) * 400, -200, 1}
		c.Transform().SetPosition(p)
		c.Transform().SetScalef(400, 400)
	}
	for i := 0; i < (4000/400)+2; i++ {
		c := staticCookie.Clone()
		c.Transform().SetParent2(Wall)
		p := engine.Vector{float32(i) * 400, 4200, 1}
		c.Transform().SetPosition(p)
		c.Transform().SetScalef(400, 400)
	}
	for i := 0; i < (4000/400)+2; i++ {
		c := staticCookie.Clone()
		c.Transform().SetParent2(Wall)
		p := engine.Vector{-200, float32(i) * 400, 1}
		c.Transform().SetPosition(p)
		c.Transform().SetScalef(400, 400)
	}
	for i := 0; i < (4000/400)+2; i++ {
		c := staticCookie.Clone()
		c.Transform().SetParent2(Wall)
		p := engine.Vector{4200, float32(i) * 400, 1}
		c.Transform().SetPosition(p)
		c.Transform().SetScalef(400, 400)
	}

	s.AddGameObject(cam)
	s.AddGameObject(gui)
	s.AddGameObject(Layer1)
	s.AddGameObject(Layer2)
	s.AddGameObject(Layer3)
	s.AddGameObject(Layer4)
	s.AddGameObject(background)
	//s.AddGameObject(shadowShader)

	fmt.Println("GameScene loaded")
}
Exemple #7
0
func (s *GameScene) Load() {
	Players = make(map[server.ID]*engine.GameObject)
	LoadTextures()
	engine.SetTitle("Space Cookies")
	queenDead = false

	var e error
	fireSound, e = wav.NewClip("./data/laser5.wav")
	if e != nil {
		fmt.Println(e)
	}

	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(-float32(engine.Width)/2+20, +float32(engine.Height)/2-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

	uvs, ind := engine.AnimatedGroupUVs(atlas, Explosion_ID)
	Explosion = engine.NewGameObject("Explosion")
	Explosion.AddComponent(engine.NewSprite3(atlas.Texture, uvs))
	Explosion.Sprite.BindAnimations(ind)
	Explosion.Sprite.AnimationSpeed = 25
	Explosion.Sprite.AnimationEndCallback = func(sprite *engine.Sprite) {
		sprite.GameObject().Destroy()
	}
	Explosion.Transform().SetScalef(30, 30)
	Explosion.Transform().SetDepth(1)

	missleGameObject := engine.NewGameObject("Missle")
	missleGameObject.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, Missle_A)))
	missleGameObject.AddComponent(engine.NewPhysics(false))
	missleGameObject.Transform().SetScalef(20, 20)
	missleGameObject.AddComponent(NewDamageDealer(50))
	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
	defender.Transform().SetScalef(50, 50)

	phx := defender.AddComponent(engine.NewPhysics(false)).(*engine.Physics)
	phx.Body.SetMass(2.5)
	phx.Body.SetMoment(phx.Shape.Moment(2.5))
	phx.Shape.SetFriction(0.5)
	//phx.Shape.Group = 2
	phx.Shape.SetElasticity(0.5)

	QueenCookie := engine.NewGameObject("Cookie")
	QueenCookie.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, Queen_A)))
	QueenCookie.AddComponent(NewDestoyable(5000, 2))
	QueenCookie.AddComponent(NewDamageDealer(200))
	QueenCookie.AddComponent(NewEnemeyAI(Player, Enemey_Boss))
	QueenCookie.Transform().SetParent2(Layer2)
	QueenCookie.Transform().SetScalef(300, 300)
	QueenCookie.Transform().SetPositionf(2000, 2000)
	QueenCookie.AddComponent(engine.NewPhysicsShape(false, chipmunk.NewCircle(vect.Vect{0, 0}, 25)))
	QueenCookie.Tag = CookieTag

	staticCookie := engine.NewGameObject("Cookie")
	staticCookie.AddComponent(engine.NewSprite(cir))
	staticCookie.Transform().SetScalef(400, 400)
	staticCookie.Transform().SetPositionf(400, 400)
	staticCookie.AddComponent(NewDestoyable(float32(engine.Inf), 2))
	staticCookie.AddComponent(engine.NewPhysicsShape(true, chipmunk.NewCircle(vect.Vect{0, 0}, 200)))

	staticCookie.Physics.Shape.SetElasticity(0)
	staticCookie.Physics.Body.SetMass(999999999999)
	staticCookie.Physics.Body.SetMoment(staticCookie.Physics.Shape.Moment(999999999999))
	staticCookie.Tag = CookieTag

	uvs, ind = engine.AnimatedGroupUVs(atlasSpace, "s")
	Background := engine.NewGameObject("Background")
	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()
		c.Transform().SetParent2(Wall)
		p := engine.Vector{float32(i) * 400, -200, 1}
		c.Transform().SetPosition(p)
		c.Transform().SetScalef(400, 400)
	}
	for i := 0; i < (4000/400)+2; i++ {
		c := staticCookie.Clone()
		c.Transform().SetParent2(Wall)
		p := engine.Vector{float32(i) * 400, 4200, 1}
		c.Transform().SetPosition(p)
		c.Transform().SetScalef(400, 400)
	}
	for i := 0; i < (4000/400)+2; i++ {
		c := staticCookie.Clone()
		c.Transform().SetParent2(Wall)
		p := engine.Vector{-200, float32(i) * 400, 1}
		c.Transform().SetPosition(p)
		c.Transform().SetScalef(400, 400)
	}
	for i := 0; i < (4000/400)+2; i++ {
		c := staticCookie.Clone()
		c.Transform().SetParent2(Wall)
		p := engine.Vector{4200, float32(i) * 400, 1}
		c.Transform().SetPosition(p)
		c.Transform().SetScalef(400, 400)
	}

	cam.AddComponent(audio.NewAudioListener())
	clip, e := ibxm.NewClip("./data/GameSong.xm")
	if e != nil {
		panic(e)
	}
	music := engine.NewGameObject("GameSong")
	as := audio.NewAudioSource(clip)
	music.AddComponent(as)
	as.SetLooping(true)

	as.SetGain(0.3)

	s.AddGameObject(cam)
	s.AddGameObject(gui)
	s.AddGameObject(Layer1)
	s.AddGameObject(Layer2)
	s.AddGameObject(Layer3)
	s.AddGameObject(Layer4)
	s.AddGameObject(music)

	//s.AddGameObject(shadowShader)

	fmt.Println("GameScene loaded")
}