Exemplo n.º 1
0
        /// <summary>
        /// Write the bullet to the buffer
        /// </summary>
        private void Write()
        {
            // Write to the buffer
            BufferEditor.Delete(coordinates.X, coordinates.Y, bullet.ToString());

            BufferEditor.WriteWithColor(0, coordinates.Y, " ", ConsoleColor.White);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Moves the enemy based on it's current direction
        /// </summary>
        private void Move()
        {
            // If the enemy is to move down
            if (IncreaseY)
            {
                // Clear the area above the enemy
                BufferEditor.WriteWithColor(0, coordinates.Y, " ", ConsoleColor.Black);
                BufferEditor.Delete(coordinates.X, coordinates.Y, "       ");

                // Moves the enemy down
                coordinates.Y++;

                // Reset the `IncreaseY` back to false
                IncreaseY = false;
            }
            // Else
            else
            {
                // If the movement type is left
                if (MovementType == MoveType.LEFT)
                {
                    // Move the enemy left
                    coordinates.X--;
                }
                // Else if the movement type is right
                else if (MovementType == MoveType.RIGHT)
                {
                    // Move the enemy right
                    coordinates.X++;
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Deletes the enemy from the buffer
 /// </summary>
 public void Delete()
 {
     // Go through all the strings in the sprite
     for (int i = 0; i < SPRITE_HEIGTH; i++)
     {
         // Write to the current buffer an empty string
         BufferEditor.Delete(coordinates.X, coordinates.Y + i, "       ");
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Writes the barriers to the buffer
        /// </summary>
        public void Write()
        {
            // Set the color to green
            BufferEditor.SetColor(ConsoleColor.Green);

            for (int i = 0; i < BARRIER_HEIGHT; i++)
            {
                BufferEditor.Delete(coordinates.X, coordinates.Y + i - 1, sprite[i]);
            }
        }
Exemplo n.º 5
0
        public void Delete()
        {
            // Go through the ship sprite array
            for (int i = 0; i < sprite.Length; i++)
            {
                // Write each string to the buffer
                BufferEditor.Delete(coordinates.X, coordinates.Y + i, "         ");

                BufferEditor.WriteWithColor(0, coordinates.Y + i, " ", ConsoleColor.Black);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Moves all enemies down
        /// </summary>
        public void MoveDown()
        {
            // If the animation timer has finished counting
            if (!animationTimer.IsCounting())
            {
                // Change the sprite to animate the enemy
                firstSprite = !firstSprite;
            }

            // If the moveDownTimer is not counting
            if (!moveDownTimer.IsCounting())
            {
                //Increase the steps by 1
                moveDownSteps++;

                // If the moveDowSteps is greater than the `MOVE_DOWN_STEPS` returns
                if (moveDownSteps > MOVE_DOWN_STEPS)
                {
                    return;
                }

                // Create a new vector2
                Vector2 coordinate;

                // Goes through every enemy in the Enemy List
                foreach (Enemy enemy in EnemyList)
                {
                    // Save the enemy coordinate to a more convinient variable
                    coordinate = enemy.Coordinates;

                    // Set the enemy to not move
                    enemy.CanMove = false;

                    // Update the enemy sprite
                    enemy.FirstSprite = firstSprite;

                    // Increase the enemy Y
                    enemy.YIncreasse();

                    // If the enemy Y coordinate is greater than the `TOP_START_ROW`
                    if (coordinate.Y > TOP_START_ROW)
                    {
                        // Delete the top line of the enemy
                        BufferEditor.Delete(coordinate.X, coordinate.Y, "       ");

                        // Update the enemy
                        enemy.Update();
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Writes the enemy sprite to the buffer
        /// </summary>
        private void WriteToBuffer()
        {
            // Select the correct sprite to render
            currentSprite = FirstSprite ? sprite1 : sprite2;

            // Go through the array of strings
            for (int i = 0; i < currentSprite.Length; i++)
            {
                // Write a string to the buffer
                BufferEditor.WriteWithColor(0, coordinates.Y + i, " ", myColor);

                // Write each string to the buffer
                BufferEditor.Delete(coordinates.X, coordinates.Y + i, currentSprite[i]);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get Ready method to animate the begining of the game or level
        /// </summary>
        private void GetReady()
        {
            // Create a new timer counter
            Timer counter = new Timer(160);

            // Create a new timer to blink the text
            Timer blinker = new Timer(9);

            // Create a new bool to display the text
            bool displayText = true;

            // While the counter is counting
            while (counter.IsCounting())
            {
                // Updates the header
                DisplayHeader();

                // Sets the `displayText` to true or false
                displayText = !blinker.IsCounting() ? !displayText : displayText;

                // If the displayText is true
                if (displayText)
                {
                    // Set a color and write to the buffer
                    BufferEditor.WriteWithColor(0, 50, " ", ConsoleColor.Yellow);
                    BufferEditor.Write(45, 50, "Get Ready!");
                }
                // Else...
                else
                {
                    // Delete from the buffer
                    BufferEditor.Delete(45, 50, "          ");
                }

                // Move the enemies down
                enemies.MoveDown();

                /// Render the frame ///
                BufferEditor.DisplayRender();

                // Delay the loop
                Thread.Sleep(BASE_DELAY);
            }

            // Delete the text again
            BufferEditor.Write(45, 50, "          ");
        }
Exemplo n.º 9
0
        /// <summary>
        /// Moves the enemies up
        /// </summary>
        public void MoveUp()
        {
            // If the moveSpeed timer is not counting and the move steps is counting
            if (!moveUpSpeed.IsCounting() && moveUpSteps.IsCounting())
            {
                // Create a new int `min`
                int min = 60;

                // Create a new coordinate
                Vector2 coordinate;

                // Go through every enemy in the enemies list
                for (int i = 0; i < EnemyList.Count; i++)
                {
                    // Save it's coordinates
                    coordinate = EnemyList[i].Coordinates;

                    // If the min is bigger than the coordinate Y
                    if (min > coordinate.Y)
                    {
                        // Set the min to be equal to the coordinate Y
                        min = coordinate.Y;
                    }
                }

                // If min is bigger than the minimum Y value
                if (min > Y_MIN)
                {
                    // Go through every enemy on the enemies list
                    for (int i = 0; i < EnemyList.Count; i++)
                    {
                        // Save it's coordinates
                        coordinate = EnemyList[i].Coordinates;

                        // Delete the under part of the enemy
                        BufferEditor.Delete(coordinate.X, coordinate.Y + 2, "       ");

                        // Decrease the enemy Y value
                        EnemyList[i].DecreaseY();
                    }
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Deletes the number from the buffer
        /// </summary>
        /// <param name="format">Used to know how many numbers will represent the value</param>
        /// <param name="x">The X position to write the numbers</param>
        private static void Delete(int format, int x)
        {
            // Create a new int `xOffset`
            int xOffset = 0;

            // Loops the ammount of numbers
            for (int i = 0; i <= format; i++)
            {
                // Loops the ammount of rows
                for (int j = 0; j < NUMBER_ROWS; j++)
                {
                    // Deletes the number from the buffer
                    BufferEditor.Delete(x + xOffset, j + 2, "  ");
                }

                // Increase the x offset by 2
                xOffset += 2;
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Delete the bullet from the buffer
 /// </summary>
 public void Delete()
 {
     // Write the bullet to the buffer
     BufferEditor.Delete(coordinates.X, coordinates.Y, " ");
 }
Exemplo n.º 12
0
 /// <summary>
 /// Deletes the Ovni from the buffer
 /// </summary>
 private void Delete()
 {
     // Delete the ovni from the buffer
     BufferEditor.Delete(coordinates.X, coordinates.Y, "         ");
     BufferEditor.Delete(coordinates.X, coordinates.Y + 1, "         ");
 }
Exemplo n.º 13
0
        /// <summary>
        /// Is called when the level is completed to play animations and initialise the next level
        /// </summary>
        private void LevelCompleted()
        {
            // Create a new timer to be a counter for the animations duration
            Timer counter = new Timer(201);

            // Create a new timer for the blinking animation
            Timer blinker = new Timer(9);

            // Create a new bool
            bool displayScore = false;

            // Clears the buffer
            BufferEditor.ClearBuffer();

            // Loops while the counter is counting
            while (counter.IsCounting())
            {
                // Sets the display score to true or false depending on the counter
                displayScore = !blinker.IsCounting() ? !displayScore : displayScore;

                // If displayScore is true
                if (displayScore)
                {
                    // Write an informational text saying that the level was completed
                    BufferEditor.WriteWithColor(0, 22, " ", ConsoleColor.Yellow);
                    BufferEditor.WriteWithColor(0, 24, " ", ConsoleColor.Yellow);
                    BufferEditor.Delete(36, 22, "L E V E L  C O M P L E T E D!");
                    BufferEditor.Delete(38, 24, "Level bonus 1000 points!");
                    NumberManager.WriteLevel(level);
                }
                else
                {
                    // Delete the previously written text
                    BufferEditor.Write(36, 22, "                             ");
                    BufferEditor.Write(38, 24, "                        ");
                    NumberManager.DeleteLevel();
                }

                // Updates the score
                score += 5;
                NumberManager.WriteScore(score);

                // Updates the header
                DisplayHeader();

                // Display the frame
                BufferEditor.DisplayRender();

                // Wait for 20 miliseconds
                Thread.Sleep(20);
            }

            // Removes the text in the middle of the screen
            BufferEditor.Write(36, 22, "                             ");
            BufferEditor.Write(38, 24, "                        ");

            // Increases the level
            level++;

            // Updates the level number
            NumberManager.WriteLevel(level);

            // Delays for 800 miliseconds
            Thread.Sleep(800);

            // Initializes the next level
            InitNextLevel();
        }