publish my project

Dependencies:   mbed

Committer:
dongyuhu
Date:
Wed Apr 29 10:51:02 2020 +0000
Revision:
7:4b92c1ee6231
Parent:
0:9e95a5ef2659
publish

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dongyuhu 0:9e95a5ef2659 1 /* ELEC2645 Embedded Systems Project
dongyuhu 0:9e95a5ef2659 2 School of Electronic & Electrical Engineering
dongyuhu 0:9e95a5ef2659 3 University of Leeds
dongyuhu 0:9e95a5ef2659 4 Name: Hu Dongyu
dongyuhu 0:9e95a5ef2659 5 Username: dongyuhu
dongyuhu 0:9e95a5ef2659 6 Student ID Number: 201199421
dongyuhu 0:9e95a5ef2659 7 Date: 04/05/2020
dongyuhu 0:9e95a5ef2659 8 */
dongyuhu 0:9e95a5ef2659 9
dongyuhu 0:9e95a5ef2659 10 #include <stdlib.h>
dongyuhu 0:9e95a5ef2659 11 #include "mbed.h"
dongyuhu 0:9e95a5ef2659 12 #include "N5110.h"
dongyuhu 0:9e95a5ef2659 13 #include "Gamepad.h"
dongyuhu 0:9e95a5ef2659 14 #include "Start.h"
dongyuhu 0:9e95a5ef2659 15
dongyuhu 0:9e95a5ef2659 16 /*Initialized data*/
dongyuhu 0:9e95a5ef2659 17 #define G_Width 84
dongyuhu 0:9e95a5ef2659 18 #define G_Height 48
dongyuhu 0:9e95a5ef2659 19 #define M_Width 3
dongyuhu 0:9e95a5ef2659 20 #define M_Height 3
dongyuhu 0:9e95a5ef2659 21 #define A_Size 2
dongyuhu 0:9e95a5ef2659 22 #define A_Speed 1
dongyuhu 0:9e95a5ef2659 23
dongyuhu 0:9e95a5ef2659 24 #define wait_time1 1
dongyuhu 0:9e95a5ef2659 25
dongyuhu 0:9e95a5ef2659 26 extern bool ifnotstop;
dongyuhu 0:9e95a5ef2659 27
dongyuhu 0:9e95a5ef2659 28
dongyuhu 0:9e95a5ef2659 29 /*Create the external class object*/
dongyuhu 0:9e95a5ef2659 30 N5110 Monitor(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);// from external class N5110
dongyuhu 0:9e95a5ef2659 31 Gamepad GP;// from external class Gamepad
dongyuhu 0:9e95a5ef2659 32 Start sta;// from external class start
dongyuhu 0:9e95a5ef2659 33
dongyuhu 0:9e95a5ef2659 34
dongyuhu 0:9e95a5ef2659 35
dongyuhu 0:9e95a5ef2659 36 void Gameinit()//Game Initialization
dongyuhu 0:9e95a5ef2659 37 {
dongyuhu 0:9e95a5ef2659 38 Monitor.init();
dongyuhu 0:9e95a5ef2659 39 GP.init();
dongyuhu 0:9e95a5ef2659 40 sta.init(M_Width,M_Height,A_Size,A_Speed);
dongyuhu 0:9e95a5ef2659 41 }
dongyuhu 0:9e95a5ef2659 42
dongyuhu 0:9e95a5ef2659 43
dongyuhu 0:9e95a5ef2659 44 void draw_frame_for_Monitor()// draw frame for the Monitor
dongyuhu 0:9e95a5ef2659 45 {
dongyuhu 0:9e95a5ef2659 46 Monitor.clear();//Monitor clear
dongyuhu 0:9e95a5ef2659 47 sta.draw(Monitor);//redraw
dongyuhu 0:9e95a5ef2659 48 Monitor.refresh();//refresh
dongyuhu 0:9e95a5ef2659 49 }
dongyuhu 0:9e95a5ef2659 50
dongyuhu 0:9e95a5ef2659 51
dongyuhu 0:9e95a5ef2659 52 void Showmenu()//show game menu
dongyuhu 0:9e95a5ef2659 53 {
dongyuhu 0:9e95a5ef2659 54
dongyuhu 0:9e95a5ef2659 55 Monitor.printString(" ARENA ",0,1);
dongyuhu 0:9e95a5ef2659 56 Monitor.printString(" Press Start ",0,4);
dongyuhu 0:9e95a5ef2659 57 Monitor.refresh();//refresh Monitor
dongyuhu 0:9e95a5ef2659 58 while ( GP.check_event(Gamepad::START_PRESSED) == false)
dongyuhu 0:9e95a5ef2659 59 {
dongyuhu 0:9e95a5ef2659 60 ;
dongyuhu 0:9e95a5ef2659 61 }
dongyuhu 0:9e95a5ef2659 62 }
dongyuhu 0:9e95a5ef2659 63
dongyuhu 0:9e95a5ef2659 64 void dofunction(int FPS)
dongyuhu 0:9e95a5ef2659 65 {
dongyuhu 0:9e95a5ef2659 66 sta.read_input(GP);
dongyuhu 0:9e95a5ef2659 67 sta.update(GP);
dongyuhu 0:9e95a5ef2659 68 draw_frame_for_Monitor();
dongyuhu 0:9e95a5ef2659 69 wait(1.0f/FPS);
dongyuhu 0:9e95a5ef2659 70 }
dongyuhu 0:9e95a5ef2659 71
dongyuhu 0:9e95a5ef2659 72 int main()
dongyuhu 0:9e95a5ef2659 73 {
dongyuhu 0:9e95a5ef2659 74 while(1)
dongyuhu 0:9e95a5ef2659 75 {
dongyuhu 0:9e95a5ef2659 76 int FPS = 10;//fps=10
dongyuhu 0:9e95a5ef2659 77 Gameinit();//initialization
dongyuhu 0:9e95a5ef2659 78 Showmenu(); //show menu
dongyuhu 0:9e95a5ef2659 79 draw_frame_for_Monitor();
dongyuhu 0:9e95a5ef2659 80 wait(wait_time1);
dongyuhu 0:9e95a5ef2659 81 while(ifnotstop)
dongyuhu 0:9e95a5ef2659 82 {
dongyuhu 0:9e95a5ef2659 83 dofunction(FPS);
dongyuhu 0:9e95a5ef2659 84 }
dongyuhu 0:9e95a5ef2659 85 if(ifnotstop == false)
dongyuhu 0:9e95a5ef2659 86 {
dongyuhu 0:9e95a5ef2659 87 Monitor.clear();
dongyuhu 0:9e95a5ef2659 88 Monitor.printString(" Game over ",0,4);
dongyuhu 0:9e95a5ef2659 89 Monitor.refresh();
dongyuhu 0:9e95a5ef2659 90 }
dongyuhu 0:9e95a5ef2659 91 wait(5);
dongyuhu 0:9e95a5ef2659 92 ifnotstop = true;
dongyuhu 0:9e95a5ef2659 93 }
dongyuhu 0:9e95a5ef2659 94 }
dongyuhu 0:9e95a5ef2659 95