Esempio n. 1
0
func NewGame(config *gutil.LuaConfig) *Game {
	g := Game{config: config}
	g.Objects = game.NewGameObjectMap()

	g.CloseChan = make(chan bool, 1)

	g.player = game.NewGameObject("")

	g.mainpanel = panel.MainScreen()
	g.panels = make(map[string]panel.Panel)

	g.panels["stats"] = NewStatsPanel()
	g.panels["view"] = NewViewPanel(&g)
	g.panels["log"] = NewLogPanel()
	g.panels["player"] = NewPlayerPanel(&g)
	g.panels["chat"] = NewChatPanel(&g, &g.Terminal)

	g.logpanel = g.panels["log"].(*LogPanel)
	g.chatpanel = g.panels["chat"].(*ChatPanel)

	//g.chatbox = NewChatBuffer(&g, &g.Terminal)

	//g.Objects = append(g.Objects, g.Player.GameObject)

	return &g
}
Esempio n. 2
0
func NewGameServer(config *gutil.LuaConfig, ls *lua.State) (*GameServer, error) {
	gs := &GameServer{
		config: config,
	}

	GS = gs

	gs.InitGraphState()

	// add nodes
	gs.Add(NewPacketRouter(gs), "router")
	gs.Add(new(PacketLogger), "logger")

	// connect processes
	// Used to be this, was throwing an error about too many arguments to gs.Graph.Connect:
	// gs.Connect("router", "Log", "logger", "In", make(chan *ClientPacket))
	gs.Connect("router", "Log", "logger", "In")

	// map external ports
	gs.MapInPort("In", "router", "In")

	gs.PacketChan = make(chan *ClientPacket, 5)
	gs.SetInPort("In", gs.PacketChan)

	// observers setup
	gs.DefaultSubject = game.NewDefaultSubject()

	// objects setup
	gs.Objects = game.NewGameObjectMap()

	// lua state
	gs.Lua = ls

	return gs, nil
}