Beispiel #1
0
        /// <summary>
        /// Updates everything while in the playing mode
        /// </summary>
        /// <param name="gameTime"></param>
        private void PlayingUpdate(GameTime gameTime, int chanceForGem, Gem.TypeOfGem type)
        {
            player.Update(gameTime, viewportWidth, viewportHeight);

            for (int i = 0; i < enemy.Length; i++)
            {
                enemy[i].Update(gameTime, viewportWidth, viewportHeight, player, enemy[i]);
            }

            for (int i = 0; i < numOfAsteroids; i++)
            {
                asteroids[i].Update(viewportWidth, viewportHeight);
            }
            for (int i = 0; i < numOfAsteroids; i++)
            {
                gem[i].Update();
            }
            Collisions(chanceForGem, type);
        }
Beispiel #2
0
        /// <summary>
        /// Comutes the collision between an asteroid and bullet
        /// </summary>
        /// <param name="asteroid"></param>
        /// <param name="gem"></param>
        /// <param name="chanceForGem"></param>
        public void BulletAsteroidCollision(Asteroids asteroid, Asteroids nextAsteroids, Gem gem, int chanceForGem,
                                            Gem.TypeOfGem type, ref int numOfAsteroids, ContentManager content)
        {
            int chance = Asteroids.rnd.Next(1, 101);

            switch (asteroid.currentAsteroid)
            {
            case Asteroids.AsteroidType.Small:
                #region SmallCollision
                if (asteroid.Alive && alive)
                {
                    int     width       = texture.Width;
                    int     height      = texture.Height;
                    Vector2 asteroidPos = asteroid.Position;

                    if (position.X + width < asteroidPos.X
                        ||
                        position.Y + height < asteroidPos.Y
                        ||
                        position.X > asteroidPos.X + asteroid.Texture.Width
                        ||
                        position.Y > asteroidPos.Y + asteroid.Texture.Height)
                    {
                    }
                    else
                    {
                        collide.Play();
                        alive          = false;
                        asteroid.Alive = false;
                        gem.MakeGem(asteroid, Asteroids.rnd.Next(1, 101), type, chanceForGem);
                    }
                }
                #endregion
                break;

            case Asteroids.AsteroidType.Medium:
                #region MediumCollision
                if (asteroid.Alive && alive)
                {
                    int     width       = texture.Width;
                    int     height      = texture.Height;
                    Vector2 asteroidPos = asteroid.Position;

                    if (position.X + width < asteroidPos.X
                        ||
                        position.Y + height < asteroidPos.Y
                        ||
                        position.X > asteroidPos.X + asteroid.Texture.Width - 25
                        ||
                        position.Y > asteroidPos.Y + asteroid.Texture.Height - 23)
                    {
                    }
                    else
                    {
                        collide.Play();
                        alive = false;
                        nextAsteroids.MakeAsteroid(Asteroids.AsteroidType.Small, asteroid.Position, content);
                        asteroid.currentAsteroid = Asteroids.AsteroidType.Small;
                        numOfAsteroids++;
                    }
                }
                #endregion
                break;

            case Asteroids.AsteroidType.Big:
                #region BigCollision
                if (asteroid.Alive && alive)
                {
                    int     width       = 24;
                    int     height      = 10;
                    Vector2 asteroidPos = asteroid.Position;

                    if (position.X + width < asteroidPos.X
                        ||
                        position.Y + height < asteroidPos.Y
                        ||
                        position.X > asteroidPos.X + asteroid.Texture.Width
                        ||
                        position.Y > asteroidPos.Y + asteroid.Texture.Height)
                    {
                    }
                    else
                    {
                        collide.Play();
                        alive = false;
                        nextAsteroids.MakeAsteroid(Asteroids.AsteroidType.Medium, asteroid.Position, content);
                        asteroid.currentAsteroid = Asteroids.AsteroidType.Medium;
                        numOfAsteroids++;
                    }
                }
                #endregion
                break;

            default:
                break;
            }
        }
Beispiel #3
0
        /// <summary>
        /// commutes collision for
        /// ** asteroid-player **
        /// ** bullet-asteroid **
        /// **  bullet-player  **
        /// **  bullet-enemy   **
        /// **  enemy-player   **
        /// </summary>
        /// <param name="chanceForGem"></param>
        /// <param name="type"></param>
        private void Collisions(int chanceForGem, Gem.TypeOfGem type)
        {
            //player-enemy
            for (int i = 0; i < enemy.Length; i++)
            {
                player.CollisionEnemy(enemy[i], ref deadElapsed);
            }

            //players bullets-enemyship
            for (int i = 0; i < player.bulletArray.Length; i++)
            {
                for (int j = 0; j < enemy.Length; j++)
                {
                    player.bulletArray[i].CollisionWithShips(enemy[j]);
                }
            }
            //enemy bullets- player
            for (int i = 0; i < enemy.Length; i++)
            {
                enemy[i].bulletArray[i].CollisionWithShips(player, ref deadElapsed);
            }

            for (int i = 0; i < numOfAsteroids; i++)
            {
                if (player.Alive)
                {
                    player.AsteroidCollision(asteroids[i], player.Texture, ref deadElapsed);
                }
                for (int j = 0; j < player.bulletArray.Length; j++)
                {
                    for (int k = 0; k < asteroids.Length; k++)
                    {
                        if (!asteroids[k].Alive)
                        {
                            freeAsteroid = k;
                            break;
                        }
                    }

                    if (player.bulletArray[j].Alive)
                    {
                        player.bulletArray[j].BulletAsteroidCollision(asteroids[i], asteroids[freeAsteroid], gem[i], chanceForGem, type, ref numOfAsteroids, this.Content);
                    }
                }
            }
            for (int i = 0; i < levels.Length; i++)
            {
                for (int j = 0; j < asteroids.Length; j++)
                {
                    if (!asteroids[i].Alive && i < levels.Length)
                    {
                        levels[i].Active = true;
                    }
                }
            }

            for (int i = 0; i < gem.Length; i++)
            {
                gem[i].PlayerCollision(player);
            }
        }