コード例 #1
0
ファイル: Game.cs プロジェクト: vblazhes/space-odyssey-game
 public void addMeteor()
 {
     if (Level == 1 && Meteors.Count <= 4)
     {
         Meteors.Add(new Meteor(this.Width));
     }
     else if (Level == 2)
     {
         Meteors.Add(new Meteor(this.Width));
     }
 }
コード例 #2
0
 public static Meteors NextMeteor(Meteors meteor)
 {
     switch (meteor)
     {
         case Meteors.Green:
             return Meteors.Red;
         case Meteors.Red:
             return Meteors.Black;
         default:
             throw new ArgumentOutOfRangeException(nameof(meteor), meteor, null);
     }
 }
コード例 #3
0
        public static Meteors NextMeteor(Meteors meteor)
        {
            switch (meteor)
            {
            case Meteors.Green:
                return(Meteors.Red);

            case Meteors.Red:
                return(Meteors.Black);

            default:
                throw new ArgumentOutOfRangeException(nameof(meteor), meteor, null);
            }
        }
コード例 #4
0
        private void OnTriggerEnter2D(Collider2D otherCollider2D)
        {
            //Enemy Projectile
            if (otherCollider2D.CompareTag("Player") && !gameObject.CompareTag("Projectile_P"))
            {
                StateManager playerState = otherCollider2D.gameObject.GetComponent <StateManager>();
                playerState.TakeDamage(Damage);
            }

            //Meteor/Asteroid - Acts like a projectile
            if (otherCollider2D.CompareTag("Meteor") || otherCollider2D.CompareTag("M_Meteor"))
            {
                Meteors meteor = otherCollider2D.gameObject.GetComponent <Meteors>();
                meteor.TakeDamage(Damage);
                gameObject.SetActive(false);
            }

            //Player Projectile
            if (otherCollider2D.tag.Contains("Enemy"))
            {
                if (otherCollider2D.CompareTag("EnemyBasic") || otherCollider2D.CompareTag("EnemyBasic_1"))
                {
                    EnemyShipBasic ship = otherCollider2D.gameObject.GetComponent <EnemyShipBasic>();
                    ship.TakeDamage(Damage);
                    gameObject.SetActive(false);
                }

                if (otherCollider2D.CompareTag("EnemyUFO"))
                {
                    UFO ufo = otherCollider2D.gameObject.GetComponent <UFO>();
                    ufo.TakeDamage(Damage);
                    gameObject.SetActive(false);
                }
            }

            //Projectile against projectile
            if (otherCollider2D.CompareTag("Projectile"))
            {
                otherCollider2D.gameObject.SetActive(false);
                gameObject.SetActive(false);
            }
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: vblazhes/space-odyssey-game
        public void CheckMeteorImpact()
        {
            if (!(Meteors is null))
            {
                foreach (Meteor meteor in Meteors)
                {
                    if (meteor.Location.Equals(Hero.Location))
                    {
                        Hero.Health = 0;
                    }

                    foreach (Enemy enemy in Enemies)
                    {
                        if (meteor.Location.Equals(enemy.Location))
                        {
                            enemy.Health = 0;
                        }
                    }
                }

                for (int i = 0; i < Enemies.Count; i++)
                {
                    if (Enemies.ElementAt(i).Health == 0)
                    {
                        Enemies.RemoveAt(i);
                        i--;
                    }
                }

                for (int i = 0; i < Meteors.Count; i++)
                {
                    if (Meteors.ElementAt(i).Location.Y > this.Height)
                    {
                        Meteors.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
コード例 #6
0
    } //end update

    private void EnemyDamage(RaycastHit2D hit)
    {
        // give enemy damage
        Meteors mt = null;

        // 10 = Enemy Layer
        if (hit.collider.gameObject.layer == 10)
        {
            //   print("Called");
            hit.transform.SendMessage("giveDamage", laserDamage);
        }
        else if (hit.collider.gameObject.layer == 14) // boss layer
        {
            hit.transform.SendMessage("giveDamage", 5f);
        }

        if (hit.collider.tag == "Meteor")
        {
            if (mt = hit.collider.gameObject.GetComponent <Meteors>())
            {
                mt.giveLaserDamage(laserDamage);
            }
        }
    }
コード例 #7
0
ファイル: Game.cs プロジェクト: vblazhes/space-odyssey-game
        public void CheckBulletsImpact()
        {
            if (Level == 1)
            {
                //Hero to Enemies
                for (int index = 0; index < Hero.bullets.Count; index++)
                {
                    foreach (Enemy enemy in Enemies)
                    {
                        Rectangle b = new Rectangle(Hero.bullets[index].Location.X, Hero.bullets[index].Location.Y, Hero.bullets[index].BulletImg.Width, Hero.bullets[index].BulletImg.Height);
                        Rectangle h = new Rectangle(enemy.Location.X, enemy.Location.Y, 37, 35);
                        if (b.IntersectsWith(h))
                        {
                            Hero.bullets[index].Hit = true;
                            enemy.Health           -= 50;
                        }
                    }
                    for (int i = 0; i < Enemies.Count; i++)
                    {
                        if (Enemies.ElementAt(i).Health <= 0)
                        {
                            Enemies.RemoveAt(i);
                            i--;
                        }
                    }
                }


                //Hero to Meteors
                for (int index = 0; index < Hero.bullets.Count; index++)
                {
                    foreach (Meteor meteor in Meteors)
                    {
                        Rectangle b = new Rectangle(Hero.bullets[index].Location.X, Hero.bullets[index].Location.Y, Hero.bullets[index].BulletImg.Width, Hero.bullets[index].BulletImg.Height);
                        Rectangle m = new Rectangle(meteor.Location.X, meteor.Location.Y, 40, 40);
                        Rectangle h = new Rectangle(Hero.Location.X, Hero.Location.Y + 30, 80, 50);
                        if (b.IntersectsWith(m))
                        {
                            Hero.bullets[index].Hit = true;
                            meteor.Health          -= 40;
                        }
                        if (h.IntersectsWith(m))
                        {
                            Hero.Health = 0;
                        }
                    }

                    for (int i = 0; i < Meteors.Count; i++)
                    {
                        if (Meteors.ElementAt(i).Health <= 0)
                        {
                            Meteors.RemoveAt(i);
                            i--;
                        }
                    }
                }

                //Enemies to Hero
                foreach (Enemy enemy in Enemies)
                {
                    for (int index = 0; index < enemy.Bullets.Count; index++)
                    {
                        Rectangle b = new Rectangle(enemy.Bullets[index].Location.X, enemy.Bullets[index].Location.Y, enemy.Bullets[index].Image.Width, enemy.Bullets[index].Image.Height);
                        Rectangle h = new Rectangle(Hero.Location.X, Hero.Location.Y + 30, 70, 80);
                        if (b.IntersectsWith(h))
                        {
                            enemy.Bullets[index].ToBeRemoved = true;
                            Hero.Health -= 1;
                        }
                    }
                }

                //Meteors to Enemies
                foreach (Meteor meteor in Meteors)
                {
                    Rectangle m = new Rectangle(meteor.Location.X, meteor.Location.Y, 50, 50);
                    foreach (Enemy enemy in Enemies)
                    {
                        Rectangle e = new Rectangle(enemy.Location.X, enemy.Location.Y, 37, 35);
                        if (m.IntersectsWith(e))
                        {
                            meteor.Health -= 40;
                            enemy.Health   = 0;
                        }
                    }
                    Rectangle h = new Rectangle(Hero.Location.X, Hero.Location.Y + 30, 80, 50);
                    if (m.IntersectsWith(h))
                    {
                        Hero.Health = 0;
                    }
                }
                for (int i = 0; i < Meteors.Count; i++)
                {
                    if (Meteors.ElementAt(i).Health <= 0)
                    {
                        Meteors.RemoveAt(i);
                        i--;
                    }
                }

                for (int i = 0; i < Enemies.Count; i++)
                {
                    if (Enemies.ElementAt(i).Health <= 0)
                    {
                        Enemies.RemoveAt(i);
                        i--;
                    }
                }
            }
            else if (Level == 2)
            {
                //Hero to Meteors
                for (int index = 0; index < Hero.bullets.Count; index++)
                {
                    foreach (Meteor meteor in Meteors)
                    {
                        Rectangle b = new Rectangle(Hero.bullets[index].Location.X, Hero.bullets[index].Location.Y, Hero.bullets[index].BulletImg.Width, Hero.bullets[index].BulletImg.Height);
                        Rectangle m = new Rectangle(meteor.Location.X, meteor.Location.Y, 40, 40);
                        Rectangle h = new Rectangle(Hero.Location.X, Hero.Location.Y + 30, 80, 50);
                        if (b.IntersectsWith(m))
                        {
                            Hero.bullets[index].Hit = true;
                            meteor.Health          -= 40;
                        }
                        if (h.IntersectsWith(m))
                        {
                            Hero.Health = 0;
                        }
                    }

                    for (int i = 0; i < Meteors.Count; i++)
                    {
                        if (Meteors.ElementAt(i).Health <= 0)
                        {
                            Meteors.RemoveAt(i);
                            i--;
                        }
                    }
                }
                foreach (Meteor meteor in Meteors)
                {
                    Rectangle m = new Rectangle(meteor.Location.X, meteor.Location.Y, 50, 50);
                    foreach (Enemy enemy in Enemies)
                    {
                        Rectangle e = new Rectangle(enemy.Location.X, enemy.Location.Y, 37, 35);
                        if (m.IntersectsWith(e))
                        {
                            meteor.Health -= 40;
                            enemy.Health   = 0;
                        }
                    }
                    Rectangle h = new Rectangle(Hero.Location.X, Hero.Location.Y + 30, 80, 50);
                    if (m.IntersectsWith(h))
                    {
                        Hero.Health = 0;
                    }
                }

                for (int i = 0; i < Meteors.Count; i++)
                {
                    if (Meteors.ElementAt(i).Health <= 0)
                    {
                        Meteors.RemoveAt(i);
                        i--;
                    }
                }

                for (int i = 0; i < Enemies.Count; i++)
                {
                    if (Enemies.ElementAt(i).Health <= 0)
                    {
                        Enemies.RemoveAt(i);
                        i--;
                    }
                }
            }
            else if (Level == 3)
            {
                Rectangle b1 = new Rectangle(Boss.Location.X, Boss.Location.Y + 20, 150, 50);
                Rectangle b2 = new Rectangle(Boss.Location.X + 55, Boss.Location.Y, 50, 150);
                Rectangle h  = new Rectangle(Hero.Location.X, Hero.Location.Y + 30, 80, 50);

                //Hero to Boss
                for (int index = 0; index < Hero.bullets.Count; index++)
                {
                    Rectangle b = new Rectangle(Hero.bullets[index].Location.X, Hero.bullets[index].Location.Y, Hero.bullets[index].BulletImg.Width, Hero.bullets[index].BulletImg.Height);
                    if (b.IntersectsWith(b1) || b.IntersectsWith(b2))
                    {
                        Boss.Health            -= 5;
                        Hero.bullets[index].Hit = true;
                    }
                }

                //Boss to Hero
                for (int index = 0; index < Boss.Bullets.Count; index++)
                {
                    Rectangle b = new Rectangle(Boss.Bullets[index].Location.X, Boss.Bullets[index].Location.Y, Boss.Bullets[index].Image.Width, Boss.Bullets[index].Image.Height);
                    if (b.IntersectsWith(h))
                    {
                        Hero.Health -= 35;
                        Boss.Bullets[index].ToBeRemoved = true;
                    }
                }

                for (int index = 0; index < Hero.bullets.Count; index++)
                {
                    foreach (Meteor meteor in Meteors)
                    {
                        Rectangle b  = new Rectangle(Hero.bullets[index].Location.X, Hero.bullets[index].Location.Y, Hero.bullets[index].BulletImg.Width, Hero.bullets[index].BulletImg.Height);
                        Rectangle m  = new Rectangle(meteor.Location.X, meteor.Location.Y, 40, 40);
                        Rectangle h1 = new Rectangle(Hero.Location.X, Hero.Location.Y + 30, 80, 50);
                        if (b.IntersectsWith(m))
                        {
                            Hero.bullets[index].Hit = true;
                            meteor.Health          -= 40;
                        }
                        if (h.IntersectsWith(m))
                        {
                            Hero.Health = 0;
                        }
                    }
                }

                for (int i = 0; i < Meteors.Count; i++)
                {
                    if (Meteors.ElementAt(i).Health <= 0)
                    {
                        Meteors.RemoveAt(i);
                        i--;
                    }
                }
                if (Boss.Health <= 0)
                {
                    //GAME OVER - WIN
                }
            }

            for (int i = 0; i < Hero.bullets.Count; i++)
            {
                if (Hero.bullets.ElementAt(i).Hit)
                {
                    Hero.bullets.RemoveAt(i);
                    i--;
                }
            }

            for (int i = 0; i < Boss.Bullets.Count; i++)
            {
                if (Boss.Bullets.ElementAt(i).ToBeRemoved)
                {
                    Boss.Bullets.RemoveAt(i);
                    i--;
                }
            }


            foreach (Enemy enemy in Enemies)
            {
                for (int i = 0; i < enemy.Bullets.Count; i++)
                {
                    if (enemy.Bullets.ElementAt(i).ToBeRemoved)
                    {
                        enemy.Bullets.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
コード例 #8
0
 protected override void OnClose()
 {
     Meteors.DOKill();
     ButtonGuide.DOKill();
 }
コード例 #9
0
 protected override void OnClose()
 {
     Meteors.DOKill();
     StopAllCoroutines();
 }