![](/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:
- 11:0183a52c1077
- Parent:
- 10:7310c9440547
- Child:
- 12:965b39a2e049
diff -r 7310c9440547 -r 0183a52c1077 TetrisGame/TetrisGame.cpp --- a/TetrisGame/TetrisGame.cpp Mon Jun 01 21:02:52 2020 +0000 +++ b/TetrisGame/TetrisGame.cpp Mon Jun 01 22:14:34 2020 +0000 @@ -10,18 +10,18 @@ } -void TetrisGame::init(int tetromino_height, int tetromino_width, int speed) +void TetrisGame::init(int speed) { // initialise game parameters - _tetromino_height = tetromino_height; - _tetromino_width = tetromino_width; -// _px = WIDTH/2 - _tetromino_width/2; -// _py = HEIGHT; +// _tetromino_height = tetromino_height; +// _tetromino_width = tetromino_width; + _px = 40; + _py = 4; _speed = speed; - _tetromino.init(_x, _y); // puts tetromino in middle SHOULD THIS INCLUDE ARRAY???? + _tetromino.init(_px, _py); // puts tetromino in middle SHOULD THIS INCLUDE ARRAY???? - printf("initiate(%i,%i,%i)\n",_tetromino_height,_tetromino_width,_speed); + printf("initiate(%i)\n",_speed); } @@ -41,7 +41,7 @@ _tetromino.draw(lcd); - printf("draw (%i,%i)\n",_x,_y); + printf("draw (%i,%i)\n",_px,_py); } @@ -49,13 +49,12 @@ { // check_score(pad); - // _p1.update(_d,_mag); _tetromino.update(_d,_mag); check_wall_collision(pad, lcd); check_tetromino_collisions(pad, lcd); - printf("update (%i,%i)\n",_x,_y); + printf("update (%i,%i,%i)\n",_px,_py,_d); } @@ -65,9 +64,9 @@ Vector2D tetromino_velocity = _tetromino.get_velocity(); // check if hit floor - if (tetromino_pos.y + _tetromino_height >= (HEIGHT-1) ) { + if (tetromino_pos.y + 4 >= (HEIGHT-1) ) { - tetromino_pos.y = (HEIGHT-1) - _tetromino_height; + tetromino_pos.y = (HEIGHT-1) - 4; tetromino_velocity.y = 0; pad.tone(750.0,0.1); @@ -76,12 +75,16 @@ lcd.drawRect(tetromino_pos.x, tetromino_pos.y, 4, 4, FILL_BLACK); - _tetromino.init(_x, _y); // drop new shame + _tetromino.init(_px, _py); // drop new shame + + printf("floor hit!\n"); } // check if hit roof else if (tetromino_pos.y <= 1) { + printf("roof hit!\n"); + exit_game(lcd); } @@ -110,7 +113,9 @@ lcd.drawRect(tetromino_pos.x, tetromino_pos.y, 4, 4, FILL_BLACK); - _tetromino.init(_tetromino_width, _tetromino_height); // break to loop back or keep this ?? + _tetromino.init(_px, _py); // break to loop back or keep this ?? + + printf("blocks stacked!\n"); } printf("tetromino collision\n"); }