Example #1
0
File: Lander.cs Project: BuDDi/GEA
    void UpdateArrow()
    {
        GameObject arrow = GameObject.Find("Arrow");
        float      x     = transform.position.x;
        float      y     = transform.position.y + 5;
        float      z     = transform.position.z + 4.5f;

        arrow.transform.position = new Vector3(x, y, z);
        if (!exploded)
        {
            GameObject nearestLandingPad = LandingPadGroup.GetInstance().GetNearestLandingPad(gameObject);
            //Debug.Log(nearestLandingPad.transform.ToString());
            Vector3 to = Vector3.forward;
            if (nearestLandingPad != null)
            {
                Vector3 landingPadSameYPosition = new Vector3(nearestLandingPad.transform.position.x, arrow.transform.position.y, nearestLandingPad.transform.position.z);
                to = Vector3.Normalize((landingPadSameYPosition - arrow.transform.position));
                //float y = Vector3.Angle (to, arrow.transform.forward);
                if (processedPrints < allowedPrints)
                {
                    //Debug.Log ("Rotate Arrow from: " + arrow.transform.position.ToString () + " to: " + to.ToString ());
                    processedPrints++;
                }
            }
            arrow.transform.forward = to;
            //arrow.transform.rotation = Quaternion.FromToRotation(arrow.transform.forward, to);
            //arrow.transform.forward = to;
        }
    }
Example #2
0
    void OnCollisionStay(Collision collision)
    {
        if (!landedBefore && activated)
        {
            //Debug.Log ("Stay, landedbefore: " + landedBefore + " activated: " + activated + " length: " + collision.contacts.Length.ToString ());
            if (collision.contacts.Length == 4)
            {
                bool  allFeet = true;
                float maxDist = 0;
                float minDist = float.MaxValue;
                foreach (ContactPoint contact in collision.contacts)
                {
                    //Debug.Log("Stay on Platform " + contact.otherCollider.name.ToString());
                    minDist = Mathf.Min((contact.point - gameObject.transform.position).magnitude, minDist);
                    maxDist = Mathf.Max((contact.point - gameObject.transform.position).magnitude, maxDist);
                    Debug.Log(contact.otherCollider.name + " " + contact.thisCollider.name);
                    if (!contact.otherCollider.name.StartsWith("foot") && !contact.thisCollider.name.StartsWith("foot"))
                    {
                        allFeet = false;
                        break;
                    }
                }
                if (allFeet)
                {
                    float averageDist = (minDist + maxDist) / 2;
                    landedBefore = true;
                    activated    = false;

                    StartCoroutine(LandingPadGroup.GetInstance().LandedOnPlatform(gameObject, averageDist, maxFuelRestore));
                }
            }
        }
    }
Example #3
0
File: Lander.cs Project: BuDDi/GEA
    private IEnumerator BlowAway()
    {
        GameObject detonator = GameObject.Find("Detonator");
        Detonator  det       = gameObject.GetComponentInChildren <Detonator> ();

        //det.gameObject.transform.parent = null;
        //transform.DetachChildren ();
        Transform[] transforms = gameObject.GetComponentsInChildren <Transform> ();
        foreach (Transform childTransform in transforms)
        {
            //Debug.Log ("Boom for: " + childTransform.gameObject.name + " Mesh: " + childTransform.name);
            childTransform.parent = null;
            MeshFilter mesh = childTransform.gameObject.GetComponent <MeshFilter> ();
            if (mesh != null)
            {
                mesh.gameObject.AddComponent(typeof(Rigidbody));
                mesh.gameObject.rigidbody.isKinematic = false;
                mesh.gameObject.rigidbody.useGravity  = true;
                mesh.gameObject.rigidbody.mass        = 10;
            }
            if (childTransform.gameObject != detonator)
            {
                // detonator kills itself
                Destroy(childTransform.gameObject, 5);
            }
        }
        //GameObject boom = GameObject.Find ("Detonator");

        //if (boom != null) {
        //yield return new WaitForSeconds(1);
        //gameObject.transform.DetachChildren ();
        //Detonator det = GameObject.Find("Detonator").GetComponent<Detonator>();
        if (det != null)
        {
            det.Explode();
        }
        else
        {
            Debug.Log("Det is null");
        }
        Destroy(gameObject, 5);

        exploded = true;
        yield return(new WaitForSeconds(3));

        //} else {
        //	Debug.Log ("Boom is null");
        //}

        //goBoom = false;
        //Transform[] childs = gameObject.GetComponentsInChildren<Transform>();
        //foreach(Transform child in childs){
        //Debug.Log("Destroy " + child.gameObject.name + " Mesh: " + child.name);
        //}
        LandingPadGroup.GetInstance().SetGameOver();
    }
Example #4
0
File: Lander.cs Project: BuDDi/GEA
    public void ReduceFuel(float speed)
    {
        float reducement = speed / 15000;

        // Debug.Log("Reduce Fuel: " + reducement);
        fuel -= reducement;
        if (fuel <= 0)
        {
            LandingPadGroup.GetInstance().SetGameOver();
        }
    }
Example #5
0
 // Update is called once per frame
 void Update()
 {
     if (outOfLevel)
     {
         secondsLeft -= Time.deltaTime;
         LandingPadGroup.GetInstance().SetMessageLabelText("Game Over in\n" + secondsLeft + " s", 12, 0.1f);
         if (secondsLeft <= 0)
         {
             // TODO GameOver
             Debug.Log("Game Over!!!");
             LandingPadGroup.GetInstance().SetGameOver();
         }
     }
 }
Example #6
0
 void OnCollisionEnter(Collision collision)
 {
     if (!landedBefore && activated)
     {
         int amountOfFeet = 0;
         foreach (ContactPoint contact in collision.contacts)
         {
             //Debug.Log("Stay on Platform " + contact.otherCollider.name.ToString());
             if (contact.otherCollider.name.StartsWith("foot") || contact.thisCollider.name.StartsWith("foot"))
             {
                 amountOfFeet++;
             }
         }
         float impact = collision.impactForceSum.magnitude;
         LandingPadGroup.GetInstance().AboutToLand(gameObject, impact, amountOfFeet);
     }
 }
Example #7
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)
     }
 }