示例#1
0
    private void CreateBullet()
    {
        float _bulletCount;

        if (bigBullets)
        {
            _bulletCount = 4;
        }
        else
        {
            _bulletCount = 1;
        }

        GameObject _b;
        float      _bulletAngle = 360 / _bulletCount;

        for (int _count = 0; _count < _bulletCount; _count++)
        {
            float _angle = bulletSpawnPoint.transform.rotation.eulerAngles.z;
            _angle += (_count * _bulletAngle);
            Vector2 _offset = Helper.MakeDistanceCoords(0.1f, _angle, _angle);
            _b = Instantiate(enemybullet, bulletSpawnPoint.transform.position + (Vector3)_offset, bulletSpawnPoint.transform.rotation);
            bullet _bb = _b.GetComponent <bullet>();
            _bb.parent = gameObject;
            _bb.SetSpeed(MM.angle, MM.speed);
        }
    }
示例#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);
    }