Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        string query;

        if (!ready && !sent)
        {
            query = "S_READY:" + client.nickName;
            client.SendData(query);
            sent  = true;
            query = null;
        }

        string toExecute = client.ReceiveData();

        if (toExecute != null)
        {
            string[] isValidCommand = toExecute.Split(':');

            if (opcodesPtr.ContainsKey(isValidCommand[0]))
            {
                opcodesPtr[isValidCommand[0]](isValidCommand);
            }
            toExecute = null;
        }

        if (ready && Input.GetKeyDown(KeyCode.Escape))
        {
            menu.SetActive(true);
            Cursor.visible = true;
        }

        if (ready && !end)
        {
            StartMusic();
            if (Physics.Raycast(player_body_transform.position, Vector3.down, 0.6f)) // isGrounded
            {
                float   fVerticalForce   = Input.GetAxis("Vertical") * (bIsOnAccelerator ? m_fAcceleratorSpeed : speed);
                Vector3 vMouvementVector = transform.rotation * new Vector3(0.0f, 0.0f, fVerticalForce) * Time.deltaTime;

                player_body.AddForce(vMouvementVector);
                player_body.MoveRotation(camera.rotation);
            }
            if (showCountdown.activeSelf)
            {
                showCountdown.SetActive(false);
            }
        }

        time += Time.deltaTime;

        if (time >= interpolationPeriod)
        {
            time = time - interpolationPeriod;

            query  = "S_MOVEMENT:" + client.nickName + ':';
            query += transform.position.x.ToString() + ':' + transform.position.y.ToString() + ':' + transform.position.z.ToString();
            client.SendData(query);
            query = null;
        }
    }
Exemple #2
0
        private void Update()
        {
            if (!connected && !sent)
            {
                string query = "S_LOGIN:";
                query += client.nickName + ':' + client.pass;
                client.SendData(query);
                sent = true;
            }

            string toExecute = client.ReceiveData();

            if (toExecute != null)
            {
                string[] isValidCommand = toExecute.Split(':');

                if (opcodesPtr.ContainsKey(isValidCommand[0]))
                {
                    opcodesPtr[isValidCommand[0]](isValidCommand);
                }
                toExecute = null;
            }

            if (connected)
            {
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    if (menuNumber == 2 || menuNumber == 7 || menuNumber == 8)
                    {
                        GoBackToMainMenu();
                        ClickSound();
                    }

                    else if (menuNumber == 3 || menuNumber == 4 || menuNumber == 5)
                    {
                        GoBackToOptionsMenu();
                        ClickSound();
                    }

                    else if (menuNumber == 6) //CONTROLS MENU
                    {
                        GoBackToGameplayMenu();
                        ClickSound();
                    }
                }

                if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
                {
                    SendInvite();
                    ClickSound();
                }
            }
        }
Exemple #3
0
        protected override void Run()
        {
            Client.Connect();

            while (IsRunning)
            {
                try
                {
                    Network data = Client.ReceiveData <Network>();
                    if (data == null)
                    {
                        continue;
                    }

                    Network = data;
                    CalculatePosition();
                }
                catch (ServerStoppedRespondingException)
                {
                    Console.WriteLine("Lost connection, trying to reconnect");
                    if (!Client.ReConnect())
                    {
                        Stop();
                        return;
                    }
                }
                catch (ServerStoppingException)
                {
                    Console.WriteLine("Server closing, trying to reconnect");
                    if (!Client.ReConnect())
                    {
                        Stop();
                        return;
                    }
                }
                catch (NoAcknowledgementException)
                {
                    Console.WriteLine("Server did not acknowledge client, trying to reconnect");
                    if (!Client.ReConnect())
                    {
                        Stop();
                        return;
                    }
                }
            }
        }
        protected override void Run()
        {
            Client.Connect();

            while (IsRunning)
            {
                try
                {
                    Sensors data = Client.ReceiveData <Sensors>();

                    if (data != null)
                    {
                        Sensors  = data;
                        Response = new Response(true, CalculatePosition(), 75);
                    }
                }
                catch (ServerStoppedRespondingException)
                {
                    Console.WriteLine("Lost connection, trying to reconnect");
                    if (!Client.ReConnect())
                    {
                        Stop();
                        return;
                    }
                }
                catch (ServerStoppingException)
                {
                    Console.WriteLine("Server closing, trying to reconnect");
                    if (!Client.ReConnect())
                    {
                        Stop();
                        return;
                    }
                }
                catch (NoAcknowledgementException)
                {
                    Console.WriteLine("Server did not acknowledge client, trying to reconnect");
                    if (!Client.ReConnect())
                    {
                        Stop();
                        return;
                    }
                }
            }
        }