clean up and expansion

This commit is contained in:
Baipyrus 2022-11-30 08:37:00 +01:00
parent 31ae09d287
commit 75801332e0

View File

@ -9,8 +9,9 @@ namespace FlappyBird {
private static string scoreText = "Your score is: ";
private static float factor = 32/1.4f;
private static int pipeInterval = 60;
private static int height = 64;
private static int width = 64;
private static int sw = 6, sh = 6;
private static int height = 96;
private static int width = 96;
private static int FPS = 60;
// Game variables
@ -43,12 +44,9 @@ namespace FlappyBird {
} else {
matrix = new(
new RGBLedMatrixOptions {
HardwareMapping = "adafruit-hat",
LimitRefreshRateHz = 0,
GpioSlowdown = 4,
Brightness = 100,
ChainLength = 1,
ScanMode = 1,
GpioSlowdown = 5,
ChainLength = 3,
Parallel = 3,
Rows = 64,
Cols = 64,
});
@ -61,7 +59,7 @@ namespace FlappyBird {
Color green = new(0, 255, 0);
// Initialize Console Color and Text-Font and -Color
RGBLedFont font = new("fonts/5x8.bdf");
RGBLedFont font = new("fonts/9x18B.bdf");
Console.ForegroundColor = ConsoleColor.White;
Color textCol = new(255, 255, 255), grey = new(127, 127, 127);
@ -84,14 +82,10 @@ namespace FlappyBird {
// Place the bird on the board
int rBY = height-1-(int)Math.Round(birdY);
board[birdX , rBY ] = 'O';
board[birdX+1, rBY ] = 'O';
board[birdX , rBY+1] = 'O';
board[birdX+1, rBY+1] = 'O';
canvas.SetPixel(birdX-1, rBY-1, yellow);
canvas.SetPixel(birdX, rBY-1, yellow);
canvas.SetPixel(birdX-1, rBY, yellow);
canvas.SetPixel(birdX, rBY, yellow);
board[birdX, rBY ] = 'O';
for (int k = 0; k < sw; k++)
for (int l = 0; l < sh; l++)
canvas.SetPixel((birdX-1)*2+k, (rBY-1)*2+l, yellow);
canvas = matrix.SwapOnVsync(canvas);
// Draw the board
@ -146,10 +140,9 @@ namespace FlappyBird {
Random rng = new Random();
int pipeX = board.GetLength(0)-2;
int spaceY = rng.Next(2,board.GetLength(1)-6-spaceHeight);
for (int i = 0; i < 2; i++)
for (int j = 1; j < board.GetLength(1)-1; j++)
if (j < spaceY || j > spaceY+spaceHeight)
board[pipeX - i, j] = '$';
for (int j = 1; j < board.GetLength(1)-1; j++)
if (j < spaceY || j > spaceY+spaceHeight)
board[pipeX, j] = '$';
}
// Handle key presses for jumping and exiting
@ -177,16 +170,10 @@ namespace FlappyBird {
// Update bird position on board
int tempY = board.GetLength(1)-1-(int)Math.Round(birdY);
if (tempY != rBY) {
board[birdX , rBY ] = ' ';
board[birdX+1, rBY ] = ' ';
board[birdX , rBY+1] = ' ';
board[birdX+1, rBY+1] = ' ';
board[birdX, rBY ] = ' ';
if (board[birdX, tempY] == '$')
EndGame();
board[birdX , tempY ] = 'O';
board[birdX+1, tempY ] = 'O';
board[birdX , tempY+1] = 'O';
board[birdX+1, tempY+1] = 'O';
board[birdX, tempY ] = 'O';
rBY = tempY;
}
@ -210,8 +197,10 @@ namespace FlappyBird {
break;
}
if (doDisplay)
canvas.SetPixel(i-1, j-1, col);
}
for (int k = 0; k < sw; k++)
for (int l = 0; l < sh; l++)
canvas.SetPixel((i-1)*2+k, (j-1)*2+l, col);
}
// Swap Frame on Vsync
canvas = matrix.SwapOnVsync(canvas);
@ -228,12 +217,12 @@ namespace FlappyBird {
while (selection) {
// Display Options and Cursor on Matrix
canvas.Clear();
canvas.DrawText(font, 0, 8, textCol, "Game Over!");
canvas.DrawText(font, 0, 24, textCol, " ) Weiter");
canvas.DrawText(font, 0, 32, textCol, " ) Beenden");
canvas.DrawText(font, 0, 48, textCol, $"Score: {score/2}");
canvas.DrawText(font, 0, 18, textCol, "Game Over!");
canvas.DrawText(font, 0, 54, textCol, " ) Weiter");
canvas.DrawText(font, 0, 72, textCol, " ) Beenden");
canvas.DrawText(font, 0, 108, textCol, $"Score: {score/2}");
// Cursor is a '#' at (0, 24 + i * 8) where i may be [0, 1]
canvas.DrawText(font, 0, 24+selectionIndex*8, textCol, "#");
canvas.DrawText(font, 0, 54+selectionIndex*18, textCol, "#");
canvas = matrix.SwapOnVsync(canvas);
// Handle key presses for continue game or exit