Jahanzeb Khan / Mbed 2 deprecated ELEC2645_Project_el19jak

Dependencies:   mbed

Revision:
2:430dcf420840
Parent:
1:0648f0052827
--- a/main.cpp	Sat May 30 21:10:30 2020 +0000
+++ b/main.cpp	Fri Jun 05 22:51:49 2020 +0000
@@ -14,14 +14,75 @@
 #include "mbed.h"
 #include "Gamepad.h"
 #include "N5110.h"
+#include "body.h"
+#include "food.h"
+#include "functions.h"
 
 
 // objects
 Gamepad pad;
 N5110 lcd;
+Food food;
+Body body;
+Functions functions;
+
+void visual();
+void start();
+void init();
+void snake_refresh();
 
 int main()
 {
+    init();
+    start();
     
+    for (;;) 
+    {
+        snake_refresh();
+        body.game_end(lcd);
+        body.food_eaten(lcd, pad, food);
+        food.food_location(lcd);
+        body.visual(lcd, pad, food);
+        functions.output_score(lcd, pad, body, food);
+        
+        wait(0.02);
+        
+    }
+}
+
+void init()
+{
+    lcd.init();
+    pad.init();
+    body.init();
+    food.init();
+        
 }
 
+void snake_refresh()
+{
+    body.user_input(pad);
+    body.trail_delete(lcd);
+    body.movement();
+}
+
+void start()
+{
+    while (pad.A_held() == 0)
+    {
+        lcd.setContrast(0.5);
+        lcd.drawCircle(42,24,22,FILL_TRANSPARENT);
+        lcd.printString("Welcome to Snake",25,2);
+        lcd.printString("Hold A to start",26,4);
+        pad.tone(1500.0,1);
+        wait(0.5);
+        pad.tone(750.0,1);
+        wait(0.5);/**Startup tone*/
+        pad.tone(1500.0,1);
+        wait(0.5);
+        pad.tone(750.0,1);
+        
+        lcd.refresh();
+    }
+}
+