![](/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:
- 25:a7c89c54454a
- Parent:
- 24:8868a01f4a8c
- Child:
- 26:00e1a6076038
diff -r 8868a01f4a8c -r a7c89c54454a TetrisGame/TetrisGame.cpp --- a/TetrisGame/TetrisGame.cpp Wed Jun 03 20:09:57 2020 +0000 +++ b/TetrisGame/TetrisGame.cpp Wed Jun 03 22:26:13 2020 +0000 @@ -19,6 +19,7 @@ _px = 40; _py = 4; _speed = speed; + score = 1; _tetromino.init(_px, _py); // puts tetromino in middle @@ -39,9 +40,11 @@ lcd.drawRect(19, 4, 42, HEIGHT - 4, FILL_TRANSPARENT); + print_scores(lcd); + _tetromino.draw(lcd); - print_scores(lcd); + // printf("draw (%i,%i)\n",_px,_py); @@ -52,6 +55,8 @@ _tetromino.update(_d,_mag); + check_score(pad); + check_wall_collision(pad, lcd); // check if block has collided with the floor check_tetromino_collisions(pad, lcd); // check if block has collided with an old block @@ -69,6 +74,8 @@ pad.tone(750.0,0.1); // play tone + score++; + cancel_line(lcd); // check if row is full _tetromino.init(_px, _py); // drop new shame @@ -100,6 +107,9 @@ ) { pad.tone(1000.0,0.1); // play tone + + score++; + cancel_line(lcd); // check if row is full _tetromino.init(_px, _py); // drop new block @@ -140,14 +150,6 @@ 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"); -// } -// } } } // printf("cancel line\n"); @@ -195,20 +197,31 @@ for (int i=0; i<=iB; i++) { z0 = Z[i]; q0 = Q[i]; - lcd.drawRect(20, z0, 40, 4, FILL_WHITE); + lcd.drawRect(20, z0, 40, 4, FILL_WHITE); // clear rectagle over where the full row is + } + currentscreen(lcd); + for (int x=20; x<=60; x++) { + for (int y=c; y>=0; y--) { // screen above row that was removed + if (buffer[x][y]) { // buffer of screen + lcd.setPixel(x,y, false); // remove pixel + lcd.setPixel(x,y+4); // replace with pixel above it + } + } } } -void TetrisGame::print_scores(N5110 &lcd) +void TetrisGame::print_scores(N5110 &lcd) // print score on screen { - char buffer[15]; - sprintf(buffer,"%d",_score); - lcd.printString(buffer, WIDTH - 20, 10); + char Sbuffer[14]; + int n, _score = score; + n=sprintf (Sbuffer, "%d",_score); +// printf ("[%s] is a string %d chars long\n",Sbuffer,n); + lcd.printString(Sbuffer,65,3); } -void TetrisGame::check_score(Gamepad &pad) +void TetrisGame::check_score(Gamepad &pad) // update scores { if ( clear_line_flag == 1) { - _score+=10; + score+=10; } } \ No newline at end of file