Exemplo n.º 1
0
    void Start()
    {
        closest = GlobalFunc.FindClosest(this.transform.position, new string[] { "Planet" }, new GameObject[] {});

        if (GameObject.FindGameObjectsWithTag("Planet").Length > 0)
        {
            if (Vector3.Distance(this.transform.position, closest.transform.position) < 6)
            {
                Destroy(this.gameObject);
            }
        }

        frozenScale = Random.Range(1f, 2.7f);
        this.transform.localScale = new Vector3(frozenScale, frozenScale, 1f);

        deleteTime = 250;
    }
Exemplo n.º 2
0
    void Update()
    {
        if (placing == false)
        {
            target = GlobalFunc.FindClosest(this.transform.position,
                                            new string[] { "Asteroid", "Red Asteroid", "Swarm", "Pirate" }, new GameObject[] {}); //Find closest swarm or asteroid

            if (target != null)
            {
                float      speed    = 30f * Time.deltaTime; //Rotate towards
                Vector2    dir      = target.transform.position - this.transform.position;
                float      angle    = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
                Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
                this.transform.rotation = Quaternion.Slerp(transform.rotation, rotation, speed);
                this.transform.position = Vector3.MoveTowards(this.transform.position, target.transform.position, FleetBuy.fleetSpeed); //Move towards
            }

            if (Vector2.Distance(this.transform.position, target.transform.position) <= 0.3f) //Check if fleet is continuously colliding with target
            {
                Destroy(target);
            }

            deleteTime -= Time.deltaTime;
        }
        else
        {
            if (deleteTime > (FleetBuy.fleetHP - 25)) //Make fleet follow mouse
            {
                this.transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y, 1);
            }
        }

        if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Q)) //Keep object on mouse cursor
        {
            placing = false;
        }

        if (deleteTime <= 0) //Destroy gameobject after 20 seconds
        {
            Destroy(this.gameObject);
        }
    }
Exemplo n.º 3
0
    void Start()
    {
        closest = GlobalFunc.FindClosest(this.transform.position, new string[] { "Planet" }, new GameObject[] {});
        if (GameObject.FindGameObjectsWithTag("Planet").Length > 0)
        {
            if (Vector3.Distance(this.transform.position, closest.transform.position) < 6)
            {
                Destroy(this.gameObject);
            }
        }


        if (this.transform.parent != null)
        {
            asteroidScale = Random.Range(1.8f, 2.5f);
        }
        else
        {
            asteroidScale = Random.Range(4.5f, 5.5f);
        }

        this.gameObject.transform.localScale = new Vector3(asteroidScale, asteroidScale, 1f);
        deleteTime = 250;
    }
