Example #1
0
 // Initialisation
 void Start()
 {
     forwardKey.text        = KeyBoardBindings.GetForwardKey().ToString();
     backwardKey.text       = KeyBoardBindings.GetBackwardKey().ToString();
     attackKey.text         = KeyBoardBindings.GetAttackKey().ToString();
     chargedAttackKey.text  = KeyBoardBindings.GetChargedAttackKey().ToString();
     pauseKey.text          = KeyBoardBindings.GetPauseKey().ToString();
     zoomInKey.text         = KeyBoardBindings.GetZoomInKey().ToString();
     zoomOutKey.text        = KeyBoardBindings.GetZoomOutKey().ToString();
     showScoreboardKey.text = KeyBoardBindings.GetScoreboardKey().ToString();
 }
Example #2
0
 // Controls
 public static void SaveKeyBindings(Dictionary <string, KeyCode> keys)
 {
     KeyBoardBindings.SetForwardKey(keys["ForwardKey"]);
     KeyBoardBindings.SetBackwardKey(keys["BackwardKey"]);
     KeyBoardBindings.SetAttackKey(keys["AttackKey"]);
     KeyBoardBindings.SetChargedAttackKey(keys["ChargedAttackKey"]);
     KeyBoardBindings.SetPauseKey(keys["PauseKey"]);
     KeyBoardBindings.SetZoomInKey(keys["ZoomInKey"]);
     KeyBoardBindings.SetZoomOutKey(keys["ZoomOutKey"]);
     KeyBoardBindings.SetScoreboardKey(keys["ScoreboardKey"]);
 }
Example #3
0
    // Update is called once per frame
    void Update()
    {
#if UNITY_ANDROID
        if (Input.GetKeyDown(KeyCode.Escape))   // alternate method instead of pause button
        {
            TogglePauseMenu();
        }
#else
        if (Input.GetKeyDown(KeyBoardBindings.GetPauseKey()))
        {
            TogglePauseMenu();
        }
        if (Input.GetKeyDown(KeyBoardBindings.GetScoreboardKey()))
        {
            scoreboard.SetActive(true);
        }
        else if (Input.GetKeyUp(KeyBoardBindings.GetScoreboardKey()))
        {
            scoreboard.SetActive(false);
        }
#endif
    }
