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.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 #include "Gamepad.h" 00003 #include "N5110.h" 00004 #include "SnakeEngine.h" 00005 00006 00007 00008 #define FOOD_X 20 00009 #define FOOD_Y 20 00010 #define SNAKE_P_X 42 00011 #define SNAKE_P_Y 24 00012 #define IN E 00013 #define CUR E 00014 #define SPAWN_TIME 200 00015 00016 #ifndef WITH_TESTING 00017 #include "tests.h" 00018 //#endif 00019 00020 struct UserInput 00021 { 00022 00023 Direction d; 00024 00025 }; 00026 00027 00028 /* 00029 ELEC2645 Embedded Systems Project 00030 School of Electronic & Electrical Engineering 00031 University of Leeds 00032 Name: Joshua Robert Marshall 00033 Username: ll13jrm 00034 Student ID Number: 200764543 00035 Date: 28/02/2018 00036 */ 00037 00038 // ----- Objects ----- 00039 00040 SnakeEngine snake_engine; 00041 Gamepad pad; 00042 Snake snake; 00043 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); 00044 //Testing test1; 00045 00046 // ----- Prototypes ----- 00047 00048 void init(); 00049 void update_game(UserInput input); 00050 void render(); 00051 void start_screen(); 00052 00053 int main() { 00054 00055 //#ifdef WITH_TESTING 00056 int number_of_failures = run_tests(); 00057 00058 if(number_of_failures > 0) return number_of_failures; 00059 #endif 00060 init(); 00061 start_screen(); 00062 render(); 00063 00064 wait(0.2); 00065 00066 while(1) { 00067 00068 00069 snake_engine.get_input(pad); 00070 snake_engine.update(pad); 00071 render(); 00072 00073 wait(0.15); 00074 00075 } 00076 } 00077 00078 // initialies all classes and libraries 00079 void init() 00080 { 00081 // need to initialise LCD and Gamepad 00082 lcd.init(); 00083 pad.init(); 00084 00085 // initialise the game with food, snake... 00086 snake_engine.init(IN, CUR, SNAKE_P_X, SNAKE_P_Y, SPAWN_TIME); 00087 00088 } 00089 00090 // this function draws each frame on the LCD 00091 void render() 00092 { 00093 // clear screen, re-draw and refresh 00094 lcd.clear(); 00095 snake_engine.draw(lcd); 00096 lcd.refresh(); 00097 00098 } 00099 00100 void start_screen() 00101 { 00102 int i = 0; 00103 lcd.setContrast(0.5); 00104 for(i = 0; i <= 4; ++i) { 00105 00106 lcd.printString(" NOTENDO ", 0,i); 00107 lcd.refresh(); 00108 wait(0.3); 00109 lcd.clear(); 00110 00111 00112 if(i == 4) { 00113 00114 lcd.printString(" NOTENDO ", 0,5); 00115 lcd.refresh(); 00116 pad.tone(0,1.75); 00117 wait(1.5); 00118 lcd.clear(); 00119 00120 } 00121 00122 } 00123 00124 while ( pad.check_event(Gamepad::START_PRESSED) == false ) { 00125 00126 00127 lcd.printString(" Welcome ", 0, 1); 00128 lcd.printString(" Press Start ", 0, 3); 00129 lcd.refresh(); 00130 00131 } 00132 00133 }
Generated on Wed Aug 3 2022 05:55:53 by
1.7.2