Building a Game with PraxisMapper

We are going to walk through the logic for the Splatter demo client. This is about as simple as a complete PraxisMapper game can get.

image

First we have the Login screen. This is necessary if we have data stored per player, which most games will. We authenticate at /Server/Login, where the client gets the Id it'll pass back on all subsequent calls to tell the server which account is talking to it. If you're logging in for the first time, you'll hit /Server/CreateAccount instead, and then the client will log you in with your credentials immediately after. Most games that have player-specific data to show immediately would shift to a loading screen and call a second plugin-specific endpoint to get that data, but Splatter doesn't need that. Outside of your Paint point total, which the client will get when you enter the first tile in the scene, there's no player data for the client to process or store.

Finally, the bottom box allows you to set your server URL in the generic client to your own specific server if you're using a precompiled build. The default server at localhost:5000 assumes you are running PraxisMapper.exe directly on your computer and are testing it out in the Solar2D simulator. If not, just update the URL to match your actual server.

Once that's successful, we move to the Splat scene. This has several moving parts, but most of them are pretty simple. There's the walkaround (GPS) part, the interaction part, and the maptile part.

image

Splatter grants the player 1 point for each 10-character PlusCode cell (Cell10 in PraxisMapper parlance) they walk through, with a 22 hour cooldown until that PlusCode can grant a point again. This is done on the client with a location event listener that fires on every GPS event. If the client sees that the player is in a different Cell10 than the previous event, it hits the /Splatter/Enter/{cell10} endpoint on the server, sending the code without the plus because the + character is reserved in URLs for a specific purpose. The server then loads the recent location activity for that user, and if the requested Cell10 is not on the recent list or is expired, it gives the user a point and sends over the new total points back.

When the user taps the screen, the client confirms the player has points to spend, works out which Cell10 was tapped, and then picks how large of a splat to make. The splat will be between 1 and 20 Cell10s in radius, with the floor set to 10% of the player's points. With that chosen, the client sends a request to Splatter/Splat/{cell10}/{radius}. The server stores each color of splatter as its own Geometry item, and shapes are updated to make sure they don't overlap against the new one. The server will confirm the player has that many points to spend, create a random splatter shape, assign it a random color, update all of the Geometries, and expire all map tiles that touch the created splatter to be redrawn on the next request.

There are 2 layers of maptiles displayed on the Splat screen. All maptiles are generated on demand, so there won't be any tiles on the server until a client requests to receive one. The bottom layer is the actual OpenStreetMap data tiles. These are generated once on the server, requested once by the client, and not checked again after download. The client stores these in Cached data, so the data can be removed and re-requested if needed. The top layer is the Splat layer, which is drawn on the server if there's no existing tile or the existing tile is expired, but the client checks every 5 seconds for the tile's GenerationID. If the server responds with a larger GenerationID than the client has, the client downloads the new Splat map tile to replace the existing one. Tiles that haven't changed don't get updated. This saves on data usage for the client and processing power for the server.

All the tiles are drawn into a locked ScrollView, so only the game can adjust its position and does so when the player moves to a new Cell10. The Zoom buttons adjust some values to determine how large to draw tiles and how many tiles to draw.

And that's the app. Any other PraxisMapper game will likely follow similar steps, even if they're more complicated or have custom plugins on the server for game logic.