Example #1
0
    // helper function that repositions the player to "stand on" the current planet
    private void StandOnCurrentPlanet()
    {
        Vector3 difference = transform.position - currentPlanet.transform.position;
        float   radius     = currentPlanet.GetComponent <CircleCollider2D>().radius *currentPlanet.transform.lossyScale.x +
                             this.GetComponent <BoxCollider2D>().size.y *this.transform.lossyScale.x / 2;
        Vector3 newDifference = difference.normalized * radius;

        transform.position = transform.position - difference + newDifference;
    }
    // Update is called once per frame
    void Update()
    {
        if (allPlanets == null)
        {
            allPlanets = FindObjectsOfType <PlanetScript>();
        }
        else
        {
            PlanetScript closestPlanet = null;
            float        dist          = 9999999f;
            for (int i = 0; i < allPlanets.Length; i++)
            {
                if (allPlanets[i] == null || allPlanets[i].gameObject.Equals(this.gameObject))
                {
                    continue;
                }

                float testDist = (allPlanets[i].transform.position - transform.position).magnitude / allPlanets[i].GetComponent <Rigidbody2D>().mass;
                if (testDist < dist)
                {
                    dist          = testDist;
                    closestPlanet = allPlanets[i];
                }
            }
            planet = closestPlanet;
        }
        if (planet != null)
        {
            Vector2 towardsPlanet = planet.transform.position - transform.position;
            float   gravDir       = 1f;
            if (planet.antigravity && towardsPlanet.magnitude < planet.GetComponent <Rigidbody2D>().mass)
            {
                gravDir = -1f;
            }
            GetComponent <Rigidbody2D>().velocity = GetComponent <Rigidbody2D>().velocity + towardsPlanet.normalized * 0.5f * Time.deltaTime * planet.GetComponent <Rigidbody2D>().mass *gravDir;
        }
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        if (transform.localScale.x < 1f)
        {
            float mult = 1 + (0.2f * Time.deltaTime * 60f);
            if (transform.localScale.x * mult > 1f)
            {
                transform.localScale = new Vector3(1f, 1f, 1f);
            }
            else
            {
                transform.localScale *= mult;
            }
        }
        if (allPlanets == null)
        {
            allPlanets = FindObjectsOfType <PlanetScript>();
        }
        else
        {
            PlanetScript closestPlanet = null;
            float        dist          = 9999999f;
            for (int i = 0; i < allPlanets.Length; i++)
            {
                if (allPlanets[i] == null || allPlanets[i].gameObject.Equals(this.gameObject))
                {
                    continue;
                }

                float testDist = (allPlanets[i].transform.position - transform.position).magnitude / allPlanets[i].GetComponent <Rigidbody2D>().mass;
                if (testDist < dist)
                {
                    dist          = testDist;
                    closestPlanet = allPlanets[i];
                }
            }
            planet = closestPlanet;
        }
        if (planet != null)
        {
            Vector2 towardsPlanet = planet.transform.position - transform.position;
            float   gravDir       = 1f;
            if (planet.antigravity && towardsPlanet.magnitude < planet.GetComponent <Rigidbody2D>().mass)
            {
                gravDir = -1f;
            }
            GetComponent <Rigidbody2D>().velocity = GetComponent <Rigidbody2D>().velocity + towardsPlanet.normalized * Time.deltaTime * planet.GetComponent <Rigidbody2D>().mass *gravDir;
        }

        if (GetComponent <PlanetScript>() != null)
        {
            GetComponent <Rigidbody2D>().velocity -= GetComponent <Rigidbody2D>().velocity *0.05f * Time.deltaTime * 60f;
            if (planet == null)
            {
                GetComponent <Rigidbody2D>().velocity -= GetComponent <Rigidbody2D>().velocity *0.5f * Time.deltaTime * 60f;
                GetComponent <Rigidbody2D>().velocity -= new Vector2(transform.position.x, transform.position.y) * 0.05f * Time.deltaTime * 60f;
            }
            else
            {
                //Vector2 towardsPlanet = planet.transform.position - transform.position;
                //GetComponent<Rigidbody2D>().velocity *= 0.95f;
                //GetComponent<Rigidbody2D>().velocity = GetComponent<Rigidbody2D>().velocity + towardsPlanet.normalized*Time.deltaTime;
                GetComponent <Rigidbody2D>().angularVelocity -= GetComponent <Rigidbody2D>().angularVelocity *0.01f * Time.deltaTime * 60f;
            }
        }

        for (int i = 0; i < connected.Count; i++)
        {
            if (connected[i] == null)
            {
                connected.RemoveAt(i);
                i--;
            }
        }
        for (int i = 0; i < chains.Count && i < connected.Count; i++)
        {
            chains[i].transform.position = transform.position;
            float angle = Vector2.SignedAngle(Vector2.right, connected[i].transform.position - transform.position);
            chains[i].transform.eulerAngles = new Vector3(0f, 0f, angle);
            chains[i].transform.localScale  = transform.localScale;
        }
        if (connected.Count > 1)
        {
            Queue <GameObject>   searchQueue = new Queue <GameObject>();
            HashSet <GameObject> allObjects  = new HashSet <GameObject>();
            searchQueue.Enqueue(this.gameObject);
            allObjects.Add(this.gameObject);
            while (searchQueue.Count > 0)
            {
                GameObject go = searchQueue.Dequeue();
                if (go.GetComponent <GemScript>() == null)
                {
                    continue;
                }
                foreach (GameObject go2 in go.GetComponent <GemScript>().connected)
                {
                    if (!allObjects.Contains(go2))
                    {
                        searchQueue.Enqueue(go2);
                        allObjects.Add(go2);
                    }
                }
            }
            if (allObjects.Count >= 4)
            {
                int destroyCount = allObjects.Count;
                FindObjectOfType <ScoreTimerScript>().AddScore(destroyCount);
                bool destroyedPlanet = false;
                foreach (GameObject go in allObjects)
                {
                    if (go.GetComponent <PlanetScript>() != null)
                    {
                        go.GetComponent <PlanetScript>().SpawnExplosion();
                        destroyedPlanet = true;
                    }
                    if (go.GetComponent <GemScript>() != null)
                    {
                        go.GetComponent <GemScript>().DestroyAllChains();
                    }
                    if (go != this.gameObject)
                    {
                        Destroy(go);
                    }
                }
                if (!destroyedPlanet)
                {
                    GameObject snd = Instantiate <GameObject>(soundPrefab);
                    snd.GetComponent <SFXScript>().sfx = successSFX;
                }
                Destroy(this.gameObject);
            }
        }
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        if (ScoreTimerScript.isPaused && thrusterSoundObject != null)
        {
            Destroy(thrusterSoundObject);
        }
        if (vss == null)
        {
            vss = FindObjectOfType <VictoryScreenScript>();
        }
        else
        {
            if (vss.gameObject.activeInHierarchy)
            {
                GetComponent <AudioSource>().volume = 0f;
                gravityArrow.SetActive(false);
                return;
            }
        }
        if (failScreen == null)
        {
            failScreen = GameObject.FindWithTag("Finish");
        }
        else
        {
            if (failScreen.activeInHierarchy)
            {
                GetComponent <AudioSource>().volume = 0f;
                return;
            }
        }

        if (gemGenerator == null)
        {
            GetComponent <AudioSource>().volume = 0f;
            return;
        }

        index = gemGenerator.GetCurrentGem();
        //float turnAngle = 0f;
        //if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0){
        //    turnAngle = Vector2.SignedAngle(new Vector2(transform.position.x, transform.position.y),new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")));
        //}
        //if (turnAngle < 0){
        //    transform.RotateAround(new Vector3(0f,0f,0f), new Vector3(0f,0f,1f), -50f*Time.deltaTime);
        //}
        //if (turnAngle > 0){
        //    transform.RotateAround(new Vector3(0f,0f,0f), new Vector3(0f,0f,1f), 50f*Time.deltaTime);
        //}

        //float turnAngle = 0f;
        //if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0){
        //    turnAngle = Vector2.SignedAngle(new Vector2(transform.up.x,transform.up.y),new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")));
        //}

        thrust = 0.005f * 40f * Time.deltaTime * 60f;
        thrust = 0.005f * 7f * Time.deltaTime * 60f;

        GetComponent <Rigidbody2D>().angularVelocity = GetComponent <Rigidbody2D>().angularVelocity *0.5f;

        if (DataTracker.originalControls)
        {
            float turnSpeed = 165f;
            if (Input.GetAxis("Horizontal") > 0)
            {
                transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), -turnSpeed * Time.deltaTime);
            }
            if (Input.GetAxis("Horizontal") < 0)
            {
                transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), turnSpeed * Time.deltaTime);
            }

            if (Input.GetAxis("Vertical") > 0)
            {
                //GetComponent<Rigidbody2D>().velocity -= GetComponent<Rigidbody2D>().velocity*0.07f*Time.deltaTime*60f;
                Vector2 front = new Vector2(transform.up.x, transform.up.y);
                Vector2 vel   = (GetComponent <Rigidbody2D>().velocity.normalized + front * Time.deltaTime * 60f * 0.11f).normalized * GetComponent <Rigidbody2D>().velocity.magnitude;
                GetComponent <Rigidbody2D>().velocity = vel;
                GetComponent <Rigidbody2D>().velocity = GetComponent <Rigidbody2D>().velocity + front * thrust;

                ThrustEffect();
            }
            else
            {
                StopThrusting();
            }

            if (Input.GetAxis("Vertical") < 0)
            {
                GetComponent <Rigidbody2D>().velocity -= GetComponent <Rigidbody2D>().velocity *0.15f * Time.deltaTime * 60f;
                if (braking)
                {
                    braking = false;
                    GameObject snd = Instantiate <GameObject>(soundPrefab);
                    snd.GetComponent <SFXScript>().sfx = brakeSFX;
                }
            }
            else
            {
                braking = true;
            }
        }
        else
        {
            Vector2 inputVector = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
            GetComponent <Rigidbody2D>().velocity = (GetComponent <Rigidbody2D>().velocity + inputVector * 15f * thrust).normalized * GetComponent <Rigidbody2D>().velocity.magnitude;
            if (inputVector.magnitude > 0f)
            {
                ThrustEffect();
                GetComponent <Rigidbody2D>().velocity += GetComponent <Rigidbody2D>().velocity.normalized *Time.deltaTime *4f;
                float angleBetween = Vector2.SignedAngle(new Vector2(transform.up.x, transform.up.y), (inputVector.normalized * 3f + GetComponent <Rigidbody2D>().velocity.normalized));
                transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), angleBetween);
            }
            else
            {
                StopThrusting();
                if (GetComponent <Rigidbody2D>().velocity.magnitude > maxSpeed / 5f)
                {
                    GetComponent <Rigidbody2D>().velocity -= GetComponent <Rigidbody2D>().velocity.normalized *Time.deltaTime *0.5f;
                }
            }
        }
        if (GetComponent <Rigidbody2D>().velocity.magnitude > maxSpeed)
        {
            GetComponent <Rigidbody2D>().velocity = GetComponent <Rigidbody2D>().velocity.normalized *maxSpeed;
        }

        bool wrapped = false;

        if (transform.position.x > 9.5f)
        {
            transform.position = new Vector3(transform.position.x - (9.5f * 2), transform.position.y, transform.position.z);
            wrapped            = true;
        }
        if (transform.position.y > 5.6f)
        {
            transform.position = new Vector3(transform.position.x, transform.position.y - (5.6f * 2), transform.position.z);
            wrapped            = true;
        }
        if (transform.position.x < -9.5f)
        {
            transform.position = new Vector3(transform.position.x + (9.5f * 2), transform.position.y, transform.position.z);
            wrapped            = true;
        }
        if (transform.position.y < -5.6f)
        {
            transform.position = new Vector3(transform.position.x, transform.position.y + (5.6f * 2), transform.position.z);
            wrapped            = true;
        }
        if (wrapped && GetComponent <SpecialChain>() != null)
        {
            GetComponent <SpecialChain>().EndChain();
        }

        if (allPlanets == null)
        {
            allPlanets = FindObjectsOfType <PlanetScript>();
        }
        else
        {
            PlanetScript closestPlanet = null;
            float        dist          = 9999999f;
            for (int i = 0; i < allPlanets.Length; i++)
            {
                if (allPlanets[i] == null)
                {
                    continue;
                }

                float testDist = (allPlanets[i].transform.position - transform.position).magnitude / allPlanets[i].GetComponent <Rigidbody2D>().mass;
                if (testDist < dist)
                {
                    dist          = testDist;
                    closestPlanet = allPlanets[i];
                }
            }
            planet = closestPlanet;
        }
        if (planet != null)
        {
            Vector2 towardsPlanet = planet.transform.position - transform.position;
            float   gravDir       = 1f;
            if (planet.antigravity && towardsPlanet.magnitude < planet.GetComponent <Rigidbody2D>().mass)
            {
                gravDir = -1f;
            }

            float gravityAngle = Vector2.SignedAngle(new Vector2(gravityArrow.transform.up.x, gravityArrow.transform.up.y), towardsPlanet);
            gravityArrow.transform.RotateAround(transform.position, new Vector3(0f, 0f, 1f), gravityAngle);
            gravityArrow.transform.localScale = new Vector3(1f, 1f, 1f);
            float alpha = 0.67f;
            Color c     = new Color(1f, 1f, 1f, alpha);
            if (index == 0)
            {
                c = new Color(1f, 0.1f, 0.1f, alpha);
            }
            else if (index == 1)
            {
                c = new Color(1f, 1f, 0.1f, alpha);
            }
            else if (index == 2)
            {
                c = new Color(0.1f, 1f, 0.1f, alpha);
            }
            else if (index == 3)
            {
                c = new Color(0.1f, 0.1f, 1f, alpha);
            }
            else if (index == 4)
            {
                c = new Color(0.6f, 0.1f, 1f, alpha);
            }
            else if (index == 4)
            {
                c = new Color(0.6f, 0.1f, 0.2f, alpha);
            }
            gravityArrow.GetComponent <SpriteRenderer>().color = c;

            GetComponent <Rigidbody2D>().velocity = GetComponent <Rigidbody2D>().velocity + towardsPlanet.normalized * planet.GetComponent <Rigidbody2D>().mass *Time.deltaTime *0.4f * gravDir;
        }

        //GetComponent<SpriteRenderer>().sprite = gemPrefabs[index].GetComponent<SpriteRenderer>().sprite;

        if (Input.GetAxis("Fire1") == 0)
        {
            gravityArrow.SetActive(false);
            if (spawnGemBool)
            {
                SpawnGem();
                spawnGemBool = false;
            }
            pressTimer += Time.deltaTime;
            if (pressTimer > 0.1f)
            {
                canPressFire = true;
                pressTimer   = 0f;
            }
        }
        if (Input.GetAxis("Fire1") > 0 && canPressFire)
        {
            gravityArrow.SetActive(true);
            pressTimer += Time.deltaTime;
            if (pressTimer > 0f)
            {
                canPressFire = false;
                spawnGemBool = true;
                pressTimer   = 0f;
            }
        }
    }