Kaif Kutchwala 201267448 ELEC2645 Project

Dependencies:   mbed

Revision:
4:08a0ff6668df
Parent:
3:f86c1cf90d0d
Child:
5:ed71996c0534
--- a/main.cpp	Mon Apr 27 21:58:35 2020 +0000
+++ b/main.cpp	Sat May 16 13:10:01 2020 +0000
@@ -1,5 +1,5 @@
 /*
-Stay Home Stay Safe
+Shoot
 ELEC2645 Project
 EL18KK
 201267448
@@ -10,176 +10,150 @@
 #include "N5110.h"
 #include "Ball.h"
 #include "Splash.h"
+#include "Game.h"
 
-
+const int a_button [9][9] = {
+    {0,0,0,1,1,1,0,0,0}, 
+    {0,0,1,0,0,0,1,0,0}, 
+    {0,1,0,0,1,0,0,1,0}, 
+    {1,0,0,1,0,1,0,0,1}, 
+    {1,0,0,1,1,1,0,0,1}, 
+    {1,0,0,1,0,1,0,0,1}, 
+    {0,1,0,0,0,0,0,1,0}, 
+    {0,0,1,0,0,0,1,0,0}, 
+    {0,0,0,1,1,1,0,0,0} 
+};
+const int b_button [9][9] = {
+    {0,0,0,1,1,1,0,0,0}, 
+    {0,0,1,0,0,0,1,0,0}, 
+    {0,1,0,1,1,1,0,1,0}, 
+    {1,0,0,1,0,0,1,0,1}, 
+    {1,0,0,1,1,1,0,0,1}, 
+    {1,0,0,1,0,0,1,0,1}, 
+    {0,1,0,1,1,1,0,1,0}, 
+    {0,0,1,0,0,0,1,0,0}, 
+    {0,0,0,1,1,1,0,0,0} 
+};
+const int x_button [9][9] = {
+    {0,0,0,1,1,1,0,0,0}, 
+    {0,0,1,0,0,0,1,0,0}, 
+    {0,1,0,0,0,0,0,1,0}, 
+    {1,0,0,1,0,1,0,0,1}, 
+    {1,0,0,0,1,0,0,0,1}, 
+    {1,0,0,1,0,1,0,0,1}, 
+    {0,1,0,0,0,0,0,1,0}, 
+    {0,0,1,0,0,0,1,0,0}, 
+    {0,0,0,1,1,1,0,0,0} 
+};
+const int y_button [9][9] = {
+    {0,0,0,1,1,1,0,0,0}, 
+    {0,0,1,0,0,0,1,0,0}, 
+    {0,1,0,0,0,0,0,1,0}, 
+    {1,0,0,1,0,1,0,0,1}, 
+    {1,0,0,0,1,0,0,0,1}, 
+    {1,0,0,0,1,0,0,0,1}, 
+    {0,1,0,0,1,0,0,1,0}, 
+    {0,0,1,0,0,0,1,0,0}, 
+    {0,0,0,1,1,1,0,0,0} 
+};
+//objects
 Gamepad pad;
 N5110 lcd;
-
+Ball ball;
+Splash splash;
+//variables
+int initial_pos = WIDTH / 2;
+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';
 
-const int baall[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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1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,0},
-        {0,1,1,0,0,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,1,0,0,1,1,0},
-        {0,1,1,0,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,1,0,1,1,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,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0},
-        {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},
-        {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},
-        {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 main()
+{
+    lcd.init();
+    lcd.setContrast(0.5);
+    pad.init();
+    lcd.backLightOn();
+    //splash.displayInfo(lcd);
+    //splash.playIntro(lcd,ball);
+    while (1)
+    {
+        display_menu();
+        if (pad.A_pressed()) {
+            while(!pad.B_pressed()) {
+                game.displayLevel(1,lcd);
+                wait_ms(100);
+                lcd.refresh();
+                lcd.clear();
+            }
+        }
+        /*
+        ball.init(lcd);
+        Vector2D joystick = pad.get_mapped_coord();
+        float ballx = WIDTH / 2 - 7;
+        float bally = 43;
+
+        lcd.drawLine(0, 24, 84, 24, 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);
 
-    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,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},
-            {0,1,0},
-            {1,1,1},
-        };
-    
-    int initial_pos = WIDTH/2;
-    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';
-    
-    Ball ball;
-    Splash splashscreen;
-    int main() {
-         
-         lcd.init();
-         lcd.setContrast(0.5);
-         pad.init();        
-         lcd.backLightOn();
-         splashscreen.displayInfo(lcd);
-         splashscreen.playIntro(lcd,ball);
-         while(1) {
-         ball.init(lcd);
-         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[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);
-         lcd.drawSprite(6,35,3,3,(int *)grass2);
-         lcd.drawSprite(72,32,3,3,(int *)grass2);
-         lcd.drawSprite(69,43,3,3,(int *)grass2);
-         lcd.drawSprite(12,45,3,3,(int *)grass2);
-         lcd.drawSprite(32,34,3,3,(int *)grass2);
-         Vector2D joystick = pad.get_mapped_coord();
-        float ballx =  WIDTH/2 - 7;
-        float bally = 43;
-         
-      
-         lcd.drawLine(0,24,84,24,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);
-         
-         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 ( aim_line < 0) {
-                    dir = 1;}
-        if(pad.A_pressed()){
+        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 (aim_line < 0)
+        {
+            dir = 1;
+        }
+
+        if (pad.A_pressed())
+        {
             wait(0.2);
-            ball.playShot(70,12,lcd);
-            
+            ball.set_status(0);
+            ball.playShot(aim_line, 12, lcd);
+
         }
+        */
+
         //printf("done");
-         wait_ms(100);                
-         lcd.refresh();
-         lcd.clear();
-        }
-        }
\ No newline at end of file
+        wait_ms(100);
+        lcd.refresh();
+        lcd.clear();
+    }
+}
+
+void display_menu()
+{
+    splash.drawLogo(13, 0, lcd, ball);
+    lcd.printString("Play", 2, 2);
+    lcd.printString("How-To?", 2, 3);
+    lcd.printString("Settings", 2, 4);
+    lcd.printString("Exit", 2, 5);
+    lcd.drawSprite(28, 15, 9, 9, (int*) a_button);
+    lcd.drawSprite(45, 23, 9, 9, (int*) b_button);
+    lcd.drawSprite(52, 31, 9, 9, (int*) x_button);
+    lcd.drawSprite(28, 39, 9, 9, (int*) y_button);
+}
\ No newline at end of file