Prettyfication

Is that even a word?
No more french, no more useless comment, no more endless switch at beginning
This commit is contained in:
Geoffrey Frogeye 2014-04-05 17:03:58 +02:00
parent 1c49459f95
commit a1301e94a0
3 changed files with 56 additions and 110 deletions

BIN
2048.G1A

Binary file not shown.

160
2048.c
View file

@ -4,25 +4,22 @@
// Sprites // Sprites
// Tiles 13*13 char tile[14][26] = {{127,240,213, 88,170,168,213, 88,170,168,213, 88,170,168,213, 88,170,168,213, 88,170,168,213, 88,127,240},
char tile0[] = {127,240,213,88,170,168,213,88,170,168,213,88,170,168,213,88,170,168,213,88,170,168,213,88,127,240}; // Vide {127,240,128, 8,128, 8,135, 8,136,136,128,136,129, 8,130, 8,132, 8,143,136,128, 8,128, 8,127,240},
char tile1[] = {127,240,128,8,128,8,135,8,136,136,128,136,129,8,130,8,132,8,143,136,128,8,128,8,127,240}; // 2 {127,240,128, 8,128, 8,129, 8,131, 8,133, 8,137, 8,143,136,129, 8,129, 8,128, 8,128, 8,127,240},
char tile2[] = {127,240,128,8,128,8,129,8,131,8,133,8,137,8,143,136,129,8,129,8,128,8,128,8,127,240}; // 4 {127,240,128, 8,128, 8,135, 8,136,136,136,136,135, 8,136,136,136,136,135, 8,128, 8,128, 8,127,240},
char tile3[] = {127,240,128,8,128,8,135,8,136,136,136,136,135,8,136,136,136,136,135,8,128,8,128,8,127,240}; // 8 {127,240,128, 8,128, 8,144,200,177, 8,146, 8,147,200,146, 40,146, 40,185,200,128, 8,128, 8,127,240},
char tile4[] = {127,240,128,8,128,8,144,200,177,8,146,8,147,200,146,40,146,40,185,200,128,8,128,8,127,240}; // 16 {127,240,128, 8,128, 8,128, 8,184,200,133, 40,152, 72,132,136,185,232,128, 8,128, 8,128, 8,127,240},
char tile5[] = {127,240,128,8,128,8,128,8,184,200,133,40,152,72,132,136,185,232,128,8,128,8,128,8,127,240}; // 32 {127,240,128, 8,128, 8,128, 8,152,104,160,168,185, 40,165,232,152, 40,128, 8,128, 8,128, 8,127,240},
char tile6[] = {127,240,128,8,128,8,128,8,152,104,160,168,185,40,165,232,152,40,128,8,128,8,128,8,127,240}; // 64 {127,240,253,248,249,248,253,248,253,248,248,248,255,248,231, 56,218,216,247, 56,238,216,195, 56,127,240},
char tile7[] = {127,240,253,248,249,248,253,248,253,248,248,248,255,248,231,56,218,216,247,56,238,216,195,56,127,240}; // 128 {127,240,249,248,246,248,253,248,251,248,240,248,255,248,195, 56,222,248,194, 56,250,216,199, 56,127,240},
char tile8[] = {127,240,249,248,246,248,253,248,251,248,240,248,255,248,195,56,222,248,194,56,250,216,199,56,127,240}; // 256 {127,240,240,248,247,248,240,248,254,248,241,248,255,248,247, 56,230,216,247,184,247,120,226, 24,127,240},
char tile9[] = {127,240,240,248,247,248,240,248,254,248,241,248,255,248,247,56,230,216,247,184,247,120,226,24,127,240}; // 512 {127,240,247, 56,230,216,246,216,246,216,227, 56,255,248,231,152,219, 88,246,216,238, 24,195,216,127,240},
char tile10[] = {127,240,247,56,230,216,246,216,246,216,227,56,255,248,231,152,219,88,246,216,238,24,195,216,127,240}; // 1024 {127,240,231, 56,218,216,246,216,238,216,195, 56,255,248,243, 56,234,216,219, 56,194,216,251, 56,127,240},
char tile11[] = {127,240,231,56,218,216,246,216,238,216,195,56,255,248,243,56,234,216,219,56,194,216,251,56,127,240}; // 2048 {127,240,255,248,255,248,248,248,247,120,255,120,254,248,253,248,255,248,253,248,255,248,255,248,127,240},
char tile12[] = {127,240,255,248,255,248,248,248,247,120,255,120,254,248,253,248,255,248,253,248,255,248,255,248,127,240}; // 4096 {127,240,255,248,255,248,253,248,253,248,253,248,253,248,253,248,255,248,253,248,255,248,255,248,127,240}};
char tile13[] = {127,240,255,248,255,248,253,248,253,248,253,248,253,248,253,248,255,248,253,248,255,248,255,248,127,240}; // WTF
// Autre
char scoreBG[] = {63,255,255,255,254,0,127,255,255,255,255,0,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,127,255,255,255,255,0,63,255,255,255,254,0}; // 41*19 char scoreBG[] = {63,255,255,255,254,0,127,255,255,255,255,0,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,255,255,255,255,255,128,127,255,255,255,255,0,63,255,255,255,254,0}; // 41*19
// Déclare les booléens ><
#define false 0 #define false 0
#define true 1 #define true 1
typedef char bool; typedef char bool;
@ -60,7 +57,7 @@ bool Game_won = false;
bool Game_terminated = false; bool Game_terminated = false;
bool Game_keepPlaying = true; bool Game_keepPlaying = true;
int storage_bestScore = 6357; int storage_bestScore = 0;
Grid Grid_grid; Grid Grid_grid;
@ -70,10 +67,8 @@ int rand_int(int min, int max) {
} }
int drawFixedTiles() { int drawFixedTiles() {
// Variables
int x, y; int x, y;
// Éxecution
for (x = 0; x <= 3; x++) { for (x = 0; x <= 3; x++) {
for (y = 0; y <= 3; y++) { for (y = 0; y <= 3; y++) {
drawTileCase(Grid_grid.array[x][y]); drawTileCase(Grid_grid.array[x][y]);
@ -82,47 +77,7 @@ int drawFixedTiles() {
} }
int drawTile(int x, int y, int value) { int drawTile(int x, int y, int value) {
ML_rectangle(x + 1, y + 1, x + 11, y + 11, 0, ML_TRANSPARENT, ML_WHITE); ML_rectangle(x + 1, y + 1, x + 11, y + 11, 0, ML_TRANSPARENT, ML_WHITE);
switch (value) { ML_bmp_or(tile[value], x, y, 13, 13);
case 0:
ML_bmp_or(tile0, x, y, 13, 13);
break;
case 1:
ML_bmp_or(tile1, x, y, 13, 13);
break;
case 2:
ML_bmp_or(tile2, x, y, 13, 13);
break;
case 3:
ML_bmp_or(tile3, x, y, 13, 13);
break;
case 4:
ML_bmp_or(tile4, x, y, 13, 13);
break;
case 5:
ML_bmp_or(tile5, x, y, 13, 13);
break;
case 6:
ML_bmp_or(tile6, x, y, 13, 13);
break;
case 7:
ML_bmp_or(tile7, x, y, 13, 13);
break;
case 8:
ML_bmp_or(tile8, x, y, 13, 13);
break;
case 9:
ML_bmp_or(tile9, x, y, 13, 13);
break;
case 10:
ML_bmp_or(tile10, x, y, 13, 13);
break;
case 11:
ML_bmp_or(tile11, x, y, 13, 13);
break;
default:
ML_bmp_or(tile12, x, y, 13, 13);
break;
}
} }
int drawTileCase(Tile tile) { int drawTileCase(Tile tile) {
@ -131,7 +86,7 @@ int drawTileCase(Tile tile) {
// Grid // Grid
bool Grid_withinBounds(Cell position) { // En abuser bool Grid_withinBounds(Cell position) {
return (position.x >= 0 && position.x < 4 && position.y >= 0 && position.y < 4); return (position.x >= 0 && position.x < 4 && position.y >= 0 && position.y < 4);
} }
@ -149,7 +104,7 @@ bool Grid_cellOccupied(Cell cell) {
return (Grid_cellContent(cell).value > 0); return (Grid_cellContent(cell).value > 0);
} }
bool Grid_cellAvailable(Cell cell) { // Pareil bool Grid_cellAvailable(Cell cell) {
return !Grid_cellOccupied(cell); return !Grid_cellOccupied(cell);
} }
@ -195,11 +150,11 @@ void storage_setBestScore(int bestScore) {
// Screen (O HTML_Actuator) // Screen (O HTML_Actuator)
void Screen_updateScore() { void Screen_updateScore() {
// Affiche le score à l'écran
} }
void Screen_updateBestScore() { void Screen_updateBestScore() {
// Affiche le meilleur score à l'écran
} }
void Screen_message(bool won) { void Screen_message(bool won) {
@ -228,12 +183,6 @@ void Screen_actuate() {
ML_display_vram(); ML_display_vram();
} }
Cell convertNumber2Pos(int number) {
Cell position;
position.x = number/4;
position.x = number%4;
}
// Game (O Game_manager) // Game (O Game_manager)
bool Game_isGameTerminated() { bool Game_isGameTerminated() {
@ -323,7 +272,7 @@ Cell Grid_randomAvaiableCell() {
avaiableCellsNumber = Grid_avaiableCellsAmount(); avaiableCellsNumber = Grid_avaiableCellsAmount();
choosenCellNumber = rand_int(1, avaiableCellsNumber); choosenCellNumber = rand_int(1, avaiableCellsNumber);
avaiableCellsNumber = 0; // Sert de compteur ici avaiableCellsNumber = 0; // Used as counter here
for (x = 0; x <= 3; x++) { for (x = 0; x <= 3; x++) {
for (y = 0; y <= 3; y++) { for (y = 0; y <= 3; y++) {
position.x = x; position.x = x;
@ -418,7 +367,7 @@ int initGame() {
ML_clear_screen(); ML_clear_screen();
// Draw Titre // Draw Title
PrintXY(67, 54, "2048", 0); PrintXY(67, 54, "2048", 0);
// Reset variables // Reset variables
@ -457,43 +406,41 @@ int AddIn_main(int isAppli, unsigned short OptionNum) {
// Variables // Variables
unsigned int key; unsigned int key;
while (1) { // Tant qu'on joue... initGame();
initGame(); while (1) { // Main loop
while (1) { // Boucle des mouvements GetKey(&key);
GetKey(&key); switch (key) {
switch (key) { case KEY_CTRL_UP:
case KEY_CTRL_UP: Game_move(0);
Game_move(0); break;
break; case KEY_CTRL_RIGHT:
case KEY_CTRL_RIGHT: Game_move(1);
Game_move(1); break;
break; case KEY_CTRL_DOWN:
case KEY_CTRL_DOWN: Game_move(2);
Game_move(2); break;
break; case KEY_CTRL_LEFT:
case KEY_CTRL_LEFT: Game_move(3);
Game_move(3); break;
break; case KEY_CTRL_DEL:
case KEY_CTRL_DEL: initGame();
initGame(); break;
break; case KEY_CHAR_PLUS: // DEBUG
case KEY_CHAR_PLUS: Game_addRandomTile();
Game_addRandomTile(); Game_actuate();
Game_actuate(); break;
break; case KEY_CHAR_STORE: // DEBUG
case KEY_CHAR_STORE: Game_actuate();
Game_actuate(); break;
break; default:
default: break;
break; }
}
}
} }
return 1; return 1; // 1 is OK here
} }
// Code propre au SDK. NE PAS MODIFIER ! // Exclusive code to any Add-in
#pragma section _BR_Size #pragma section _BR_Size
unsigned long BR_Size; unsigned long BR_Size;
@ -507,4 +454,3 @@ int InitializeSystem(int isAppli, unsigned short OptionNum) {
} }
#pragma section #pragma section

View file

@ -2,7 +2,7 @@
[_1] [_1]
Type=5 Type=5
Order=2 Order=1
Top=60 Top=60
Left=1965 Left=1965
Height=10080 Height=10080
@ -14,7 +14,7 @@ OptionA=0
[_2] [_2]
Type=1 Type=1
Order=0 Order=2
Top=0 Top=0
Left=12645 Left=12645
Height=4665 Height=4665
@ -92,7 +92,7 @@ OptionA=0
[_9] [_9]
Type=15 Type=15
Order=1 Order=0
Top=0 Top=0
Left=2010 Left=2010
Height=11580 Height=11580