ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18zc_

Dependencies:   mbed

Revision:
5:7207c9b70108
Parent:
1:86da5130732b
Child:
6:b393cfe4e0a7
diff -r e46c295d4baf -r 7207c9b70108 main.cpp
--- a/main.cpp	Sat May 23 18:12:03 2020 +0000
+++ b/main.cpp	Wed May 27 21:13:59 2020 +0000
@@ -1,27 +1,93 @@
-/* 
-ELEC2645 Embedded Systems Project
-School of Electronic & Electrical Engineering
-University of Leeds
-2019/20
-
-Name:Chen Zirui
-Username:el18zc
-Student ID Number:201235448
-Date:5.03.2020
-*/
-
-// includes
+///////// pre-processor directives ////////
 #include "mbed.h"
 #include "Gamepad.h"
 #include "N5110.h"
+#include "Touch.h"
+#ifdef WITH_TESTING
+#include "test.h"
+#endif
 
+#define PADDLE_WIDTH 2
+#define PADDLE_HEIGHT 8
+#define BALL_SIZE 2
+#define BALL_SPEED 3
 
-// objects
+/////////////// structs /////////////////
+struct UserInput {
+    Direction d;
+    float mag;
+};
+/////////////// objects ///////////////
+N5110 lcd;
 Gamepad pad;
-N5110 lcd;
+Touch touch;
 
+///////////// prototypes ///////////////
+void init();
+void update_game(UserInput input);
+void render();
+void welcome();
+
+///////////// functions ////////////////
 int main()
 {
-    
+#ifdef WITH_TESTING
+    int number_of_failures = run_all_tests();
+
+    if(number_of_failures > 0) return number_of_failures;
+#endif
+    int fps = 6;  // frames per second
+ init();     // initialise and then display welcome screen...
+    welcome();  // waiting for the user to start;
+    render();  // first draw the initial frame 
+    wait(1.0f/fps);  // and wait for one frame period
+
+    //lcd.drawRect(0,0,84,24,FILL_BLACK);
+    // game loop - read input, update the game state and render the display
+    while (1) {
+        touch.read_input(pad);
+        touch.update(pad,lcd);
+        render();
+        //lcd.drawRect(0,0,84,24,FILL_BLACK);
+        wait(1.0f/fps);
+    }
 }
 
+// initialies all classes and libraries
+void init()
+{
+    // need to initialise LCD and Gamepad 
+    lcd.init();
+    pad.init();
+     
+    // initialise the game with correct ball and paddle sizes
+ pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED,lcd);
+
+}
+
+// this function draws each frame on the LCD
+void render()
+{
+    // clear screen, re-draw and refresh
+    lcd.clear();  
+    touch.draw(lcd);
+    lcd.refresh();
+}
+
+// simple splash screen displayed on start-up
+void welcome() {
+    
+    lcd.printString("     touch!    ",0,1);  
+    lcd.printString("  Press Start ",0,4);
+    lcd.refresh();
+     
+    // wait flashing LEDs until start button is pressed 
+    while ( pad.start_pressed() == false) {
+        lcd.setContrast( pad.read_pot1());
+        pad.leds_on();
+        wait(0.1);
+        pad.leds_off();
+        wait(0.1);
+    }
+ 
+}