Game Development Reference
In-Depth Information
How to do it
To accomplish the assignment of players, following are the steps to be followed:
1. For a set up purpose for this add some enums, hash define constants and properties
as shown below:
◦ Declare an enum called NetworkPacketCode in which we add only
the KNetworkPacketCodePlayerAllotment packet code for now,
and in the future more packet codes can be added for sending and receiv-
ing packets from the game.
typedef enum {
KNetworkPacketCodePlayerAllotment,
// More to be added while creating the game
} NetworkPacketCode;
◦ Add texts to be shown to players when the player roles are being decided.
// Blue is the First and Red is the Second Player
#define kFirstPlayerLabelText @"You're First
Player"
#define kSecondPlayerLabelText @"You're Second
Player"
◦ Add the max packet size constant and some properties like gamePack-
etNumber , gameUniqueIdForPlayerAllocation in GameS-
cene.m to be used while sending packets.
#define kMaxTankPacketSize 1024
int gameUniqueIdForPlayerAllocation;
@property (nonatomic, assign) int
gamePacketNumber;
2. Now to send data from one device to another, we have an encapsulated data con-
tainer, which is called a packet. Now this packet is sent over the network and the
other player's device will update the view and position accordingly. For this, create
a method to send the packet with a header NetworkPacketCode and data spe-
cifying peerId to which the data packet has to be sent and whether the packet
should be sent with a reliable service or not.
Search WWH ::




Custom Search