Example #1
0
        // Performs all tasks necessary for the game to be played (game logic)
        private void UpdateScene()
        {
            //increase the interval of the time before a mushroom is displayed by one
            timeBeforeDisplayingMushrooms++;
            //if the time before mushroom is displayed in idenitcal to the time a mushroom should be displayed
            if (timeBeforeDisplayingMushrooms == timeToDisplayMushrooms)
            {
                //run an index for loop to add mushrooms to game form
                for (int index = 0; index < mushrooms.Length; index++)
                {
                    //create a new mushroom to game form
                    mushrooms[index] = new Mushroom();
                    //randomly add the mushroom by row and column
                    mushrooms[index].X = building.Windows[randomNumber.Next(0, building.Windows.GetLength(0)), 0].X + building.Windows[randomNumber.Next(0, building.Windows.GetLength(0)), 0].Width / 2 - mushrooms[index].Width / 2;
                    mushrooms[index].Y = building.Windows[0, randomNumber.Next(0, building.Windows.GetLength(1))].Y + building.Windows[0, randomNumber.Next(0, building.Windows.GetLength(1))].Width / 2 - mushrooms[index].Width / 2;
                }
                //display the mushroom on the screen
                displayMushrooms = true;
            }
            //increase the time internal by 1
            time++;

            // if the time is equal to the diffuclty set by file and the game is not over
            if (time == difficultyTime && gameOver == false)
            {
                //make bowser follow mario by closing the distance b/w them
                bowser.X = mario.X - 25;
                //set the time back to 0
                time = 0;
                //fire a fireball throws mario
                Fireball[] tempBricks = new Fireball[fireballs.Length];
                //copy the array
                Array.Copy(fireballs, tempBricks, fireballs.Length);
                //and create a new fireball
                fireballs = new Fireball[tempBricks.Length + 1];
                //do it agian
                Array.Copy(tempBricks, fireballs, tempBricks.Length);
                fireballs[fireballs.Length - 1] = new Fireball();
                fireballs[fireballs.Length - 1].X = bowser.X;
                fireballs[fireballs.Length - 1].Y = bowser.Y;
                bowser.Smash();
                time = 0;
            }
            //run index for loop for the fireball
            for (int index = 0; index < fireballs.Length; index++)
            {
                //move the fire ball down the building
                fireballs[index].Y += 3;
                //after the fireball reaches the limtis of the display
                if (fireballs[index].Y > DisplayRectangle.Height)
                {
                    //rin removefireball subprogram to remove the fireball from the game
                    RemoveFireball(ref fireballs, index);
                }

                //if the fireball collides with mario
                if (Collision(fireballs[index], mario) == true)
                {
                    //remove the fireball from display
                    RemoveFireball(ref fireballs, index);
                    //and cause mario (user) to lose one of their lives
                    mario.LoseLife();
                }
            }

            //run for loop for bird movement
            for (int index = 0; index < birds.Length; index++)
            {
                //move birds based on per decided speed for them
                birds[index].X += birdSpeed;
                //the given bird passes the width of th display
                if (birds[index].X > DisplayRectangle.Width)
                {
                    //randomly add a new bird to the display
                    birds[index].X = randomNumber.Next(-500, -birds[index].Width);
                    birds[index].Y = building.Windows[0, randomNumber.Next(0, 6)].Y;
                }

                //if the bird collides with mario
                if (Collision(birds[index], mario) == true)
                {
                    //run the bird impact subprogram for the bird
                    birds[index].Impact();
                    //make the bird jump after collision
                    birds[index].X += 200;
                    //with collision mario will lose one of his lives
                    mario.LoseLife();
                }
            }

            //run a index for loops for the mushroom pwr ups
            for (int index = 0; index < mushrooms.Length; index++)
            {
                //if mushroom is played on screen
                if (displayMushrooms == true)
                {
                    //and if mario has collided with the mushroom
                    if (Collision(mushrooms[index], mario) == true)
                    {
                        //run mario subprogram to gain a lif e
                        mario.GainLife();
                        //and run the subprogram to remove the given mushroom
                        RemoveMushroom(ref mushrooms, index);
                    }
                }
            }

            //create a new life array for users remaining lices
            lives = new Life[mario.Lives];
            //run a index for loop for the lives
            for (int index = 0; index < lives.Length; index++)
            {
                //the lives will be assigned
                lives[index] = new Life();

                //if the index
                if (index == 0)
                {
                    lives[index].X = DisplayRectangle.Width - lives[index].Width;
                }
                else
                {
                    lives[index].X = lives[index - 1].X - lives[index].Width;
                }
            }
        }
Example #2
0
        //subprogram to remove mushrooms from the screen
        private void RemoveMushroom(ref Mushroom[] mushrooms, int index)
        {
            //create a temporary array for the mushroom array
            Mushroom[] tempArray = new Mushroom[mushrooms.Length - 1];

            //run an index for loop to add to the temp mushroom array
            for (int indexToCopy = 0; indexToCopy < index; indexToCopy++)
            {
                //copies all the mushrooms to the temp array that are before the mushroom that is to be removed
                tempArray[indexToCopy] = mushrooms[indexToCopy];
            }

            //run an index for loop to add to the temp mushroom array
            for (int indexToCopy = index + 1; indexToCopy < mushrooms.Length; indexToCopy++)
            {
                //copies all the mushrooms to the temp array that are after the mushroom that is to be removed
                tempArray[indexToCopy - 1] = mushrooms[indexToCopy];
            }
            //mushrooms will be equal to the new mushrooms array (the original length minus 1)
            mushrooms = new Mushroom[tempArray.Length];
            //copy the array as an means to remove the mushrooms from the previous array
            Array.Copy(tempArray, mushrooms, tempArray.Length);
        }