Simple fish eat program

Dependencies:   mbed mbed-rtos N5110 ShiftReg Tone

Revision:
12:20ac766b3175
Parent:
10:e221bd1ce3ec
Child:
13:183bd19f3d7d
--- a/classes/Graphics.cpp	Wed Apr 21 11:08:02 2021 +0000
+++ b/classes/Graphics.cpp	Wed Apr 21 15:24:31 2021 +0000
@@ -1,7 +1,8 @@
 #include "Graphics.h"
 
+//draws title screen
 void Graphics::titleScreen(N5110 &lcd){
-            //  x   y
+    //draws an F x   y
     const int F[20][12] =   {
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
@@ -25,7 +26,7 @@
     { 1,1,1,1,0,0,0,0,0,0,0,0, },
     };
 
-        //  x   y
+    //draws an I x   y
     const int I[20][4] =   {
     { 1,1,1,1, },
     { 1,1,1,1, },
@@ -49,7 +50,7 @@
     { 1,1,1,1, },
     };
 
-        //  x   y
+    //draws an s x   y
     const int S[20][12] =   {
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
@@ -73,7 +74,7 @@
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
     };
 
-        //  x   y
+    //draws an h x   y
     const int H[20][12] =   {
     { 1,1,1,1,0,0,0,0,1,1,1,1, },
     { 1,1,1,1,0,0,0,0,1,1,1,1, },
@@ -97,7 +98,7 @@
     { 1,1,1,1,0,0,0,0,1,1,1,1, },
     };
 
-        //  x   y
+    //draws an e x   y
     const int E[20][12] =   {
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
@@ -121,7 +122,7 @@
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
     };
 
-        //  x   y
+    //draws an a x   y
     const int A[20][12] =   {
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
@@ -145,7 +146,7 @@
     { 1,1,1,1,0,0,0,0,1,1,1,1, },
     };
 
-        //  x   y
+    //draws an t x   y
     const int T[20][12] =   {
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
     { 1,1,1,1,1,1,1,1,1,1,1,1, },
@@ -183,8 +184,9 @@
     lcd.drawSprite(51,26,20,12,(int *)T);   
 }
 
+//creates a confirmation screen to ensure that the player is ready
 void Graphics::confirmationScreen(N5110 &lcd){
-                  //  x   y
+    //draws an uneaten fish  x   y
     const int Title_fish[44][21] =   {
     { 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,1,1,1,1,1,1,0,0,0,0,0,0,0,0, },
@@ -232,7 +234,7 @@
     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, },
     };
 
-                        //  x   y
+    //draws an eaten fish      x   y
     const int Title_fish_eaten[44][21] =   {
     { 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,1,1,1,1,1,1,0,0,0,0,0,0,0,0, },
@@ -283,17 +285,18 @@
     lcd.clear();
     lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws screen border
     lcd.printString("Hold",12,2);
-    lcd.printString("A",24,3);
+    lcd.printString("B",24,3);
     lcd.drawSprite(59,2,44,21,(int*)Title_fish);
-    lcd.refresh(); // refresh the LCD so the pixels appear
+    lcd.refresh();
     wait_ms(1000);
     lcd.drawSprite(59,2,44,21,(int*)Title_fish_eaten);
     lcd.refresh();
     wait_ms(1000);
 }
 
+//flashes the screen using normal and inverse lcd functions
 void Graphics::screenFlash(N5110 &lcd){
-    int i = 0;
+    i = 0;
 
     while(i<4){
         lcd.inverseMode();
@@ -306,6 +309,76 @@
     }
 }
 
+//displays playing instructions
+void Graphics::playerInstruc(N5110 &lcd){
+    lcd.clear();
+    lcd.printString("-- Welcome --",3,0);
+    lcd.printString("Use the",0,2);
+    lcd.printString("joystick to ",0,3);
+    lcd.printString("move the fish",0,4);
+    lcd.refresh();
+    wait_ms(4000);
+        
+    lcd.clear();
+    lcd.printString("remember to",0,1);
+    lcd.printString("only eat fish",0,2);
+    lcd.printString("smaller than",0,3);
+    lcd.printString("or same as",0,4);
+    lcd.printString("you!!",0,5);
+    lcd.refresh();   
+    wait_ms(4000);
+        
+    lcd.clear();
+    lcd.printString("At the top",0,1);
+    lcd.printString("left youll",0,2);
+    lcd.printString("see your",0,3);
+    lcd.printString("growth bar...",0,4);
+    lcd.refresh();
+    wait_ms(4000);
+        
+    lcd.clear();
+    lcd.printString("When this is",0,1);
+    lcd.printString("full your fish",0,2);
+    lcd.printString("will grow!!",0,3);
+    lcd.refresh();
+    wait_ms(4000);
+        
+    lcd.clear();
+    lcd.printString("Be careful!",0,1);
+    lcd.printString("Eat a bigger",0,2);
+    lcd.printString("fish, you'll",0,3);
+    lcd.printString("loose a life!",0,4);
+    lcd.refresh();
+    wait_ms(4000);
+        
+    lcd.clear();
+    lcd.printString("Good Luck!!!",6,1);
+    lcd.refresh();
+    wait_ms(4000);
+}
+
+void Graphics::gameOver(N5110 &lcd){
+    lcd.clear();
+    lcd.printString("Game Over!!!",6,1);
+    lcd.refresh();
+    wait_ms(4000);
+}
+
+//displays congatulations screen
+void Graphics::newHighscore(N5110 &lcd, int score){
+    int displayScore = score;
+    
+                            //string            int
+    stringCon2 = sprintf(writeScore2, "%i", displayScore); //converts int into string 
+    lcd.clear();
+    lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws screen border
+    lcd.printString("New", 33, 1);
+    lcd.printString("High Score", 14, 2);
+    lcd.printString(writeScore2, 29, 4);
+    lcd.refresh();
+    wait_ms(4000);
+}
+
 void Graphics::Fish_1(N5110 &lcd, int _x, int _y){
     //             x  y
     const int Fish_1[4][9]= {
@@ -373,64 +446,6 @@
     lcd.drawSprite(_x,_y,12,23,(int*)Fish_4);
 }
 
-
-void Graphics::upArrow(N5110 &lcd){
-    //             x  y
-    const int upArrow[3][6] =   {
-    { 0,0,1,1,0,0, },
-    { 0,1,1,1,1,0, },
-    { 1,1,1,1,1,1, },
-    };
-    
-    //pos / sprite x y / x  y
-    lcd.drawSprite(30,2,3,6,(int*)upArrow);
-}
-    
-    
-void Graphics::downArrow(N5110 &lcd){
-     //             x  y
-    const int downArrow[3][6] =   {
-    { 1,1,1,1,1,1, },
-    { 0,1,1,1,1,0, },
-    { 0,0,1,1,0,0, },
-    };
-    
-    //pos / sprite x y / x  y
-    lcd.drawSprite(30,7,3,6,(int*)downArrow);
-}
-
-
-void Graphics::leftArrow(N5110 &lcd){
-    //             x  y
-    const int leftArrow[6][3] =   {
-    { 0,0,1, },
-    { 0,1,1, },
-    { 1,1,1, },
-    { 1,1,1, },
-    { 0,1,1, },
-    { 0,0,1, },
-    };
-    
-    //pos / sprite x y / x  y
-    lcd.drawSprite(30,12,6,3,(int*)leftArrow);
-}
-
-
-void Graphics::rightArrow(N5110 &lcd){
-     //             x  y
-    const int rightArrow[6][3] =   {
-    { 1,0,0, },
-    { 1,1,0, },
-    { 1,1,1, },
-    { 1,1,1, },
-    { 1,1,0, },
-    { 1,0,0, },
-    };
-    
-    //pos / sprite x y / x  y
-    lcd.drawSprite(30,20,6,3,(int*)rightArrow);
-}
-
 void Graphics::E_Fish_1(N5110 &lcd, int _x, int _y){
     //             x  y    
     const int E_Fish_1[4][9]= {