LÖVE

Follow these steps to quickly set up and start using Planetary Processing with your LÖVE game. For more detailed information on both the SDK and the server-side API, please visit our documentation.

LÖVE Version

We recommend using LÖVE's most recent release version. If you are using an older version, we recommend a minimum of 11.0 for a successful integration.

Create a Planetary Processing Game

  1. Click Create Game in the top right

  2. Provide the details of your game. Upon its creation, you will be taken to your Game Dashboard.

  3. For this quick start, we will be using Anonymous Auth, which allows players to connect without a username and password. To enable this, navigate to the settings section of your Game Dashboard and enable Anonymous Auth as the Player Authentication Type within Game Settings.

Clone your Game Repository

  1. Clone the git repository as listed in your game dashboard - this is your Planetary Processing backend code.

Setting Up Your LÖVE Project

In a separate directory, set up a new LÖVE project with at least a main.lua file.

  1. Save an empty text document as main.lua, in your chosen directory.

  2. Clone the Planetary Processing SDK into the same directory by running the following command:

  1. Save a conf.lua file in the same directory, with the following code for print() debugging to console.

Connecting to your game server

  1. Edit main.lua to use the sdk. The sdk object can be used to interact with your game server.

  1. Create a love.load() function, containing sdk.init() and sdk.join(), to connect to the server and join as a player.

  2. Set the first parameter of sdk.init() to be your Game Id. This is a number which can be found on your game dashboard, next to your game’s name and repo link.

  1. Create a love.update(dt) function, with sdk.update() to receive data from the game server.

main.lua (basic connection)
main.lua (basic connection - no comments)

Creating Entities

While connected, the sdk will receive updated data about any entities visible to the player, and store it in sdk.entities. Entities are stored as tables which follow the format in the LÖVE SDK documentation.

  1. Create a love.draw() function, to display each entity.

main.lua (display entities)
main.lua (display entities - no comments)

Test your connection

You now have everything you need to establish a basic connection between LÖVE and the server-side demo code.

  1. On the Planetary Processing games web panel, select your game to enter its dashboard.

  2. Click Actions>Start Game to start the server-side simulation.

  3. Run your main.lua file using LÖVE.

You should be able to see all your entities displayed in a messy jumble in the top left of your game window. With the cats, or 'C's, slowly moving. Your Planetary Processing game dashboard map will also show that a player has joined!

Syncing the World Map and Window Origin

The Planetary Processing game world has its origin in the centre of the world, whereas LÖVE 's origin is in the top left of the game window. This can be resolved by displaying entities with an offset.

  1. Create class variables in main.lua for storing an X and Y offset.

  1. Set these variables in the start of love.load().

  1. Apply the offset before the entities are drawn each frame, at the start of love.draw().

Your viewport will now be centred on your game world's origin (0,0), where you can see the 'P' icon representing the player.

main.lua (centred origin)
main.lua (centred origin - no comments)

Syncing the World Map and Window Axis

LÖVE 's top left origin means that the game client's Y axis runs in the opposite direction to the game server's. Inverting any Y position values from the server will correct this.

  1. Create a class variable in main.lua for inverting the Y axis.

  1. Apply that variable to each entity's Y value in love.draw(), to correct its position.

main.lua (inverted y axis)
main.lua (inverted axis - no comments)

Syncing the World Map and Window Scale

The entity's coordinates are also currently using pixels, making everything display very close together. You can improve the viewport zoom by scaling the entity positions again.

  1. Create a class variable in main.lua for scaling the viewport zoom.

  1. Apply that variable to each entity's X and Y values in love.draw(), to correct its position.

main.lua (zoomed)
main.lua (zoomed - no comments)

Player Movement

Now that the game world is visible and orientated, we can start interacting with it. We use sdk.message(msg) to send data to the player entity on the backend.

  1. Edit the love.update(dt) function, to send a table containing XY movement values to the server whenever a WASD input key is pressed.

When this message is sent each frame, the player should now move both visibly in LÖVE and on the game dashboard map.

main.lua (player movement)
main.lua(player movement - no comments)

Follow Player Movement

To see the rest of our world, we can use the same world offsetting principle as before to show the world around the player.

  1. Create class variables in main.lua for storing an X and Y offset from the player's position.

  1. Get the player's position, to calculate the offset at the end of the love.update(dt) function.

  1. Apply the player offset alongside the world position offset, in love.draw().

main.lua (follow player)
main.lua (follow player - no comments)

Resizing Your Window (Optional)

At this point you can start customising your LÖVE game client however you like. Take note that actions such as resizing the window will alter your world origin offset and must be corrected.

  1. Set your window to resizable at the start of the love.load() function.

  1. Make a love.resize() function, to get the new offset from the resized window.

main.lua (complete - but remember to change the Game ID to your own)
main.lua (complete - no comments)

Editing Your Backend Code

Using the repo we cloned earlier you can edit the behaviour of entities by changing their Lua file within the entity directory.

You can also change how many and what entities are spawned in the init.lua file.

We recommend experimenting here to get a sense of what you can do with Planetary Processing. When you add or change entities, make sure your server-side changes match up with your game engine client.

Push Your Planetary Processing Backend Code to the Game Repository

  1. After configuring your game entities and logic, push your changes to the game repository:

Deploy Latest Version in the Web UI

  1. Go back to your game dashboard in our web panel.

  2. From the actions menu in the top right, select "Deploy Latest Version" - this will roll out your updated server-side code.

Start Game in the Web UI

  1. Click "Start Game" to begin your server-side simulation.

Play Your Multiplayer Game!

  1. Launch your LÖVE project.

  2. Connect to the multiplayer game through the game client, authenticate, and enjoy playing with others!

  3. If you want to learn more about updating your server-side code, check out our server-side tutorial video: https://www.youtube.com/watch?v=QYWtedo1kr4&list=PLW5OY4K85Qhn7lwZeSPVZXH_Lg5IwhjNC

Troubleshooting

If you have encountered any issues, we have a premade demo of this guide: https://drive.google.com/drive/folders/1A7pIeFlghVxURlJEsGoiu0G1UGDuVwc6?usp=drive_link If you have further questions, please get in touch on our Discord.

Last updated