Example #1
0
    public void LaunchRocket(Whose atWhose, Position targetPosition)
    {
        //		gav4.LogEvent (CATEGORY, "LaunchRocket", atWhose.ToString (), 0);
        RocketController rocketController = GetGridController(atWhose).MakeRocket();
        Vector3          localTargetPos   = targetPosition.AsGridLocalPosition(Marker.Aim);

        PosRot start = new PosRot(rocketController.transform);

        Transform targetGridTransform = GetGridController(atWhose).transform;
        Vector3   pos = targetGridTransform.position + (targetGridTransform.rotation * localTargetPos);

        pos += targetGridTransform.right * .5f + targetGridTransform.up * .5f;
        PosRot end = new PosRot(pos, targetGridTransform.rotation);

        firing++;
        rocketFlightTime = Mathf.Max(1f, .95f * rocketFlightTime);
        rocketController.Launch(atWhose, targetPosition, start, end, rocketFlightTime, delegate {
            firing--;
        });
        rocketsLaunched++;
        if (atWhose == Whose.Ours && rocketsLaunched < 7)
        {
            float duration = .7f * rocketFlightTime;
            float delay    = rocketFlightTime - duration;
            centerPanelController.IssueWarning(delay, duration);
        }
    }
Example #2
0
    public void LaunchRocket()
    {
        GameObject       rocketObject = Instantiate(rocketPrefab, rigidbody2d.position + lookDirection * new Vector2(0.5f, 0.5f), lookRotation);
        RocketController rocket       = rocketObject.GetComponent <RocketController>();

        rocket.SetLauncherGameObject(this);
        rocket.SetRocketDamage(rocketDamage);
        rocket.Launch(lookDirection, rocketSpeed);
    }
    /// <summary>
    /// Fires the rocket at given angle and power level
    /// </summary>
    /// <param name="angle">angle in standard degrees</param>
    /// <param name="power">power level</param>
    private void ShootRocket(float angle, int power)
    {
        inPlay                           = true; // starts gravity
        displayStatistics                = false;
        inputController.displayRings     = false;
        rocketController.aimLine.enabled = false;
        launchCounter++;

        rocketController.Launch(angle, power);
        SetCameraFollowMode(CameraMode.FollowRocket);
        SetOxygenMode(OxygenMode.Flying);
    }
Example #4
0
    void Update()
    {
        if (playerControlled)
        {
            if (Input.GetKeyUp(pauseKey))
            {
                if (isPaused)
                {
                    isPaused = false;
                    pauseGame.SetActive(false);
                    Time.timeScale = 1;
                }
                else
                {
                    isPaused = true;
                    pauseGame.SetActive(true);
                    Time.timeScale = 0;
                }
            }

            // Throttle controls
            else if (Input.GetKey(throttleKey))
            {
                throttle = 1;
            }
            else if (Input.GetKey(brakeKey))
            {
                throttle = -brakingConstant;
            }
            else
            {
                throttle = 0;
            }

            // Turning controls
            if (Input.GetKey(leftKey))
            {
                if (turn <= 0)
                {
                    turn = 1;
                }
                else if (turn < 50)
                {
                    turn += 1.5f;
                }
            }
            else if (Input.GetKey(rightKey))
            {
                if (turn >= 0)
                {
                    turn = -1;
                }
                else if (turn > -50)
                {
                    turn -= 1.5f;
                }
            }
            else
            {
                turn = 0;
            }

            // Handbrake control
            if (Input.GetKey(handbrakeKey))
            {
                handbrake = 1;
            }
            else
            {
                handbrake = 0;
            }

            // Nitro control
            if (Input.GetKey(nitroKey) && nitroTank > 0.01f && throttle != 0)
            {
                nitro          = 1;
                flames.enabled = true;
                if (flamesTimer <= 0)
                {
                    if (flameSpriteSelector)
                    {
                        flames.sprite       = flameSprite;
                        flameSpriteSelector = !flameSpriteSelector;
                    }
                    else
                    {
                        flames.sprite       = flameSprite2;
                        flameSpriteSelector = !flameSpriteSelector;
                    }
                    flamesTimer = 0.2f;
                }
                else
                {
                    flamesTimer -= Time.deltaTime;
                }
                flamesAudio.mute = false;
            }
            else
            {
                nitro            = 0;
                flames.enabled   = false;
                flamesAudio.mute = true;
            }

            if (Input.GetKey(rocketKey))
            {
                if (hasRocket)
                {
                    RC.Launch();
                }
            }
        }
        else
        {
            //TODO AI implementation
            //transform.position = Vector2.MoveTowards(transform.position, Player.position,  100 * Time.deltaTime);

            //var dir = Player.position - transform.position;
            //var angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg) - 90;
            //transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            throttle = 1;
            var dir = Player.position - transform.position;
            dir = transform.InverseTransformDirection(dir);
            var angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg);
            //Debug.Log(angle);
            if (angle > 90 || angle < -90)
            {
                turn = 50;
            }
            else if (angle > -90 && angle < 90)
            {
                turn = -50;
            }
            else
            {
                turn = 0;
            }
        }
        if (instantNitroTimer > 0)
        {
            instantNitroTimer -= Time.deltaTime;
        }
        if (instantSlowDownTimer > 0)
        {
            instantSlowDownTimer -= Time.deltaTime;
        }
        if (shieldTimer > 0)
        {
            shieldTimer -= Time.deltaTime;
            if (shieldTimer <= 0)
            {
                gameObject.GetComponent <SpriteRenderer> ().color = Color.white;
            }
        }
        if (switchControlsTimer > 0)
        {
            switchControlsTimer -= Time.deltaTime;
            if (switchControlsTimer <= 0)
            {
                switchControls();
            }
        }
        if (immunityTimer > 0)
        {
            immunityTimer -= Time.deltaTime;
            if (immunityTimer <= 0)
            {
                gameObject.GetComponent <SpriteRenderer> ().color = Color.white;
            }
        }
        if (!hasRocket && rocketBlitz)
        {
            if (rocketBlitzTimer > 0)
            {
                rocketBlitzTimer -= Time.deltaTime;
            }
            else
            {
                hasRocket = true;
                GameObject Rocket = GameObject.Instantiate(Resources.Load("RocketObject") as GameObject);
                RC     = Rocket.AddComponent <RocketController> ();
                RC.Car = this;
                Physics2D.IgnoreCollision(RC.GetComponent <Collider2D> (), GetComponent <Collider2D> ());
                rocketBlitzTimer = rocketBlitzInterval;
            }
        }
    }