Networked player movement

Networked player movement

Mar 17, 2019. | By: Evan Diamond
2 mins

Getting player’s to move round a board over a network.

Overview

Within our tabletop game the biggest addition we are making compared to the original one we made is adding a board for the players to move arounnd. We are adding this to help regulate when players recieve and give in produce by putting those effects on spaces on the board. This is instead of doing both at the start of every turn which felt boring and repetitve. We are also making it so produce has to be given to other players not to a bank which gives more interaction between players.

Board Implementation

For the board, a tile class and board class was created which the board class having an array of 32 tiles. Each tile has a type from an enum along with a sprite. When the board class is initalised it loops through the array of tiles and initialises them giving them their type which in turn tells the tile what sprite to load. Each tile is then positioned using if statements and ternary operators to put them into a loop (same a monopoly).

Board Image

Here is a current image of the board with two players on it.

Movement Implementation.

Each player starts on one of the corners of the board and when they need to move the user presses the space bar. This button press sends a packet to the server telling it that that player whishes to move which is this game is rolling a six-sided dice. The server then randomly generates a number between 1 and 6 and sends it back in a packet to all clients along with the number of the client whose roll it is. The clients recieve the packet and set the player’s position on the board to their current position + the number rolled. This is done by the player class holding all the infomation about the player also holding an index of the tile the player is on in the tile array in the board class.

Packet id

For both the clients and the server to identify what packets have been sent to them the first value stored in every packed is the id of what type the packet is. The id comes from an enum of PacketTypes and on both client and server the first thing they do with the packets is get it’s id out and use a switch case to determin what to do with the rest of the packet data.

About

Gamers developing new games.

Social Links

Our Bunker

University of the West of England,
Frenchay Campus, Bristol, BS16 1QY,
United Kingdom.