ELEC2645 (2018/19) / Mbed 2 deprecated ml17z4c_attempt2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 ELEC2645 Embedded Systems Project
00003 School of Electronic & Electrical Engineering
00004 University of Leeds
00005 Name:ZIYI CHEN
00006 Username: ml17z4c
00007 Student ID Number:201214999
00008 Date:may 2019
00009 */
00010 
00011 
00012 #include "mbed.h"
00013 #include "Gamepad.h"
00014 #include "N5110.h"
00015 #include "Eng.h"
00016 
00017 
00018 //defination
00019 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
00020 Eng gameset;
00021 Gamepad gamepad;
00022 Direction d;
00023 
00024 void init();
00025 
00026 void renderSnake();
00027 
00028 void welcome();
00029 
00030 void restart();
00031 
00032 
00033 
00034 
00035 int main()
00036 {
00037 
00038     init();
00039     welcome();
00040 
00041     bool started = false;
00042     while (1) {
00043 
00044         if(gamepad.check_event(Gamepad::START_PRESSED) == true) {
00045             started = true;
00046         }
00047         if(started) {
00048             gameset.userinput(gamepad);
00049             gameset.update(gamepad);
00050             renderSnake();
00051             if (gameset.getGameOver()) { 
00052                 gameset.score(lcd);
00053                 restart();
00054             }
00055         }
00056 
00057     }
00058 }
00059 
00060 void init()
00061 {
00062     
00063     gameset.init();
00064     lcd.init();
00065     lcd.setContrast(0.5);
00066     gamepad.init();
00067 
00068 
00069 }
00070 void welcome()
00071 {
00072 
00073 
00074     lcd.printString("   snake  ",0,1);
00075     lcd.printString("  Press Start ",0,4);
00076     lcd.refresh();
00077 
00078     while ( gamepad.check_event(Gamepad::START_PRESSED) == false) {
00079         gamepad.leds_on();
00080         wait(0.1);
00081         gamepad.leds_off();
00082         wait(0.1);
00083     }
00084     wait(0.1);
00085 
00086 }
00087 
00088 
00089 
00090 void restart()
00091 {
00092  
00093     gameset.init();      
00094 }
00095 
00096 void renderSnake()
00097 {
00098     lcd.clear();
00099     gameset.draw(lcd);
00100     lcd.refresh();
00101     wait(0.2); 
00102 
00103 }
00104 
00105 
00106