Exemplo n.º 1
0
        /// <summary>
        /// Checks if there was a collision between a bomb and a player.
        /// </summary>
        /// <param name="bomb">Bomb that was launched by an Alien to be checked for collisions.</param>
        protected override bool checkCollision(ProjectileSprite bomb)
        {
            bool collision = false;

            if (bomb.GetBoundary().Intersects(player.GetBoundary()))
            {
                onPlayerCollision(player, 0);
                collision = true;
                playerDeathSound.Play();
            }

            return(collision);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game component to update itself.
        /// The AlienSquad will move to the edge of the screen, when reached will shift down 1 movement,
        /// then start moving back across the screen.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            if (game.GetGameState() == Game1.GameState.Playing)
            {
                fireTime = 60;

                for (int ctr1 = 0; ctr1 < alienSquad.GetLength(0); ctr1++)
                {
                    for (int ctr2 = 0; ctr2 < alienSquad.GetLength(1); ctr2++)
                    {
                        switch (dir)
                        {
                        case Direction.LEFT:
                        {
                            if (alienSquad[ctr1, ctr2].GetAlienState() != AlienState.INACTIVE)
                            {
                                if (!alienSquad[ctr1, ctr2].TryMove(dir))
                                {
                                    dir         = Direction.DOWN;
                                    previousDir = Direction.LEFT;
                                }
                            }
                            break;
                        }

                        case Direction.RIGHT:
                        {
                            if (alienSquad[ctr1, ctr2].GetAlienState() != AlienState.INACTIVE)
                            {
                                if (!alienSquad[ctr1, ctr2].TryMove(dir))
                                {
                                    dir         = Direction.DOWN;
                                    previousDir = Direction.RIGHT;
                                }
                            }
                            break;
                        }
                        }
                    }
                }

                for (int ctr1 = 0; ctr1 < alienSquad.GetLength(0); ctr1++)
                {
                    for (int ctr2 = 0; ctr2 < alienSquad.GetLength(1); ctr2++)
                    {
                        alienSquad[ctr1, ctr2].Move(dir);
                        if (alienSquad[ctr1, ctr2].GetAlienState() == AlienState.ACTIVE)
                        {
                            if (alienSquad[ctr1, ctr2].GetBoundary().Bottom >= screenHeight - playerSprite.GetBoundary().Height)
                            {
                                onGameOver();
                            }
                        }
                    }
                }

                if (dir == Direction.DOWN)
                {
                    if (previousDir == Direction.LEFT)
                    {
                        dir = Direction.RIGHT;
                    }
                    if (previousDir == Direction.RIGHT)
                    {
                        dir = Direction.LEFT;
                    }
                }


                if (fireCap % fireTime == 0)
                {
                    int squadRow = random.Next(0, alienSquad.GetLength(0));
                    int squadCol = random.Next(0, alienSquad.GetLength(1));

                    if (alienSquad[squadRow, squadCol].GetAlienState() != AlienState.INACTIVE)
                    {
                        bomb.Launch(alienSquad[squadRow, squadCol].GetBoundary(), gameTime);
                    }
                }
                fireCap++;
            }
            base.Update(gameTime);
        }