All there but errors need fixing
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* 00002 ELEC2645 Embedded Systems Project 00003 School of Electronic & Electrical Engineering 00004 University of Leeds 00005 2019/20 00006 00007 Name: Ruby Smith 00008 Username: el18rs 00009 Student ID Number: 201259470 00010 Date: 22/05/20 00011 */ 00012 00013 // includes 00014 #include "mbed.h" 00015 #include "Gamepad.h" 00016 #include "N5110.h" 00017 #include "TetrisGame.h" 00018 00019 // set defaults 00020 #define TETROMINO_WIDTH 4 00021 #define TETROMINO_HEIGHT 4 00022 // #define TETROMINO_SIZE 4 00023 #define TETROMINO_SPEED 1 00024 #define HEIGHT 48 00025 #define WIDTH 84 00026 // STRUCTS // 00027 00028 struct UserInput { 00029 Direction d; 00030 float mag; 00031 }; 00032 00033 // OBJECTS // 00034 00035 N5110 lcd; 00036 Gamepad pad; 00037 TetrisGame tetris; 00038 00039 // PROTOTYPES // 00040 00041 void init(); 00042 void update_game(UserInput input); 00043 void render(); 00044 void welcome(); 00045 void exit_game(); 00046 void cancel_line(); 00047 int score = 0; 00048 00049 // int ScreenHeight = 84; 00050 // int ScreenWidth = 48; 00051 00052 // FUNCTIONS // 00053 00054 int main() 00055 { 00056 int fps = 6; // 6 frames per second 00057 00058 init(); // initialise and display welcome screen 00059 welcome(); // wait for user to press start 00060 00061 render(); // draw initial frame 00062 wait(1.0f/fps); // wait one frame period 00063 00064 // game loop 00065 while(1) { 00066 tetris.read_input(pad); // read input 00067 tetris.update(pad); 00068 //play_game(); // update game state 00069 render(); // render the display 00070 wait(1.0f/fps); // wait one frame period 00071 break; 00072 00073 } 00074 } 00075 00076 void exit_game() { 00077 lcd.clear(); 00078 lcd.printString(" GAME OVER ",0, 3); 00079 lcd.refresh(); 00080 wait(10); 00081 lcd.clear(); 00082 lcd.printString(" press RESET ",0,6); 00083 lcd.refresh(); 00084 exit(1.0); 00085 } 00086 00087 00088 void cancel_line() { 00089 int count; 00090 for(int j=0; j<=46; j+=1) { 00091 for(int i=0; i<=82; i++) { 00092 if (lcd.getPixel(i,j)==0) { 00093 count=0; 00094 break; 00095 } else if (lcd.getPixel(i,j)==1){ 00096 count ++; 00097 } 00098 } 00099 if(count==83) { 00100 count = 0; 00101 lcd.drawLine(0,j,82,j,0); // clear line 00102 score++; 00103 for(int x=0; x<=82; x++) { 00104 for(int y=j; y>=0; y--) { 00105 lcd.setPixel(x,y,false); 00106 lcd.setPixel(x,y+1); 00107 } 00108 } 00109 } 00110 } 00111 00112 00113 } 00114 00115 00116 // initialise classes and libraries 00117 void init() { 00118 lcd.init(); // initialise lcd 00119 pad.init(); // initialise Gamepad 00120 00121 // initialise the game with correct tetromino sizes etc 00122 tetris.init(0, WIDTH/2 - 2, HEIGHT, 1); 00123 00124 } 00125 00126 void render() { // draws each frame on the lcd 00127 00128 lcd.clear(); // clear screen 00129 tetris.draw(lcd); // re-draw 00130 lcd.refresh(); // refresh screen 00131 } 00132 00133 // welcome screen display 00134 void welcome() { 00135 00136 lcd.printString(" TETRIS ",0,1); 00137 lcd.printString(" Press Start ",0,4); 00138 lcd.refresh(); 00139 00140 // flash LEDs untile start button pressed 00141 while (pad.start_pressed() == false) { 00142 lcd.setContrast(pad.read_pot1()); 00143 pad.leds_on(); 00144 wait(0.1); 00145 pad.leds_off(); 00146 wait(0.1); 00147 } 00148 }
Generated on Wed Jul 13 2022 22:47:28 by
1.7.2