Ejemplo n.º 1
0
func (m *MouseDebugger) Update() {
	if input.MouseDown(glfw.MouseLeft) {

		mousePosition := m.Transform().WorldPosition()

		sprite3 := engine.NewGameObject("Sprite")
		sprite3.AddComponent(engine.NewSprite(cir))
		sprite3.Transform().SetParent2(GameSceneGeneral.Layer2)
		sprite3.Transform().SetWorldPosition(mousePosition)

		sprite3.Transform().SetScale(engine.NewVector2(30, 30))

		phx := sprite3.AddComponent(engine.NewPhysicsShape(false, chipmunk.NewCircle(vect.Vect{0, 0}, 15))).(*engine.Physics)
		phx.Shape.SetFriction(0.5)
		//phx.Shape.Group = 1
		phx.Shape.SetElasticity(0.5)
	}
	if input.MouseDown(glfw.MouseRight) {

		mousePosition := m.Transform().WorldPosition()

		sprite3 := engine.NewGameObject("Sprite")
		sprite3.AddComponent(engine.NewSprite(box))
		sprite3.Transform().SetParent2(GameSceneGeneral.Layer2)
		sprite3.Transform().SetWorldPosition(mousePosition)

		sprite3.Transform().SetScale(engine.NewVector2(30, 30))
		phx := sprite3.AddComponent(engine.NewPhysics(false)).(*engine.Physics)
		phx.Shape.SetFriction(0.5)
		//phx.Shape.Group = 2
		phx.Shape.SetElasticity(0.5)
	}
}
Ejemplo n.º 2
0
func CreateChud() {
	chud := engine.NewGameObject("chud")
	Ch = chud.AddComponent(NewChud()).(*Chud)
	chud.AddComponent(engine.NewSprite2(ChudAtlas.Texture, engine.IndexUV(ChudAtlas, Spr_chud)))
	chud.Transform().SetWorldPositionf(200, 550)
	chud.Transform().SetWorldScalef(100, 100)
}
Ejemplo n.º 3
0
func CreateEnemy() {
	uvs, ind := engine.AnimatedGroupUVs(Atlas, "enemy_walk", "enemy_stand", "enemy_attack", "enemy_jump", "enemy_hit")
	Regular = engine.NewGameObject("Enemy")
	Regular.AddComponent(engine.NewSprite3(Atlas.Texture, uvs))
	Regular.Sprite.BindAnimations(ind)
	Regular.Transform().SetWorldScalef(50, 100)
	Regular.AddComponent(engine.NewPhysics(false, 1, 1))
	Regular.Physics.Shape.SetFriction(0.7)
	Regular.Physics.Shape.SetElasticity(0.2)

	HpBar = engine.NewGameObject("hpBar")
	HpBar.GameObject().AddComponent(engine.NewSprite2(Player.ChudAtlas.Texture, engine.IndexUV(Player.ChudAtlas, Player.Spr_chudHp)))
	HpBar.GameObject().Sprite.SetAlign(engine.AlignLeft)
	HpBar.GameObject().Transform().SetWorldScalef(10, 15)
	HpBar.AddComponent(GUI.NewBar(17))
}
Ejemplo n.º 4
0
func Create() {
	Object = engine.NewGameObject("bg")
	Object.AddComponent(engine.NewSprite2(Atlas.Texture, engine.IndexUV(Atlas, Spr_bg)))
	Object.Transform().SetScalef(2000, 1800)
	Object.Transform().SetPositionf(0, 0)
	Object.AddComponent(NewBack())
}
Ejemplo n.º 5
0
func createSplinter() {
	Splinter = engine.NewGameObject("Splinter")
	Splinter.AddComponent(engine.NewSprite2(ObjectsAtlas.Texture, engine.IndexUV(ObjectsAtlas, Spr_splinter)))
	Splinter.Transform().SetWorldScalef(100, 30)
	Splinter.AddComponent(engine.NewPhysics(true, 1, 1))
	Splinter.Physics.Shape.IsSensor = true
	Splinter.Tag = "splinter"
}
Ejemplo n.º 6
0
func createBox() {
	Box = engine.NewGameObject("box")
	Box.AddComponent(engine.NewSprite2(ObjectsAtlas.Texture, engine.IndexUV(ObjectsAtlas, Spr_box)))
	Box.Transform().SetWorldScalef(40, 40)
	Box.AddComponent(engine.NewPhysics(false, 1, 1))
	Box.Physics.Body.SetMass(1.5)
	Box.Physics.Shape.SetFriction(0.3)
}
Ejemplo n.º 7
0
func createLader() {
	Lader = engine.NewGameObject("lader")
	Lader.AddComponent(engine.NewSprite2(ObjectsAtlas.Texture, engine.IndexUV(ObjectsAtlas, Spr_lader)))
	Lader.Transform().SetWorldScalef(60, 100)
	Lader.AddComponent(engine.NewPhysics(true, 1, 1))
	Lader.Physics.Shape.IsSensor = true
	Lader.Physics.Shape.SetFriction(2)
	Lader.Tag = "lader"
}
Ejemplo n.º 8
0
func (sp *ShipController) Start() {
	ph := sp.GameObject().Physics
	ph.Body.SetMass(50)
	ph.Shape.Group = 1
	sp.Destoyable = sp.GameObject().ComponentTypeOf(sp.Destoyable).(*Destoyable)
	sp.OnHit(nil, nil)

	sp.JetFireParent = engine.NewGameObject("JetFireParent")
	sp.JetFireParent.Transform().SetParent2(sp.GameObject())
	sp.JetFireParent.Transform().SetPositionf(0, 0)
	sp.JetFireParent.Transform().SetScalef(1, 1)
	sp.JetFireParent.Transform().SetRotationf(0)
	uvJet := engine.IndexUV(atlas, Jet_A)

	if sp.JetFire != nil {
		l := 1
		sp.JetFirePool = make([]*ResizeScript, l*len(sp.JetFirePosition))

		for i := 0; i < len(sp.JetFirePosition); i++ {
			for j := 0; j < l; j++ {

				jfp := engine.NewGameObject("JetFireParent2")
				jfp.Transform().SetParent2(sp.JetFireParent)
				jfp.Transform().SetPosition(sp.JetFirePosition[i])
				jfp.Transform().SetRotationf(0)
				rz := NewResizeScript(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
				jfp.AddComponent(rz)

				jf := sp.JetFire.Clone()
				jf.Transform().SetParent2(jfp)
				jf.Transform().SetPositionf(0, -((uvJet.Ratio)/2)*jf.Transform().Scale().Y)
				jf.Transform().SetRotationf(0)
				//	jf.Transform().SetWorldScalef(10, 10, 1)

				sp.JetFirePool[(i*l)+j] = rz
			}
		}
	}

	myPos := engine.Vector{sp.Transform().Position().X - float32(engine.Width/2), sp.Transform().Position().Y - float32(engine.Height/2), 0}
	GameSceneGeneral.SceneData.Camera.Transform().SetPosition(myPos)
	sp.MaxMissleLevel = len(sp.MisslesDirection) - 1
	//sp.Physics.Shape.Friction = 0.5
}
Ejemplo n.º 9
0
func SpawnMainPlayer(spawnPlayer server.SpawnPlayer) {
	Health := engine.NewGameObject("HP")
	Health.Transform().SetParent2(GameSceneGeneral.Camera.GameObject())
	Health.Transform().SetPositionf(-float32(engine.Width)/2+150, -float32(engine.Height)/2+50)

	HealthGUI := engine.NewGameObject("HPGUI")
	HealthGUI.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, HPGUI_A)))
	HealthGUI.Transform().SetParent2(Health)
	HealthGUI.Transform().SetDepth(3)
	HealthGUI.Transform().SetPositionf(0, 0)
	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().SetDepth(2)
	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)))

	Player.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, SpaceShip_A)))
	PlayerShip = Player.AddComponent(NewShipController()).(*ShipController)
	Player.Transform().SetWorldPositionf(spawnPlayer.PlayerTransform.X, spawnPlayer.PlayerTransform.Y)
	Player.Transform().SetWorldRotationf(spawnPlayer.PlayerTransform.Rotation)
	Player.Transform().SetWorldScalef(100, 100)
	Player.AddComponent(components.NewSmoothFollow(nil, 2, 200))
	shipHP := float32(1000)
	PlayerShip.HPBar = HealthBar
	PlayerShip.JetFire = JetFire
	PlayerShip.Missle = missle
	Player.AddComponent(NewDestoyable(shipHP, 1))
	as := audio.NewAudioSource(fireSound)
	Player.AddComponent(as)
	PlayerShip.FireSource = as
	as.Pause()
}
Ejemplo n.º 10
0
func createFloor() {

	uvs, ind := engine.AnimatedGroupUVs(Tileset, "ground")
	Floor = engine.NewGameObject("floor")
	Floor.AddComponent(engine.NewSprite3(Tileset.Texture, uvs))
	Floor.Sprite.BindAnimations(ind)
	Floor.Sprite.AnimationSpeed = 0
	Floor.Transform().SetWorldScalef(100, 100)
	Floor.AddComponent(engine.NewPhysics(true, 1, 1))
}
Ejemplo n.º 11
0
func createChest() {
	uvs, ind := engine.AnimatedGroupUVs(ObjectsAtlas, "chest")
	ChestO = engine.NewGameObject("chest")
	ChestO.AddComponent(engine.NewSprite3(ObjectsAtlas.Texture, uvs))
	ChestO.Sprite.BindAnimations(ind)
	ChestO.Transform().SetWorldScalef(70, 70)
	ChestO.AddComponent(engine.NewPhysics(false, 1, 1))
	ChestO.Physics.Shape.IsSensor = true
	ChestO.Sprite.AnimationSpeed = 0
	ChestO.Physics.Body.IgnoreGravity = true
	ChestO.AddComponent(NewChest(-1))
}
Ejemplo n.º 12
0
func (u *upText) Start() {
	label := engine.NewGameObject("Label")
	label.Transform().SetParent(u.Transform().Parent())
	p := u.Transform().WorldPosition()
	si := u.Transform().WorldScale()
	label.Transform().SetWorldPositionf(p.X+si.X/2, p.Y+si.Y/2)
	label.Transform().SetScalef(20, 20)
	txt2 := label.AddComponent(components.NewUIText(Fonts.ArialFont2, u.content)).(*components.UIText)
	txt2.SetAlign(engine.AlignLeft)
	u.text = txt2
	u.label = label
	tween.Create(&tween.Tween{Target: label.GameObject(), From: []float32{p.Y}, To: []float32{p.Y + 100},
		Algo: tween.Linear, Type: tween.WorldPosition, Time: time.Second * 4, Loop: tween.None, Format: "y", EndCallback: func() { u.GameObject().Destroy(); u.label.GameObject().Destroy() }})
}
Ejemplo n.º 13
0
func (this *PlayerController) Start() {
	j := engine.NewGameObject("Joint")
	j.Transform().SetParent2(GameSceneGeneral.Layer1)
	j.Transform().SetWorldPosition(this.Transform().WorldPosition())
	j.AddComponent(engine.NewPhysics(false))
	j.Physics.Body.SetMass(engine.Inf)
	j.Physics.Body.SetMoment(engine.Inf)
	this.Joint = chipmunk.NewPivotJoint(j.Physics.Body, this.GameObject().Physics.Body)
	engine.Space.AddConstraint(this.Joint)
	j.Physics.Shape.IsSensor = true
	this.Joint.MaxBias = vect.Float(this.WalkSpeed)
	this.Joint.MaxForce = 3000
	this.JointGameObject = j
}
Ejemplo n.º 14
0
func SpawnPlayer(spawnPlayer server.SpawnPlayer) {
	newPlayer, exists := Players[spawnPlayer.PlayerInfo.PlayerID]
	if !exists {
		newPlayer = engine.NewGameObject(spawnPlayer.PlayerInfo.Name)
	}
	newPlayer.Transform().SetParent2(GameSceneGeneral.Layer2)
	newPlayer.Transform().SetWorldPositionf(spawnPlayer.PlayerTransform.X, spawnPlayer.PlayerTransform.Y)
	newPlayer.Transform().SetWorldRotationf(spawnPlayer.PlayerTransform.Rotation)
	newPlayer.Transform().SetWorldScalef(100, 100)
	newPlayer.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, SpaceShip_A)))

	if !exists {
		Players[spawnPlayer.PlayerInfo.PlayerID] = newPlayer
	}
}
Ejemplo n.º 15
0
func (s *Bar) Start() {
	if !s.inited {
		label := engine.NewGameObject("Label")
		label.Transform().SetParent(s.Transform().Parent())
		p := s.Transform().WorldPosition()
		si := s.Transform().WorldScale()
		label.Transform().SetWorldPositionf(p.X+si.X/2, p.Y+si.Y/2)
		label.Transform().SetScalef(20, 20)
		txt2 := label.AddComponent(components.NewUIText(Fonts.ArialFont2, "100/100")).(*components.UIText)
		txt2.SetAlign(engine.AlignLeft)
		s.text = txt2
		s.label = label
	}
	s.inited = true

}
Ejemplo n.º 16
0
func CreatePlayer() {
	uvs, ind := engine.AnimatedGroupUVs(Atlas, "player_walk", "player_stand", "player_attack", "player_jump", "player_bend", "player_hit", "player_climb")
	Pl = engine.NewGameObject("Player")
	Pl.AddComponent(engine.NewSprite3(Atlas.Texture, uvs))
	Pl.Sprite.BindAnimations(ind)
	Pl.Sprite.AnimationSpeed = 10
	Pl.Transform().SetWorldPositionf(100, 180)
	Pl.Transform().SetWorldScalef(50, 100)
	PlComp = Pl.AddComponent(NewPlayer()).(*Player)
	Pl.AddComponent(components.NewSmoothFollow(nil, 1, 30))
	Pl.AddComponent(engine.NewPhysics(false, 1, 1))
	Pl.Physics.Shape.SetFriction(0.7)
	Pl.Physics.Shape.SetElasticity(0.2)
	Pl.Tag = "player"

	Hp := engine.NewGameObject("hpBar")
	Hp.GameObject().AddComponent(engine.NewSprite2(ChudAtlas.Texture, engine.IndexUV(ChudAtlas, Spr_chudHp)))
	Hp.GameObject().Sprite.SetAlign(engine.AlignLeft)
	Hp.GameObject().Transform().SetWorldPosition(engine.Vector{156, 580, 0})
	Hp.GameObject().Transform().SetWorldScalef(17, 20)
	Ch.Hp = (Hp.AddComponent(GUI.NewBar(17))).(*GUI.Bar)

	Cp := engine.NewGameObject("cpBar")
	Cp.GameObject().AddComponent(engine.NewSprite2(ChudAtlas.Texture, engine.IndexUV(ChudAtlas, Spr_chudCp)))
	Cp.GameObject().Sprite.SetAlign(engine.AlignLeft)
	Cp.GameObject().Transform().SetWorldPosition(engine.Vector{156, 555, 0})
	Cp.GameObject().Transform().SetWorldScalef(17, 20)
	Ch.Cp = (Cp.AddComponent(GUI.NewBar(17))).(*GUI.Bar)

	Exp := engine.NewGameObject("expBar")
	Exp.GameObject().AddComponent(engine.NewSprite2(ChudAtlas.Texture, engine.IndexUV(ChudAtlas, Spr_chudExp)))
	Exp.GameObject().Sprite.SetAlign(engine.AlignLeft)
	Exp.GameObject().Transform().SetWorldPosition(engine.Vector{156, 530, 0})
	Exp.GameObject().Transform().SetWorldScalef(17, 20)
	Ch.Exp = (Exp.AddComponent(GUI.NewBar(17))).(*GUI.Bar)

	money := engine.NewGameObject("money")
	money.Transform().SetWorldPositionf(100, 500)
	money.Transform().SetScalef(20, 20)
	Ch.Money = money.AddComponent(components.NewUIText(Fonts.ArialFont2, "0")).(*components.UIText)
	Ch.Money.SetAlign(engine.AlignLeft)

	level := engine.NewGameObject("level")
	level.Transform().SetWorldPositionf(50, 500)
	level.Transform().SetScalef(20, 20)
	Ch.Level = level.AddComponent(components.NewUIText(Fonts.ArialFont2, "1")).(*components.UIText)
	Ch.Level.SetAlign(engine.AlignLeft)
}
Ejemplo n.º 17
0
func (s *MenuScene) Load() {
	MenuSceneG = s
	LoadTextures()
	s.Camera = engine.NewCamera()
	cam := engine.NewGameObject("Camera")
	cam.AddComponent(s.Camera)

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

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

	layerButtons := engine.NewGameObject("LayerButton")
	layerBg := engine.NewGameObject("LayerBackground")

	s.layerBackground = layerBg
	s.layerButtons = layerButtons

	mbg = engine.NewGameObject("mbg")
	mbg.AddComponent(engine.NewSprite2(menuAtlas.Texture, engine.IndexUV(menuAtlas, spr_menuback)))
	mbg.Transform().SetWorldScalef(float32(engine.Width), float32(engine.Height))
	mbg.Transform().SetWorldPositionf(float32(engine.Width)/2, float32(engine.Height)/2)
	mbg.Transform().SetParent2(s.layerBackground)

	newGame := engine.NewGameObject("bng")
	newGame.AddComponent(engine.NewPhysics(false, 1, 1))
	newGame.Physics.Shape.IsSensor = true
	newGame.Transform().SetWorldScalef(100, 100)
	newGame.Transform().SetWorldPositionf(100, 100)
	newGame.Transform().SetParent2(s.layerButtons)
	newGame.AddComponent(engine.NewSprite2(menuAtlas.Texture, engine.IndexUV(menuAtlas, spr_menunew)))
	newGame.AddComponent(components.NewUIButton(func() {
		engine.LoadScene(Ps)
	}, func(on bool) {
		if on {
			newGame.Sprite.Color = engine.Vector{1, 0.3, 0.2}
		} else {
			newGame.Sprite.Color = engine.Vector{1, 1, 1}
		}
	}))

	s.AddGameObject(cam)
	s.AddGameObject(s.layerButtons)
	s.AddGameObject(s.layerBackground)

}
Ejemplo n.º 18
0
func (s *LoginScene) Load() {
	engine.SetTitle("Space Cookies")
	LoadTextures()

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

	LoginSceneGeneral = s

	s.Camera = engine.NewCamera()

	cam := engine.NewGameObject("Camera")
	cam.AddComponent(s.Camera)
	cam.Transform().SetPosition(engine.NewVector3(0, 0, -50))
	cam.Transform().SetScalef(1, 1)

	background := engine.NewGameObject("Background")
	background.AddComponent(engine.NewSprite(backgroundTexture))
	//background.Transform().SetScalef(float32(backgroung.Height()), float32(backgroung.Height()), 1)
	background.Transform().SetScalef(800, 800)
	background.Transform().SetPositionf(0, 0)
	background.Transform().SetDepth(-1)

	gui := engine.NewGameObject("GUI")
	gui.Transform().SetParent2(cam)

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

	FPSDrawer := engine.NewGameObject("FPS")
	FPSDrawer.Transform().SetParent2(gui)
	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)

	/*
		tween.Create(&tween.Tween{Target: FPSDrawer, From: []float32{1}, To: []float32{100},
			Algo: tween.Linear, Type: tween.Scale, Time: time.Second * 3, Loop: tween.PingPong})

			tween.Create(&tween.Tween{Target: FPSDrawer, From: []float32{400}, To: []float32{500},
				Algo: tween.Linear, Type: tween.Position, Time: time.Second * 3, Loop: tween.PingPong, Format: "y"})

			tween.Create(&tween.Tween{Target: FPSDrawer, From: []float32{0}, To: []float32{180},
				Algo: tween.Linear, Type: tween.Rotation, Time: time.Second * 6, Loop: tween.PingPong})

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

			FPSDrawer.Transform().SetPositionf(20, float32(engine.Height)-500)
			FPSDrawer.Transform().SetScalef(20, 20)
		}
	*/

	//
	tBox := engine.NewGameObject("TextBox")
	tBox.Transform().SetParent2(gui)

	txt2 := tBox.AddComponent(components.NewUIText(ArialFont2, "Type your name: ")).(*components.UIText)
	txt2.SetFocus(false)
	txt2.SetWritable(false)
	txt2.SetAlign(engine.AlignLeft)
	txt2.Transform().SetDepth(1)

	tBox.Transform().SetPositionf(-txt2.Width()*20, 0)
	tBox.Transform().SetScalef(20, 20)
	//
	input := engine.NewGameObject("TextBoxInput")
	input.Transform().SetParent2(gui)
	p := tBox.Transform().Position()
	p.X += txt2.Width() * 20
	input.Transform().SetPosition(p)
	input.Transform().SetScalef(20, 20)
	input.Transform().SetDepth(1)

	name := input.AddComponent(components.NewUIText(ArialFont2, "")).(*components.UIText)
	name.SetFocus(true)
	name.SetWritable(true)
	name.SetAlign(engine.AlignLeft)
	//
	/*
		{
			input := engine.NewGameObject("TextBoxInput")
			input.Transform().SetParent2(gui)
			p := tBox.Transform().Position()
			p.X += txt2.Width() * 20
			input.Transform().SetPosition(p)
			input.Transform().SetScalef(20, 20)

			name := input.AddComponent(components.NewUIText(ArialFont2, "")).(*components.UIText)
			name.SetFocus(true)
			name.SetWritable(true)
			name.SetAlign(engine.AlignTopCenter)
		}
		{
			input := engine.NewGameObject("TextBoxInput")
			input.Transform().SetParent2(gui)
			p := tBox.Transform().Position()
			p.X += txt2.Width() * 20
			input.Transform().SetPosition(p)
			input.Transform().SetScalef(20, 20)

			name := input.AddComponent(components.NewUIText(ArialFont2, "")).(*components.UIText)
			name.SetFocus(true)
			name.SetWritable(true)
			name.SetAlign(engine.AlignBottomRight)
		}
	*/
	//
	errLabel := engine.NewGameObject("TextBoxInput")
	errLabel.Transform().SetParent2(gui)
	errLabel.Transform().SetPositionf(0, -100)
	errLabel.Transform().SetScalef(24, 24)

	errLabelTxt := errLabel.AddComponent(components.NewUIText(ArialFont2, "")).(*components.UIText)
	errLabelTxt.SetFocus(false)
	errLabelTxt.SetWritable(false)
	errLabelTxt.SetAlign(engine.AlignCenter)
	errLabelTxt.Color = engine.Color_White
	//
	LoginButton := engine.NewGameObject("LoginButton")
	LoginButton.Transform().SetParent2(cam)
	LoginButton.Transform().SetPositionf(0, -50)
	LoginButton.AddComponent(engine.NewSprite(button))
	LoginButton.AddComponent(engine.NewPhysics(false))
	LoginButton.Physics.Shape.IsSensor = true
	LoginButton.Transform().SetScalef(50, 50)
	LoginButton.Sprite.Color = engine.Color{0.5, 0.5, 0.5, 1}
	LoginButton.Transform().SetDepth(0)

	/*
		{
			LoginButton := engine.NewGameObject("LoginButton")
			LoginButton.Transform().SetParent2(cam)
			LoginButton.Transform().SetPositionf(float32(engine.Width)/2, float32(engine.Height)/2-50)
			LoginButton.AddComponent(engine.NewSprite(button))
			LoginButton.AddComponent(engine.NewPhysics(false, 1, 1))
			LoginButton.Physics.Shape.IsSensor = true
			LoginButton.Transform().SetScalef(50, 50)
			LoginButton.Sprite.Color = engine.Vector{0.5, 0.5, 0.5}
			LoginButton.Sprite.SetAlign(engine.AlignTopLeft)
			LoginButton.AddComponent(components.NewUIButton(nil, func(enter bool) {
				if enter {
					LoginButton.Sprite.Color = engine.Vector{0.4, 0.4, 0.4}
				} else {
					LoginButton.Sprite.Color = engine.Vector{0.5, 0.5, 0.5}
				}
			}))
		}
		{
			LoginButton := engine.NewGameObject("LoginButton")
			LoginButton.Transform().SetParent2(cam)
			LoginButton.Transform().SetPositionf(float32(engine.Width)/2, float32(engine.Height)/2-50)
			LoginButton.AddComponent(engine.NewSprite(button))
			LoginButton.AddComponent(engine.NewPhysics(false, 1, 1))
			LoginButton.Physics.Shape.IsSensor = true
			LoginButton.Transform().SetScalef(50, 50)
			LoginButton.Sprite.Color = engine.Vector{0.5, 0.5, 0.5}
			LoginButton.Sprite.SetAlign(engine.AlignBottomRight)
			LoginButton.AddComponent(components.NewUIButton(nil, func(enter bool) {
				if enter {
					LoginButton.Sprite.Color = engine.Vector{0.4, 0.4, 0.4}
				} else {
					LoginButton.Sprite.Color = engine.Vector{0.5, 0.5, 0.5}
				}
			}))
		}
	*/
	loginText := engine.NewGameObject("LoginButtonText")
	loginText.Transform().SetParent2(LoginButton)
	loginText.Transform().SetWorldScalef(24, 24)
	loginText.Transform().SetPositionf(0, 0.1)
	loginText.Transform().SetDepth(1)

	if game.MyClient != nil {
		game.MyClient.Socket.Close()
		game.MyClient = nil
	}

	var errChan chan error
	LoginButton.AddComponent(components.NewUIButton(func() {
		if errChan == nil && game.MyClient == nil {
			go game.Connect(name.String(), &errChan)
			errLabelTxt.SetString("Connecting...")
		}
	}, func(enter bool) {
		if enter {
			LoginButton.Sprite.Color = engine.Color{0.4, 0.4, 0.4, 1}
		} else {
			LoginButton.Sprite.Color = engine.Color{0.5, 0.5, 0.5, 1}
		}
	}))

	txt2 = loginText.AddComponent(components.NewUIText(ArialFont2, "Log in")).(*components.UIText)
	txt2.SetFocus(false)
	txt2.SetWritable(false)
	txt2.SetAlign(engine.AlignCenter)
	txt2.Color = engine.Color{1, 1, 1, 1}
	//

	cr.Start(func() {
		for {

			if errChan == nil {
				cr.Skip()
				continue
			}
			select {
			case loginErr := <-errChan:
				if loginErr != nil {
					errLabelTxt.SetString(loginErr.Error())
					errChan = nil
				}
			default:

			}
			cr.Skip()
		}
	})

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

	//cam.Transform().SetPositionf(float32(engine.Width)/2, float32(engine.Height)/2)
	//
	cam.AddComponent(audio.NewAudioListener())
	clip, e := ibxm.NewClip("./data/LoginSong.xm")
	if e != nil {
		panic(e)
	}
	music := engine.NewGameObject("Music")
	as := audio.NewAudioSource(clip)
	music.AddComponent(as)

	s.AddGameObject(cam)
	s.AddGameObject(background)
	s.AddGameObject(music)

	fmt.Println("LoginScene loaded")
}
Ejemplo n.º 19
0
func (s *GameScene) Load() {
	ArialFont, err := engine.NewFont("./data/Fonts/arial.ttf", 48)
	if err != nil {
		panic(err)
	}

	ArialFont2, err := engine.NewFont("./data/Fonts/arial.ttf", 24)
	if err != nil {
		panic(err)
	}
	_ = ArialFont2
	_ = ArialFont

	GameSceneGeneral = s

	s.Camera = engine.NewCamera()

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

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

	gui := engine.NewGameObject("GUI")

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

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

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

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

	{
		FPSDrawer := engine.NewGameObject("Counter")
		txt := FPSDrawer.AddComponent(components.NewUIText(ArialFont2, "")).(*components.UIText)
		txt.SetAlign(engine.AlignLeft)
		bt.Start(func() bt.Command {
			txt.SetString(fmt.Sprintf("Bodies: %d", len(engine.Space.Bodies)))
			return bt.Restart
		})
		FPSDrawer.Transform().SetParent2(cam)
		FPSDrawer.Transform().SetPositionf(-float32(engine.Width)/2+10, +float32(engine.Height)/2-45)
		FPSDrawer.Transform().SetScalef(20, 20)
	}

	//SPACCCEEEEE
	engine.Space.Gravity.Y = -300
	engine.Space.Iterations = 10

	atlas := engine.NewManagedAtlas(512, 512)
	e := atlas.LoadGroup("./data/fire")
	if e != nil {
		fmt.Println(e)
	}
	e = atlas.LoadGroup("./data/Charecter")
	if e != nil {
		fmt.Println(e)
	}
	err, rectID := atlas.LoadImage("./data/rect.png")
	if err != nil {
		panic(err)
	}
	err, circleID := atlas.LoadImage("./data/circle.png")
	if err != nil {
		panic(err)
	}

	atlas.BuildAtlas()

	atlas.BuildMipmaps()
	atlas.SetFiltering(engine.MipMapLinearNearest, engine.Nearest)

	uvsFire, indFire := engine.AnimatedGroupUVs(atlas, "fire")
	_ = uvsFire
	_ = indFire

	clone2 := engine.NewGameObject("Sprite")
	s2 := clone2.AddComponent(engine.NewSprite3(atlas.Texture, uvsFire)).(*engine.Sprite)
	s2.BindAnimations(indFire)
	s2.AnimationSpeed = 6
	clone2.Transform().SetPositionf(775, 300)
	clone2.Transform().SetScalef(58, 58)
	clone2.Transform().SetParent2(Layer1)

	f := clone2.Clone()
	f.Transform().SetPositionf(25, 300)
	f.Transform().SetParent2(Layer1)

	box, _ = engine.LoadTexture("./data/rect.png")
	cir, _ = engine.LoadTexture("./data/circle.png")
	cir.BuildMipmaps()
	cir.SetFiltering(engine.MipMapLinearNearest, engine.Nearest)

	ball := engine.NewGameObject("Ball")
	ball.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, circleID)))
	ball.Transform().SetScalef(30, 30)
	ball.AddComponent(engine.NewPhysicsShape(false, chipmunk.NewCircle(vect.Vect{0, 0}, 15)))
	ball.Physics.Body.SetMass(10)
	ball.Physics.Body.SetMoment(ball.Physics.Shape.Moment(10))
	ball.Physics.Shape.SetFriction(0.8)
	ball.Physics.Shape.SetElasticity(0.8)

	for i := 0; i < 0; i++ {
		sprite3 := engine.NewGameObject("Sprite" + fmt.Sprint(i))
		sprite3.AddComponent(engine.NewSprite2(atlas.Texture, engine.IndexUV(atlas, rectID)))
		sprite3.Transform().SetParent2(Layer2)
		sprite3.Transform().SetRotationf(180)
		sprite3.Transform().SetPositionf(160, 120+float32(i*31))
		sprite3.Transform().SetScalef(30, 30)

		phx := sprite3.AddComponent(engine.NewPhysics(false)).(*engine.Physics)
		phx.Shape.SetFriction(1)
		phx.Shape.SetElasticity(0.0)
		phx.Body.SetMass(1)
	}

	for i := 0; i < 200; i++ {
		sprite3 := ball.Clone()
		sprite3.Transform().SetParent2(Layer2)
		sprite3.Transform().SetPositionf(200+float32(i%4)*25, float32(i*30)+120)
	}

	floor := engine.NewGameObject("Floor")
	floor.AddComponent(engine.NewSprite(box))
	floor.AddComponent(engine.NewPhysics(true))
	floor.Transform().SetParent2(Layer2)
	floor.Transform().SetPositionf(100, -20)
	floor.Transform().SetScalef(10000, 100)
	floor.Physics.Shape.SetFriction(1)
	floor.Physics.Shape.SetElasticity(1)

	floor2 := floor.Clone()
	floor2.Transform().SetParent2(Layer2)
	floor2.Transform().SetPositionf(800, -20)
	floor2.Transform().SetRotationf(90)

	floor3 := floor2.Clone()
	floor3.Transform().SetParent2(Layer2)
	floor3.Transform().SetPositionf(0, -20)

	uvs2, ind := engine.AnimatedGroupUVs(atlas, "stand", "walk")
	_ = uvs2
	_ = ind

	sprite4 := engine.NewGameObject("Sprite")
	sprite := sprite4.AddComponent(engine.NewSprite3(atlas.Texture, uvs2)).(*engine.Sprite)
	sprite.BindAnimations(ind)
	//sprite4.AddComponent(NewSprite(sp))
	sprite.AnimationSpeed = 5
	player := sprite4.AddComponent(NewPlayerController()).(*PlayerController)
	//sprite4.AddComponent(NewRotator())
	ph := sprite4.AddComponent(engine.NewPhysics(false)).(*engine.Physics)
	player.Fire = clone2
	sprite4.Transform().SetParent2(Layer1)
	sprite4.Transform().SetPositionf(900, 100)
	sprite4.Transform().SetScalef(100, 100)
	ph.Body.SetMass(100)
	ph.Body.IgnoreGravity = false
	ph.Body.SetMoment(engine.Inf)
	ph.Shape.SetFriction(1)
	ph.Shape.SetElasticity(0)

	/*
		floor = NewGameObject("Box")
		bbBox := NewSprite(box)
		floor.AddComponent(bbBox)
		phx = floor.AddComponent(NewPhysics(true, 500, 500)).(*Physics)
		floor.Transform().SetParent2(Layer2)
		floor.Transform().SetPosition(NewVector2(900, 200))
		floor.Transform().SetScale(NewVector2(500, 500))
		phx.Shape.SetFriction(1)
		phx.Shape.SetElasticity(1)
		phx.Shape.IsSensor = true
		//phx.Shape.Friction = 1
		_ = phx
	*/

	//sShadow.Sprite = bbBox
	//
	{
		sprite3 := ball.Clone()
		sprite3.Transform().SetParent2(Layer2)
		sprite3.Transform().SetPositionf(200, 120)

		joint := chipmunk.NewPivotJoint(mouse.Physics.Body, sprite3.Physics.Body)
		joint.MaxForce = 5000000
		//mouseJoint->errorBias = cpfpow(1.0f - 0.15f, 60.0f);
		engine.Space.AddConstraint(joint)
	}

	cam.Transform().SetWorldPosition(player.Transform().WorldPosition())

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

	fmt.Println("Scene loaded")
}
Ejemplo n.º 20
0
func (s *PirateScene) Load() {
	Ps = s
	LoadTextures()
	Fonts.ArialFont2, _ = engine.NewFont("./data/Fonts/arial.ttf", 24)
	Fonts.ArialFont2.Texture.SetReadOnly()

	engine.Space.Gravity.Y = -100
	engine.Space.Iterations = 10

	Layer1 = engine.NewGameObject("Layer1")
	Layer2 = engine.NewGameObject("Layer2")
	Layer3 = engine.NewGameObject("Layer3")
	Layer4 = engine.NewGameObject("Layer4")
	background = engine.NewGameObject("Background")

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

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

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

	up = engine.NewGameObject("up")
	up.Transform().SetParent2(cam)

	Objects.CreateObjects()
	Background.Create()
	Background.Object.Transform().SetParent2(background)

	for i := 0; i < 1; i++ {
		slc := Objects.Splinter.Clone()
		slc.Transform().SetParent2(Layer3)
		slc.Transform().SetWorldPositionf(230, 130)
	}

	Player.CreateChud()
	Player.Ch.Transform().SetParent2(cam)
	Player.CreatePlayer()
	Player.Pl.Transform().SetParent2(Layer2)

	Enemy.CreateEnemy()
	sd := GUI.NewBar(10)
	for i := 0; i < 2; i++ {
		ec := Enemy.Regular.Clone()
		hpB := Enemy.HpBar.Clone()
		hpBd := hpB.ComponentTypeOfi(sd).(*GUI.Bar)

		ec.Transform().SetWorldPositionf(200+rand.Float32(), 110)
		ec.AddComponent(Enemy.NewEnemy(hpBd))
		ec.Transform().SetParent2(Layer2)

		ec.Sprite.AnimationSpeed = 10
		hpB.Transform().SetParent2(up)
	}

	for i := 0; i < 1; i++ {
		bc := Objects.Box.Clone()
		bc.Transform().SetParent2(Layer3)
		bc.Transform().SetWorldPositionf(30, 150)
	}

	for i := 0; i < 1; i++ {
		lc := Objects.Lader.Clone()
		lc.Transform().SetParent2(Layer3)
		lc.Transform().SetWorldPositionf(150, 150)
	}

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

	for i := 0; i < 2; i++ {
		s := Objects.ChestO.Clone()
		s.Transform().SetWorldPositionf(300+20*float32(i)+float32(rand.Int()%300), 150)
		s.Transform().SetParent2(Layer3)
	}

	Player.Ch.Hp.Transform().SetParent2(up)
	Player.Ch.Cp.Transform().SetParent2(up)
	Player.Ch.Exp.Transform().SetParent2(up)
	Player.Ch.Exp.Start()
	Player.Ch.Exp.SetValue(0, 100)
	Player.Ch.Money.Transform().SetParent2(cam)
	Player.Ch.Level.Transform().SetParent2(cam)
	Player.PlComp.MenuScene = func() {
		engine.LoadScene(MenuSceneG)
	}
	txt2 := label.AddComponent(GUI.NewTestBox(func(tx *GUI.TestTextBox) {
		Player.Ch.Cp.Transform().SetPositionf(156, float32(tx.V))
	})).(*GUI.TestTextBox)
	txt2.SetAlign(engine.AlignLeft)
	for i := 0; i < 10; i++ {
		f := Objects.Floor.Clone()
		f.Transform().SetWorldPositionf(float32(i)*100, 50)
		f.Sprite.SetAnimationIndex(4)
		f.Transform().SetParent2(Layer3)
	}
	s.AddGameObject(up)
	s.AddGameObject(cam)
	s.AddGameObject(Layer1)
	s.AddGameObject(Layer2)
	s.AddGameObject(Layer3)
	s.AddGameObject(Layer4)
	s.AddGameObject(background)

}
Ejemplo n.º 21
0
	"math/rand"
	"strconv"
	//	"github.com/vova616/chipmunk/vect"
	//	"github.com/vova616/chipmunk"
)

