Przemek Wirkus
/
MBEDtetris
Simple tetris game to show usage of C12832 LCD.
Revision 3:dbd1976e4add, committed 2014-03-18
- Comitter:
- PrzemekWirkus
- Date:
- Tue Mar 18 16:55:43 2014 +0000
- Parent:
- 2:da22b028cf2e
- Commit message:
- Working version. No game features implemented yet. Next: full line cut.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mtrix.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r da22b028cf2e -r dbd1976e4add main.cpp --- a/main.cpp Tue Mar 18 10:03:03 2014 +0000 +++ b/main.cpp Tue Mar 18 16:55:43 2014 +0000 @@ -15,32 +15,47 @@ #define JOY_KEY_UP 4 #define JOY_KEY_DOWN 8 -#define BOUNCER_SIZE 2 - -bool KEYS[4] = {false, false, false, false}; +#define BOUNCER_SIZE 4 int main() { // Welcome message lcd.cls(); - + + std::pair<int, int> brick_prev_pos = game.get_brick_pos(); + clock_t t1, t2; + while(1) { - clock_t t1, t2; t1 = clock(); int joy_key = joy.read(); switch (joy_key) { case JOY_KEY_LEFT: { game.try_move_left(); break; } case JOY_KEY_RIGHT: { game.try_move_right(); break; } - case JOY_KEY_UP: { game.try_rotate(); break; } - case JOY_KEY_DOWN: { game.move_brick_down(); break; } + case JOY_KEY_UP: { game.try_rotate(); break; } + case JOY_KEY_DOWN: { game.move_brick_down(); break; } } - + + // Erase prev brick from screen + for (int x = 0; x < BRICK_SIZE_X; x++) + { + for (int y = 0; y < BRICK_SIZE_Y; y++) + { + int color = game.get_brick_cell(x, y); + { + int draw_pix_x = (brick_prev_pos.first + x) * BOUNCER_SIZE; + int draw_pix_y = (brick_prev_pos.second + y) * BOUNCER_SIZE; + lcd.rect(draw_pix_y, draw_pix_x, draw_pix_y+BOUNCER_SIZE-1, draw_pix_x+BOUNCER_SIZE-1, 0); + } + } + } + // PRINT MATRIX for (int x = 0; x < LCD_W; x++) { for (int y = 0; y < LCD_H; y++) - { + { + // This should be replaces with just 'putpixel on LCD' int draw_pix_x = x*BOUNCER_SIZE; int draw_pix_y = y*BOUNCER_SIZE; @@ -53,32 +68,36 @@ else { //lcd.rect(draw_pix_x, draw_pix_y, draw_pix_x+BOUNCER_SIZE-1, draw_pix_y+BOUNCER_SIZE-1, 0); - lcd.rect(draw_pix_y, draw_pix_x, draw_pix_y+BOUNCER_SIZE-1, draw_pix_x+BOUNCER_SIZE-1, 0); + // lcd.rect(draw_pix_y, draw_pix_x, draw_pix_y+BOUNCER_SIZE-1, draw_pix_x+BOUNCER_SIZE-1, 0); } } } - + // PRINT BRICK for (int x = 0; x < BRICK_SIZE_X; x++) { for (int y = 0; y < BRICK_SIZE_Y; y++) { - if (game.get_brick_cell(x, y)) + int color = game.get_brick_cell(x, y); + if (color) { std::pair<int, int> brick_pos = game.get_brick_pos(); int draw_pix_x = (brick_pos.first + x) * BOUNCER_SIZE; int draw_pix_y = (brick_pos.second + y) * BOUNCER_SIZE; //lcd.rect(draw_pix_x, draw_pix_y, draw_pix_x+BOUNCER_SIZE-1, draw_pix_y+BOUNCER_SIZE-1, 1); - lcd.rect(draw_pix_y, draw_pix_x, draw_pix_y+BOUNCER_SIZE-1, draw_pix_x+BOUNCER_SIZE-1, 1); + lcd.rect(draw_pix_y, draw_pix_x, draw_pix_y+BOUNCER_SIZE-1, draw_pix_x+BOUNCER_SIZE-1, color); } } } lcd.copy_to_lcd(); + + brick_prev_pos = game.get_brick_pos(); + game.move_brick_down(); t2 = clock(); float diff = (((float)t2 - (float)t1) / CLOCKS_PER_SEC ); - wait(diff); + wait(0.2); } }
diff -r da22b028cf2e -r dbd1976e4add mtrix.h --- a/mtrix.h Tue Mar 18 10:03:03 2014 +0000 +++ b/mtrix.h Tue Mar 18 16:55:43 2014 +0000 @@ -4,8 +4,8 @@ #include <string> #include <utility> -#define LCD_W 16 -#define LCD_H 20 +#define LCD_W 8 +#define LCD_H 24 #define BRICK_SIZE_X 4 #define BRICK_SIZE_Y 4