예제 #1
0
        private void process(MoveMessage moveMsg)
        {
            OtherPlayer found = OtherPlayers.FirstOrDefault(o => o.playerData.playerID == moveMsg.playerID);

            if (found != null)
            {
                found.Position = new Vector2(moveMsg.NewX, moveMsg.NewY);
            }
        }
예제 #2
0
        private OtherPlayer createOtherPlayer(PlayerData playerData)
        {
            Texture2D   tx          = Content.Load <Texture2D>(@"PlayerImages\" + playerData.imageName);
            OtherPlayer otherPlayer = new OtherPlayer(tx, new Vector2(playerData.X, playerData.Y), 1, playerData);

            // Create a score for the other player in all clients
            LidgrenClient.SendScore(new ScoreData {
                playerID = playerData.playerID,
                Tag      = playerData.GamerTag,
                score    = 0
            });
            return(otherPlayer);
        }
예제 #3
0
        private object process(PlayerData playerData)
        {
            //PlayerData otherPlayer = DataHandler.ExtractMessage<PlayerData>(v);
            if (playerData == null)
            {
                return(null);
            }
            if (player == null)
            {
                if (playerData.header == "Accepted")
                {
                    setupPlayer(playerData);
                }
            }
            // if it's the same player back just ignore it
            //if ((playerData.playerID == player.playerData.playerID))
            //    return null;

            switch (playerData.header)
            {
            case "Joined":
                // Current Player getting Joined Message Back
                if (playerData.playerID == player.playerData.playerID)
                {
                    playerJoined = true;
                }
                else
                {
                    // Add the player to this game as another player
                    string ImageName = "Badges_" + Utility.NextRandom(0, playerTextures.Count - 1);
                    // Create other players
                    OtherPlayer newPlayer = createOtherPlayer(playerData);
                    new FadeText(this, Vector2.Zero, playerData.GamerTag + " has Joined the Game ");
                    OtherPlayers.Add(newPlayer);
                }
                break;

            case "Moved_To":
                // Ignore Move to for this client
                if (playerData.playerID == player.playerData.playerID)
                {
                    return(null);
                }
                // Add the player to this game as another player
                var movedPlayer = OtherPlayers.Find(p => p.playerData.playerID == playerData.playerID);
                if (movedPlayer != null)
                {
                    movedPlayer.Position = new Vector2(playerData.X, playerData.Y);
                }
                break;

            case "Left":
                OtherPlayer found = OtherPlayers
                                    .Find(o => o.playerData.playerID == playerData.playerID);
                if (found != null)
                {
                    new FadeText(this, Vector2.Zero, found.playerData.GamerTag + " has left the Game ");
                    OtherPlayers.Remove(found);
                }
                break;

            default:
                break;
            }
            return(playerData);
        }