ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Revision:
51:2231e2e141b9
Parent:
45:fe5fc85a5c73
Child:
52:29772e31a620
--- a/Menu/Menu.cpp	Thu May 09 06:02:20 2019 +0000
+++ b/Menu/Menu.cpp	Thu May 09 08:42:25 2019 +0000
@@ -11,6 +11,7 @@
 {
 
 }
+// menu sprites
 const int kestrelSprite[44][37] =   {
     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
@@ -305,17 +306,17 @@
 };
 void Menu::init(int ycursor)
 {
+    // initialize the ycursor value
     _ycursor = ycursor;
 
 }
 void Menu::title(N5110 &lcd,SHIP shipUsed)
 {
-
-    // Print start
+    // menu options
     lcd.printString("Play ",2,2);
     lcd.printString("Ship ",2,3);
     lcd.printString("Menu",2,4);
-
+    // display ship on menu according to the ship selected
     switch (shipUsed) {
         case kestrel:
             lcd.drawSprite(45,1,44,37,(int *)kestrelSprite);
@@ -332,12 +333,12 @@
     lcd.drawRect(0,0,84,48,FILL_TRANSPARENT);
     lcd.drawSprite(0,0,9,48,(int *)title_screen);
     lcd.drawRect(0,_ycursor-1,26,9,FILL_TRANSPARENT);
-
 }
 
 void Menu::update(Direction d, Vector2D joystick)
 {
     if(-0.25 > joystick.x || joystick.x > 0.25 || -0.25 > joystick.y || joystick.y > 0.25) {
+        // update the x and y cursor values based on joystick motion
         if (d == N) {
             _ycursor = _ycursor - 8;
         }
@@ -350,7 +351,7 @@
         if (d == E) {
             _xcursor = _xcursor + 1;
         }
-        // limit _xursor and _ycursor values 
+        // limit _xursor and _ycursor values
         if(_ycursor < 16) {
             _ycursor = 16;
         }
@@ -376,20 +377,19 @@
 }
 void Menu::disp_ships(N5110 &lcd)
 {
-    if(_xcursor == 0) {
-        lcd.drawSprite(2,1,44,37,(int *)kestrelSprite);
-        lcd.drawSprite(41,1,45,41,(int *)kestrelStats);
-    }
-    if(_xcursor == 1) {
-        lcd.drawSprite(12,6,39,17,(int *)imperionSprite);
-        lcd.drawSprite(41,1,45,41,(int *)imperionStats);
-    }
-    if(_xcursor == 2) {
-        lcd.drawSprite(9,1,45,26,(int *)orionSprite);
-        lcd.drawSprite(41,1,45,41,(int *)orionStats);
+    // Switch ship sprite based on what ship is being used
+    switch (_xcursor) {
+        case 0:
+            lcd.drawSprite(2,1,44,37,(int *)kestrelSprite);
+            lcd.drawSprite(41,1,45,41,(int *)kestrelStats);
+            break;
+        case 1:
+            lcd.drawSprite(12,6,39,17,(int *)imperionSprite);
+            lcd.drawSprite(41,1,45,41,(int *)imperionStats);
+            break;
+        case 2:
+            lcd.drawSprite(9,1,45,26,(int *)orionSprite);
+            lcd.drawSprite(41,1,45,41,(int *)orionStats);
+            break;
     }
 }
-/*void Menu::scroll(N5110 &lcd, Direction d)
-{
-
-}*/
\ No newline at end of file