Kaif Kutchwala 201267448 ELEC2645 Project

Dependencies:   mbed

Revision:
2:21973e665a32
Parent:
1:35d2e82b764e
Child:
3:f86c1cf90d0d
--- a/main.cpp	Fri Apr 24 22:38:03 2020 +0000
+++ b/main.cpp	Sat Apr 25 21:56:30 2020 +0000
@@ -9,9 +9,48 @@
 #include "Gamepad.h"
 #include "N5110.h"
 
+
 Gamepad pad;
 N5110 lcd;
 
+
+const int ball[3][11][15] = {
+    {{0,0,0,0,0,1,1,1,1,1,0,0,0,0,0},
+    {0,0,0,1,1,0,1,1,1,0,1,1,0,0,0},
+    {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},
+    {0,1,0,0,0,0,1,1,1,0,0,0,0,1,0},
+    {0,1,1,0,0,1,1,1,1,1,0,0,1,1,0},
+    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+    {0,1,1,0,0,1,1,1,1,1,0,0,1,1,0},
+    {0,1,0,0,0,0,1,1,1,0,0,0,0,1,0},
+    {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},
+    {0,0,0,1,1,0,1,1,1,0,1,1,0,0,0},
+    {0,0,0,0,0,1,1,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,1,1,1,1,1,0,0,0,0,0},
+    {0,0,0,0,1,0,0,1,0,0,1,0,0,0,0},
+    {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0},
+    {0,0,1,1,0,0,1,1,1,0,0,1,1,0,0},
+    {0,0,1,1,1,1,1,1,1,1,1,1,1,0,0},
+    {0,0,1,1,0,0,1,1,1,0,0,1,1,0,0},
+    {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0},
+    {0,0,0,0,1,0,1,1,1,0,1,0,0,0,0},
+    {0,0,0,0,0,1,1,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,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,0,0,0,0,0,1,1,1,0,0,0,0,0,0},
+    {0,0,0,0,0,1,0,1,0,1,0,0,0,0,0},
+    {0,0,0,0,1,1,1,1,1,1,1,0,0,0,0},
+    {0,0,0,0,0,1,0,1,0,1,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,0,0,0},
+    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
+};
 int goal[24][70] = {
         {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,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,0,0,0,0},
         {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
@@ -39,28 +78,26 @@
         {0,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,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,1,0},
         
     };
-    int ball[11][15] = {
-            {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0},
-            {0,0,0,1,1,0,1,1,1,0,1,1,0,0,0},
-            {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},
-            {0,1,0,0,0,0,0,1,0,0,0,0,0,1,0},
-            {0,1,1,0,0,0,1,1,1,0,0,0,1,1,0},
-            {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
-            {0,1,1,0,0,0,1,1,1,0,0,0,1,1,0},
-            {0,1,0,0,0,0,0,1,0,0,0,0,0,1,0},
-            {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0},
-            {0,0,0,1,1,0,1,1,1,0,1,1,0,0,0},
-            {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0},
-        };
     
-    int grass1[7][7] = {
-            {0,0,0,0,0,0,0},
+
+    int grass1[2][7][7] = {
+            {{0,0,0,0,0,0,0},
             {0,0,0,0,0,0,0},
             {0,0,1,0,0,0,0},
             {0,0,1,0,1,0,0},
             {0,1,0,1,0,1,0},
             {0,1,0,1,0,1,0},
-            {1,0,1,0,0,0,1},
+            {1,0,1,0,0,0,1}},
+            
+            {{1,1,1,1,1,1,1},
+            {0,0,0,0,0,0,0},
+            {0,0,1,0,0,0,0},
+            {0,0,1,0,1,0,0},
+            {0,1,0,1,0,1,0},
+            {0,1,0,1,0,1,0},
+            {1,0,1,0,0,0,1},},
+            
+            
         };
     int grass2[3][3] = {
             {1,0,1},
@@ -69,7 +106,19 @@
         };
     
     int initial_pos = WIDTH/2;
-    int dir =1;
+    int dir =1 ;
+    int dirr =1;
+    int aim_line = WIDTH/2;
+    int _user_input_x = 40;
+    int _user_input_y = 12;
+    
+    int _ball_x = 35;
+    int _ball_y = 43;
+    int j = 0;
+    int k = 0;
+    int sizex = 11;
+    int sizey = 15;
+    char sprite = 'b';
     
     int main() {
          
@@ -77,10 +126,13 @@
          lcd.setContrast(0.5);
          pad.init();
          lcd.backLightOn();
+       
          while(1) {
+        
+         lcd.drawLine(WIDTH/2,41,aim_line,24,2);
          lcd.drawSprite(7,0,24,70,(int *)goal);
-         lcd.drawSprite(1,17,7,7,(int *)grass1);
-         lcd.drawSprite(76,17,7,7,(int *)grass1);
+         lcd.drawSprite(1,17,7,7,(int *)grass1[0]);
+         lcd.drawSprite(76,17,7,7,(int *)grass1[1]);
          lcd.drawSprite(67,26,3,3,(int *)grass2);
          lcd.drawSprite(67,26,3,3,(int *)grass2);
          lcd.drawSprite(16,30,3,3,(int *)grass2);
@@ -91,24 +143,48 @@
          lcd.drawSprite(32,34,3,3,(int *)grass2);
          Vector2D joystick = pad.get_mapped_coord();
         float ballx =  WIDTH/2 - 7;
-        float bally = 40;
-         lcd.drawSprite(ballx,bally,11,15,(int *)ball);
+        float bally = 43;
+         
+      
          lcd.drawLine(0,24,84,24,1);
-         lcd.drawLine(WIDTH/2-5,38,initial_pos,HEIGHT/2+4,1);
-         lcd.drawLine(WIDTH/2+5,38,initial_pos,HEIGHT/2+4,1);
-         lcd.drawLine(WIDTH/2+5,38,WIDTH/2-5,38,1);
+         lcd.drawLine(WIDTH/2-5,41,initial_pos,HEIGHT/2+7,1);
+         lcd.drawLine(WIDTH/2+5,41,initial_pos,HEIGHT/2+7,1);
+         lcd.drawLine(WIDTH/2+5,41,WIDTH/2-5,41,1);
          lcd.printString("Score",0,5);
          
-         
-            initial_pos += dir;
-            wait(0.05);
-            if (initial_pos > 56) {
+         aim_line += dir;
+         initial_pos += dirr;
+         if(initial_pos >84) {
+                dirr = -1;
+             } 
+        if ( initial_pos < 0) {
+                    dirr = 1;
+                }
+        
+        
+        if (aim_line > 84) {
                     dir = -1;
                 }
-            if ( initial_pos < 28) {
+        if ( aim_line < 0) {
                     dir = 1;
                 }
-            
+        
+          while(_user_input_x != _ball_x || _user_input_y != _ball_y) {
+                if(_user_input_x < _ball_x ) { _ball_x --;}
+                else if(_user_input_x > _ball_x ) { _ball_x ++;}
+                
+                if(_user_input_y < _ball_y ) { _ball_y --;}
+                else if(_user_input_y > _ball_y ) { _ball_y ++;}
+                lcd.drawSprite(_ball_x,_ball_y,sizex,sizey,(int *)ball[j]);
+                
+                if(k == 4) {j = 0;}
+                        if(k == 16) {j = 1; sprite = 'g';}
+                        
+                   
+                wait_ms(100);
+                k++;
+                break;}
+                printf("%d",k); 
          lcd.refresh();
          lcd.clear();
         }