Example #1
0
    public void Update()
    {
        switch (mode)
        {
        case ShieldMode.off:
        {
            _guiText.text = "OFF";
            break;
        }

        case ShieldMode.auto:
        {
            _guiText.text = "AUTO";
            break;
        }

        case ShieldMode.on:
        {
            _guiText.text = "ON";
            break;
        }

        default:
        {
            _guiText.text = "BROKEN";
            break;
        }
        }
        if (energy.damaged)
        {
            shieldEnabled = false;
        }
        else
        {
            if (ShieldMode.off == mode)
            {
                shieldEnabled = false;
            }
            if (ShieldMode.on == mode)
            {
                shieldEnabled = true;
            }
            if (ShieldMode.auto == mode)
            {
                shieldEnabled = FindVisible();
            }
        }
        if (shieldEnabled)
        {
            // running the shields slows recharge
            energy.DoDrain(energy.rechargePerFrame * shieldRechargeDrag);
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        // cheat during development
        if ((!GGS.capsuleLaunched) && (cheating))
        {
            energy.energy = Mathf.Clamp(energy.energy, 100, 400);
        }

        DoDriveSound();

        compass.transform.position = transform.position;

        bool  _turning      = false;
        bool  _accelerating = false;
        float speed         = mm.speed;

        for (int _count = 0; _count < Targetting.playerLeadTime; _count++)
        {
            if (showTargettingSolution)
            {
                trail[_count].transform.position = new Vector2(Targetting.playerLead[_count].x, Targetting.playerLead[_count].y);
            }
        }

        if ((!destroyed) && (!GGS.capsuleLaunched))
        {
            if (Input.GetKeyDown(KeyCode.F10))
            {
                cheating = !cheating;
                GameObject.FindGameObjectWithTag("CheatingText").GetComponent <TextMeshPro>().enabled = cheating;
            }

            if (Input.GetKey(KeyCode.M))
            {
                if (speed < maxSpeed)
                {
                    energy.DoDrain(impulseEnergyCost);
                }
                speed        += forwardImpulse;
                _accelerating = true;
            }

            if (Input.GetKey(KeyCode.Comma))
            {
                if (speed > 0)
                {
                    energy.DoDrain(impulseEnergyCost);
                }
                speed -= forwardImpulse;
            }

            if (Input.GetKey(KeyCode.X))
            {
                if (turn > -maxTurn)
                {
                    energy.DoDrain(turnEnergyCost);
                }
                turn    -= rotationImpulse;
                _turning = true;
            }

            if (Input.GetKey(KeyCode.Z))
            {
                if (turn < maxTurn)
                {
                    energy.DoDrain(turnEnergyCost);
                }
                turn    += rotationImpulse;
                _turning = true;
            }

            if (Input.GetKey(KeyCode.N))
            {
                if (nextFire < Time.time)
                {
                    bulletSound.Play();
                    GameObject _newBullet = Instantiate(playerBulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);
                    bullet     _b         = _newBullet.GetComponent <bullet>();
                    _b.parent = gameObject;
                    _b.SetSpeed(transform.rotation.eulerAngles.z, speed);
                    nextFire = Time.time + fireRate;
                    energy.DoDrain(_b.fireEnergy);
                }
            }

            if (!GGS.capsuleLaunched)
            {
                if (Input.GetKey(KeyCode.F))
                {
                    GGS.capsuleLaunched = true;
                    GameObject _capsule = Instantiate(capsule, capsuleLeftSpawn.position, capsuleLeftSpawn.rotation);
                    bullet     _b       = _capsule.GetComponent <bullet>();
                    _b.parent = gameObject;
                }
                else if (Input.GetKey(KeyCode.G))
                {
                    GGS.capsuleLaunched = true;
                    GameObject _capsule = Instantiate(capsule, capsuleRightSpawn.position, capsuleRightSpawn.rotation);
                    bullet     _b       = _capsule.GetComponent <bullet>();
                    _b.parent = gameObject;
                }

                if (GGS.capsuleLaunched)
                {
                    capsuleDootSound.pitch  = 1;
                    capsuleDootSound.volume = 1;
                    GGS.capsuleSurvived     = true;
                    destructionTimer        = Time.time + 5;
                    GameObject.FindGameObjectWithTag("EscapeCapsuleText").GetComponent <TextMeshPro>().enabled = true;
                }
            }



            if (Input.GetKeyDown(KeyCode.C))
            {
                shield.mode = Shield.ShieldMode.off;
            }

            if (Input.GetKeyDown(KeyCode.V))
            {
                shield.mode = Shield.ShieldMode.auto;
            }

            if (Input.GetKeyDown(KeyCode.B))
            {
                shield.mode = Shield.ShieldMode.on;
            }

            if (Input.GetKeyDown(KeyCode.Period))
            {
                Instantiate(playerExplosion, gameObject.transform.position, gameObject.transform.rotation);
            }

            if (Input.GetKeyDown(KeyCode.F1))
            {
                if (turnDamping == 0)
                {
                    turnDamping = turnDampingBaseline;
                }
                else
                {
                    turnDamping = 0;
                }
            }

            if (Input.GetKeyDown(KeyCode.F2))
            {
                if (speedDamping == 0)
                {
                    speedDamping = speedDampingBaseline;
                }
                else
                {
                    speedDamping = 0;
                }
            }
        }

        if (!destroyed)
        {
            speed = Mathf.Clamp(speed, 0, maxSpeed);
            // speed is always positive (or zero)
            if ((speedDamping > 0) && (!_accelerating))
            {
                if (speed > speedDamping)
                {
                    energy.DoDrain(impulseEnergyCost);
                    speed -= speedDamping;
                }
                else
                {
                    speed = 0;
                }
            }
            turn = Mathf.Clamp(turn, -maxTurn, maxTurn);

            if ((turnDamping > 0) && (!_turning))
            {
                // turn is positive or negative, so needs a bit more work.
                if (Mathf.Abs(turn) > turnDamping)
                {
                    energy.DoDrain(turnEnergyCost);
                    turn -= turnDamping * Mathf.Sign(turn);
                }
                else
                {
                    turn = 0;
                }
            }
            if ((GGS.capsuleLaunched) && (GGS.capsuleSurvived))
            {
                DoCapsuleDoots();
            }
        }
        else
        {
        }

        if (destructionTimer > 0)
        {
            if (Time.time > destructionTimer)
            {
                // KERBLAMMO
                energy.DoDrain(2000);
            }
        }

        mm.speed  = speed;
        mm.angle += turn;

        float _xbp = (-1 / maxTurn) * turn;
        float _ybp = (1 / maxSpeed) * mm.speed;

        xBar.transform.localScale = new Vector3(_xbp, 1, 1);
        yBar.transform.localScale = new Vector3(1, _ybp, 1);

        Vector2 _newPosition = Helper.MakeDistanceCoords(speed, mm.angle, mm.angle);

        transform.position += new Vector3(-_newPosition.x, _newPosition.y, 0);
    }