Lunar is a library for developing multiplayer games with LibGDX. In it's current state its more appropriate for small scale multiplayer games or prototypes.
provided without any context of course, but you get the idea.
final MyPlayer player = ...;
world.spawnPlayerInWorld(player, 0.0f, 0.0f);
final PlayerConnectionHandler connection = clientServer.getConnection();
connection.registerPacket(MyCustomPacket.ID, MyCustomPacket::new, packet -> handleMyPacket(packet));
// override default behaviour
connection.registerHandlerSync(S2CPacketJoinWorld.PACKET_ID, packet -> world.handleWorldJoin((S2CPacketJoinWorld) packet));
// an example of a basic player with many customizable configuration options
public final class DemoPlayer extends LunarPlayer {
public DemoPlayer(boolean initializeComponents, TextureRegion playerTexture) {
super(initializeComponents);
setMoveSpeed(6.0f);
disablePlayerCollision(true);
setNetworkSendRateInMs(10, 10);
// default player texture
addRegion("player", playerTexture);
// default player configuration
setSize(16, 16, (1 / 16.0f));
}
}
// Create a networked world for others to join us.
// By default the world will handle physics, player updates and network updates!
world = new MultiplayerGameWorld(player, new World(Vector2.Zero, true), myGameInstance);
// add default world systems
world.addWorldSystems();
// ignore player collisions
world.addDefaultPlayerCollisionListener();
// Spawn our player in the world.
player.spawnEntityInWorld(world, mySpawnX, mySpawnY);
// connect to remote server.
final LunarClientServer server = new LunarClientServer(myProtocol, "localhost", 6969);
server.connect();
// get our connection
final PlayerConnection connection = (PlayerConnection) server.getConnection();
// join a remote server world
connection.joinWorld("MyWorld", player.getName());
// provide our own implementation for player connections
server.setConnectionProvider(channel -> new MyPlayerConnectionHandler(channel, protocol));
The wiki includes most things you will need to get started. Not all methods are described, I encourage to explore the source of a few key components like AbstractLunarEntity
and AbstractGameWorld
as this is where most fundamentals reside.
things that should have been implemented forever ago
Lunar uses Java 21.
You can find releases in the releases section. Both client and server rely on the Protocol dependency.
A netty dependency is also required:
// or whatever version
implementation group: 'io.netty', name: 'netty-all', version: '4.1.100.Final'