Esempio n. 1
0
func (c *Client) HandlePacket(packet server.Packet) {
	defer c.OnPanic()
	switch packet.ID() {
	case server.ID_SpawnPlayer:
		spawnPlayer := packet.(server.SpawnPlayer)
		c.GameJobs <- func() {
			if spawnPlayer.PlayerInfo.PlayerID == c.ID {
				SpawnMainPlayer(spawnPlayer)
			} else {
				SpawnPlayer(spawnPlayer)
			}
		}
	case server.ID_EnterGame:
		enterGame := packet.(server.EnterGame)
		c.ID = enterGame.PlayerID
		c.Name = enterGame.Name
		engine.LoadScene(GameSceneGeneral)
	case server.ID_LoginError:
		error := packet.(server.LoginError)
		LoginErrChan <- fmt.Errorf(error.Error)
		panic(error)
	case server.ID_PlayerTransform:
		trans := packet.(server.PlayerTransform)
		c.GameJobs <- func() {
			p, exist := Players[trans.PlayerID]
			if !exist {
				println("player does not exists")
				return
			}
			p.Transform().SetPositionf(trans.X, trans.Y)
			p.Transform().SetRotationf(trans.Rotation)
		}
	}
}
Esempio n. 2
0
func Start() {
	defer func() {
		if p := recover(); p != nil {
			fmt.Println(p, engine.PanicPath())
		}

		engine.Terminate()
	}()
	engine.StartEngine()
	_ = game.GameSceneGeneral
	_ = networkOnline.GameSceneGeneral
	_ = login.LoginSceneGeneral
	_ = zumbies.GameSceneGeneral

	/*
		Running local server.
	*/
	go server.StartServer()

	scene := 0

	engine.LoadScene(login.LoginSceneGeneral)
	for engine.MainLoop() {
		if input.KeyPress('`') {
			scene = (scene + 1) % 3
			switch scene {
			case 0:
				engine.LoadScene(login.LoginSceneGeneral)
			case 1:
				engine.LoadScene(networkOnline.GameSceneGeneral)
			case 2:
				engine.LoadScene(zumbies.GameSceneGeneral)
			}

		}
	}
}
Esempio n. 3
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)

}
Esempio n. 4
0
func Start() {
	defer func() {
		if p := recover(); p != nil {
			fmt.Println(p, engine.PanicPath())
		}

		engine.Terminate()
	}()
	engine.StartEngine()
	_ = Game.MenuSceneG

	/*
		Running local server.
	*/
	//go Server.StartServer()

	engine.LoadScene(Game.MenuSceneG)
	for engine.MainLoop() {

	}
}
Esempio n. 5
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)

}