Jump to content

Multiplayer Test


Josh
 Share

Recommended Posts

Create or join a lobby, then hold V key to talk.

MultiplayerGame.zip

Source looks like this:

#include "App.h"

using namespace Leadwerks;

int main(int argc, const char *argv[])
{
	Steamworks::Initialize();

	//World setup
	auto window = Window::Create("Multiplayer Game", 0, 0, 1024, 768);
	auto context = Context::Create(window);
	auto world = World::Create();
	auto gui = GUI::Create(context);	
	auto camera = Camera::Create();
	
	//Create server list
	auto serverlist = Widget::ListBox(20, 20, 400, 300, gui->GetBase());
	int count = Lobby::Count({ { "game","mplayertest" } });
	Lobby* lobby = nullptr;
	for (int n = 0; n < count; ++n)
	{
		lobby = Lobby::Get(n);
		serverlist->AddItem(String(lobby->steamid),n==0);
	}
	lobby = nullptr;

	//GUI buttons
	auto button_join = Widget::Button("Join",20, 20+300, 76, 28, gui->GetBase());
	auto button_create = Widget::Button("Create", 20 + 76 + 2, 20+300, 76, 28, gui->GetBase());
	bool recording = false;
	
	while (true)
	{
		if (window->KeyHit(Key::Escape)) break;
		if (window->Closed()) break;
		
		if (lobby)
		{
			if (recording)
			{
				if (!window->KeyDown(Key::V))
				{
					Sound::StopRecording(lobby);
					recording = false;
				}								
			}
			else
			{
				if (window->KeyDown(Key::V))
				{
					Sound::StartRecording();
					recording = true;
				}
			}
		}
		
		P2P::Receive(-101);
		
		Time::Update();
		world->Update();
		world->Render();
		
		while (EventQueue::Peek())
		{
			auto event = EventQueue::Wait();
			if (event.id == Event::WidgetAction)
			{
				if (event.source == button_join)
				{
					int index = serverlist->GetSelectedItem();
					lobby = Lobby::Get(index);
					lobby->Join();
					gui->Hide();
				}
				else if (event.source == button_create)
				{
					lobby = Lobby::Create();
					lobby->SetKey("game", "mplayertest");
					gui->Hide();
				}
			}
		}
		
		context->Sync();
	}
	return 0;
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...