コード例 #1
0
ファイル: player.go プロジェクト: banad/PirateLand
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)
}
コード例 #2
0
ファイル: Enemy.go プロジェクト: banad/PirateLand
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))
}
コード例 #3
0
ファイル: PirateScene.go プロジェクト: banad/PirateLand
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)

}