ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18s2a_2

Dependencies:   mbed

Revision:
4:07aada4c8421
Parent:
3:bd4c7eccde17
Child:
5:e63e1024294e
--- a/main.cpp	Thu Jun 04 15:57:13 2020 +0000
+++ b/main.cpp	Thu Jun 04 16:14:12 2020 +0000
@@ -34,9 +34,8 @@
 int borderW, borderH, appleX, appleY, score;
 enum eDirection {STOP = 0, LEFT, RIGHT, UP, DOWN};
 eDirection dir;
-
-
-
+char buffer[14];  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
+         
 
 
 void setup()
@@ -44,7 +43,7 @@
     gameOver = false;
     dir = STOP;
     borderW = WIDTH;                  //Fence width and height
-    borderH = HEIGHT;
+    borderH = HEIGHT-8;
     appleX = rand() % borderW;
     appleY = rand() % borderH;
     score = 0;
@@ -53,11 +52,15 @@
 void draw() {
     lcd.clear();  
     
- lcd.drawRect(0,0,borderW,borderH,FILL_TRANSPARENT);
+ lcd.drawRect(0,8,borderW,borderH,FILL_TRANSPARENT);    // Border
+        int length = sprintf(buffer,"Score:%2d",score); // Score
+        if (length <= 14) 
+            lcd.printString(buffer,WIDTH/2-25,0);  // centers the score
   lcd.refresh();
      
     }
 
+
 ///////////// functions ////////////////
 int main()
 {