mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-24 06:49:24 -05:00
Fixed Tetris by eliminating some classes (#1890)
This commit is contained in:
parent
2f48fc2ef9
commit
1800939833
6
firmware/application/external/external.cmake
vendored
6
firmware/application/external/external.cmake
vendored
@ -5,8 +5,8 @@ set(EXTCPPSRC
|
|||||||
# external/pacman/ui_pacman.cpp
|
# external/pacman/ui_pacman.cpp
|
||||||
|
|
||||||
#tetris
|
#tetris
|
||||||
# external/tetris/main.cpp
|
external/tetris/main.cpp
|
||||||
# external/tetris/ui_tetris.cpp
|
external/tetris/ui_tetris.cpp
|
||||||
|
|
||||||
#afsk_rx
|
#afsk_rx
|
||||||
external/afsk_rx/main.cpp
|
external/afsk_rx/main.cpp
|
||||||
@ -79,5 +79,5 @@ set(EXTAPPLIST
|
|||||||
gpssim
|
gpssim
|
||||||
spainter
|
spainter
|
||||||
keyfob
|
keyfob
|
||||||
# tetris
|
tetris
|
||||||
)
|
)
|
||||||
|
@ -56,35 +56,43 @@ static const Color pp_colors[] = {
|
|||||||
Color::black(),
|
Color::black(),
|
||||||
};
|
};
|
||||||
|
|
||||||
class SPI_TFT_ILI9341 {
|
// NB: ELIMINATED SPI_TFT_ILI9341 DISPLAY CLASS DUE TO GLOBAL OBJECT INITIALIZATION ISSUE WITH EXTERNAL APPS
|
||||||
public:
|
|
||||||
SPI_TFT_ILI9341(int, int, int, int, int, int, std::string) { (void)0; };
|
|
||||||
|
|
||||||
void claim(__FILE* x) { (void)x; };
|
static void claim(__FILE* x) {
|
||||||
|
(void)x;
|
||||||
|
};
|
||||||
|
|
||||||
void cls() {
|
static void cls() {
|
||||||
painter.fill_rectangle({0, 0, portapack::display.width(), portapack::display.height()}, Color::black());
|
painter.fill_rectangle({0, 0, portapack::display.width(), portapack::display.height()}, Color::black());
|
||||||
};
|
};
|
||||||
|
|
||||||
void background(int color) { bg_color = color; };
|
static void background(int color) {
|
||||||
void foreground(int color) { fg_color = color; };
|
bg_color = color;
|
||||||
|
};
|
||||||
|
|
||||||
void locate(int x, int y) {
|
static void foreground(int color) {
|
||||||
x_pos = x;
|
fg_color = color;
|
||||||
y_pos = y;
|
};
|
||||||
};
|
|
||||||
void set_orientation(int x) { (void)x; };
|
|
||||||
void set_font(unsigned char* x) { (void)x; };
|
|
||||||
|
|
||||||
void fillrect(int x1, int y1, int x2, int y2, int color) {
|
static void locate(int x, int y) {
|
||||||
painter.fill_rectangle({x1, y1, x2 - x1, y2 - y1}, pp_colors[color]);
|
x_pos = x;
|
||||||
};
|
y_pos = y;
|
||||||
|
};
|
||||||
|
|
||||||
void rect(int x1, int y1, int x2, int y2, int color) {
|
static void set_orientation(int x) {
|
||||||
painter.draw_rectangle({x1, y1, x2 - x1, y2 - y1}, pp_colors[color]);
|
(void)x;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
static void set_font(unsigned char* x) {
|
||||||
|
(void)x;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void fillrect(int x1, int y1, int x2, int y2, int color) {
|
||||||
|
painter.fill_rectangle({x1, y1, x2 - x1, y2 - y1}, pp_colors[color]);
|
||||||
|
};
|
||||||
|
|
||||||
|
static void rect(int x1, int y1, int x2, int y2, int color) {
|
||||||
|
painter.draw_rectangle({x1, y1, x2 - x1, y2 - y1}, pp_colors[color]);
|
||||||
};
|
};
|
||||||
|
|
||||||
static void printf(std::string str) {
|
static void printf(std::string str) {
|
||||||
|
2
firmware/application/external/tetris/mbed.h
vendored
2
firmware/application/external/tetris/mbed.h
vendored
@ -67,7 +67,7 @@ static bool but_DOWN;
|
|||||||
static bool but_SELECT;
|
static bool but_SELECT;
|
||||||
|
|
||||||
//
|
//
|
||||||
// AnalogIn Class -- DID NOT WORK BECAUSE INITIALIZER CODE WON'T EXECUTE -- hacked original code module instead
|
// AnalogIn Class -- DID NOT WORK DUE TO GLOBAL OBJECT INITIALIZER ISSUE WITH EXTERNAL APPS -- hacked original code module instead
|
||||||
//
|
//
|
||||||
// dp9 = joystick rotate button --> select button
|
// dp9 = joystick rotate button --> select button
|
||||||
// dp10 = joystick y --> up & down buttons
|
// dp10 = joystick y --> up & down buttons
|
||||||
|
188
firmware/application/external/tetris/tetris.cpp
vendored
188
firmware/application/external/tetris/tetris.cpp
vendored
@ -4,9 +4,15 @@
|
|||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
//////// PORTAPACK CHANGES HIGHLIGHTED
|
//////// HACKED FOR PORTAPACK -- CHANGES HIGHLIGHTED
|
||||||
int main();
|
int main();
|
||||||
void pause_game();
|
void pause_game();
|
||||||
|
void Initialize(unsigned char c);
|
||||||
|
void DeleteFigure();
|
||||||
|
void DrawFigure();
|
||||||
|
bool InCollisionDown(char delta);
|
||||||
|
bool InCollisionLeft();
|
||||||
|
bool InCollisionRight();
|
||||||
//////// PORTAPACK
|
//////// PORTAPACK
|
||||||
|
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
@ -15,32 +21,29 @@ void pause_game();
|
|||||||
|
|
||||||
#define dp23 P0_0
|
#define dp23 P0_0
|
||||||
|
|
||||||
|
//////// PORTAPACK - DISABLED MOST CLASSES DUE TO GLOBAL OBJECT INITIALIZER ISSUE WITH EXTERNAL APPS:
|
||||||
//deklaracija display-a
|
//deklaracija display-a
|
||||||
SPI_TFT_ILI9341 display(dp2, dp1, dp6, dp24, dp23, dp25, "TFT");
|
//SPI_TFT_ILI9341 display(dp2, dp1, dp6, dp24, dp23, dp25, "TFT");
|
||||||
|
//
|
||||||
//////// PORTAPACK - DISABLED ANALOGIN CLASS DUE TO OBJECT INITIALIZER CODE NOT RUNNING:
|
|
||||||
//analogni ulazi za joystick
|
//analogni ulazi za joystick
|
||||||
// AnalogIn VRx(dp11);
|
// AnalogIn VRx(dp11);
|
||||||
// AnalogIn VRy(dp10);
|
// AnalogIn VRy(dp10);
|
||||||
|
//
|
||||||
|
// AnalogIn random(dp13); //analogni ulaz za generisanje random vrijednosti
|
||||||
//////// PORTAPACK
|
//////// PORTAPACK
|
||||||
|
|
||||||
//taster na joysticku za rotaciju
|
//taster na joysticku za rotaciju
|
||||||
InterruptIn taster(dp9);
|
InterruptIn taster(dp9);
|
||||||
|
|
||||||
//////// PORTAPACK - DISABLED ANALOGIN CLASS DUE TO OBJECT INITIALIZER CODE NOT RUNNING:
|
|
||||||
// AnalogIn random(dp13); //analogni ulaz za generisanje random vrijednosti
|
|
||||||
//////// PORTAPACK
|
|
||||||
|
|
||||||
//ticker za spustanje figure
|
//ticker za spustanje figure
|
||||||
//timer za debouncing tastera na joysticku
|
//timer za debouncing tastera na joysticku
|
||||||
Ticker game, joystick;
|
Ticker game, joystick;
|
||||||
Timer debounceTaster;
|
Timer debounceTaster;
|
||||||
|
|
||||||
|
|
||||||
unsigned char level = 0; //mora biti tipa usigned char jer inače se može desiti da level bude manji od 0, a i da ne trošimo memoriju
|
unsigned char level = 0; //mora biti tipa usigned char jer inače se može desiti da level bude manji od 0, a i da ne trošimo memoriju
|
||||||
const float delays[4] = {1.2, 0.7, 0.4, 0.25}; //svakih koliko se spusti jedan red, ovo provjeriti da li je presporo ili prebrzo, ovisi o levelu
|
const float delays[4] = {1.2, 0.7, 0.4, 0.25}; //svakih koliko se spusti jedan red, ovo provjeriti da li je presporo ili prebrzo, ovisi o levelu
|
||||||
|
|
||||||
//////// PORTAPACK - UNNEEDED JOYSTICK HYSTERESIS VARIABLES
|
//////// PORTAPACK - DELETED UNNEEDED JOYSTICK HYSTERESIS VARIABLES
|
||||||
//char leftBoundary = 1, rightBoundary = 5, downBoundary = 1, upBoundary = 5;// sada je ovo tipa char
|
//char leftBoundary = 1, rightBoundary = 5, downBoundary = 1, upBoundary = 5;// sada je ovo tipa char
|
||||||
//////// PORTAPACK
|
//////// PORTAPACK
|
||||||
|
|
||||||
@ -49,7 +52,6 @@ bool firstTime = true; //ako je prvi put, figura se crta u Tickeru
|
|||||||
bool gameStarted = false;
|
bool gameStarted = false;
|
||||||
unsigned char nextFigure = 1; //ovo je sad globalna varijabla, da bi mogli unaprijed generisati sljedeću figuru radi prikaza
|
unsigned char nextFigure = 1; //ovo je sad globalna varijabla, da bi mogli unaprijed generisati sljedeću figuru radi prikaza
|
||||||
|
|
||||||
|
|
||||||
//white - no figure
|
//white - no figure
|
||||||
//I - BLUE
|
//I - BLUE
|
||||||
//O - YELLOW
|
//O - YELLOW
|
||||||
@ -69,81 +71,70 @@ short figuresY[7][4] = {{0,1,2,3}, {1,0,0,1}, {1,1,2,0}, {0,1,1,2}, {0,1,1,2}, {
|
|||||||
unsigned int GenerateRandomSeed() {
|
unsigned int GenerateRandomSeed() {
|
||||||
//////// PORTAPACK - USE RTC FOR SEED
|
//////// PORTAPACK - USE RTC FOR SEED
|
||||||
return LPC_RTC->CTIME0;
|
return LPC_RTC->CTIME0;
|
||||||
// unsigned int randomNumber = 0;
|
|
||||||
// for(int i = 0; i <= 32; i += 2) {
|
|
||||||
// randomNumber += ((random.read_u16() % 3) << i);
|
|
||||||
// wait_us(10);
|
|
||||||
// }
|
|
||||||
// return randomNumber;
|
|
||||||
//////// PORTAPACK
|
//////// PORTAPACK
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init() {
|
void Init() {
|
||||||
//ovo su zajedničke osobine za sve prikaze na display-u
|
//ovo su zajedničke osobine za sve prikaze na display-u
|
||||||
//nikad se ne mijenjaju i pozvat ćemo je jednom prije petlje
|
//nikad se ne mijenjaju i pozvat ćemo je jednom prije petlje
|
||||||
display.claim(stdout);
|
claim(stdout);
|
||||||
display.set_orientation(2); // 2 ili 0, zavisi kako okrenemo display, provjerit ćemo na labu kako nam je najlakše povezat
|
set_orientation(2); // 2 ili 0, zavisi kako okrenemo display, provjerit ćemo na labu kako nam je najlakše povezat
|
||||||
display.set_font((unsigned char*) Arial12x12);
|
set_font((unsigned char*) Arial12x12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ShowScore() {
|
void ShowScore() {
|
||||||
//pomocna funkcija za prikazivanje score-a
|
//pomocna funkcija za prikazivanje score-a
|
||||||
display.fillrect(165, 20, 235, 50, White); //popunimo pravugaonik da obrišemo stari score
|
fillrect(165, 20, 235, 50, White); //popunimo pravugaonik da obrišemo stari score
|
||||||
display.locate(200, 35); //valjda je na sredini pravougaonika
|
locate(200, 35); //valjda je na sredini pravougaonika
|
||||||
printf("%d", score);
|
printf("%d", score);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowNextFigure() {
|
void ShowNextFigure() {
|
||||||
//prikaz sljedeće figure koristeći pomoćnu varijablu nextFigure
|
//prikaz sljedeće figure koristeći pomoćnu varijablu nextFigure
|
||||||
display.fillrect(165, 70, 235, 120, White);
|
fillrect(165, 70, 235, 120, White);
|
||||||
int upperLeftX = 176, upperLeftY = 83;
|
int upperLeftX = 176, upperLeftY = 83;
|
||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++) {
|
||||||
int x = upperLeftX + DIMENSION_NEXT * figuresY[nextFigure - 1][i], y = upperLeftY + DIMENSION_NEXT * figuresX[nextFigure - 1][i];
|
int x = upperLeftX + DIMENSION_NEXT * figuresY[nextFigure - 1][i], y = upperLeftY + DIMENSION_NEXT * figuresX[nextFigure - 1][i];
|
||||||
display.fillrect(x, y, x + DIMENSION_NEXT, y + DIMENSION_NEXT, colors[nextFigure]);
|
fillrect(x, y, x + DIMENSION_NEXT, y + DIMENSION_NEXT, colors[nextFigure]);
|
||||||
display.rect(x, y, x + DIMENSION_NEXT, y + DIMENSION_NEXT, Black);
|
rect(x, y, x + DIMENSION_NEXT, y + DIMENSION_NEXT, Black);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//funkcija za crtanje cursora za odabir levela
|
//funkcija za crtanje cursora za odabir levela
|
||||||
void DrawCursor(int color, unsigned char lev) {
|
void DrawCursor(int color, unsigned char lev) {
|
||||||
display.fillrect(60, lev * 70 + 50, 72, lev * 70 + 50 + 12, color);
|
fillrect(60, lev * 70 + 50, 72, lev * 70 + 50 + 12, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PORTAPACK - ADDED EXTRA LEVEL:
|
// PORTAPACK - ADDED EXTRA LEVEL:
|
||||||
void ShowLevelMenu() {
|
void ShowLevelMenu() {
|
||||||
//ovdje inicijalizujemo display
|
//ovdje inicijalizujemo display
|
||||||
display.cls(); // brišemo prethodno
|
cls(); // brišemo prethodno
|
||||||
display.background(Black);
|
background(Black);
|
||||||
display.foreground(White);
|
foreground(White);
|
||||||
display.locate(80, 50);
|
locate(80, 50);
|
||||||
printf("LEVEL 1");
|
printf("LEVEL 1");
|
||||||
display.locate(80, 120);
|
locate(80, 120);
|
||||||
printf("LEVEL 2");
|
printf("LEVEL 2");
|
||||||
display.locate(80, 190);
|
locate(80, 190);
|
||||||
printf("LEVEL 3");
|
printf("LEVEL 3");
|
||||||
display.locate(80, 260);
|
locate(80, 260);
|
||||||
printf("LEVEL 4");
|
printf("LEVEL 4");
|
||||||
DrawCursor(White, level);
|
DrawCursor(White, level);
|
||||||
}
|
}
|
||||||
|
//////// PORTAPACK
|
||||||
|
|
||||||
//////// PORTAPACK - KLUDGED FOR BUTTONS VS JOYSTICK:
|
//////// PORTAPACK - USE BUTTONS VS JOYSTICK:
|
||||||
void ReadJoystickForLevel(){
|
void ReadJoystickForLevel(){
|
||||||
unsigned char old = level;
|
unsigned char old = level;
|
||||||
if(but_UP){
|
if(but_UP){
|
||||||
// upBoundary = 4;
|
|
||||||
(level == 0) ? level = 3 : level--;
|
(level == 0) ? level = 3 : level--;
|
||||||
}
|
}
|
||||||
else if(but_DOWN){
|
else if(but_DOWN){
|
||||||
//ne radi ona prethodna varijanta jer % vraća i negastivni rezultat
|
//ne radi ona prethodna varijanta jer % vraća i negastivni rezultat
|
||||||
//to što ne koristimo unsigned tip ne pomaže jer će doći do overflow-a
|
//to što ne koristimo unsigned tip ne pomaže jer će doći do overflow-a
|
||||||
// downBoundary = 2;
|
|
||||||
level = (level + 1) % 4;
|
level = (level + 1) % 4;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// downBoundary = 1;
|
|
||||||
// upBoundary = 5;
|
|
||||||
}
|
|
||||||
DrawCursor(Black, old); //na prethodni level popunimo bojom pozadine
|
DrawCursor(Black, old); //na prethodni level popunimo bojom pozadine
|
||||||
DrawCursor(White, level); //na novi level popunimo bijelom bojom - pozadina je crna
|
DrawCursor(White, level); //na novi level popunimo bijelom bojom - pozadina je crna
|
||||||
//koristio sam fillrect, jer njega svakako moramo koristiti, jer možda budemo morali da brišemo fillcircle iz biblioteke
|
//koristio sam fillrect, jer njega svakako moramo koristiti, jer možda budemo morali da brišemo fillcircle iz biblioteke
|
||||||
@ -169,11 +160,11 @@ main();
|
|||||||
|
|
||||||
void StartGame()
|
void StartGame()
|
||||||
{
|
{
|
||||||
display.cls(); // brišemo ShowLevelMenu
|
cls(); // brišemo ShowLevelMenu
|
||||||
display.background(White);
|
background(White);
|
||||||
display.foreground(Black);
|
foreground(Black);
|
||||||
display.fillrect(0, 0, 160, 320, White);
|
fillrect(0, 0, 160, 320, White);
|
||||||
display.fillrect(160, 0, 240, 320, Black); //dio za prikazivanje rezultata će biti crni pravougaonik, a tabla je bijeli
|
fillrect(160, 0, 240, 320, Black); //dio za prikazivanje rezultata će biti crni pravougaonik, a tabla je bijeli
|
||||||
ShowScore();
|
ShowScore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,34 +197,34 @@ void PutBorders(short x, short y) {
|
|||||||
for(int i = x - 1; i <= x + 1; i++) {
|
for(int i = x - 1; i <= x + 1; i++) {
|
||||||
for(int j = y - 1; j <= y + 1; j++) {
|
for(int j = y - 1; j <= y + 1; j++) {
|
||||||
if(i < 0 || i > 9 || j < 0 || j > 19 || board[j][i] == 0) continue;
|
if(i < 0 || i > 9 || j < 0 || j > 19 || board[j][i] == 0) continue;
|
||||||
display.rect(i * DIMENSION, j * DIMENSION, (i + 1) * DIMENSION, (j + 1) * DIMENSION, Black);
|
rect(i * DIMENSION, j * DIMENSION, (i + 1) * DIMENSION, (j + 1) * DIMENSION, Black);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Tetromino{
|
//////// PORTAPACK - ELIMINATED CLASSES DUE TO GLOBAL OBJECT INITIALIZATION ISSUE WITH EXTERNAL APPS:
|
||||||
private:
|
//class Tetromino{
|
||||||
|
//private:
|
||||||
short X[4];
|
short X[4];
|
||||||
short Y[4];
|
short Y[4];
|
||||||
short boardX, boardY;
|
short boardX, boardY;
|
||||||
unsigned char colorIndex;//dodao sam colorIndex zasad, jer nema drugog načina da popunimo matricu sa indeksima boja
|
unsigned char colorIndex;//dodao sam colorIndex zasad, jer nema drugog načina da popunimo matricu sa indeksima boja
|
||||||
//ovo je najbezbolnija varijanta što se memorije tiče
|
//ovo je najbezbolnija varijanta što se memorije tiče
|
||||||
public:
|
//public:
|
||||||
Tetromino(){
|
// Tetromino(){
|
||||||
//////// PORTAPACK - NOTE - DEFAULT INITIALIZER CODE DOESN'T GET EXECUTED FOR SOME REASON:
|
// unsigned char r = rand() % 7 + 1;
|
||||||
unsigned char r = rand() % 7 + 1;
|
// Initialize(r);
|
||||||
Initialize(r);
|
// }
|
||||||
|
|
||||||
|
void Tetromino(unsigned char c) {
|
||||||
|
Initialize(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tetromino(unsigned char colorIndex) {
|
void Initialize(unsigned char c) {
|
||||||
Initialize(colorIndex);
|
colorIndex = c;
|
||||||
}
|
|
||||||
|
|
||||||
void Initialize(unsigned char colorIndex) {
|
|
||||||
Tetromino::colorIndex = colorIndex;
|
|
||||||
boardX = 0;
|
boardX = 0;
|
||||||
boardY = 4; //3,4 ili 5 najbolje da vidimo kad imamo display
|
boardY = 4; //3,4 ili 5 najbolje da vidimo kad imamo display
|
||||||
copyCoordinates(X, Y, colorIndex - 1);
|
copyCoordinates(X, Y, c - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rotate(){
|
void Rotate(){
|
||||||
@ -266,13 +257,9 @@ public:
|
|||||||
//stavio sam 16 za početak, možemo se opet skontati na labu
|
//stavio sam 16 za početak, možemo se opet skontati na labu
|
||||||
//ovo pretpostavlja da nema margina, mogu se lagano dodati uz neku konstantu kao offset
|
//ovo pretpostavlja da nema margina, mogu se lagano dodati uz neku konstantu kao offset
|
||||||
int upperLeftX = (boardX + X[i]) * DIMENSION, upperLeftY = (boardY + Y[i]) * DIMENSION;
|
int upperLeftX = (boardX + X[i]) * DIMENSION, upperLeftY = (boardY + Y[i]) * DIMENSION;
|
||||||
display.fillrect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, colors[colorIndex]);
|
fillrect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, colors[colorIndex]);
|
||||||
//ovo boji granice blokova u crno, možemo skloniti ako ti se ne sviđa
|
//ovo boji granice blokova u crno, možemo skloniti ako ti se ne sviđa
|
||||||
|
rect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, Black);
|
||||||
//////// PORTAPACK - HIDE DEFAULT WHITE BLOCK (ALTERNATE KLUDGE FOR TETRONIMO INITIALIZATION CODE NOT RUNNING AT CONSTRUCTION)
|
|
||||||
if (colorIndex != White)
|
|
||||||
//////// PORTAPACK
|
|
||||||
display.rect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, Black);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +267,7 @@ if (colorIndex != White)
|
|||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++) {
|
||||||
//ista logika kao u DrawFigure, samo popunjavamo sve blokove sa bijelim pravougaonicima
|
//ista logika kao u DrawFigure, samo popunjavamo sve blokove sa bijelim pravougaonicima
|
||||||
short upperLeftX = (boardX + X[i]) * DIMENSION, upperLeftY = (boardY + Y[i]) * DIMENSION;
|
short upperLeftX = (boardX + X[i]) * DIMENSION, upperLeftY = (boardY + Y[i]) * DIMENSION;
|
||||||
display.fillrect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, White);
|
fillrect( upperLeftY, upperLeftX, upperLeftY + DIMENSION, upperLeftX + DIMENSION, White);
|
||||||
PutBorders(upperLeftY, upperLeftX);
|
PutBorders(upperLeftY, upperLeftX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,9 +282,6 @@ if (colorIndex != White)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MoveDown(char delta = 1){
|
bool MoveDown(char delta = 1){
|
||||||
//////// PORTAPACK - MOVE DEFAULT WHITE BLOCK TO BOTTOM IMMEDIATELY (ALTERNATE KLUDGE FOR TETRONIMO INITIALIZATION CODE NOT RUNNING AT CONSTRUCTION)
|
|
||||||
if (colorIndex == White) delta = 19;
|
|
||||||
//////// PORTAPACK
|
|
||||||
if(!InCollisionDown(delta)){
|
if(!InCollisionDown(delta)){
|
||||||
DeleteFigure();
|
DeleteFigure();
|
||||||
boardX+=delta;
|
boardX+=delta;
|
||||||
@ -384,34 +368,23 @@ if (colorIndex == White) delta = 19;
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
// };
|
||||||
|
|
||||||
|
// Tetromino currentTetromino;
|
||||||
|
|
||||||
Tetromino currentTetromino;
|
//////// PORTAPACK - USE BUTTONS VS JOYSTICK, AND ADDED PAUSE FEATURE:
|
||||||
|
|
||||||
//////// PORTAPACK - KLUDGED FOR BUTTONS VS JOYSTICK:
|
|
||||||
void ReadJoystickForFigure() {
|
void ReadJoystickForFigure() {
|
||||||
if(but_LEFT) {
|
if(but_LEFT) {
|
||||||
// leftBoundary = 2;
|
MoveLeft();
|
||||||
currentTetromino.MoveLeft();
|
|
||||||
}
|
}
|
||||||
else if(but_RIGHT) {
|
else if(but_RIGHT) {
|
||||||
// rightBoundary = 4;
|
MoveRight();
|
||||||
currentTetromino.MoveRight();
|
|
||||||
}
|
}
|
||||||
else if(but_UP) {
|
else if(but_UP) {
|
||||||
// downBoundary = 2;
|
pause_game();
|
||||||
pause_game();
|
|
||||||
}
|
}
|
||||||
else if(but_DOWN) {
|
else if(but_DOWN) {
|
||||||
// upBoundary = 4;
|
SoftDrop();
|
||||||
currentTetromino.SoftDrop();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// leftBoundary = 1;
|
|
||||||
// rightBoundary = 5;
|
|
||||||
// downBoundary = 1;
|
|
||||||
// upBoundary = 5;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//////// PORTAPACK
|
//////// PORTAPACK
|
||||||
@ -460,10 +433,10 @@ void UpdateBoard()
|
|||||||
board[i][j] = board[i - numberOfLines][j];
|
board[i][j] = board[i - numberOfLines][j];
|
||||||
board[i - numberOfLines][j] = 0;
|
board[i - numberOfLines][j] = 0;
|
||||||
short tmp = i - numberOfLines;
|
short tmp = i - numberOfLines;
|
||||||
display.fillrect( j * DIMENSION,i * DIMENSION, (j + 1) * DIMENSION , (i + 1) * DIMENSION , colors[board[i][j]]); // bojimo novi blok
|
fillrect( j * DIMENSION,i * DIMENSION, (j + 1) * DIMENSION , (i + 1) * DIMENSION , colors[board[i][j]]); // bojimo novi blok
|
||||||
display.fillrect( j * DIMENSION, tmp * DIMENSION,(j + 1) * DIMENSION, (tmp + 1) * DIMENSION , White);
|
fillrect( j * DIMENSION, tmp * DIMENSION,(j + 1) * DIMENSION, (tmp + 1) * DIMENSION , White);
|
||||||
if(board[i][j] != 0)
|
if(board[i][j] != 0)
|
||||||
display.rect( j * DIMENSION,i * DIMENSION, (j + 1) * DIMENSION , (i + 1) * DIMENSION , Black);
|
rect( j * DIMENSION,i * DIMENSION, (j + 1) * DIMENSION , (i + 1) * DIMENSION , Black);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
score += UpdateScore(numberOfLines);
|
score += UpdateScore(numberOfLines);
|
||||||
@ -480,26 +453,23 @@ bool IsOver() {
|
|||||||
|
|
||||||
void ShowGameOverScreen() {
|
void ShowGameOverScreen() {
|
||||||
//////// PORTAPACK - SKIP CLS
|
//////// PORTAPACK - SKIP CLS
|
||||||
// display.cls();
|
// cls();
|
||||||
// display.background(Black);
|
// background(Black);
|
||||||
// display.foreground(White);
|
// foreground(White);
|
||||||
display.background(White);
|
background(White);
|
||||||
display.foreground(Black);
|
foreground(Black);
|
||||||
//////// PORTAPACK
|
//////// PORTAPACK
|
||||||
display.locate(60, 120);
|
locate(60, 120);
|
||||||
printf("GAME OVER");
|
printf("GAME OVER");
|
||||||
display.locate(40, 150);
|
locate(40, 150);
|
||||||
printf("YOUR SCORE IS %d", score);
|
printf("YOUR SCORE IS %d", score);
|
||||||
wait(5); //ovaj prikaz traje 3s (možemo mijenjati) a nakon toga se ponovo prikazuje meni sa levelima
|
wait(5); //ovaj prikaz traje 3s (možemo mijenjati) a nakon toga se ponovo prikazuje meni sa levelima
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitGame() {
|
void InitGame() {
|
||||||
if(firstTime) {
|
if(firstTime) {
|
||||||
//////// PORTAPACK - NOTE - ATTEMPTED WORKAROUND FOR SKIPPED INITIALIZER CODE - BUT ANY OF THESE CRASHES FIRMWARE AT POWER-UP EVEN IF THERE'S NO TETRIS APP INSTALLED:
|
Tetromino(rand() % 7 + 1);
|
||||||
// currentTetromino = Tetromino(rand() % 7 + 1); // TEST #1
|
DrawFigure();
|
||||||
// currentTetromino.Initialize(rand() % 7 + 1); // TEST #2
|
|
||||||
//////// PORTAPACK
|
|
||||||
currentTetromino.DrawFigure();
|
|
||||||
nextFigure = rand() % 7 + 1;
|
nextFigure = rand() % 7 + 1;
|
||||||
ShowNextFigure();
|
ShowNextFigure();
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
@ -508,13 +478,13 @@ void InitGame() {
|
|||||||
|
|
||||||
void PlayGame(){
|
void PlayGame(){
|
||||||
InitGame();
|
InitGame();
|
||||||
if(!currentTetromino.MoveDown()){
|
if(!MoveDown()){
|
||||||
currentTetromino.OnAttached();
|
OnAttached();
|
||||||
UpdateBoard();
|
UpdateBoard();
|
||||||
ShowScore();
|
ShowScore();
|
||||||
|
|
||||||
currentTetromino = Tetromino(nextFigure);
|
Tetromino(nextFigure);
|
||||||
currentTetromino.DrawFigure();
|
DrawFigure();
|
||||||
nextFigure = rand() % 7 + 1;
|
nextFigure = rand() % 7 + 1;
|
||||||
ShowNextFigure();
|
ShowNextFigure();
|
||||||
if(IsOver()) {
|
if(IsOver()) {
|
||||||
@ -531,7 +501,7 @@ void PlayGame(){
|
|||||||
void OnTasterPressed(){
|
void OnTasterPressed(){
|
||||||
if(debounceTaster.read_ms() > 200) {
|
if(debounceTaster.read_ms() > 200) {
|
||||||
if(gameStarted){
|
if(gameStarted){
|
||||||
currentTetromino.Rotate();
|
Rotate();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
joystick.detach();
|
joystick.detach();
|
||||||
@ -568,7 +538,7 @@ return 0;
|
|||||||
void pause_game() {
|
void pause_game() {
|
||||||
game.detach();
|
game.detach();
|
||||||
joystick.detach();
|
joystick.detach();
|
||||||
display.locate(180, 200);
|
locate(180, 200);
|
||||||
printf("PAUSED");
|
printf("PAUSED");
|
||||||
while ((get_switches_state().to_ulong() & 0x10) == 0); // wait for SELECT button to resume
|
while ((get_switches_state().to_ulong() & 0x10) == 0); // wait for SELECT button to resume
|
||||||
printf(" ");
|
printf(" ");
|
||||||
|
Loading…
Reference in New Issue
Block a user