protected void UpdateLocalPlayer(GameTime gameTime) { //you know this will def be the local gamer as there is only 1 allowed LocalNetworkGamer localGamer = networkSession.LocalGamers[0]; //gotta get the sprite to modify it UserControlledSprite localSprite = (UserControlledSprite)localGamer.Tag; //now actually update sprite regualrly //moving is true because this is just you controlling it localSprite.Update(gameTime, Window.ClientBounds, true); if (!localSprite.isChasing) { localSprite.score += gameTime.ElapsedGameTime.Milliseconds; } writer.Write((int)MessageType.UpdatePlayerPos); writer.Write(localSprite.Position); if (!localSprite.isChasing) { writer.Write(localSprite.score); } //simple sprites may not send data, you must use the localnetworkgamer object //the options is InOrder because its ok if the packets dont get there, but they at least must be in order localGamer.SendData(writer, SendDataOptions.ReliableInOrder); //if your local sprite is a chaser if (localSprite.isChasing) { //if you're able to drop a bomb if (bombCoolDown <= 0) { //and if you press space if (Keyboard.GetState().IsKeyDown(Keys.Space)) { AddBomb(localSprite.Position); writer.Write((int)MessageType.AddBomb); writer.Write(localSprite.Position); localGamer.SendData(writer, SendDataOptions.ReliableInOrder); } } } }
protected void UpdateOtherPlayer(GameTime gameTime) { NetworkGamer otherPlayer = GetOtherPlayer(); UserControlledSprite otherSprite = (UserControlledSprite)otherPlayer.Tag; //you will always need the packet reader to read a vector or int to update a remote player from another comp Vector2 otherPosition = reader.ReadVector2(); otherSprite.Position = otherPosition; if (!otherSprite.isChasing) { int score = reader.ReadInt32(); otherSprite.score = score; } //set moving to false because you dont want to move it, you already set position, only animate frame otherSprite.Update(gameTime, Window.ClientBounds, false); }