ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Revision:
10:6c6e09023942
Parent:
9:a81db6a703b7
Child:
11:f481ec642cc5
--- a/Ball/Ball.cpp	Sun Apr 21 17:35:15 2019 +0000
+++ b/Ball/Ball.cpp	Mon Apr 22 17:34:11 2019 +0000
@@ -13,7 +13,6 @@
 
 void Ball::init(int size,int speed)
 {
-    direction_set=0;
     _size = size;
     _x1=42;
     _y1=3;
@@ -22,23 +21,6 @@
     bat.init(3,4);
     bowled=0;
 
-    srand(time(NULL));
-    int direction = rand() % 4; // randomise initial direction. 
-
-    // 4 possibilities. Get random modulo and set velocities accordingly
-    if (direction == 0) {
-        _velocity.x = speed;
-        _velocity.y = speed;
-    } else if (direction == 1) {
-        _velocity.x = speed;
-        _velocity.y = -speed;
-    } else if (direction == 2) {
-        _velocity.x = speed;
-        _velocity.y = speed;
-    } else {
-        _velocity.x = -speed;
-        _velocity.y = -speed;
-    }
 }
 int Ball::bowler_start(){
     if(_y1!=15){
@@ -49,32 +31,42 @@
         return 1;
     }
 }
-void Ball::start(N5110 &lcd,int checkHit, Direction dir){
-   int ball_start_check=bowler_start();
-   printf("bowled %i \n",bowled);
-   if (ball_start_check==1){
-        printf("HELLO\n");
-        printf("y= %i",_y);
+Vector2D Ball::get_pos()
+{
+    Vector2D p = {_x,_y};
+    return p;
+}
+
+void Ball::set_pos(Vector2D p)
+{
+    _x = p.x;
+    _y = p.y;
+}
+/*
+void Ball::ball_start(N5110 &lcd,int checkHit, Direction dir){
+   int bowler_start_check=bowler_start();
+   if (bowler_start_check==1){
          if (_y!=36){ 
-            _y+=1;        
+            _y+=1;
+            return 0;        
         }
-        else if (bowled==1){
-            update_ball(checkHit, dir);
-        }
-        else if ( _y==36){
+        else{
             bowled=1;
+            return 1;
         } 
-        else{
-            printf("lol");
-        }
+    }
+    else{
+        return 0;
     }   
 }
+*/
 void Ball::draw(N5110 &lcd)
 {
     lcd.drawCircle(_x1,_y1,2,FILL_BLACK);
-    lcd.drawCircle(_x,_y,1,FILL_BLACK);
+    lcd.drawCircle(_x,_y,2,FILL_TRANSPARENT);
     //lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
 }
+/*
 void Ball::update_ball(int checkHit, Direction dir){
      if (direction_set!=1){
          ball_direction=dir;
@@ -98,44 +90,13 @@
 }
     
 }
+*/
 void Ball::reset(){
     bowled=0;
     ballHit=0;
 }
     
-
-void Ball::update()
-{
-    _x += _velocity.x;
-    _y += _velocity.y;
-}
-
-void Ball::set_velocity(Vector2D v)
-{
-    _velocity.x = v.x;
-    _velocity.y = v.y;
-}
-
-Vector2D Ball::get_velocity()
-{
-    Vector2D v = {_velocity.x,_velocity.y};
-    return v;
-}
-
-Vector2D Ball::get_pos()
-{
-    Vector2D p = {_x,_y};
-    return p;
-}
-
-void Ball::set_pos(Vector2D p)
-{
-    _x = p.x;
-    _y = p.y;
-}
-void Ball::get_direction(Gamepad &pad){
-    _d = pad.get_direction();
-}
+/*
 void Ball::draw_field(N5110 &lcd){
     lcd.drawCircle(field[0].x,field[0].y,2,FILL_BLACK);
     lcd.drawCircle(field[1].x,field[1].y,2,FILL_BLACK);
@@ -144,90 +105,159 @@
 }
 void Ball::set_field(N5110 &lcd){
     int d=0;
+    int fieldersCount=0;
     int pos=0;
+    int i=0;
+    int continueCount=0;
     srand(time(NULL));
-    for(int i=0;i<6;i++){
-        d = 1+ rand() % 5;
+    while (fieldersCount!=5){
+        d = 1+ rand() % 6;
+        printf("DIRECTION %i\n",d);
         pos=rand()%2;    
         for (int j=0;j<10;j++){
-            if (fieldNumbers[j]==d){
-                d=1+ rand() % 6;
-                break;
-    f (d==1){ //NW
+           if (fieldNumbers[j]==d){
+                printf("CHECK");
+                continueCount=1;
+            }
+        }
+        if (continueCount==1){
+            printf("IM HERE");
+            continueCount=0;
+            continue;
+        }
+        printf("YESS");
+        if (d==1){ //NW
             if (pos==1){
+              field[i].dir=NW;
               field[i].x=30;
               field[i].y=9;
               field[i].position=1;
+              fieldNumbers[i]=d;
+              i++;
+              fieldersCount++;
             }
             else{
+              field[i].dir=NW;
               field[i].x=25;
               field[i].y=2;
               field[i].position=0;
+              fieldNumbers[i]=d;
+              i++;
+              fieldersCount++;
             }
         }
         
         
         if (d==2){ //NE
             if (pos==1){
+            field[i].dir=NE;
             field[i].x=55;
             field[i].y=9;
             field[i].position=1;
+            fieldNumbers[i]=d;
+              i++;
+              fieldersCount++;
             }
             else{
+            field[i].dir=NE;
                 field[i].x=65;
                  field[i].y=2;
                  field[i].position=0;
+                 fieldNumbers[i]=d;
+                  i++;
+                  fieldersCount++;
             }
         }
         
                 
         if (d==3){ //SW
             if (pos==1){
+                field[i].dir=SW;
                 field[i].x=33;
                 field[i].y=40;
                 field[i].position=1;
+                fieldNumbers[i]=d;
+                i++;
+                fieldersCount++;
             }
                 
             else{
+              field[i].dir=SW;
               field[i].x=25;
               field[i].y=44;
               field[i].position=0;
+              fieldNumbers[i]=d;
+              i++;
+              fieldersCount++;
             }
         }
         
         if (d==4){ //SE
             if (pos==1){
+              field[i].dir=SE;
               field[i].x=55;
               field[i].y=40;
               field[i].position=1;
+              fieldNumbers[i]=d;
+              i++;
+              fieldersCount++;
             }
             else{
+              field[i].dir=SE;
               field[i].x=65;
               field[i].y=44;
               field[i].position=0;
+              fieldNumbers[i]=d;
+              i++;
+              fieldersCount++;
             }
         }
         
         if (d==5){ //W
             if (pos==1){
+              field[i].dir=W;
               field[i].x=3;
               field[i].y=25;
               field[i].position=1;
+              fieldNumbers[i]=d;
+              i++;
+              fieldersCount++;
             }
             else{
+              field[i].dir=W;
               field[i].x=25;
               field[i].y=25;
               field[i].position=0;
+              fieldNumbers[i]=d;
+              i++;
+              fieldersCount++;
             }
         }
         
         if (d==6){ //W
-            field[i].x=80;
-            field[i].y=20;
-            field[i].position=1;
+            if (pos==1){
+                field[i].dir=E;
+                field[i].x=80;
+                field[i].y=20;
+                field[i].position=1;
+                fieldNumbers[i]=d;
+                i++;
+                fieldersCount++;
+            }
+            else{
+                 field[i].dir=E;
+                field[i].x=50;
+                field[i].y=20;
+                field[i].position=1;
+                fieldNumbers[i]=d;
+                i++;
+                fieldersCount++;
+            }
+                
         }
         
   }
   
   
 }    
+*/