Example #4
0
    // Update is called once per frame
    //[Client]
    void Update()
    {
        if (isLocalPlayer)
        {
            // Checks for overlay active done in Player.cs

            //float horizontal = Input.GetAxis("Horizontal") * turningSpeed * Time.deltaTime;
            //transform.Rotate(0, horizontal, 0);

            //float vertical = Input.GetAxis("Vertical") * movementSpeed * Time.deltaTime;
            //transform.Translate(0, 0, vertical);

            //transform.Translate(movementSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, movementSpeed * Input.GetAxis("Vertical") * Time.deltaTime);


            //float inputX = Input.GetAxis("Horizontal");
            //float inputZ = Input.GetAxis("Vertical");
            //
            //float moveX = inputX * movementSpeed * Time.deltaTime;
            //float moveZ = inputZ * movementSpeed * Time.deltaTime;
            //
            //transform.Translate(moveX, 0f, moveZ);

            //rbody.AddForce(moveX, 0f, moveZ);

            // Rotation & Angles
            UpdatePitch();
            UpdateYaw();    // roll updates here too

            // update player's Euler angles
            //this.transform.eulerAngles = new Vector3(-pitch, yaw, -yaw * 0.5f);
            this.transform.eulerAngles = new Vector3(-pitch, yaw, roll);

            Quaternion rotation = Quaternion.Euler(-pitch, yaw, 0f);
            SetView(rotation * new Vector3(0, 0, 1));

            // SLOWLY PITCH BACK
            if (this.pitch != 0)
            {
                if (this.pitch < 0)
                {
                    this.pitch += changeSpeed * Time.deltaTime;
                    if (this.pitch > 0)
                    {
                        this.pitch = 0;
                    }
                }
                else
                {
                    this.pitch -= changeSpeed * Time.deltaTime;
                    if (this.pitch < 0)
                    {
                        this.pitch = 0;
                    }
                }
            }

            // SLOWLY ROLL BACK
            if (this.roll != 0)
            {
                if (this.roll < 0)
                {
                    this.roll += changeSpeed * Time.deltaTime;
                    if (this.roll > 0)
                    {
                        this.roll = 0;
                    }
                }
                else
                {
                    this.roll -= changeSpeed * Time.deltaTime;
                    if (this.roll < 0)
                    {
                        this.roll = 0;
                    }
                }
            }

            // Movement
            force = Vector3.zero;

#if UNITY_ANDROID
            // get joystick movement
            force         = joystick.GetJoystickDelta() * 100f * view;
            keyNotPressed = false;
#else
            if (Input.GetKey(KeyBoardBindings.GetForwardKey()))
            {
                force         = 100f * view;
                keyNotPressed = false;
            }
            else if (Input.GetKey(KeyBoardBindings.GetBackwardKey()))
            {
                force         = -100f * view;
                keyNotPressed = false;
            }
#endif

            velocity += force * Time.deltaTime;

            if (!velocity.Equals(Vector3.zero))
            {
                this.transform.position += velocity * Time.deltaTime;

                // decelerate
                Vector3 velDir      = velocity.normalized;
                float   decelerator = (5f + velocity.magnitude * 0.5f);
                if (keyNotPressed)
                {
                    decelerator *= 2f;
                }
                else
                {
                    keyNotPressed = true;

                    if (decelerator > 20f)
                    {
                        decelerator = 20f;
                    }
                }
                velocity -= decelerator * velDir * Time.deltaTime;

                double cosOfAngle = (velDir.x * velocity.x + velDir.y * velocity.y + velDir.z * velocity.z);
                if (cosOfAngle < 0)     // -ve, parallel & opp direction
                {
                    velocity = Vector3.zero;
                }
            }

            if (rbody.velocity.magnitude > 0.5f)
            {
                rbody.velocity.Normalize();
                rbody.velocity *= 0.5f;
            }

            // Update the server with position/rotation
            updateInterval += Time.deltaTime;
            if (updateInterval > 0.11f) // 9 times per sec (default unity send rate)
            {
                updateInterval = 0;
                CmdSync(transform.position, transform.rotation, view);
            }
        }
        else
        {
            transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
            transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
            view = Vector3.Lerp(view, realView, 0.1f);
        }
    }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        if (!playerScript.isLocalPlayer)
        {
            return;
        }

        // find remoteplayers & add
        if (lengthPlayerGo != GameObject.FindGameObjectsWithTag("Player").Length)
        {
            addPlayerToRadar();
            ++lengthPlayerGo;
        }

        DrawRadarDots();

        for (int i = 0; i < worldObject.Count; ++i)
        {
            // the position of all the gameobjects on the map
            Vector3 radarPos         = worldObject[i].transform.position;
            Vector3 worldObjectScale = worldObject[i].transform.localScale;

            // the position of players
            Vector3 playerPos = PlayerUI.playerPos;//playerScript.transform.position;


            // check for gameobject above the player
            if (radarPos.y - worldObjectScale.y > (playerPos.y + offsetY))
            {
                radIcons[i].iconHigher.gameObject.SetActive(true);
                radIcons[i].iconLower.gameObject.SetActive(false);
                radIcons[i].icon.gameObject.SetActive(false);
                radIcons[i].currentIcon = radIcons[i].iconHigher;
            }
            // check for gameobject below the player
            else if (radarPos.y + worldObjectScale.y < (playerPos.y - offsetY))
            {
                radIcons[i].iconHigher.gameObject.SetActive(false);
                radIcons[i].iconLower.gameObject.SetActive(true);
                radIcons[i].icon.gameObject.SetActive(false);
                radIcons[i].currentIcon = radIcons[i].iconLower;
            }
            // in the middle
            else
            {
                radIcons[i].iconHigher.gameObject.SetActive(false);
                radIcons[i].iconLower.gameObject.SetActive(false);
                radIcons[i].icon.gameObject.SetActive(true);
                radIcons[i].currentIcon = radIcons[i].icon;
            }
        }

