Compare commits
7 Commits
Matrix-1.0
...
master
Author | SHA1 | Date | |
---|---|---|---|
42ea2a5fc1 | |||
4f10d60575 | |||
e2ad89c25e | |||
cd6527afb3 | |||
0575054fba | |||
c69b48f6ae | |||
3a9992befd |
418
RPI-Matrix.cs
418
RPI-Matrix.cs
|
@ -1,27 +1,28 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
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 bool selection = true, focusHeight, focusGravity, focusJump, isFocused;
|
||||
private static List<string> gamepadListeners = new();
|
||||
private static int selectionIndex, keypressFrame, frameCount;
|
||||
private static bool hasSelected, isInGame, isTetris, isFlappy, isSnake;
|
||||
private static bool selection = true, isFocused, focusHeight, focusGravity, focusJump, focusLength;
|
||||
|
||||
public static void Main() {
|
||||
public static void Main(string[] args) {
|
||||
// Connect to RGB LED Matrix
|
||||
RGBLedMatrix 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,
|
||||
});
|
||||
|
@ -33,10 +34,10 @@ namespace RPI_Matrix {
|
|||
Tetris.Tetris.Init(matrix, canvas);
|
||||
|
||||
// Start listening and interpreting Gamepad input in parallel
|
||||
(new Thread(InterpretGamepadInput)).Start();
|
||||
|
||||
new Thread(InterpretGamepadInput).Start();
|
||||
|
||||
// Initialize Text-Font and -Color
|
||||
RGBLedFont font = new("fonts/5x8.bdf");
|
||||
RGBLedFont font = new("fonts/9x18B.bdf");
|
||||
Color col = new(255, 255, 255);
|
||||
|
||||
// Game Menu
|
||||
|
@ -49,15 +50,15 @@ namespace RPI_Matrix {
|
|||
while (selection) {
|
||||
// Display Games and Cursor on Matrix
|
||||
canvas.Clear();
|
||||
canvas.DrawText(font, 0, 8, col, "Spielauswahl:");
|
||||
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, " ) Einstell.");
|
||||
canvas.DrawText(font, 0, 64, col, " ) Beenden");
|
||||
canvas.DrawText(font, 0, 18, col, "Spielauswahl:");
|
||||
canvas.DrawText(font, 0, 54, col, " ) SnakeGame");
|
||||
canvas.DrawText(font, 0, 72, col, " ) FlappyBird");
|
||||
canvas.DrawText(font, 0, 90, col, " ) Tetris");
|
||||
canvas.DrawText(font, 0, 126, col, " ) Einstellungen");
|
||||
canvas.DrawText(font, 0, 144, col, " ) Beenden");
|
||||
// Cursor is a '#' at (0, 24 + i * 8) where i may be [0, 1, 2, 3, 5]
|
||||
int nx = selectionIndex + ((selectionIndex >= 3) ? 1 : 0);
|
||||
canvas.DrawText(font, 0, 24 + nx * 8, col, "#");
|
||||
canvas.DrawText(font, 0, 54 + nx * 18, col, "#");
|
||||
canvas = matrix.SwapOnVsync(canvas);
|
||||
|
||||
// Handle key presses for selecting a game
|
||||
|
@ -87,7 +88,7 @@ namespace RPI_Matrix {
|
|||
switch (selectionIndex) {
|
||||
case 0:
|
||||
// Start SnakeGame in Singleplayer
|
||||
playSnakeGame("-s");
|
||||
playSnakeGame();
|
||||
break;
|
||||
case 1:
|
||||
// Start FlappyBird
|
||||
|
@ -133,7 +134,7 @@ namespace RPI_Matrix {
|
|||
selection = false;
|
||||
|
||||
// Initialize Text-Font and -Color
|
||||
RGBLedFont font = new("fonts/5x8.bdf");
|
||||
RGBLedFont font = new("fonts/9x18B.bdf");
|
||||
Color col = new(255, 255, 255);
|
||||
|
||||
// Game selection Menu
|
||||
|
@ -141,20 +142,23 @@ namespace RPI_Matrix {
|
|||
while (debugMenu) {
|
||||
// Display Games and Cursor on Matrix
|
||||
canvas.Clear();
|
||||
canvas.DrawText(font, 0, 8, col, "Tetris:");
|
||||
canvas.DrawText(font, 0, 16, col, $" ) PTB Logo {(Tetris.Tetris.ptbLogo ? "I" : "O")}");
|
||||
canvas.DrawText(font, 0, 24, col, "FlappyBird:");
|
||||
canvas.DrawText(font, 0, 32, col, $" ) Höhe {FlappyBird.FlappyBird.spaceHeight}");
|
||||
canvas.DrawText(font, 0, 40, col, $" ) Grav. {FlappyBird.FlappyBird.gravity}");
|
||||
canvas.DrawText(font, 0, 48, col, $" ) Spr. {FlappyBird.FlappyBird.jumpVel}");
|
||||
canvas.DrawText(font, 0, 64, col, " ) Zurück");
|
||||
canvas.DrawText(font, 0, 18, col, "Tetris:");
|
||||
canvas.DrawText(font, 0, 36, col, $" ) PTB Logo {(Tetris.Tetris.ptbLogo ? "I" : "O")}");
|
||||
canvas.DrawText(font, 0, 54, col, "FlappyBird:");
|
||||
canvas.DrawText(font, 0, 72, col, $" ) Höhe {FlappyBird.FlappyBird.spaceHeight}");
|
||||
canvas.DrawText(font, 0, 90, col, $" ) Gravitation {FlappyBird.FlappyBird.gravity}");
|
||||
canvas.DrawText(font, 0, 108, col, $" ) Sprung Ges. {FlappyBird.FlappyBird.jumpVel}");
|
||||
canvas.DrawText(font, 0, 126, col, "SnakeGame");
|
||||
canvas.DrawText(font, 0, 144, col, $" ) Basis Länge {SnakeGame.SnakeGame.baseLength}");
|
||||
canvas.DrawText(font, 0, 180, col, " ) Zurück");
|
||||
|
||||
// Cursor is a '#' at (0, 24 + i * 8) where i may be [0, 2]
|
||||
int nx = debugIndex;
|
||||
if (debugIndex >= 1) nx++;
|
||||
if (debugIndex >= 4) nx++;
|
||||
if (debugIndex >= 5) nx++;
|
||||
|
||||
canvas.DrawText(font, 0, 16 + nx * 8, col, "#");
|
||||
canvas.DrawText(font, 0, 36 + nx * 18, col, "#");
|
||||
canvas = matrix.SwapOnVsync(canvas);
|
||||
|
||||
// Handle key presses for selecting a game
|
||||
|
@ -167,7 +171,7 @@ namespace RPI_Matrix {
|
|||
debugIndex--;
|
||||
break;
|
||||
case ConsoleKey.DownArrow:
|
||||
if (debugIndex < 1)
|
||||
if (debugIndex < 5)
|
||||
debugIndex++;
|
||||
break;
|
||||
case ConsoleKey.Enter:
|
||||
|
@ -200,6 +204,11 @@ namespace RPI_Matrix {
|
|||
isFocused = true;
|
||||
break;
|
||||
case 4:
|
||||
// Go back to menu
|
||||
focusLength = true;
|
||||
isFocused = true;
|
||||
break;
|
||||
case 5:
|
||||
// Go back to menu
|
||||
debugMenu = false;
|
||||
break;
|
||||
|
@ -212,11 +221,12 @@ namespace RPI_Matrix {
|
|||
}
|
||||
}
|
||||
|
||||
private static void playSnakeGame(string arg) {
|
||||
private static void playSnakeGame(string arg = "") {
|
||||
// Set Game identification variables and start playing SnakeGame
|
||||
isSnake = true;
|
||||
isInGame = true;
|
||||
selection = false;
|
||||
SnakeGame.SnakeGame.players = gamepadListeners;
|
||||
SnakeGame.SnakeGame.Main(new[] { arg });
|
||||
}
|
||||
|
||||
|
@ -237,10 +247,35 @@ namespace RPI_Matrix {
|
|||
}
|
||||
|
||||
private static void InterpretGamepadInput() {
|
||||
// Read file "/dev/input/js0" in Raspbian for Raspberry 4 4GB.
|
||||
// Read file "/dev/input/js*" in Raspbian for Raspberry 4 4GB.
|
||||
// All inputs on a Gamepad are accessible from within here.
|
||||
// Interpreting this data may only work in this program using a SNES Controller.
|
||||
FileInfo targetFile = new FileInfo("/dev/input/js0");
|
||||
while (true) {
|
||||
string dir = "/dev/input/";
|
||||
IEnumerable<string> files = from retrieved in Directory.EnumerateFiles(dir)
|
||||
where retrieved.Contains("js")
|
||||
select retrieved;
|
||||
foreach (string f in files) {
|
||||
string name = f.Replace(dir, "");
|
||||
if (!gamepadListeners.Contains(name)) {
|
||||
gamepadListeners.Add(name);
|
||||
new Thread(() => {
|
||||
try {
|
||||
WatchInputFile(dir, f);
|
||||
}
|
||||
catch (Exception) {
|
||||
gamepadListeners.Remove(name);
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WatchInputFile(string dir, string file) {
|
||||
FileInfo targetFile = new FileInfo(file);
|
||||
using FileStream fs = targetFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
// Initialize Buffer (byte Array) to put read bytes into
|
||||
byte[] buffer = new byte[1024];
|
||||
|
@ -253,156 +288,177 @@ namespace RPI_Matrix {
|
|||
// And do it again in SnakeGame while it's playing.
|
||||
else if (isSnake && !SnakeGame.SnakeGame.gameOver)
|
||||
SnakeGame.SnakeGame.keypressFrame = SnakeGame.SnakeGame.frameCount;
|
||||
|
||||
|
||||
// Convert Buffer to Hexadecimal, each Byte separated by a '-'
|
||||
switch (BitConverter.ToString(buffer, 4, 4)) {
|
||||
case "01-00-01-00":
|
||||
// Code for X-Button Press
|
||||
if (isTetris)
|
||||
Tetris.Tetris.swapMemory();
|
||||
break;
|
||||
case "01-00-01-01":
|
||||
// Code for A-Button Press
|
||||
// If not already in a Game, now ready up to select one.
|
||||
if (!isInGame)
|
||||
hasSelected = true;
|
||||
// Select given option in Tetris' 'GameOver' Screen
|
||||
else if (isSnake && SnakeGame.SnakeGame.selection)
|
||||
SnakeGame.SnakeGame.enterSelection();
|
||||
else if (isFlappy && FlappyBird.FlappyBird.selection)
|
||||
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
|
||||
if (isFlappy) {
|
||||
// Jump
|
||||
if (FlappyBird.FlappyBird.isReady)
|
||||
FlappyBird.FlappyBird.JumpOnce();
|
||||
// Start Game
|
||||
else
|
||||
FlappyBird.FlappyBird.isReady = true;
|
||||
// Place the current Block in Tetris
|
||||
} else if (isTetris)
|
||||
Tetris.Tetris.placeDownBlock();
|
||||
else if (!isSnake) {
|
||||
focusGravity = false;
|
||||
focusHeight = false;
|
||||
focusJump = false;
|
||||
isFocused = false;
|
||||
}
|
||||
break;
|
||||
case "01-00-01-04":
|
||||
// Code for L-Button Press
|
||||
// If in Tetris, rotate the current Block counter-Clockwise
|
||||
if (isTetris)
|
||||
Tetris.Tetris.rotateCounterClockwise();
|
||||
break;
|
||||
case "01-00-01-05":
|
||||
// Code for R-Button Press
|
||||
// If in Tetris, rotate the current Block Clockwise
|
||||
if (isTetris)
|
||||
Tetris.Tetris.rotateClockwise();
|
||||
break;
|
||||
case "01-00-01-09":
|
||||
// Code for Start-Button Press
|
||||
// If in SnakeGame, end the Game and return to menu
|
||||
if (isSnake)
|
||||
SnakeGame.SnakeGame.EndGame();
|
||||
else if (isFlappy) {
|
||||
// If in FlappyBirds' 'ready' Screen, return to menu
|
||||
if (!FlappyBird.FlappyBird.isReady)
|
||||
FlappyBird.FlappyBird.stopPlaying = true;
|
||||
// Otherwise go back to 'ready' Screen by ending the Game
|
||||
else {
|
||||
FlappyBird.FlappyBird.EndGame();
|
||||
FlappyBird.FlappyBird.selection = false;
|
||||
}
|
||||
// If in Tetris, end the Game and return to menu
|
||||
} else if (isTetris)
|
||||
Tetris.Tetris.EndGame();
|
||||
break;
|
||||
case "01-80-02-01":
|
||||
// Code for Arrow-Up Press
|
||||
// If in the selection screen, decrement index
|
||||
if (!isInGame && selectionIndex > 0)
|
||||
selectionIndex--;
|
||||
else if (isSnake) {
|
||||
// Handle index in 'GameOver' Screen
|
||||
if (SnakeGame.SnakeGame.selection && SnakeGame.SnakeGame.selectionIndex > 0)
|
||||
SnakeGame.SnakeGame.selectionIndex--;
|
||||
// If in SnakeGame, Steer the Snake upwards
|
||||
else
|
||||
SnakeGame.SnakeGame.SteerUp(SnakeGame.SnakeGame.self);
|
||||
// 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)
|
||||
FlappyBird.FlappyBird.selectionIndex--;
|
||||
else if (focusGravity)
|
||||
FlappyBird.FlappyBird.gravity += 0.01f;
|
||||
else if (focusHeight && FlappyBird.FlappyBird.spaceHeight < 58)
|
||||
FlappyBird.FlappyBird.spaceHeight += 1;
|
||||
else if (focusJump)
|
||||
FlappyBird.FlappyBird.jumpVel += 0.01f;
|
||||
else if (debugIndex > 0 && !isFocused)
|
||||
debugIndex--;
|
||||
break;
|
||||
case "FF-7F-02-01":
|
||||
// Code for Arrow-Down Press
|
||||
// If in the selection screen, decrement index
|
||||
if (!isInGame && selectionIndex < 4)
|
||||
selectionIndex++;
|
||||
// If in SnakeGame, Steer the Snake downwards
|
||||
else if (isSnake) {
|
||||
// Handle index in 'GameOver' Screen
|
||||
if (SnakeGame.SnakeGame.selection && SnakeGame.SnakeGame.selectionIndex < 1)
|
||||
SnakeGame.SnakeGame.selectionIndex++;
|
||||
// If in SnakeGame, Steer the Snake downwards
|
||||
else
|
||||
SnakeGame.SnakeGame.SteerDown(SnakeGame.SnakeGame.self);
|
||||
// If in Tetris and in Tetris' 'GameOver' Screen, decrement its index.
|
||||
} else if (isTetris)
|
||||
// If in Tetris and in Tetris' 'GameOver' Screen, increment its index.
|
||||
if (Tetris.Tetris.selection && Tetris.Tetris.selectionIndex < 1)
|
||||
Tetris.Tetris.selectionIndex++;
|
||||
// Otherwise, move Tetris piece down
|
||||
else
|
||||
Tetris.Tetris.moveDownOnce();
|
||||
else if (isFlappy && FlappyBird.FlappyBird.selection && FlappyBird.FlappyBird.selectionIndex < 1)
|
||||
FlappyBird.FlappyBird.selectionIndex++;
|
||||
else if (focusGravity && FlappyBird.FlappyBird.gravity > 0)
|
||||
FlappyBird.FlappyBird.gravity -= 0.01f;
|
||||
else if (focusHeight && FlappyBird.FlappyBird.spaceHeight > 2)
|
||||
FlappyBird.FlappyBird.spaceHeight -= 1;
|
||||
else if (focusJump && FlappyBird.FlappyBird.jumpVel > 0)
|
||||
FlappyBird.FlappyBird.jumpVel -= 0.01f;
|
||||
else if (debugIndex < 4 && !isFocused)
|
||||
debugIndex++;
|
||||
break;
|
||||
case "01-80-02-00":
|
||||
// Code for Arrow-Left Press
|
||||
// If in SnakeGame, Steer the Snake to the left
|
||||
if (isSnake)
|
||||
SnakeGame.SnakeGame.SteerLeft(SnakeGame.SnakeGame.self);
|
||||
// If in Tetris, move current Block to the left
|
||||
else if (isTetris)
|
||||
Tetris.Tetris.moveLeftSide();
|
||||
break;
|
||||
case "FF-7F-02-00":
|
||||
// Code for Arrow-Right Press
|
||||
// If in SnakeGame, Steer the Snake to the right
|
||||
if (isSnake)
|
||||
SnakeGame.SnakeGame.SteerRight(SnakeGame.SnakeGame.self);
|
||||
// If in Tetris, move current Block to the right
|
||||
else if (isTetris)
|
||||
Tetris.Tetris.moveRightSide();
|
||||
break;
|
||||
}
|
||||
Delegate method = BitConverter.ToString(buffer, 4, 4) switch {
|
||||
"01-00-01-00" => XButtonPressed,
|
||||
"01-00-01-01" => AButtonPressed,
|
||||
"01-00-01-02" => BButtonPressed,
|
||||
"01-00-01-04" => LButtonPressed,
|
||||
"01-00-01-05" => RButtonPressed,
|
||||
"01-00-01-09" => StartButtonPressed,
|
||||
"01-80-02-01" => UpArrowButtonPressed,
|
||||
"FF-7F-02-01" => DownArrowPressed,
|
||||
"01-80-02-00" => LeftArrowPressed,
|
||||
"FF-7F-02-00" => RightArrowPressed,
|
||||
_ => (string player) => {}
|
||||
};
|
||||
// Execute function mapped by buffer/button press as current player
|
||||
method.DynamicInvoke(file.Replace(dir, ""));
|
||||
}
|
||||
}
|
||||
|
||||
private static void RightArrowPressed(string player) {
|
||||
// Code for Arrow-Right Press
|
||||
// If in SnakeGame, Steer the Snake to the right
|
||||
if (isSnake) SnakeGame.SnakeGame.SteerRight(SnakeGame.SnakeGame.snakes[player]);
|
||||
// If in Tetris, move current Block to the right
|
||||
else if (isTetris) Tetris.Tetris.moveRightSide();
|
||||
}
|
||||
|
||||
private static void LeftArrowPressed(string player) {
|
||||
// Code for Arrow-Left Press
|
||||
// If in SnakeGame, Steer the Snake to the left
|
||||
if (isSnake) SnakeGame.SnakeGame.SteerLeft(SnakeGame.SnakeGame.snakes[player]);
|
||||
// If in Tetris, move current Block to the left
|
||||
else if (isTetris) Tetris.Tetris.moveLeftSide();
|
||||
}
|
||||
|
||||
private static void DownArrowPressed(string player) {
|
||||
// Code for Arrow-Down Press
|
||||
// If in the selection screen, decrement index
|
||||
if (!isInGame && selectionIndex < 4)
|
||||
selectionIndex++;
|
||||
// If in SnakeGame, Steer the Snake downwards
|
||||
else if (isSnake) {
|
||||
// Handle index in 'GameOver' Screen
|
||||
if (SnakeGame.SnakeGame.selection && SnakeGame.SnakeGame.selectionIndex < 1)
|
||||
SnakeGame.SnakeGame.selectionIndex++;
|
||||
// If in SnakeGame, Steer the Snake downwards
|
||||
else SnakeGame.SnakeGame.SteerDown(SnakeGame.SnakeGame.snakes[player]);
|
||||
// If in Tetris and in Tetris' 'GameOver' Screen, decrement its index.
|
||||
}
|
||||
else if (isTetris)
|
||||
// If in Tetris and in Tetris' 'GameOver' Screen, increment its index.
|
||||
if (Tetris.Tetris.selection && Tetris.Tetris.selectionIndex < 1)
|
||||
Tetris.Tetris.selectionIndex++;
|
||||
// Otherwise, move Tetris piece down
|
||||
else Tetris.Tetris.moveDownOnce();
|
||||
else if (isFlappy && FlappyBird.FlappyBird.selection && FlappyBird.FlappyBird.selectionIndex < 1)
|
||||
FlappyBird.FlappyBird.selectionIndex++;
|
||||
else if (focusGravity && FlappyBird.FlappyBird.gravity > 0)
|
||||
FlappyBird.FlappyBird.gravity -= 0.01f;
|
||||
else if (focusHeight && FlappyBird.FlappyBird.spaceHeight > 2)
|
||||
FlappyBird.FlappyBird.spaceHeight -= 1;
|
||||
else if (focusJump && FlappyBird.FlappyBird.jumpVel > 0)
|
||||
FlappyBird.FlappyBird.jumpVel -= 0.01f;
|
||||
else if (focusLength && SnakeGame.SnakeGame.baseLength > 0)
|
||||
SnakeGame.SnakeGame.baseLength -= 1;
|
||||
else if (debugIndex < 5 && !isFocused)
|
||||
debugIndex++;
|
||||
}
|
||||
|
||||
private static void UpArrowButtonPressed(string player) {
|
||||
// Code for Arrow-Up Press
|
||||
// If in the selection screen, decrement index
|
||||
if (!isInGame && selectionIndex > 0)
|
||||
selectionIndex--;
|
||||
else if (isSnake) {
|
||||
// Handle index in 'GameOver' Screen
|
||||
if (SnakeGame.SnakeGame.selection && SnakeGame.SnakeGame.selectionIndex > 0)
|
||||
SnakeGame.SnakeGame.selectionIndex--;
|
||||
// If in SnakeGame, Steer the Snake upwards
|
||||
else SnakeGame.SnakeGame.SteerUp(SnakeGame.SnakeGame.snakes[player]);
|
||||
// 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)
|
||||
FlappyBird.FlappyBird.selectionIndex--;
|
||||
else if (focusGravity)
|
||||
FlappyBird.FlappyBird.gravity += 0.01f;
|
||||
else if (focusHeight && FlappyBird.FlappyBird.spaceHeight < 58)
|
||||
FlappyBird.FlappyBird.spaceHeight += 1;
|
||||
else if (focusJump)
|
||||
FlappyBird.FlappyBird.jumpVel += 0.01f;
|
||||
else if (focusLength)
|
||||
SnakeGame.SnakeGame.baseLength += 1;
|
||||
else if (debugIndex > 0 && !isFocused)
|
||||
debugIndex--;
|
||||
}
|
||||
|
||||
private static void StartButtonPressed(string player) {
|
||||
// Code for Start-Button Press
|
||||
// If in SnakeGame, end the Game and return to menu
|
||||
if (isSnake)
|
||||
SnakeGame.SnakeGame.EndGame();
|
||||
else if (isFlappy) {
|
||||
// If in FlappyBirds' 'ready' Screen, return to menu
|
||||
if (!FlappyBird.FlappyBird.isReady)
|
||||
FlappyBird.FlappyBird.stopPlaying = true;
|
||||
// Otherwise go back to 'ready' Screen by ending the Game
|
||||
else {
|
||||
FlappyBird.FlappyBird.EndGame();
|
||||
FlappyBird.FlappyBird.selection = false;
|
||||
}
|
||||
// If in Tetris, end the Game and return to menu
|
||||
}
|
||||
else if (isTetris)
|
||||
Tetris.Tetris.EndGame();
|
||||
}
|
||||
|
||||
private static void RButtonPressed(string player) {
|
||||
// Code for R-Button Press
|
||||
// If in Tetris, rotate the current Block Clockwise
|
||||
if (isTetris) Tetris.Tetris.rotateClockwise();
|
||||
}
|
||||
|
||||
private static void LButtonPressed(string player) {
|
||||
// Code for L-Button Press
|
||||
// If in Tetris, rotate the current Block counter-Clockwise
|
||||
if (isTetris) Tetris.Tetris.rotateCounterClockwise();
|
||||
}
|
||||
|
||||
private static void BButtonPressed(string player) {
|
||||
// Code for B-Button Press
|
||||
if (isFlappy) {
|
||||
// Jump
|
||||
if (FlappyBird.FlappyBird.isReady)
|
||||
FlappyBird.FlappyBird.JumpOnce();
|
||||
// Start Game
|
||||
else FlappyBird.FlappyBird.isReady = true;
|
||||
// Place the current Block in Tetris
|
||||
}
|
||||
else if (isTetris)
|
||||
Tetris.Tetris.placeDownBlock();
|
||||
else if (!isSnake) {
|
||||
focusGravity = false;
|
||||
focusLength = false;
|
||||
focusHeight = false;
|
||||
focusJump = false;
|
||||
isFocused = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void AButtonPressed(string player) {
|
||||
// Code for A-Button Press
|
||||
// If not already in a Game, now ready up to select one.
|
||||
if (!isInGame)
|
||||
hasSelected = true;
|
||||
// Select given option in Tetris' 'GameOver' Screen
|
||||
else if (isSnake && SnakeGame.SnakeGame.selection)
|
||||
SnakeGame.SnakeGame.enterSelection();
|
||||
else if (isFlappy && FlappyBird.FlappyBird.selection)
|
||||
FlappyBird.FlappyBird.enterSelection();
|
||||
else if (isTetris && Tetris.Tetris.selection)
|
||||
Tetris.Tetris.enterSelection();
|
||||
else debugSelect = true;
|
||||
}
|
||||
|
||||
private static void XButtonPressed(string player) {
|
||||
// Code for X-Button Press
|
||||
if (isTetris) Tetris.Tetris.swapMemory();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user