Exemplo n.º 1
0
    public IEnumerator LandedOnPlatform(GameObject landingPad, float distanceToCenter, float maxFuelRestore)
    {
        if (landingPad.Equals(lastLandingPad))
        {
            Debug.Log("Feet on the Ground: " + amountOfFeet + " ... you get Points and Fuel! Dist: " + distanceToCenter.ToString());
            bool perfectLanding = amountOfFeet == 4;
            int  multiplier     = amountOfFeet;

            /*if(perfectLanding){
             *      // TODO perfect landing
             *      Debug.Log("Perfect Landing");
             *      SetMessageLabelText("Perfect Landing", 1f);
             *      yield return new WaitForSeconds(1f);
             * }*/
            LandingPlatform platformScript  = landingPad.GetComponent <LandingPlatform>();
            float           points          = platformScript.scorePoints - distanceToCenter - impact;
            int             bonusMultiplier = platformScript.multiply;
            int             score           = ((int)(points + 0.5f)) * (multiplier + bonusMultiplier);
            string          scoreText       = (perfectLanding ? "Perfect Landing\n" : "") +
                                              (multiplier + bonusMultiplier).ToString() + " x " + ((int)(score / (multiplier + bonusMultiplier))).ToString();
            SetMessageLabelText(scoreText, 24, 2f);
            yield return(new WaitForSeconds(2f));

            currentLevelScore += score;

            // TODO Score textlabel aufblitzen lassen
            float bonusFuel = (maxFuelRestore * multiplier) - distanceToCenter;
            Lander.GetInstance().AddFuel(bonusFuel / 3);
            Debug.Log("Added Fuel");
            if (GetRemainingLandingPads() == 0)
            {
                yield return(StartCoroutine(EndLevel()));
            }
        }
    }
Exemplo n.º 2
0
    private void ActivateThruster(ParticleSystem particleSystem, AudioSource sound, ref float speedToAdjust, float accelerationVal, float maxSpeedVal)
    {
        // TODO play Sound
        float fuel = Lander.GetInstance().GetFuel();

        if (fuel > 0)
        {
            if (!sound.isPlaying)
            {
                sound.Play();
            }

            if (!particleSystem.isPlaying)
            {
                particleSystem.Play();
            }
            speedToAdjust += accelerationVal * Time.deltaTime;
            if (speedToAdjust > maxSpeedVal)
            {
                speedToAdjust = maxSpeedVal;
            }
            Lander.GetInstance().ReduceFuel(speedToAdjust);
        }
        else
        {
            DisableThruster(particleSystem, sound, ref speedToAdjust);
        }
    }
Exemplo n.º 3
0
    void FixedUpdate()
    {
        if (Lander.GetInstance().isStarted())
        {
            direction = jetBone.transform.right;
            //Debug.Log("Fly to: " + direction.ToString());


            if (speed > 0)
            {
                if (transform.position.y >= maxHeight)
                {
                    direction.y = 0;
                }
                //rigidbody.AddForceAtPosition(direction * speed * Time.fixedDeltaTime, mainThruster.transform.position);
                rigidbody.AddForce(direction * speed * Time.fixedDeltaTime);
            }
            if (frontThrusterSpeed > 0)
            {
                //Debug.Log ("Backthruster angle " + finalAngleForward);
                float   speedRot = frontThrusterSpeed * Time.fixedDeltaTime;
                Vector3 force    = frontThruster.transform.forward * speedRot * -1;
                rigidbody.AddForceAtPosition(force, frontThruster.transform.position);
            }
            if (backThrusterSpeed > 0)
            {
                //Debug.Log ("Frontthruster angle: " + finalAngleForward);
                float   speedRot = backThrusterSpeed * Time.fixedDeltaTime;
                Vector3 force    = backThruster.transform.forward * speedRot * -1;
                //rigidbody.AddRelativeTorque (torque);
                rigidbody.AddForceAtPosition(force, backThruster.transform.position);
            }
            if (rightThrusterSpeed > 0)
            {
                //Debug.Log ("Rightthruster angle: " + finalAngleRight);
                float   speedRot = rightThrusterSpeed * Time.fixedDeltaTime;
                Vector3 force    = rightThruster.transform.forward * speedRot * -1;
                //rigidbody.AddRelativeTorque (torque);
                rigidbody.AddForceAtPosition(force, rightThruster.transform.position);
            }
            if (leftThrusterSpeed > 0)
            {
                //Debug.Log ("Leftthruster angle: " + finalAngleRight);
                float   speedRot = leftThrusterSpeed * Time.fixedDeltaTime;
                Vector3 force    = leftThruster.transform.forward * speedRot * -1;
                //rigidbody.AddRelativeTorque (torque);
                rigidbody.AddForceAtPosition(force, leftThruster.transform.position);
            }
            if (topThrusterSpeed > 0)
            {
                //Debug.Log ("Leftthruster angle: " + finalAngleRight);
                float   speedRot = topThrusterSpeed * Time.fixedDeltaTime;
                Vector3 force    = topThruster.transform.forward * speedRot * -1;
                //rigidbody.AddRelativeTorque (torque);
                rigidbody.AddForce(force);
            }
        }
    }
