![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
All there but errors need fixing
Dependencies: mbed
Overview:
Rookie Tetris is a jigsaw style game based on the classic Tetris.
A block will appear at the top of the screen, you must move it (your options for movement are left, right and down - you cannot move up the board). The block will stop when it if placed either on the floor of the board or on-top of another block.
Your goal is to fill a complete row of the board with the blocks; when you do so the row will delete and the pattern above it will drop down. The game is over when your pattern is tall enough to reach to the top of the board!
Controls:
Use the joystick to move your block! Your block cannot move out of the parameters of the board.
Pot 2 controls the contrast of the screen.
Diff: TetrisGame/TetrisGame.cpp
- Revision:
- 22:403759d2f093
- Parent:
- 21:6d4dd906edde
- Child:
- 23:cbfa9d1ee3db
diff -r 6d4dd906edde -r 403759d2f093 TetrisGame/TetrisGame.cpp --- a/TetrisGame/TetrisGame.cpp Wed Jun 03 13:34:52 2020 +0000 +++ b/TetrisGame/TetrisGame.cpp Wed Jun 03 16:44:09 2020 +0000 @@ -1,6 +1,7 @@ #include "TetrisGame.h" volatile int iH; +volatile int iB; TetrisGame::TetrisGame() { @@ -26,7 +27,7 @@ } -void TetrisGame::read_input(Gamepad &pad) // read inputs +void TetrisGame::read_input(Gamepad &pad) // read inputs { _d = pad.get_direction(); _mag = pad.get_mag(); @@ -44,7 +45,7 @@ } -void TetrisGame::update(Gamepad &pad, N5110 &lcd) // update values +void TetrisGame::update(Gamepad &pad, N5110 &lcd) // update values { // check_score(pad); @@ -61,13 +62,13 @@ { Vector2D tetromino_pos = _tetromino.get_pos(); // get current positioning of block - if (tetromino_pos.y + 4 >= (HEIGHT-1) ) { // if bottom of block is on bottom boundary + if (tetromino_pos.y + 4 >= (HEIGHT-1) ) { // if bottom of block is on bottom boundary tetromino_pos.y = (HEIGHT-1) - 4; // stop block - pad.tone(750.0,0.1); // play tone + pad.tone(750.0,0.1); // play tone - cancel_line(lcd); // check if row is full + cancel_line(lcd); // check if row is full _tetromino.init(_px, _py); // drop new shame @@ -75,9 +76,9 @@ b = tetromino_pos.y; floor_hit_flag = 1; // set flag so program knows to draw block on next screen - - if (b <= 4) { // if pattern reaches top of screen - exit_game(lcd); // game over + + if (b <= 4) { // if pattern reaches top of screen + exit_game(lcd); // game over } printf("floor hit!\n"); @@ -86,18 +87,18 @@ // printf("wall collision\n"); } -void TetrisGame::check_tetromino_collisions(Gamepad &pad, N5110 &lcd) // check if block has old block beneath it +void TetrisGame::check_tetromino_collisions(Gamepad &pad, N5110 &lcd) // check if block has old block beneath it { Vector2D tetromino_pos = _tetromino.get_pos(); // get current position of block if ( - (lcd.getPixel(tetromino_pos.x, tetromino_pos.y + 4) == 1) || + (lcd.getPixel(tetromino_pos.x, tetromino_pos.y + 4) == 1) || (lcd.getPixel(tetromino_pos.x + 1, tetromino_pos.y + 4) == 1) || (lcd.getPixel(tetromino_pos.x + 2, tetromino_pos.y + 4) == 1) || - (lcd.getPixel(tetromino_pos.x + 3, tetromino_pos.y + 4) == 1) // if any of the 4 pixels directly below the block are black + (lcd.getPixel(tetromino_pos.x + 3, tetromino_pos.y + 4) == 1) // if any of the 4 pixels directly below the block are black ) { - pad.tone(1000.0,0.1); // play tone + pad.tone(1000.0,0.1); // play tone cancel_line(lcd); // check if row is full _tetromino.init(_px, _py); // drop new block @@ -106,9 +107,9 @@ b = tetromino_pos.y; floor_hit_flag = 1; // set flag so program knows to draw block on next screen - - if (b <= 4) { // if pattern reaches top of screen - exit_game(lcd); // game over + + if (b <= 4) { // if pattern reaches top of screen + exit_game(lcd); // game over } printf("blocks stacked!\n"); @@ -116,34 +117,38 @@ // printf("tetromino collision\n"); } -void TetrisGame::cancel_line(N5110 &lcd) // check if row is full, if it is then delete line and drop pattern down +void TetrisGame::cancel_line(N5110 &lcd) // check if row is full, if it is then delete line and drop pattern down { - int count; - for(int j=4; j<=46; j++) { + for(int j=4; j<=46; j++) { for(int i=20; i<=60; i++) { if (lcd.getPixel(i,j)==0) { // if the pixel is empty the counting stops and exits loop (row is not full) count=0; + printf("line not full\n"); break; - } else if (lcd.getPixel(i,j)==1) { // if the pixel is full carries on counting + } else if (lcd.getPixel(i,j)==1) { // if the pixel is full carries on counting count ++; + printf("counting... count=%i\n",count); } - } - if(count==61) { // if gets to end of line - count = 0; - lcd.drawLine(20,j,60,j,0); // clear line - printf("line canceled!\n"); + if (count==48) { // if gets to end of line + count = 0; + printf("line full\n"); +// lcd.drawRect(20,j,40,4,FILL_WHITE); // clear line + c = j; + clear_line_flag = 1; + floor_hit_flag = 0; + printf("line canceled!\n"); + } // score++; - for(int x=20; x<=60; x++) { - for(int y=j; y>=4; y--) { - lcd.setPixel(x,y,false); - lcd.setPixel(x,y+1); // sets pixel to the one above - printf("line dropped!\n"); - } - } +// for(int x=20; x<=60; x++) { +// for(int y=j; y>=4; y--) { +// lcd.setPixel(x,y,false); +// lcd.setPixel(x,y+1); // sets pixel to the one above +// printf("line dropped!\n"); +// } +// } } } -// printf("cancel line\n"); - + printf("cancel line\n"); } void TetrisGame::exit_game(N5110 &lcd) @@ -168,4 +173,12 @@ lcd.drawRect(x0, y0, 4, 4, FILL_BLACK); // printf("block drawn\n"); } +} + +void TetrisGame::clearline(N5110 &lcd, int iP) +{ + for (int i=0; i<=iB; i++) { + z0 = Z[i]; + lcd.drawRect(20, z0, 40, 4, FILL_WHITE); + } } \ No newline at end of file