Ejemplo n.º 1
0
        static void sendMovementToMatchBall(NetworkConnection conn, int playerID)
        {
            ServerDataPackage     s = conn.ReadUDP() as ServerDataPackage;
            PlayerMovementPackage movementPackage = new PlayerMovementPackage();
            RawPlayer             correctPlayer   = null;

            movementPackage.PlayerID = playerID;
            if (s == null)
            {
                return;
            }
            foreach (RawPlayer p in s.Players)
            {
                if (p.ID == playerID)
                {
                    correctPlayer = p;
                    break;
                }
            }
            if (s.Ball.PositionY < correctPlayer.PositionY + GameInitializers.GetPlayerHeight(8) / 2)
            {
                movementPackage.PlayerMovement = ClientMovement.Up;
            }
            else
            {
                movementPackage.PlayerMovement = ClientMovement.Down;
            }
            conn.SendTCP(movementPackage);
        }
Ejemplo n.º 2
0
        public void CalculateNextFrame()
        {
            ServerDataPackage ServerPackage = new ServerDataPackage();

            GetNetworkDataForNextFrame();
            long timePassedInTenthOfAMilliseconds = (FrameDistanceWatch.ElapsedTicks * 10000) / Stopwatch.Frequency;

            FrameDistanceWatch.Restart();
            ServerPackage = NextFramePackage(timePassedInTenthOfAMilliseconds);
            Network.BroadcastFramesToClients(ServerPackage);
        }
Ejemplo n.º 3
0
        static void sendRandomMovemet(NetworkConnection conn, int playerID)
        {
            List <ClientMovement> movements = new List <ClientMovement> {
                ClientMovement.Down, ClientMovement.Up, ClientMovement.StopMoving, ClientMovement.NoInput
            };
            ServerDataPackage     s = conn.ReadUDP() as ServerDataPackage;
            PlayerMovementPackage movementPackage = new PlayerMovementPackage();

            movementPackage.PlayerID       = playerID;
            movementPackage.PlayerMovement = movements[RandomGenerator.Next(4)];
            conn.SendTCP(movementPackage);
        }
Ejemplo n.º 4
0
        private ServerDataPackage NextFramePackage(long timePassedInTenthOfAMilliseconds)
        {
            NextFrame = new ServerDataPackage();

            foreach (KeyValuePair <int, GameStructure.GameTeam> Team in GameStructure.GameTeams)
            {
                foreach (Player player in Team.Value.PlayerList)
                {
                    GameEngine.SetPlayerMovement(player, GetLastPlayerMovement(player.ID));
                    NextFrame.Players.Add(player);
                }
            }

            GameEngine.CalculateFrame(timePassedInTenthOfAMilliseconds);
            NextFrame.Ball.PositionX = GameStructure.Ball.PositionX;
            NextFrame.Ball.PositionY = GameStructure.Ball.PositionY;

            return(NextFrame);
        }
Ejemplo n.º 5
0
        private void ApplyServerPositions(ServerDataPackage gameState)
        {
            for (int i = 0; i < gameState.Players.Count; i++)
            {
                Player    localPlayer;
                RawPlayer serverPlayer = gameState.Players[i];

                if ((localPlayer = GetPlayerWithID(serverPlayer.ID)) == null)
                {
                    continue;
                }

                localPlayer.PositionX = serverPlayer.PositionX;
                localPlayer.PositionY = serverPlayer.PositionY;
            }

            Structure.Ball.PositionX = gameState.Ball.PositionX;
            Structure.Ball.PositionY = gameState.Ball.PositionY;
        }
Ejemplo n.º 6
0
 public void BroadcastFramesToClients(ServerDataPackage Frame)
 {
     Out.BroadCastUDP(Frame);
 }
Ejemplo n.º 7
0
 public void BroadcastFramesToClients(ServerDataPackage serverData, int GameID)
 {
     BroadCastUDP(serverData);
 }