Exemplo n.º 4
0
    private IEnumerator EndLevel()
    {
        this.currentLevelScore += (int)((finishScore + timeToBeat + Lander.GetInstance().GetFuel()) + 0.5f);
        //this.currentLevelScore += (int)( + 0.5f);
        TheBrain.GetInstance().ApplyCurrentScore(currentLevelScore);

        SetMessageLabelText("Well done ...", 48, 3);

        yield return(new WaitForSeconds(3));

        // TODO vernünftiges Verhalten für das Beenden eines Levels
        SetGameOver();
    }
Exemplo n.º 5
0
    void Update()
    {
        if ((isPaused || gameOver) && WiimoteReceiver.Instance.wiimotes.ContainsKey(1))
        {
            //print ("Got WiiMote in Menu");
            Wiimote wiimote           = WiimoteReceiver.Instance.wiimotes [1];
            float   elapsedToggleTime = Time.realtimeSinceStartup - lastButtonToggleTime;
            if (wiimote.BUTTON_DOWN > 0 && elapsedToggleTime > 0.3f)
            {
                print("DOWN");
                activeMenuButton++;
                if (activeMenuButton >= currentButtons.Length)
                {
                    activeMenuButton = 0;
                }
                lastButtonToggleTime = Time.realtimeSinceStartup;
                audio.PlayOneShot(selectSound);
            }
            if (wiimote.BUTTON_UP > 0 && elapsedToggleTime > 0.3f)
            {
                print("UP");
                activeMenuButton--;
                if (activeMenuButton < 0)
                {
                    activeMenuButton = currentButtons.Length - 1;
                }
                lastButtonToggleTime = Time.realtimeSinceStartup;
                audio.PlayOneShot(selectSound);
            }
        }
        if (Lander.GetInstance().isStarted() && !isPaused)
        {
            this.timeToBeat  -= Time.deltaTime;
            this.elapsedTime += Time.deltaTime;

            this.timeLabel.text = ((int)Mathf.Round(timeToBeat)).ToString() + " s";

            this.remainingPadsLabel.text = GetRemainingLandingPads().ToString() + "/" +
                                           landingPads.Length.ToString();

            this.scoreLabel.text = "Score: " + currentLevelScore.ToString();

            this.messageLabelDisplayTime -= Time.deltaTime;

            if (timeToBeat <= 0)
            {
                SetGameOver();
            }
        }
        else
        {
            //print("Countdown " + this.messageLabelDisplayTime.ToString());
            this.messageLabelDisplayTime -= Time.deltaTime;
            //print("Countdown2 " + this.messageLabelDisplayTime.ToString() + " " + Time.deltaTime);
            int displayTime = (int)Mathf.Round(this.messageLabelDisplayTime - 1);
            this.messageLabelText = displayTime.ToString();
            if (displayTime == 0)
            {
                this.messageLabelText = "Start";
            }
            else if (displayTime < 0)
            {
                this.messageLabelText = null;
                Lander.GetInstance().startSimulation();
            }
        }

        /*if(landedRecently) {
         *      if(scoreLabelScale < 2 && scalingUp){
         *              scalingUp = true;
         *              scoreLabelScale += Time.deltaTime;
         *      }
         *      else if(scoreLabelScale >= 2){
         *              scalingUp = false;
         *              scoreLabelScale -= Time.deltaTime;
         *      }
         *      if(!scalingUp && scoreLabelScale <= 2) {
         *              scoreLabelScale = 1;
         *              landedRecently = false;
         *      }
         *      scoreLabel.fontSize = (int)((18 * scoreLabelScale)+0.5f);
         * }*/
    }