#if !UNITY_ANDROID
        // zoom in/out
        if (Input.GetKeyDown(KeyBoardBindings.GetZoomInKey()))
        {
            this.ZoomIn();
        }
        else if (Input.GetKeyDown(KeyBoardBindings.GetZoomOutKey()))
        {
            this.ZoomOut();
        }
        if (Input.GetAxis("Mouse ScrollWheel") != 0f)   // mouse scroll
        {
            mapScale += 0.01f * Input.GetAxis("Mouse ScrollWheel");
            //if (mapScale < 0.02f)
            //    mapScale = 0.002f;
            //
            //if (mapScale > 0.05f)
            //    mapScale = 0.005f;
        }
#endif
    }   // end of Update()
Example #6
0
    // Update is called once per frame
    void Update()
    {
        // Checks for overlay active done in Player.cs
        if (!isLocalPlayer)
        {
            return;
        }
#if UNITY_ANDROID
        if (touchID == -1)  // not touching the screen; not charging up yet
        {
            if (lightsource.intensity > 0)
            {
                lightsource.intensity -= Time.deltaTime * LightSourceIntensityMultilpier;
            }

            for (int i = 0; i < Input.touchCount; ++i)
            {
                if (Input.GetTouch(i).phase == TouchPhase.Began)    // if the touch just began, check if it's not on a GUI object
                {
                    PointerEventData ped = new PointerEventData(null);
                    ped.position = Input.GetTouch(i).position;
                    List <RaycastResult> results = new List <RaycastResult>();
                    raycaster.Raycast(ped, results);
                    if (results.Count == 0)
                    {
                        if (energy.currentEnergy >= energy.EnergyNeededToRun)
                        {
                            exceptionCharge = true;
                            touchID         = i;
                            break;
                        }
                    }
                }
            }
        }
        else
        {                                                          // there is a touch; start to charge up
            if (Input.GetTouch(touchID).phase == TouchPhase.Ended) // if the touch has ended, release the charged fireball
            {
                CmdChargedAttack(FireBallTarget());
                exceptionCharge = false;
                touchID         = -1;

                // reduce the energy
                energy.AmtenergyCharge   = 0;
                energy.recharging        = true;
                energy.timer             = 0;
                energy.ChargedReadyToUse = false;
            }
            else if (energy.currentEnergy >= energy.MinimumCharge || exceptionCharge)
            {
                energy.ChargeEnergy();
                if (lightsource.intensity <= MaxLightIntensity)
                {
                    lightsource.intensity = (energy.AmtenergyCharge / energy.MaxCharge) * MaxLightIntensity;
                }
            }
        }
#else
        // Debug text
        //if (energyMeterText != null)
        //    energyMeterText.text = energy.currentEnergy.ToString();

        if (Input.GetKeyDown(KeyBoardBindings.GetAttackKey()) && energy.readyToUse)
        {
            CmdFireBallAttack(FireBallTarget());
            energy.DecreaseEnergy();
        }
        else
        {
            keypress = false;
        }

        if (energy.currentEnergy >= energy.MinimumCharge)
        {
            exceptionCharge = true;
        }

        if (Input.GetKey(KeyBoardBindings.GetChargedAttackKey()) && (energy.currentEnergy >= energy.MinimumCharge || exceptionCharge))
        {
            energy.ChargeEnergy();
            if (lightsource.intensity <= MaxLightIntensity)
            {
                lightsource.intensity = (energy.AmtenergyCharge / energy.MaxCharge) * MaxLightIntensity;
            }
        }
        else
        {
            if (lightsource.intensity > 0)
            {
                lightsource.intensity -= Time.deltaTime * LightSourceIntensityMultilpier;
            }
        }
        if (Input.GetKeyUp(KeyBoardBindings.GetChargedAttackKey()))
        {
            if (energy.ChargedReadyToUse)
            {
                CmdChargedAttack(FireBallTarget());
                exceptionCharge = false;

                energy.AmtenergyCharge   = 0;
                energy.recharging        = true;
                energy.timer             = 0;
                energy.ChargedReadyToUse = false;
            }
            else
            {
                //energy.recharging = true;
                energy.unchargeEnergy = true;
                energy.readyToUse     = false;
                exceptionCharge       = false;
            }
        }
#endif
    }