Ejemplo 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)
		}
	}
}
Ejemplo 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)
			}

		}
	}
}