Пример #1
0
    public void sendInput(float x, float y)
    {
        CmdPacket packet = new CmdPacket();

        packet.WriteUShort(Proto.C_GameShot);
        packet.WriteFloat(x);
        packet.WriteFloat(y);
        send(packet);
    }
Пример #2
0
 void Update()
 {
     if (m_state == State.ST_Start)
     {
         m_state           = State.ST_Running;
         m_time            = 0;
         m_input.m_enabled = true;
         if (m_bottom)
         {
             m_other.position = m_tranUp.position;
             m_other.rotation = m_tranUp.rotation;
             Camera.main.transform.position = m_tranBottom.position;
             Camera.main.transform.rotation = m_tranBottom.rotation;
         }
         else
         {
             m_other.position = m_tranBottom.position;
             m_other.rotation = m_tranBottom.rotation;
             Camera.main.transform.position = m_tranUp.position;
             Camera.main.transform.rotation = m_tranUp.rotation;
         }
         m_ball.position = m_tranBall.position;
         m_ball.rotation = m_tranBall.rotation;
     }
     if (m_state == State.ST_Running)
     {
         if (m_time > m_gameTime)
         {
             m_state = State.ST_End;
             CmdPacket packet = new CmdPacket();
             //packet.WriteUShort(Proto.C_AutoMatch);
             //m_client.m_client.Send(packet);
         }
         m_time += Time.deltaTime;
         //同步位置和速度
         if (m_bSer)
         {
             //if (Time.realtimeSinceStartup - m_lstSyncTime > Time.deltaTime)
             {
                 CmdPacket packet = new CmdPacket();
                 packet.WriteUShort(Proto.Synch_Pos);
                 packet.WriteUInt64(TimeMgr.getTimeStampMicro());
                 packet.WriteFloat(m_ball.position.x);
                 packet.WriteFloat(m_ball.position.z);
                 packet.WriteFloat(m_ball.rigidbody.velocity.x);
                 packet.WriteFloat(m_ball.rigidbody.velocity.z);
                 m_client.send(packet);
                 m_lstSyncTime = Time.realtimeSinceStartup;
             }
         }
     }
 }
Пример #3
0
    void Update()
    {
        Vector3 vec = ball.rigidbody.velocity;

        if (vec.x > 50)
        {
            vec.x = 50;
        }
        if (vec.x < -50)
        {
            vec.x = -50;
        }
        if (vec.z > 50)
        {
            vec.z = 50;
        }
        if (vec.z < -50)
        {
            vec.z = -50;
        }
        ball.rigidbody.velocity = vec;
        Vector3 cameraVec = Camera.main.transform.position;

        if (cameraVec.x < -3)
        {
            cameraVec.x = -3;
        }
        if (cameraVec.x > 3)
        {
            cameraVec.x = 3;
        }
        Camera.main.transform.position = cameraVec;
        if (m_game.m_state != Game.State.ST_Running)
        {
            return;
        }
        if (m_game.m_bottom && ball.position.z <= 0 || !m_game.m_bottom && ball.position.z >= 0)
        {
            bool click = false;
            if (m_automatic)
            {
                if (Time.realtimeSinceStartup - m_lstClickTime > 0.11f)
                {
                    click          = true;
                    m_lstClickTime = Time.realtimeSinceStartup;
                }
            }
            else if (Input.GetMouseButtonUp(0))
            {
                click = true;
            }
            if (click)
            {
                Vector3 direction = ball.position - selfGun.position;
                direction.y = 0;
                Debug.Log("self:" + direction);
                ball.rigidbody.velocity = direction * rate;
                //ball.rigidbody.AddForce(direction * rate, ForceMode.Impulse);

                CmdPacket packet = new CmdPacket();
                packet.WriteUShort(Proto.C_GameShot);
                packet.WriteFloat(ball.rigidbody.velocity.x);
                packet.WriteFloat(ball.rigidbody.velocity.z);
                m_client.send(packet);
            }
        }
        if (Input.GetKey(KeyCode.A))
        {
            cameraVec.x += -1 * Time.deltaTime * cameraMoveSpeed;
        }
        if (Input.GetKey(KeyCode.D))
        {
            cameraVec.x += 1 * Time.deltaTime * cameraMoveSpeed;
        }
    }