Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 ///////// pre-processor directives //////// 00002 #include "mbed.h" 00003 #include "Gamepad.h" 00004 #include "N5110.h" 00005 #include "Touch.h" 00006 #include "Bitmap.h" 00007 #ifdef WITH_TESTING 00008 # include "tests.h" 00009 #endif 00010 00011 #define BOARD_WIDTH 2 00012 #define BOARD_LENGTH 8 00013 #define BULLET_SIZE 2 00014 #define BULLET_SPEED 3 00015 00016 /////////////// structs ///////////////// 00017 struct UserInput { 00018 Direction d; 00019 float mag; 00020 }; 00021 /////////////// objects /////////////// 00022 N5110 lcd; 00023 Gamepad pad; 00024 Touch touch; 00025 ///////////// prototypes /////////////// 00026 void init(); 00027 void update_game(UserInput input); 00028 void render(); 00029 void welcome(); 00030 00031 ///////////// functions //////////////// 00032 int main() 00033 { 00034 #ifdef WITH_TESTING 00035 int number_of_failures = run_all_tests(); 00036 //test part 00037 if(number_of_failures > 0) return number_of_failures; 00038 #endif 00039 int fps = 6; // frames per second 00040 init(); // initialise 00041 welcome(); // welcome screen for user to start 00042 render(); // first draw the initial frame 00043 wait(1.0f/fps); // and wait for one frame period 00044 pad.leds_on(); //turn on all leds as 'lives' showing 00045 00046 00047 while (1) //while loop, execute reading, updating, drawing,juding part frequentrly 00048 { 00049 touch.reading(pad); 00050 touch.update(pad,lcd); 00051 render(); 00052 if(touch._leds>=6) 00053 { 00054 break; // if all lives finish , you will lsot game 00055 } 00056 wait(1.0f/fps); 00057 } 00058 lcd.init(); 00059 pad.init(); 00060 lcd.printString(" You fail ",0,1); 00061 lcd.printString(" Press reset ",0,4); // the reminder of game lost 00062 lcd.refresh(); //function to refresh the display 00063 } 00064 00065 // initialies all classes and libraries 00066 void init() 00067 { 00068 lcd.init(); 00069 pad.init(); 00070 touch.init(BOARD_WIDTH,BOARD_LENGTH,BULLET_SIZE,BULLET_SPEED,lcd); 00071 } 00072 //clearing record before and drawing frames 00073 void render() 00074 { 00075 00076 lcd.clear(); 00077 touch.draw(lcd); 00078 lcd.refresh(); 00079 } 00080 //welcome screen 00081 void welcome() { 00082 00083 lcd.printString(" touch! ",0,1); 00084 lcd.printString(" Press Start ",0,4); 00085 lcd.refresh(); 00086 00087 // wait flashing LEDs until start button is pressed 00088 while ( pad.start_pressed() == false) { 00089 lcd.setContrast( pad.read_pot1()); 00090 pad.leds_on(); 00091 wait(0.1); 00092 pad.leds_off(); 00093 wait(0.1); 00094 } 00095 00096 }
Generated on Mon Jul 18 2022 10:48:25 by
1.7.2