zhangxinyu01text
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 ///////// pre-processor directives //////// 00002 #include "mbed.h" 00003 #include "Gamepad.h" 00004 #include "N5110.h" 00005 #include "cxkEngine.h" 00006 00007 #ifdef WITH_TESTING 00008 # include "tests.h" 00009 #endif 00010 00011 /* ELEC2645 Embeeded System Project 00012 School of Elctronic & Electrical Enigneering 00013 University of Leeds 00014 00015 Name : Zhang Xinyu 00016 Username : Zhang Xin yu 00017 Student ID number : 201090208 00018 Date : 2019. 05.6 00019 00020 */ 00021 00022 00023 /////////////// structs ///////////////// 00024 struct UserInput { 00025 Direction d; 00026 float vara; // vara is the magnitude of the joystich 00027 }; 00028 00029 /////////////// objects /////////////// 00030 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); 00031 Gamepad pad; 00032 cxkEngine basketball; 00033 00034 ///////////// prototypes define the void /////////////// 00035 void init(); 00036 void update_game(UserInput input); 00037 void render();// main contain 00038 void welcome(); 00039 void over(); 00040 00041 ///////////// functions //////////////// 00042 int main() 00043 { 00044 00045 int fps = 8; // frames 8k per second 00046 00047 init(); // initialise and then display welcome screen... 00048 welcome(); // waiting for the user to start 00049 00050 render(); // first draw the initial frame 00051 wait(1.0f/fps); // and wait for one frame period 00052 00053 00054 // game loop - read input, update the game state and render the display 00055 while (1) { 00056 basketball.read_input(pad); 00057 basketball.update(pad); 00058 render(); 00059 wait(1.0f/fps); 00060 } 00061 } 00062 00063 // initialies all classes and libraries 00064 void init() 00065 { 00066 // need to initialise LCD and Gamepad 00067 lcd.init(); 00068 pad.init(); 00069 00070 // initialise the game with correct ball and paddle sizes 00071 basketball.init(2,8,2,3); 00072 00073 } 00074 00075 // this function draws each frame on the LCD 00076 void render() 00077 { 00078 // clear screen, re-draw and refresh 00079 lcd.clear(); 00080 basketball.draw(lcd); 00081 lcd.refresh(); 00082 } 00083 00084 // simple splash screen displayed on start-up 00085 void welcome() { 00086 00087 lcd.printString(" U beautiful",0,1); 00088 lcd.printString("zhang xinyu",0,2); 00089 lcd.printString(" Press Start ",0,4); 00090 lcd.refresh(); 00091 00092 // wait flashing LEDs until start button is pressed 00093 while ( pad.check_event(Gamepad::START_PRESSED) == false) { 00094 pad.leds_on(); 00095 wait(0.1); 00096 pad.leds_off(); 00097 wait(0.1); 00098 } 00099 00100 }
Generated on Mon Feb 20 2023 02:55:49 by
1.7.2