/// <summary> /// Displays the header /// </summary> private void DisplayHeader() { // Set the color to red BufferEditor.WriteWithColor(0, 0, " ", ConsoleColor.Red); BufferEditor.WriteWithColor(0, 5, " ", ConsoleColor.Red); // Loop 100 times for (int i = 0; i < 100; i++) { // Write to the buffer BufferEditor.Write(i, 0, "-"); BufferEditor.Write(i, 5, "-"); } // Change the color to blue BufferEditor.WriteWithColor(0, 1, " ", ConsoleColor.Blue); // Write to the buffer BufferEditor.Write(1, 1, "Score:"); BufferEditor.Write(30, 1, "Level:"); BufferEditor.Write(47, 1, "Lifes:"); // Write the numbers to the buffer NumberManager.WriteScore(score); NumberManager.WriteLevel(level); NumberManager.WriteLifes(lifes); }
/// <summary> /// Writes the ship sprite to the buffer /// </summary> private void WriteToBuffer() { // Go through the ship sprite array for (int i = 0; i < sprite.Length; i++) { // Write each string to the buffer BufferEditor.Write(coordinates.X, coordinates.Y + i, sprite[i]); // Set the color to white BufferEditor.WriteWithColor(0, coordinates.Y + i, " ", ConsoleColor.White); } }
/// <summary> /// Delete a string from the current buffer /// </summary> /// <param name="x">String x position</param> /// <param name="y">String Y position</param> /// <param name="str">The string</param> public static void Delete(int x, int y, string str) { // Goes through every char on the given string for (int i = 0; i < str.Length; i++) { // Set's the char for the current pixel currentPixel.pixelChar = str[i]; // Writes that pixel to the buffer buffer2D.current[x + i, y] = currentPixel; } // Write to the buffer BufferEditor.Write(x, y, str); }
/// <summary> /// Writes the ovni to the buffer /// </summary> public void Write() { // If the current state is Flying if (currentState == State.FLYING) { // Loop the height of the ovni sprite for (int i = 0; i < OVNI_HEIGHT; i++) { // Set the color BufferEditor.WriteWithColor(0, coordinates.Y + i, " ", ConsoleColor.DarkMagenta); // Write the ovni to the buffer BufferEditor.Write(coordinates.X, coordinates.Y + i, sprite[i]); } } }
/// <summary> /// Writes the number to the buffer /// </summary> /// <param name="value"> /// The value it self (number of lifes, score, etc...)</param> /// <param name="xOffset"> /// Offset the number to the right depending on the number of numbers</param> /// <param name="x">The x value where the number will be displayed</param> private static void WriteNumber(int value, int xOffset, int x) { // Loops 3 times... for (int i = 0; i < NUMBER_ROWS; i++) { // Change the color depending on the row BufferEditor.WriteWithColor(0, i + 2, " ", i == 0 ? ConsoleColor.White : i == 1 ? ConsoleColor.Yellow : ConsoleColor.DarkYellow); // Write each string to the buffer BufferEditor.Write(x + xOffset, i + 2, digits[value][i]); } }
/// <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, " "); }
/// <summary> /// Renders all the sprites in the menu /// </summary> public void RenderMenu() { // Display the enemies in the menu // Enemy 1 for (int i = 0; i < Sprites.enemy1String.Length; i++) { BufferEditor.WriteWithColor(0, 10 + i, " ", ConsoleColor.Green); BufferEditor.Write(6, 10 + i, Sprites.enemy1String[i]); BufferEditor.Write(85, 10 + i, Sprites.enemy1String[i]); } // Enemy 2 for (int i = 0; i < Sprites.enemy2String.Length; i++) { BufferEditor.WriteWithColor(0, 17 + i, " ", ConsoleColor.Cyan); BufferEditor.Write(6, 17 + i, Sprites.enemy2String[i]); BufferEditor.Write(85, 17 + i, Sprites.enemy2String[i]); } // Enemy 3 for (int i = 0; i < Sprites.enemy3String.Length; i++) { BufferEditor.WriteWithColor(0, 24 + i, " ", ConsoleColor.Magenta); BufferEditor.Write(6, 24 + i, Sprites.enemy3String[i]); BufferEditor.Write(85, 24 + i, Sprites.enemy3String[i]); } // Enemy 4 for (int i = 0; i < Sprites.enemy4String.Length; i++) { BufferEditor.WriteWithColor(0, 31 + i, " ", ConsoleColor.Blue); BufferEditor.Write(6, 31 + i, Sprites.enemy4String[i]); BufferEditor.Write(85, 31 + i, Sprites.enemy4String[i]); } // Enemy 5 for (int i = 0; i < Sprites.enemy5String.Length; i++) { BufferEditor.WriteWithColor(0, 37 + i, " ", ConsoleColor.DarkGreen); BufferEditor.Write(6, 37 + i, Sprites.enemy5String[i]); BufferEditor.Write(85, 37 + i, Sprites.enemy5String[i]); } // Display Title for (int i = 0; i < Sprites.spaceString.Length; i++) { BufferEditor.WriteWithColor(0, 21 + i, " ", ConsoleColor.Yellow); BufferEditor.Write(21, 21 + i, Sprites.spaceString[i]); BufferEditor.Write(45, 21 + i, Sprites.invadersString[i]); } // Display Buttons for (int i = 0; i < Sprites.playString.Length; i++) { BufferEditor.WriteWithColor(0, 28 + i, " ", ConsoleColor.White); BufferEditor.Write(22, 28 + i, Sprites.playString[i]); BufferEditor.Write(63, 28 + i, Sprites.quitString[i]); } // Display Button Selector for (int i = 0; i < Sprites.selectionString.Length; i++) { BufferEditor.WriteWithColor(0, 33 + i, " ", ConsoleColor.White); // If we have the play button selected if (playSelected) { // Draw the ship bellow the play button BufferEditor.Write(PLAY_X_SELECTION, Y_SELECTION + i, Sprites.selectionString[i]); BufferEditor.Write(QUIT_X_SELECTION, Y_SELECTION + i, " "); } // If we have the quit button selected else if (quitSelected) { // Draw the ship bellow the quit button BufferEditor.Write(QUIT_X_SELECTION, Y_SELECTION + i, Sprites.selectionString[i]); BufferEditor.Write(PLAY_X_SELECTION, Y_SELECTION + i, " "); } } // Tells the double buffer to render the frame BufferEditor.DisplayRender(); // Gets the input from the user GetInput(); }
/// <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(); }