![](/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: main.cpp
- Revision:
- 3:522c6f850e91
- Parent:
- 2:55092965eadd
- Child:
- 4:7ddd287a5d28
diff -r 55092965eadd -r 522c6f850e91 main.cpp --- a/main.cpp Sat May 23 13:59:06 2020 +0000 +++ b/main.cpp Sun May 24 11:18:33 2020 +0000 @@ -14,16 +14,29 @@ #include "mbed.h" #include "Gamepad.h" #include "N5110.h" +#include "TetrisGame.h" + +#define TETROMINO_WIDTH 4 +#define TETROMINO_HEIGHT 4 + +struct UserInput { + Direction d; + float mag; +}; + +N5110 lcd; +Gamepad pad; +TetrisGame tetris; + +void init(); +void update_game(UserInput input); +void render(); +void welcome(); -// objects -Gamepad pad; -N5110 lcd; - - -int ScreenHeight = 84; -int ScreenWidth = 48; -string block[7] // store tetromino blocks as a w-string +// int ScreenHeight = 84; +// int ScreenWidth = 48; +// string block[7] // store tetromino blocks as a w-string @@ -50,48 +63,51 @@ } */ -void title() +int main() { - using namespace std: + int fps = 6; - system("cls"); + init(); + welcome(); - cout << "--------------------------------------------------------\n"; + render(); + wait(1.0f/fps); - cout << "------- ------- ------- ------- --- -----\n"; - cout << " | | | | | | | ||n"; - cout << " | | | | | | |\n"; - cout << " | ----- | ------- | -----\n"; - cout << " | | | | | | |\n"; - cout << " | | | | | | | |\n"; - cout << " | ------- | | | --- -----\n"; + while(1) { + tetris.read_input(pad); + tetris.update(pad); + render(); + wait(1.0f/fps); + } +} + +void init() +{ + lcd.init(); + padinit(); - cout << "\t<menu>\n"; - cout << "\t1: Start Game\n\t2: Quit\n\n"; - - cout << "---------------------------------------------------------\n"; + tetris.init(TETROMINO_WIDTH, TETROMINO_HEIGHT); } -int GameOver() +void render() { - using namespace std; - - char a; - cout << " ----- - - - ------- ------- - - -------- ------\n"; - cout << "| | | | || || | | | | | | | |\n"; - cout << "| | | | | | | | | | | | | | |\n"; - cout << "| ---- | | | | | ----- | | | | ------ ------\n"; - cout << "| | |-----| | | | | | | | | | |\n"; - cout << "| | | | | | | | | | | | | |\n"; - cout << " ----- | | | | ------- ------- | -------- | |\n"; - cout << "\n\nPress any key\n"; - - return 0; -} -int main() -{ - - + lcd.clear(); + tetris.draw(lcd); + lcd.refresh(); } +void welcome() { + + lcd.printString(" TETRIS ",0,1); + lcd.printString(" Press Start ",0,4); + lcd.refresh(); + + while (pad.start_pressed() == false) { + lcd.setContrast(pad.read_pot1()); + pad.leds_on(); + wait(0.1); + pad.leds_off(); + wait(0.1); + } +} \ No newline at end of file