예제 #1
0
    void Update()
    {
        // periodically check for servers
        if (!net.Connected)
        {
            if (serverSearch + 5f < Time.time)
            {
                serverSearch = Time.time;
                lookForServer();
            }
        }

        // see if escaping company logo splash
        if (CcInput.Started(UserAction.Menu) ||         // wanna bring up menu from ANY other mode
            Mode == HudMode.SplashLogos &&
            CcInput.Started(UserAction.Activate)        // allow alt splash screen escape
            )
        {
            if (Mode == HudMode.MainMenu)
            {
//				if (net.Connected)
//					Mode = HudMode.Playing;
            }
            else
            {
                Mode = HudMode.MainMenu;
            }
        }

        if (CcInput.Started(UserAction.Scores))
        {
            playMode.ShowingScores = !playMode.ShowingScores;
        }
    }
예제 #2
0
    public void MaybeJumpOrFall(Actor ne, CcNet net)
    {
        if (grounded)
        {
            yMove = 0f;

            if (CcInput.Started(UserAction.MoveUp) || JumpBoosted)
            {
                yMove = JumpBoosted ? 7f : 4f;

                if /****/ (JumpBoosted)
                {
                    ne.PlaySound("spacey");
                }
                else
                {
                    ne.PlaySound("Jump");
                }

                net.SendTINYUserUpdate(ne.User.viewID, UserAction.MoveUp);
                // FIXME: this makes remote players play normal jump sound even when bouncepadding
            }
        }
        else           // we're in the air
        {
            yMove -= Time.deltaTime * net.CurrMatch.Gravity;
        }
    }
예제 #3
0
 public void Update()
 {
     if (CcInput.Started(UserAction.Activate))
     {
         Debug.Log("aSrc.Play();");
         //aSrc.Play();
     }
 }
예제 #4
0
    void stickToSpectated()
    {
        if (net.Entities.Count > 0)
        {
            if (MeshInHand)
            {
                MeshInHand.GetComponent <Renderer>().enabled = false;
            }

            if (CcInput.Started(UserAction.Activate) ||
                net.Entities[Spectatee].lives <= 0
                )
            {
                Spectatee++;

                if (Spectatee >= net.Entities.Count)
                {
                    Spectatee = 0;
                }
            }

            Camera.main.transform.parent   = null;
            Camera.main.transform.position = net.Entities[Spectatee].Actor.transform.position;
            //CurrModel.transform.position = net.Entities[Spectatee].Visuals.transform.position;

            float yChange = 1f;             // y angle change
            if (locUser.LookInvert)
            {
                yChange = -1f;
            }

            if (Cursor.lockState == CursorLockMode.Locked)
            {
                camAngle.x -= Input.GetAxis("Mouse Y") * Time.deltaTime * 30f * locUser.LookSensitivity * yChange;
                camAngle.y += Input.GetAxis("Mouse X") * Time.deltaTime * 30f * locUser.LookSensitivity;

                if (camAngle.x > 85f)
                {
                    camAngle.x = 85f;
                }
                if (camAngle.x < -85f)
                {
                    camAngle.x = -85f;
                }
            }

            Camera.main.transform.eulerAngles = camAngle;
            Camera.main.transform.Translate(0, 0, -3);
        }
    }
예제 #5
0
 void selectSpecificWeapon()
 {
     for (int i = (int)UserAction.Pistol; i <= (int)UserAction.Spatula; i++)
     {
         if (CcInput.Started((UserAction)i))
         {
             if (                /* not already equipped, but carrying */
                 (Gun)i != GunInHand &&
                 arse.Guns[i].Carrying)
             {
                 GunOnBack = GunInHand;
                 GunInHand = (Gun)i;
                 weaponSwitchingSoundAndVisual();
             }
         }
     }
 }
예제 #6
0
    void switchWeapon()
    {
        bool nex, pre;

        CcInput.PollScrollWheel(out nex, out pre);
        bool next = CcInput.Started(UserAction.Next);
        bool prev = CcInput.Started(UserAction.Previous);

        if (next || prev || nex || pre)
        {
            Gun juggledItem = GunInHand;

            // switch weapon
            while (GunInHand == juggledItem ||
                   !arse.Guns[(int)GunInHand].Carrying)
            {
                if (next || nex)
                {
                    GunInHand++;
                    if ((int)GunInHand >= arse.Guns.Length)
                    {
                        GunInHand = Gun.Pistol;
                    }
                }
                else
                {
                    GunInHand--;
                    if (GunInHand < Gun.Pistol)
                    {
                        GunInHand = (Gun)arse.Guns.Length - 1;
                    }
                }
            }

            GunOnBack = juggledItem;
            weaponSwitchingSoundAndVisual();
        }
    }