Exemplo n.º 6
0
 // Update is called once per frame
 void Update()
 {
     if (receiver.wiimotes.ContainsKey(1) && Lander.GetInstance().isStarted())                // If mote 1 is connected
     {
         Wiimote mymote = receiver.wiimotes [1];
         rotateNozzle(-(mymote.PRY_PITCH * Mathf.Rad2Deg - 30), mymote.PRY_ROLL * Mathf.Rad2Deg - 30);
         if (mymote.BUTTON_B > 0)
         {
             ActivateThruster(mainThruster, mainThrusterSource, ref speed, acceleration, maxSpeed);
         }
         else
         {
             DisableThruster(mainThruster, mainThrusterSource, ref speed);
         }
         if (mymote.NUNCHUK_Z > 0 && mymote.NUNCHUK_JOY_X < 0.45)
         {
             ActivateThruster(rightThruster, rightThrusterSource, ref rightThrusterSpeed, sideThrusterAcceleration, maxSideThrusterSpeed);
         }
         else
         {
             DisableThruster(rightThruster, rightThrusterSource, ref rightThrusterSpeed);
         }
         if (mymote.NUNCHUK_Z > 0 && mymote.NUNCHUK_JOY_X > 0.55)
         {
             ActivateThruster(leftThruster, leftThrusterSource, ref leftThrusterSpeed, sideThrusterAcceleration, maxSideThrusterSpeed);
         }
         else
         {
             DisableThruster(leftThruster, leftThrusterSource, ref leftThrusterSpeed);
         }
         if (mymote.NUNCHUK_Z > 0 && mymote.NUNCHUK_JOY_Y > 0.55)
         {
             ActivateThruster(backThruster, backThrusterSource, ref backThrusterSpeed,
                              sideThrusterAcceleration, maxSideThrusterSpeed);
         }
         else
         {
             DisableThruster(backThruster, backThrusterSource, ref backThrusterSpeed);
         }
         if (mymote.NUNCHUK_Z > 0 && mymote.NUNCHUK_JOY_Y < 0.45)
         {
             ActivateThruster(frontThruster, frontThrusterSource, ref frontThrusterSpeed,
                              sideThrusterAcceleration, maxSideThrusterSpeed);
         }
         else
         {
             DisableThruster(frontThruster, frontThrusterSource, ref frontThrusterSpeed);
         }
         if (mymote.NUNCHUK_C > 0)
         {
             ActivateThruster(topThruster, topThrusterSource, ref topThrusterSpeed,
                              topThrusterAcceleration, maxTopThrusterSpeed);
         }
         else
         {
             DisableThruster(topThruster, topThrusterSource, ref topThrusterSpeed);
         }
         if (mymote.BUTTON_LEFT > 0)
         {
             Lander.GetInstance().SwitchCameraLeft();
         }
         if (mymote.BUTTON_RIGHT > 0)
         {
             Lander.GetInstance().SwitchCameraRight();
         }
         if (mymote.BUTTON_HOME > 0)
         {
             LandingPadGroup.GetInstance().TogglePause();
         }
     }
     else
     {
         // TODO Problem to display (connect any Wiimote)
     }
 }