Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
17ff309a01 | |||
7baabd7cc3 | |||
1b8c0a32a5 | |||
d6e3b48700 | |||
c603e9932e | |||
df1ae2ea4b | |||
34ff7be91a |
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
bin/*
|
||||
obj/*
|
||||
obj/*
|
||||
.idea/*
|
107
Tetris.cs
107
Tetris.cs
|
@ -7,13 +7,13 @@ namespace Tetris {
|
|||
public static class Tetris {
|
||||
// Static variables
|
||||
private static readonly Color[] colors = {
|
||||
new(255, 0, 0), // Red
|
||||
new(255, 127, 0), // Orange
|
||||
new(255, 255, 0), // Yellow
|
||||
new(0, 255, 0), // Green
|
||||
new(0, 255, 255), // Cyan
|
||||
new(0, 127, 255), // Blue
|
||||
new(255, 0, 255) }; // Purple
|
||||
new(255, 0, 0), // Red
|
||||
new(255, 127, 0), // Orange
|
||||
new(255, 255, 0), // Yellow
|
||||
new( 0, 255, 0), // Green
|
||||
new( 0, 255, 255), // Cyan
|
||||
new( 0, 127, 255), // Blue
|
||||
new(255, 0, 255) }; // Purple
|
||||
|
||||
private static readonly int[][][] blocks = {
|
||||
new[] { new[] { 0, 0 }, new[] { 1, 0 }, new[] { 1, 1 }, new[] { 2, 1 } }, // Mirrored-Z
|
||||
|
@ -32,6 +32,7 @@ namespace Tetris {
|
|||
private static Player player = new(), next = new(true);
|
||||
public static bool selection, ptbLogo = true;
|
||||
public static int selectionIndex, frameCount;
|
||||
public static int sw = 3, sh = 3;
|
||||
private static int score, bounds;
|
||||
|
||||
// Matrix variables
|
||||
|
@ -56,9 +57,9 @@ namespace Tetris {
|
|||
new RGBLedMatrixOptions {
|
||||
HardwareMapping = "adafruit-hat",
|
||||
LimitRefreshRateHz = 0,
|
||||
GpioSlowdown = 4,
|
||||
Brightness = 100,
|
||||
GpioSlowdown = 5,
|
||||
ChainLength = 1,
|
||||
Parallel = 1,
|
||||
ScanMode = 1,
|
||||
Rows = 64,
|
||||
Cols = 64,
|
||||
|
@ -81,8 +82,6 @@ namespace Tetris {
|
|||
canvas.Clear();
|
||||
canvas = matrix.SwapOnVsync(canvas);
|
||||
|
||||
// Inner loop for actual Gameplay
|
||||
score = 0;
|
||||
// Initialize board
|
||||
if (!hasStarted) {
|
||||
initBoard();
|
||||
|
@ -91,6 +90,7 @@ namespace Tetris {
|
|||
gameOver = false;
|
||||
while (!gameOver) {
|
||||
// Start of Frame
|
||||
stopwatch.Restart();
|
||||
canvas.Clear();
|
||||
Console.SetCursorPosition(0, 0);
|
||||
Console.WriteLine($"Score: {score}");
|
||||
|
@ -106,38 +106,60 @@ namespace Tetris {
|
|||
for (int j = 0; j < board.GetLength(1); j++) {
|
||||
Color current = board[i, j];
|
||||
if (!current.Equals(black))
|
||||
for (int k = 0; k < 3; k++)
|
||||
for (int l = 0; l < 3; l++)
|
||||
canvas.SetPixel(i * 3 + k, j * 3 + l, current);
|
||||
for (int k = 0; k < sw; k++)
|
||||
for (int l = 0; l < sh; l++)
|
||||
canvas.SetPixel(i * sw + k, j * sh + l, current);
|
||||
}
|
||||
|
||||
// Display player onto Matrix
|
||||
foreach (var current in player.positions) {
|
||||
for (int k = 0; k < 3; k++)
|
||||
for (int l = 0; l < 3; l++)
|
||||
canvas.SetPixel((player.x + current[0]) * 3 + k, (player.y + current[1]) * 3 + l, player.color);
|
||||
for (int k = 0; k < sw; k++)
|
||||
for (int l = 0; l < sh; l++)
|
||||
canvas.SetPixel((player.x + current[0]) * sw + k, (player.y + current[1]) * sh + l, player.color);
|
||||
}
|
||||
|
||||
// Calculate ghost piece y-coordinate
|
||||
int ty = player.y;
|
||||
while (!collisionCheck(player.x, ++ty, player.positions)) { }
|
||||
ty--;
|
||||
// Display ghost piece onto Matrix
|
||||
foreach (var current in player.positions) {
|
||||
for (int k = 0; k < sw; k+=sw-1)
|
||||
for (int l = 0; l < sh; l++)
|
||||
canvas.SetPixel((player.x + current[0]) * sw + k, (ty + current[1]) * sh + l, player.color);
|
||||
for (int k = 0; k < sw; k++)
|
||||
for (int l = 0; l < sh; l+=sh-1)
|
||||
canvas.SetPixel((player.x + current[0]) * sw + k, (ty + current[1]) * sh + l, player.color);
|
||||
}
|
||||
|
||||
// Draw line "in the middle"
|
||||
for (int i = 0; i < 64; i++)
|
||||
canvas.SetPixel(30, i, grey);
|
||||
canvas.SetPixel(sw*10, i, grey);
|
||||
|
||||
// Statically display stored item on the right side
|
||||
canvas.DrawText(font, 38, 8, col, "Save:");
|
||||
canvas.DrawText(font, 33, 8, col, "Save:");
|
||||
if (player.memDis != null && player.memCol != null)
|
||||
foreach (int[] b in player.memDis)
|
||||
for (int k = 0; k < 3; k++)
|
||||
for (int l = 0; l < 3; l++)
|
||||
canvas.SetPixel((14 + b[0]) * 3 + k, (4+ b[1]) * 3 + l, (Color)player.memCol);
|
||||
for (int k = 0; k < sw; k++)
|
||||
for (int l = 0; l < sh; l++)
|
||||
canvas.SetPixel(34 + b[0] * sw + k, 13 + b[1] * sh + l, (Color)player.memCol);
|
||||
|
||||
// Statically display next item below the previous
|
||||
canvas.DrawText(font, 38, 40, col, "Next:");
|
||||
canvas.DrawText(font, 33, 30, col, "Next:");
|
||||
if (next.memDis != null)
|
||||
foreach (int[] b in next.memDis)
|
||||
for (int k = 0; k < 3; k++)
|
||||
for (int l = 0; l < 3; l++)
|
||||
canvas.SetPixel((14 + b[0]) * 3 + k, (15+ b[1]) * 3 + l, (Color)next.color);
|
||||
|
||||
for (int k = 0; k < sw; k++)
|
||||
for (int l = 0; l < sh; l++)
|
||||
canvas.SetPixel(34 + b[0] * sw + k, 35 + b[1] * sh + l, next.color);
|
||||
|
||||
// Fill bottom
|
||||
for (int j = 0; j < sw*10; j++)
|
||||
canvas.SetPixel(j, 63, grey);
|
||||
|
||||
// Display score
|
||||
canvas.DrawText(font, 33, 52, col, $"Score:");
|
||||
canvas.DrawText(font, 33, 60, col, score.ToString());
|
||||
|
||||
// Move Player down every few frames
|
||||
if (frameCount % 30 == 0 && collisionCheck(player.x, ++player.y, player.positions)) {
|
||||
player.y--;
|
||||
|
@ -206,6 +228,8 @@ namespace Tetris {
|
|||
frameCount++;
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
// Reset score
|
||||
score = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -286,17 +310,14 @@ namespace Tetris {
|
|||
}
|
||||
j--;
|
||||
}
|
||||
|
||||
// Add to score
|
||||
if (rows >= 4) {
|
||||
int tetris = rows / 4;
|
||||
if (tetris > 1)
|
||||
score += 1200 * tetris;
|
||||
else
|
||||
score += 800;
|
||||
} else if (rows == 3)
|
||||
score += 400;
|
||||
else
|
||||
score += 100 * rows;
|
||||
switch (rows) {
|
||||
case 1: score += 40; break;
|
||||
case 2: score += 100; break;
|
||||
case 3: score += 300; break;
|
||||
case 4: score += 1200; break;
|
||||
}
|
||||
|
||||
|
||||
// Generating new Block
|
||||
|
@ -594,15 +615,9 @@ namespace Tetris {
|
|||
public void initSelf(int blockIndex) {
|
||||
int xB;
|
||||
switch (blockIndex) {
|
||||
default:
|
||||
xB = 3;
|
||||
break;
|
||||
case 2:
|
||||
xB = 2;
|
||||
break;
|
||||
case 4:
|
||||
xB = 4;
|
||||
break;
|
||||
default: xB = 3; break;
|
||||
case 2: xB = 2; break;
|
||||
case 4: xB = 4; break;
|
||||
}
|
||||
|
||||
x = 4 - xB / 2;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<SelfContained>true</SelfContained>
|
||||
<RuntimeIdentifier>linux-arm64</RuntimeIdentifier>
|
||||
<RuntimeIdentifier>linux-arm</RuntimeIdentifier>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
|
||||
</PropertyGroup>
|
||||
|
|
BIN
librgbmatrix.so
BIN
librgbmatrix.so
Binary file not shown.
Loading…
Reference in New Issue
Block a user