예제 #7
0
    void localUserUpdate()
    {
        var lastPos = transform.position;

        // item pick up
        if (User.Health > 0f)
        {
            managePickingUpItem();
        }
        offeredPickup = "";         // must do after the above check

        if (User.Health > 0f)
        {
            if (Camera.main.transform.parent == null)
            {
                SetModelVisibility(false);
            }

            net.LocEnt.FraggedBy                = null;
            Camera.main.transform.parent        = camHolder.transform;
            Camera.main.transform.localPosition = Vector3.zero;
            // this makes sure we can walk along walls/ceilings with proper mouselook orientation
            Camera.main.transform.localRotation = Quaternion.Slerp(
                Camera.main.transform.localRotation,
                Quaternion.Euler(Vector3.zero),
                Time.deltaTime * 5f);

            float invY = 1f;
            if (locUser.LookInvert)
            {
                invY = -1f;
            }

            if (Cursor.lockState == CursorLockMode.Locked &&
                hud.Mode == HudMode.Playing ||
                hud.Mode == HudMode.Editing
                )
            {
                camAngle.x -= Input.GetAxis("Mouse Y") * locUser.LookSensitivity * invY;
                camAngle.y += Input.GetAxis("Mouse X") * locUser.LookSensitivity;
                float max = 89f;                 // degrees up or down limit
                if (camAngle.x > max)
                {
                    camAngle.x = max;
                }
                if (camAngle.x < -max)
                {
                    camAngle.x = -max;
                }
            }

            if (CcInput.Started(UserAction.Sprint))
            {
                if (bod.sprinting)
                {
                    bod.sprinting = false;
                }
                else if (SprintEnergy > 0.2f)
                {
                    bod.sprinting = true;
                    sprintRelease = 0f;
                }
                else
                {
                    PlaySound("Exhausted");
                }
            }

            bod.TickEnergy(this);

            sprintRelease += Time.deltaTime;

            camHolder.transform.localEulerAngles = camAngle;
            var inputVector = Vector3.zero;

            if (CcInput.Holding(UserAction.MoveForward))
            {
                inputVector += animObj.transform.forward;
            }

            if (CcInput.Holding(UserAction.MoveBackward))
            {
                inputVector -= animObj.transform.forward;
            }

            if (CcInput.Holding(UserAction.MoveRight))
            {
                inputVector += animObj.transform.right;
            }

            if (CcInput.Holding(UserAction.MoveLeft))
            {
                inputVector -= animObj.transform.right;
            }

            if (inputVector != Vector3.zero)
            {
                sprintRelease = 0f;
            }

            if (sprintRelease > maxSprintRelease)
            {
                bod.sprinting = false;
            }

            //inputVector.y = 0f;
            inputVector.Normalize();

            bod.UpVector = animObj.transform.up;



            var speedUpright   = 10f;
            var speedCrouching = 5f;
            if (crouching)
            {
                bod.Move(inputVector * Time.deltaTime * speedCrouching);
            }
            else
            {
                bod.Move(inputVector * Time.deltaTime * speedUpright);
            }



            SprintEnergy = bod.GetEnergy();
            bod.VerticalMove(this);
            bod.MaybeJumpOrFall(this, net);

            bod.Move(transform.up * bod.yMove * Time.deltaTime * 5f);

            crouching = false;
            if (CcInput.Holding(UserAction.MoveDown))
            {
                crouching = true;
            }

            moveVec = inputVector;

            Ray        lavaRay       = new Ray(lastPos, transform.position - lastPos);
            RaycastHit lavaHit       = new RaycastHit();
            float      lavaRayLength = Vector3.Distance(transform.position, lastPos);
            int        lavaLayer     = (1 << 10);
            if (Physics.Raycast(lavaRay, out lavaHit, lavaRayLength, lavaLayer))
            {
                transform.position = lavaHit.point + (Vector3.up * 0.35f);
                sendRPCUpdate      = true;
                inputVector        = Vector3.zero;
                net.RegisterHit(Gun.Lava, User.viewID, User.viewID, lavaHit.point);
            }


            //sendRPCUpdate = false;
            if (camAngle != lastCamAngle && Time.time > rpcCamTime)
            {
                sendRPCUpdate = true;
            }
            if (moveVec != lastMoveVector)
            {
                sendRPCUpdate = true;
            }
            if (crouching != crouchingPrev)
            {
                sendRPCUpdate = true;
            }
            if (bod.yMove != lastYmove)
            {
                sendRPCUpdate = true;
            }
            if (User.Health != lastHealth)
            {
                sendRPCUpdate = true;
            }
            if (net.broadcastPos)
            {
                net.broadcastPos = false;
                sendRPCUpdate    = true;
            }

            lastCamAngle   = camAngle;
            lastMoveVector = moveVec;
            crouchingPrev  = crouching;
            lastYmove      = bod.yMove;
            lastHealth     = User.Health;

            if (sendRPCUpdate)
            {
                net.SendUserUpdate(User.viewID, transform.position, camAngle, crouching, moveVec, bod.yMove,
                                   (int)GunInHand, (int)GunOnBack, transform.up, transform.forward);
                sendRPCUpdate = false;

                rpcCamTime = Time.time;                 // + 0.02f;
            }

            var gun = arse.Guns[(int)GunInHand];
            if (GunInHand >= Gun.Pistol &&
                gun.Cooldown > 0f &&
                gun.Cooldown - Time.deltaTime <= 0f &&
                gun.Delay >= 1f
                )
            {
                PlaySound("click");
            }

            gun.Cooldown -= Time.deltaTime;
            if (gun.Cooldown < 0f)
            {
                gun.Cooldown = 0f;
            }

            manageTargetLocking();

            // basketball arrow
            if (net.CurrMatch.basketball)
            {
                if (bballArrowObj == null)
                {
                    bballArrowObj = (GameObject)GameObject.Instantiate(bballArrowPrefab);
                    bballArrowObj.transform.parent        = Camera.main.transform;
                    bballArrowObj.transform.localPosition = Vector3.forward - (Vector3.right * 0.8f) + (Vector3.up * 0.5f);
                }
                if (User.hasBall)
                {
                    bballArrowObj.GetComponent <Renderer>().enabled = false;
                }
                else
                {
                    bballArrowObj.GetComponent <Renderer>().enabled = true;
                    bballArrowObj.transform.LookAt(net.GetBball().transform.position);
                }
            }
            else
            {
                if (bballArrowObj != null)
                {
                    bballArrowObj.GetComponent <Renderer>().enabled = false;
                }
            }

            // gravulator arrow
            if (GunInHand == Gun.Gravulator)
            {
                if (gravArrowObj == null)
                {
                    gravArrowObj = (GameObject)GameObject.Instantiate(gravArrowPrefab);
                    //gravArrowObj.layer =
                    gravArrowObj.transform.parent        = Camera.main.transform;
                    gravArrowObj.transform.localPosition = Vector3.forward;
                }

                Ray        gravRay   = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
                RaycastHit gravHit   = new RaycastHit();
                int        gravLayer = 1 << 0;

                if (Physics.Raycast(gravRay, out gravHit, 999f, gravLayer))
                {
                    gravArrowObj.transform.LookAt(gravArrowObj.transform.position - gravHit.normal);
                    gravArrowObj.GetComponent <Renderer>().enabled = true;
                }
                else
                {
                    gravArrowObj.GetComponent <Renderer>().enabled = false;
                }
            }
            else
            {
                if (gravArrowObj != null)
                {
                    gravArrowObj.GetComponent <Renderer>().enabled = false;
                }
            }

            if             // we can shoot
            (gun.Cooldown <= 0f &&
             Cursor.lockState == CursorLockMode.Locked &&
             prevLockMode == CursorLockMode.Locked &&
             !User.hasBall &&
             GunInHand >= Gun.Pistol
            )
            {
                if                 // gun repeats while pressed
                (arse.Guns[(int)GunInHand].AutoFire)
                {
                    if (CcInput.Holding(UserAction.Activate))
                    {
                        Fire(gun);
                    }
                }
                else                   // single shot
                {
                    if (CcInput.Started(UserAction.Activate))
                    {
                        Fire(gun);
                    }
                    if (CcInput.Started(UserAction.Alt))
                    {
                        Fire(gun, true);
                    }
                }
            }

            selectSpecificWeapon();

            if (hud.Mode == HudMode.Playing)
            {
                // ....then allow scrollwheel to cycle weaps/items
                switchWeapon();
            }
            if (CcInput.Started(UserAction.Activate))
            {
                throwBall();
            }
            if (CcInput.Started(UserAction.Suicide))
            {
                net.RegisterHitRPC((int)Gun.Suicide, User.viewID, User.viewID, transform.position);
            }

            moveFPGun();
        }
        else           // we be dead
        {
            if (Camera.main.transform.parent != null)
            {
                SetModelVisibility(true);
            }

            if (net.LocEnt.FraggedBy != null)
            {
                Camera.main.transform.parent   = null;
                Camera.main.transform.position = transform.position - animObj.transform.forward;
                Camera.main.transform.LookAt(net.LocEnt.FraggedBy.transform.position, transform.up);
                Camera.main.transform.Translate(0, 0, -2f);
            }
        }
    }