Ejemplo n.º 1
0
 void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.tag == "Obstacle")
     {
         ExplodingAsteroid temp  = collider.GetComponent <ExplodingAsteroid>();
         Asteroid          temp2 = collider.GetComponent <Asteroid>();
         Obstacle          temp3 = collider.GetComponent <Obstacle>();
         if (temp != null)
         {
             temp.Damage(1000);
         }
         else if (temp2 != null)
         {
             temp2.Damage(1000, MathHelper.degreeBetween2Points(collider.transform.position, transform.position), false);
         }
         else if (temp3 != null)
         {
             temp3.Damage(1000);
         }
         else
         {
             Debug.Log("Something collided with something it should not " + collider.name);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// The logic implement movement of destroing asteroids and calculating using a timer
        /// This method chek if lives == 0 -> Game Over
        /// </summary>
        private void AnimationTimer_Tick(object sender, EventArgs e)
        {
            if (destroyedImageCounter > 1 && destroyed)
            {
                ExplodingAsteroid.Hide();
                destroyed             = false;
                destroyedImageCounter = 0;
            }
            else if (destroyed)
            {
                destroyedImageCounter++;
            }

            if (nukeCity && !destroyed)
            {
                if (nukeCloudCounter == 0)
                {
                    MissCounter();

                    if (missCount == 0)
                    {
                        AsteroidPositionTimer.Stop();
                        StartGame.IsStarted = false;

                        BombPB.Hide();
                        RedGift.Hide();
                        NukeCloud.Hide();
                        ExplodingAsteroid.Hide();
                        RocketPB.Hide();
                        RocketGift.Hide();
                        Lives.Hide();

                        GameOver.Show();
                    }

                    nukeCity           = true;
                    NukeCloud.Location = new Point(Bomb.X, Bomb.Y);
                    NukeCloud.Show();
                    PlaySound.PlayExplodeSound();

                    Bomb.Life = BombLife;
                    SpawnNewBomb();
                }
                else if (nukeCloudCounter > 10)
                {
                    NukeCloud.Hide();
                    AnimationTimer.Stop();
                    nukeCity = false;
                }

                nukeCloudCounter++;
            }
        }
Ejemplo n.º 3
0
 IEnumerator PeriodicShock()
 {
     while (true)
     {
         List <GameObject> tempList = new List <GameObject>(asteroidsInRange);
         if (GameManager.Instance.isSoundOn && tempList.Count != 0)
         {
             fireSound.Play();
         }
         foreach (GameObject asteroid in tempList)
         {
             if (asteroid != null)
             {
                 GameObject effect = (GameObject)Instantiate(lightningEffect, transform.parent);
                 effect.transform.Find("Destination").transform.position = asteroid.transform.position;
                 //effect.transform.FindChild("Destination").transform.parent = asteroid.transform;
                 effect.transform.Find("Source").transform.position = transform.position;
                 ExplodingAsteroid temp  = asteroid.GetComponent <ExplodingAsteroid>();
                 Asteroid          temp2 = asteroid.GetComponent <Asteroid>();
                 Obstacle          temp3 = asteroid.GetComponent <Obstacle>();
                 if (temp != null)
                 {
                     temp.Damage(damage);
                 }
                 else if (temp2 != null)
                 {
                     temp2.Damage(damage, MathHelper.degreeBetween2Points(asteroid.transform.position, transform.position), false);
                 }
                 else if (temp3 != null)
                 {
                     temp3.Damage(damage);
                 }
                 else
                 {
                     Debug.Log("Something collided with something it should not " + GetComponent <Collider>().name);
                 }
                 //effect.GetComponent<Lightn>
             }
             else
             {
                 asteroidsInRange.Remove(asteroid);
             }
         }
         yield return(new WaitForSeconds(0.75f));
     }
 }
Ejemplo n.º 4
0
            public static void Main1(string[] args)
            {
                Asteroid          theAsteroid          = new Asteroid();
                ExplodingAsteroid theExplodingAsteroid = new ExplodingAsteroid();
                SpaceShip         theSpaceShip         = new SpaceShip();
                ApolloSpacecraft  theApolloSpacecraft  = new ApolloSpacecraft();

                theAsteroid.CollideWith(theSpaceShip);
                theAsteroid.CollideWith(theApolloSpacecraft);
                theExplodingAsteroid.CollideWith(theSpaceShip);
                theExplodingAsteroid.CollideWith(theApolloSpacecraft);
                Console.WriteLine("-------------------------");

                Asteroid  theExplodingAsteroidRef = new ExplodingAsteroid();
                SpaceShip theApolloSpacecraftRef  = new ApolloSpacecraft();

                theExplodingAsteroidRef.CollideWith(theApolloSpacecraftRef);
            }
Ejemplo n.º 5
0
        public AsteroidsForm()
        {
            InitializeComponent();

            ExplodingAsteroid.Hide();
            NukeCloud.Hide();
            RocketPB.Hide();
            RedGift.Hide();
            LaserPB.Hide();
            RocketGift.Hide();
            DashboardGiftLabel.Hide();
            GameOver.Hide();

            LaserPB.BringToFront();

            Bomb.X       = 200;
            Bomb.Y       = -60;
            Bomb.Life    = BombLife;
            Rocket.Count = 10;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Logic implement Destroying a Bomb
        /// Hide unnecessary pictures
        /// Show destroing animation, reset the constants and spawn new bomb.
        /// </summary>
        private void DestroyBomb()
        {
            PlaySound.PlayExplodeSound();
            BombPB.Hide();
            RocketPB.Hide();
            LaserPB.Hide();

            ExplodingAsteroid.Left = BombPB.Left - 10;
            ExplodingAsteroid.Top  = BombPB.Top - 20;
            ExplodingAsteroid.Show();

            destroyed        = true;
            nukeCity         = false;
            Bomb.IsExploding = false;
            Rocket.IsFired   = false;
            Bomb.Life        = 3;

            SpawnNewBomb();
            ScoreCounter();
            AnimationTimer.Start();
        }
Ejemplo n.º 7
0
 void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Obstacle")
     {
         ExplodingAsteroid temp  = collision.GetComponent <ExplodingAsteroid>();
         Asteroid          temp2 = collision.GetComponent <Asteroid>();
         Obstacle          temp3 = collision.GetComponent <Obstacle>();
         if (temp != null)
         {
             temp.Damage(damage);
         }
         else if (temp2 != null)
         {
             temp2.Damage(damage, MathHelper.degreeBetween2Points(collision.transform.position, transform.position), true);
         }
         else if (temp3 != null)
         {
             temp3.Damage(damage);
         }
         else
         {
             Debug.Log("Something collided with something it should not " + collision.name);
         }
     }
     else if (collision.tag == "Player")
     {
         PlayerController player = collision.GetComponent <PlayerController>();
         if (player != null)
         {
             player.Destroy();
         }
         else
         {
             Debug.Log("Something collided with something it should not");
         }
     }
 }
Ejemplo n.º 8
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        startTime = Time.time;
        float      hp       = collider.GetComponent <Obstacle>().hp;
        GameObject asteroid = null;

        if (damage > hp)
        {
            float distance = float.MaxValue;
            for (int i = 0; i < GeneratorManager.Instance.asteroids.Count; i++)
            {
                if (GeneratorManager.Instance.asteroids[i] != collider.gameObject)
                {
                    float tempDistance = MathHelper.distanceBetween2Points(transform.position, GeneratorManager.Instance.asteroids[i].transform.position);
                    if (distance > tempDistance)
                    {
                        asteroid = GeneratorManager.Instance.asteroids[i];
                        distance = tempDistance;
                    }
                }
            }
            if (asteroid != null)
            {
                float degree = MathHelper.degreeBetween2Points(transform.position, asteroid.transform.position);
                rb.velocity = new Vector2(speed * (float)Mathf.Cos(degree * Mathf.PI / 180), speed * (float)Mathf.Sin(degree * Mathf.PI / 180));
            }
        }
        if (collider.tag == "Obstacle")
        {
            ExplodingAsteroid temp  = collider.GetComponent <ExplodingAsteroid>();
            Asteroid          temp2 = collider.GetComponent <Asteroid>();
            Obstacle          temp3 = collider.GetComponent <Obstacle>();
            if (temp != null)
            {
                temp.Damage(damage);
                temp3.createDebris(transform.position, MathHelper.degreeBetween2Points(collider.transform.position, transform.position));
            }
            else if (temp2 != null)
            {
                temp2.Damage(damage, MathHelper.degreeBetween2Points(collider.transform.position, transform.position), false);
                temp3.createDebris(transform.position, MathHelper.degreeBetween2Points(collider.transform.position, transform.position));
            }
            else if (temp3 != null)
            {
                temp3.Damage(damage);
                temp3.createDebris(transform.position, MathHelper.degreeBetween2Points(collider.transform.position, transform.position));
            }
            else
            {
                Debug.Log("Something collided with something it should not " + collider.name);
            }
        }
        transform.localScale *= (damage - hp) / damage;
        if (transform.localScale.x < 0.4f)
        {
            transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
        }
        damage -= hp;
        if (damage <= 0)
        {
            Destroy();
        }
    }
Ejemplo n.º 9
0
    // Update is called once per frame
    void FixedUpdate()
    {
        int layerMask = LayerMask.GetMask("Obstacle");

        if (currentLaserTimer < laserDuration)
        {
            lr.enabled = true;
            laserEffectEnd.gameObject.SetActive(true);
            RaycastHit2D hit = Physics2D.Raycast(transform.position, new Vector2(Mathf.Cos(player.transform.rotation.eulerAngles.z * Mathf.Deg2Rad), Mathf.Sin(player.transform.rotation.eulerAngles.z * Mathf.Deg2Rad)), 25, layerMask);
            lr.SetPosition(0, laserEffectStart.position);
            currentLaserTimer += Time.deltaTime;
            if (hit.collider != null)
            {
                lr.SetPosition(1, hit.point);
                laserEffectEnd.position = hit.point;
                ExplodingAsteroid temp  = hit.collider.GetComponent <ExplodingAsteroid>();
                Asteroid          temp2 = hit.collider.GetComponent <Asteroid>();
                Obstacle          temp3 = hit.collider.GetComponent <Obstacle>();
                if (temp != null)
                {
                    temp.Damage(damage * Time.fixedDeltaTime);
                    if (lastDebriGenerateTime + 0.5f < Time.time)
                    {
                        temp3.createDebris(hit.point, MathHelper.degreeBetween2Points(hit.transform.position, hit.point));
                        lastDebriGenerateTime = Time.time;
                    }
                }
                else if (temp2 != null)
                {
                    temp2.Damage(damage * Time.fixedDeltaTime, MathHelper.degreeBetween2Points(hit.transform.position, hit.point), false);
                    if (lastDebriGenerateTime + 0.5f < Time.time)
                    {
                        temp3.createDebris(hit.point, MathHelper.degreeBetween2Points(hit.transform.position, hit.point));
                        lastDebriGenerateTime = Time.time;
                    }
                }
                else if (temp3 != null)
                {
                    temp3.Damage(damage * Time.fixedDeltaTime);
                    if (lastDebriGenerateTime + 0.5f < Time.time)
                    {
                        temp3.createDebris(hit.point, MathHelper.degreeBetween2Points(hit.transform.position, hit.point));
                        lastDebriGenerateTime = Time.time;
                    }
                }
                else
                {
                    Debug.Log("Something collided with something it should not " + GetComponent <Collider>().name);
                }
            }
            else
            {
                lr.SetPosition(1, lrAim.position);
                laserEffectEnd.position = lrAim.position;
            }
        }
        else if (!isLaserCharging)
        {
            isLaserCharging = true;
            lr.enabled      = false;
            laserEffectEnd.gameObject.SetActive(false);
            laserEffectStart.gameObject.SetActive(false);
            StartCoroutine(LaserStarter());
        }
    }