Exemplo n.º 4
0
    void Update()
    {
        this.transform.Rotate(new Vector3(0, 0, localRotate));
        travelTime -= Time.deltaTime;

        if (currentType.Equals("Swarm"))
        {
            if (travelTime <= 0)
            {
                GameObject[] planets = GameObject.FindGameObjectsWithTag("Planet");

                int        randNum    = Random.Range(0, planets.Length);
                GameObject randPlanet = planets[randNum];

                targetPos  = new Vector3(randPlanet.transform.position.x + Random.Range(-10, 10), randPlanet.transform.position.y + Random.Range(-10, 10), randPlanet.transform.position.z);
                travelTime = 1.5f;

                AlienSpawn.swarmTime = 0;
            }

            this.transform.position = Vector3.MoveTowards(this.transform.position, targetPos, 0.3f);

            depleteTime -= Time.deltaTime;
            if (depleteTime <= 0)
            {
                Stats.stars -= (int)(Stats.stars / 8);
                Stats.life  -= (int)(Stats.life / 80);
                depleteTime  = 3f;
            }
        }
        else if (currentType.Equals("Pirate"))
        {
            if (travelTime <= 0)
            {
                if (Stats.stars <= 0)
                {
                    Stats.life--;
                }

                this.GetComponent <PirateController>().randPlanet = GlobalFunc.FindClosest(this.transform.position, new string[] { "Planet" }, new GameObject[] {});
                travelTime = 2f;
            }
        }
        else if (currentType.Equals("Mega"))
        {
            if (Vector3.Distance(this.transform.position, targetPos) <= 1f)
            {
                GameObject[] planets = GameObject.FindGameObjectsWithTag("Planet");

                int        randNum    = Random.Range(0, planets.Length);
                GameObject randPlanet = planets[randNum];

                targetPos            = new Vector3(randPlanet.transform.position.x + Random.Range(-25, 25), randPlanet.transform.position.y + Random.Range(-25, 25), randPlanet.transform.position.z);
                PlaySounds.bossClip3 = true;

                Stats.stars -= (int)(Stats.stars / 4);

                if (Stats.stars <= 10 && Stats.life <= 110)
                {
                    Stats.life -= 2;
                }
                else
                {
                    Stats.life -= (int)(Stats.life / 55);
                }
            }

            float      speed    = 5f * Time.deltaTime;     //Rotate towards
            Vector2    dir      = targetPos - this.transform.position;
            float      angle    = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
            Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            this.transform.rotation = Quaternion.Slerp(this.transform.rotation, rotation, speed);
            this.transform.position = Vector3.MoveTowards(this.transform.position, targetPos, 0.45f); //Move towards
        }
    }
Exemplo n.º 5
0
    void Update()
    {
        if (randPlanet != null)
        {
            dist = Vector2.Distance(this.transform.position, randPlanet.transform.position);
            if (this.tag.Equals("Boss"))
            {
                if (dist > 10f && moveTime <= 0)
                {
                    this.transform.position = Vector2.MoveTowards(this.transform.position, randPlanet.transform.position, 0.3f);
                }
                else if (dist <= 12f)
                {
                    moveTime = 4f;
                }
                else if (dist <= 15f)
                {
                    isClose = true;
                }
                else
                {
                    moveTime -= Time.deltaTime;
                }
            }
            else
            {
                if (dist > 3 && moveTime <= 0)                 //Travel towards planet if distance hits limit
                {
                    this.transform.position = Vector2.MoveTowards(this.transform.position, randPlanet.transform.position, 0.3f);
                }
                else if (dist <= 3.8f)
                {
                    moveTime = 1f;
                }
                else if (dist <= 15f && !isClose)
                {
                    isClose = true;
                }
                else
                {
                    moveTime -= Time.deltaTime;
                }
            }
        }
        else
        {
            newPlanet();
        }

        target = GlobalFunc.FindClosest(this.transform.position, new string[] { "Fleet" }, new GameObject[] { randPlanet });

        float      speed    = 30f * Time.deltaTime; //Rotate towards planet
        Vector2    dir      = target.transform.position - this.transform.position;
        float      angle    = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
        Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);

        this.transform.rotation = Quaternion.Slerp(transform.rotation, rotation, speed);

        if (isClose)           //Fire bullets if close enough to planet
        {
            bulletTime -= Time.deltaTime;
            if (bulletTime <= 0)
            {
                GameObject thisBullet = Instantiate(bullet, this.transform.position, this.transform.rotation);
                thisBullet.GetComponent <Rigidbody2D>().velocity = (target.transform.position - this.transform.position) * 5f;
                bulletTime = 0.7f;

                if (this.tag.Equals("Boss"))
                {
                    thisBullet.transform.localScale = new Vector3(10f, 10f, this.transform.localScale.z);
                    PlaySounds.bossClip2            = true;
                }
                else
                {
                    PlaySounds.shootClip = true;
                }
            }
        }

        if (Vector2.Distance(this.transform.position, GameObject.FindGameObjectWithTag("Sun").transform.position) > 80)
        {
            Destroy(this.gameObject);
        }
    }