var (
	Atlas *engine.ManagedAtlas
)
var Items = struct {
	Spot    *engine.GameObject
	BigSpot *engine.GameObject
	Coin    *engine.GameObject
	Coin10  *engine.GameObject
	Diamond *engine.GameObject
}{engine.NewGameObject("spot"), engine.NewGameObject("bigspot"), engine.NewGameObject("coin"), engine.NewGameObject("coin10"), engine.NewGameObject("diamond")}

const (
	Spr_coin    = 1
	Spr_coin10  = 2
	Spr_diamond = 3
	Spr_spot    = 4
	Spr_bigspot = 4
)

type Item struct {
	engine.BaseComponent
	coll     func(*engine.GameObject)
	takeable bool
}
Ejemplo n.º 22
0
func initItems() {
	Items.Spot.AddComponent(engine.NewSprite2(Atlas.Texture, engine.IndexUV(Atlas, Spr_spot)))
	Items.Spot.AddComponent(engine.NewPhysics(false, 1, 1))
	Items.Spot.Transform().SetScalef(30, 30)
	Items.Spot.AddComponent(NewItem(func(so *engine.GameObject) {
		var r int64 = int64(rand.Int()%10 + 5)
		Player.PlComp.AddHp(float32(r))
		te := engine.NewGameObject("textup")
		te.Transform().SetParent(so.Transform().Parent())
		te.Transform().SetPosition(so.Transform().Position())
		te.Transform().SetScalef(100, 100)
		te.AddComponent(GUI.NewUpText(strconv.FormatInt(r, 10)))
	}))

	Items.BigSpot.AddComponent(engine.NewSprite2(Atlas.Texture, engine.IndexUV(Atlas, Spr_bigspot)))
	Items.BigSpot.AddComponent(engine.NewPhysics(false, 1, 1))
	Items.BigSpot.Transform().SetScalef(30, 30)
	Items.BigSpot.AddComponent(NewItem(func(so *engine.GameObject) {
		var r int64 = int64(rand.Int()%15 + 15)
		Player.PlComp.AddHp(float32(r))

		te := engine.NewGameObject("textup")
		te.Transform().SetParent(so.Transform().Parent())
		te.Transform().SetPosition(so.Transform().Position())
		te.Transform().SetScalef(100, 100)
		te.AddComponent(GUI.NewUpText(strconv.FormatInt(r, 10)))
	}))

	Items.Coin.AddComponent(engine.NewSprite2(Atlas.Texture, engine.IndexUV(Atlas, Spr_coin)))
	Items.Coin.AddComponent(engine.NewPhysics(false, 1, 1))
	Items.Coin.Transform().SetScalef(30, 30)
	Items.Coin.AddComponent(NewItem(func(so *engine.GameObject) {
		Player.PlComp.AddMoney(1)
		te := engine.NewGameObject("textup")
		te.Transform().SetParent(so.Transform().Parent())
		te.Transform().SetPosition(so.Transform().Position())
		te.Transform().SetScalef(100, 100)
		te.AddComponent(GUI.NewUpText("10"))
	}))

	Items.Coin10.AddComponent(engine.NewSprite2(Atlas.Texture, engine.IndexUV(Atlas, Spr_coin10)))
	Items.Coin10.AddComponent(engine.NewPhysics(false, 1, 1))
	Items.Coin10.Transform().SetScalef(30, 30)
	Items.Coin10.AddComponent(NewItem(func(so *engine.GameObject) {
		Player.PlComp.AddMoney(10)
		te := engine.NewGameObject("textup")
		te.Transform().SetParent(so.Transform().Parent())
		te.Transform().SetPosition(so.Transform().Position())
		te.Transform().SetScalef(100, 100)
		te.AddComponent(GUI.NewUpText("10"))
	}))

	Items.Diamond.AddComponent(engine.NewSprite2(Atlas.Texture, engine.IndexUV(Atlas, Spr_diamond)))
	Items.Diamond.AddComponent(engine.NewPhysics(false, 1, 1))
	Items.Diamond.Transform().SetScalef(30, 30)
	Items.Diamond.AddComponent(NewItem(func(so *engine.GameObject) {
		var r int64 = int64(rand.Intn(50) + 20)
		Player.PlComp.AddMoney(int(r))
		te := engine.NewGameObject("textup")
		te.Transform().SetParent(so.Transform().Parent())
		te.Transform().SetPosition(so.Transform().Position())
		te.Transform().SetScalef(100, 100)
		te.AddComponent(GUI.NewUpText(strconv.FormatInt(r, 10)))
	}))
}
Ejemplo n.º 23
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")
}
Ejemplo n.º 24
0
func (s *GameScene) Load() {
	s.LoadTextures()
	engine.SetTitle("Zumbies")
	rand.Seed(time.Now().UnixNano())

	Layers = make([]*Map, 0, 10)

	ArialFont, err := engine.NewFont("./data/Fonts/arial.ttf", 48)
	if err != nil {
		panic(err)
	}

	ArialFont2, err := engine.NewFont("./data/Fonts/arial.ttf", 24)
	if err != nil {
		panic(err)
	}
	_ = ArialFont2
	_ = ArialFont

	GameSceneGeneral = s

	s.Camera = engine.NewCamera()

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

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

	gui := engine.NewGameObject("GUI")
	gui.Transform().SetParent2(cam)

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

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

	Mouse = engine.NewGameObject("Mouse")
	Mouse.AddComponent(engine.NewMouse())
	Mouse.Transform().SetParent2(gui)

	FPSDrawer := engine.NewGameObject("FPS")
	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))
	})
	FPSDrawer.Transform().SetParent2(gui)
	FPSDrawer.Transform().SetPositionf(60, float32(engine.Height)-20)
	FPSDrawer.Transform().SetScalef(20, 20)

	{
		Map := engine.NewGameObject("Map")
		uvs := engine.AnimatedUV{}
		for _, id := range TileIDs {
			uvs = append(uvs, engine.IndexUV(TileAtlas, id))
		}
		m := NewMap(TileAtlas.Texture, uvs)
		Map.AddComponent(m)
		Map.Transform().SetPositionf(0, 0)
		Map.Transform().SetScalef(32, 32)

		ca4 := Tile(0).SetCollision(CollisionAll)
		l4 := Tile(0).SetLayerConnection(true)

		m.Tiles = []Tile{
			1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
			2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
			1, 1, 1, 2, ca4, ca4, ca4, ca4, ca4, ca4, ca4, ca4, ca4, ca4, ca4, ca4, ca4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
			2, 1, 1, 2, ca4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ca4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,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2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
			2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
			1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}

		m.Width = int(60)
		m.Height = int(23)

		Layers = append(Layers, m)
	}

	{
		Map := engine.NewGameObject("Map")
		uvs := engine.AnimatedUV{}
		for _, id := range TileIDs {
			uvs = append(uvs, engine.IndexUV(TileAtlas, id))
		}
		m := NewMap(TileAtlas.Texture, uvs)
		Map.AddComponent(m)
		Map.Transform().SetPositionf(0, 0)
		Map.Transform().SetScalef(32, 32)

		u5 := Tile(4).SetSide2(SideUp).SetType2(5)
		d5 := Tile(4).SetSide2(SideDown).SetType2(5)
		l5 := Tile(4).SetSide2(SideLeft).SetType2(5)
		r5 := Tile(4).SetSide2(SideRight).SetType2(5)

		dc5 := Tile(5).SetSide(SideDown).SetCollision(CollisionAll)

		l4 := Tile(4).SetLayerConnection(true)

		u6 := Tile(4).SetSide2(SideUp).SetType2(6)
		d6 := Tile(4).SetSide2(SideDown).SetType2(6)
		l6 := Tile(4).SetSide2(SideLeft).SetType2(6)
		r6 := Tile(4).SetSide2(SideRight).SetType2(6)

		_, _, _, _ = u5, d5, l5, r5

		m.Tiles = []Tile{
			0, 0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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

		m.Width = int(60)
		m.Height = int(23)

		Layers = append(Layers, m)

	}

	for i := len(Layers) - 1; i >= 0; i-- {
		Layers[i].Layer = int(1 << uint(i))
		Layers[i].Transform().SetParent2(Layer1)
	}

	playerObject := engine.NewGameObject("Player")
	player := NewPlayer()
	playerObject.AddComponent(engine.NewSprite2(TileAtlas.Texture, engine.IndexUV(TileAtlas, PlayerID)))
	playerObject.AddComponent(player)
	playerObject.AddComponent(NewPlayerController(player))
	playerObject.AddComponent(components.NewSmoothFollow(nil, 0, 200))
	playerObject.AddComponent(engine.NewPhysicsCircle(false))
	playerObject.Physics.Interpolate = true
	playerObject.Physics.Body.SetMoment(engine.Inf)
	playerObject.Transform().SetScalef(64, 64)
	playerObject.Transform().SetWorldPositionf(159.99995, 32)
	playerObject.Transform().SetDepth(1)
	MainPlayer = player

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

	s.AddGameObject(cam)
	s.AddGameObject(playerObject)
	s.AddGameObject(Layer1)
	s.AddGameObject(Layer2)
	s.AddGameObject(Layer3)

	//s.AddGameObject(shadowShader)

	fmt.Println("Scene loaded")
}
Ejemplo n.º 25
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")
}