![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All there but errors need fixing
Diff: main.cpp
- Revision:
- 3:522c6f850e91
- Parent:
- 2:55092965eadd
- Child:
- 4:7ddd287a5d28
--- 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