debug menu and optional PTB-Logo
This commit is contained in:
parent
500c8de618
commit
2cf5332c50
|
@ -6,6 +6,8 @@ using rpi_rgb_led_matrix_sharp;
|
|||
namespace RPI_Matrix {
|
||||
public static class RPI_Matrix {
|
||||
// Initialize variables
|
||||
private static int debugIndex;
|
||||
private static bool debugMenu, debugSelect;
|
||||
private static bool hasSelected, isInGame, isTetris, isFlappy, isSnake;
|
||||
private static int selectionIndex, keypressFrame, frameCount;
|
||||
private static bool selection = true;
|
||||
|
@ -51,9 +53,10 @@ namespace RPI_Matrix {
|
|||
canvas.DrawText(font, 0, 24, col, " ) SnakeGame");
|
||||
canvas.DrawText(font, 0, 32, col, " ) FlappyBird");
|
||||
canvas.DrawText(font, 0, 40, col, " ) Tetris");
|
||||
canvas.DrawText(font, 0, 56, col, " ) Beenden");
|
||||
// Cursor is a '#' at (0, 24 + i * 8) where i may be [0, 1, 2, 4]
|
||||
int nx = selectionIndex + ((selectionIndex == 3) ? 1 : 0);
|
||||
canvas.DrawText(font, 0, 48, col, " ) Debug");
|
||||
canvas.DrawText(font, 0, 64, col, " ) Beenden");
|
||||
// Cursor is a '#' at (0, 24 + i * 8) where i may be [0, 1, 2, 3, 5]
|
||||
int nx = selectionIndex + ((selectionIndex == 4) ? 1 : 0);
|
||||
canvas.DrawText(font, 0, 24 + nx * 8, col, "#");
|
||||
canvas = matrix.SwapOnVsync(canvas);
|
||||
|
||||
|
@ -68,7 +71,7 @@ namespace RPI_Matrix {
|
|||
selectionIndex--;
|
||||
break;
|
||||
case ConsoleKey.DownArrow:
|
||||
if (!isInGame && selectionIndex < 3)
|
||||
if (!isInGame && selectionIndex < 4)
|
||||
selectionIndex++;
|
||||
break;
|
||||
case ConsoleKey.Enter:
|
||||
|
@ -95,6 +98,10 @@ namespace RPI_Matrix {
|
|||
playTetris();
|
||||
break;
|
||||
case 3:
|
||||
// Open debug Menu
|
||||
openDebugMenu(matrix, canvas);
|
||||
break;
|
||||
case 4:
|
||||
// Exit program
|
||||
Environment.Exit(0);
|
||||
break;
|
||||
|
@ -120,6 +127,67 @@ namespace RPI_Matrix {
|
|||
}
|
||||
}
|
||||
|
||||
private static void openDebugMenu(RGBLedMatrix matrix, RGBLedCanvas canvas) {
|
||||
// Set identification variables and load settings
|
||||
isInGame = true;
|
||||
selection = false;
|
||||
|
||||
// Initialize Text-Font and -Color
|
||||
RGBLedFont font = new("fonts/5x8.bdf");
|
||||
Color col = new(255, 255, 255);
|
||||
|
||||
// Game selection Menu
|
||||
debugMenu = true;
|
||||
while (debugMenu) {
|
||||
// Display Games and Cursor on Matrix
|
||||
canvas.Clear();
|
||||
canvas.DrawText(font, 0, 8, col, "Einstellung:");
|
||||
canvas.DrawText(font, 0, 24, col, $" ) PTB Logo {(Tetris.Tetris.ptbLogo ? "I" : "O")}");
|
||||
canvas.DrawText(font, 0, 40, col, " ) Zurück");
|
||||
// Cursor is a '#' at (0, 24 + i * 8) where i may be [0, 2]
|
||||
int nx = debugIndex + ((debugIndex == 1) ? 1 : 0);
|
||||
canvas.DrawText(font, 0, 24 + nx * 8, col, "#");
|
||||
canvas = matrix.SwapOnVsync(canvas);
|
||||
|
||||
// Handle key presses for selecting a game
|
||||
if (Console.KeyAvailable) {
|
||||
switch (Console.ReadKey(true).Key) {
|
||||
case ConsoleKey.Escape:
|
||||
return;
|
||||
case ConsoleKey.UpArrow:
|
||||
if (debugIndex > 0)
|
||||
debugIndex--;
|
||||
break;
|
||||
case ConsoleKey.DownArrow:
|
||||
if (debugIndex < 1)
|
||||
debugIndex++;
|
||||
break;
|
||||
case ConsoleKey.Enter:
|
||||
debugSelect = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Use selected index to change a setting
|
||||
if (debugSelect) {
|
||||
debugSelect = false;
|
||||
switch (debugIndex) {
|
||||
case 0:
|
||||
// Toggle Tetris PTB Logo
|
||||
Tetris.Tetris.ptbLogo = !Tetris.Tetris.ptbLogo;
|
||||
break;
|
||||
case 1:
|
||||
// Go back to menu
|
||||
debugMenu = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for next frame and keep count
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
private static void playSnakeGame(string arg) {
|
||||
// Set Game identification variables and start playing SnakeGame
|
||||
isSnake = true;
|
||||
|
@ -180,6 +248,8 @@ namespace RPI_Matrix {
|
|||
FlappyBird.FlappyBird.enterSelection();
|
||||
else if (isTetris && Tetris.Tetris.selection)
|
||||
Tetris.Tetris.enterSelection();
|
||||
else
|
||||
debugSelect = true;
|
||||
break;
|
||||
case "01-00-01-02":
|
||||
// Code for B-Button Press
|
||||
|
@ -241,13 +311,16 @@ namespace RPI_Matrix {
|
|||
// If in Tetris and in Tetris' 'GameOver' Screen, decrement its index.
|
||||
} else if (isTetris && Tetris.Tetris.selection && Tetris.Tetris.selectionIndex > 0)
|
||||
Tetris.Tetris.selectionIndex--;
|
||||
else if (isFlappy && FlappyBird.FlappyBird.selection && FlappyBird.FlappyBird.selectionIndex > 0)
|
||||
else if (isFlappy && FlappyBird.FlappyBird.selection &&
|
||||
FlappyBird.FlappyBird.selectionIndex > 0)
|
||||
FlappyBird.FlappyBird.selectionIndex--;
|
||||
else if (debugIndex > 0)
|
||||
debugIndex--;
|
||||
break;
|
||||
case "FF-7F-02-01":
|
||||
// Code for Arrow-Down Press
|
||||
// If in the selection screen, decrement index
|
||||
if (!isInGame && selectionIndex < 3)
|
||||
if (!isInGame && selectionIndex < 4)
|
||||
selectionIndex++;
|
||||
// If in SnakeGame, Steer the Snake downwards
|
||||
else if (isSnake) {
|
||||
|
@ -267,6 +340,8 @@ namespace RPI_Matrix {
|
|||
Tetris.Tetris.moveDownOnce();
|
||||
else if (isFlappy && FlappyBird.FlappyBird.selection && FlappyBird.FlappyBird.selectionIndex < 1)
|
||||
FlappyBird.FlappyBird.selectionIndex++;
|
||||
else if (debugIndex < 1)
|
||||
debugIndex++;
|
||||
break;
|
||||
case "01-80-02-00":
|
||||
// Code for Arrow-Left Press
|
||||
|
|
Loading…
Reference in New Issue
Block a user