Zirui Chen 201235448

Dependencies:   mbed

Revision:
7:f61ac963eb07
Parent:
6:b393cfe4e0a7
Child:
9:a8420b353bb0
--- a/Board/Board.cpp	Thu May 28 01:11:47 2020 +0000
+++ b/Board/Board.cpp	Fri May 29 02:55:37 2020 +0000
@@ -1,105 +1,86 @@
 #include "Board.h"
-
-// nothing doing in the constructor and destructor
-Board::Board()
-{
-
-}
-
-Board::~Board()
-{
+#define LENGTH 84
 
-}
 //borad initial function
-void Board::init(int x,int y,int height,int width)
+void Board::init(int x,int y,int length,int width)
 {
-    _x=x ; // horizontal coordinate of Board
-    _y=y ;// vertical coordinate of board
-    _height =height;
-    _width = width;
-    _speed = 1;  // default speed
-    _score = 0;
-    //lcd.drawRect(0,0,84,24,FILL_BLACK);
+    _x=x ;                                      // horizontal coordinate of Board
+    _y=y ;                                      // vertical coordinate of board
+    _length =length;                            // length
+    _width = width;                             // width
+    _speed = 1;                                 // default speed
+    _score = 0;                                 // initi8al socre
     
-    }
-    void Board::draw(N5110 &lcd)
-    {
-        //lcd.drawRect(_x+(_height/2)-(_width/2),_y,_width,_height,FILL_BLACK);
-        lcd.drawRect(_x,_y,_height,_width,FILL_BLACK);
-       // lcd.drawRect(0,0,84,24,FILL_BLACK);
-       // lcd.drawRect(41,24,10,10,FILL_TRANSPARENT);
-      //  lcd.clearPixel(10,24);
-        
-        
-    }
-        void Board::update(Direction d,float mag)
-        {
-            _speed = int(mag*10.0f);  // scale is arbitrary, could be changed in future
-           //if((ball_pos.y >= 0)&&(ball_pos.y <= 24))
-          //  {
-           //     lcd.drawRect(24,41,10,10,FILL_TRANSPARENT);
-           // }
-        //  lcd.clearPixel(10,24);
-
-    // update y value depending on direction of movement
-    // North is decrement as origin is at the top-left so decreasing moves up
+    
+}
+void Board::draw(N5110 &lcd)                     // use N5110 series function to draw a board
+{
+      lcd.drawRect(_x,_y,_length,_width,FILL_BLACK);
+}
+void Board::update(Direction d,float mag)        // update position and speed increment information
+{
+    _speed = int(mag*10.0f);                     // speed variable
+         
+            // eight directions control
             if (d == N) 
             {
-                _y-=_speed;
+                _y-=_speed;                     // North-up
             }else if (d == S) 
             {
-                _y+=_speed;
-            }else if(d == W)
+                _y+=_speed;                     // South-down   
+            }else if(d == W)                   
             {
-                _x-=_speed;
-            }else if(d == E)
+                _x-=_speed;                     // West-left
+            }else if(d == E)                    
             {
-                _x+=_speed;
+                _x+=_speed;                     // East-right
             }else if(d == NE)
             {
                 _y+=_speed;
-                _x+=_speed;
+                _x+=_speed;                     //Northeast-upright
             }else if(d == NW)
             {
                 _y+=_speed;
-                _x-=_speed;
+                _x-=_speed;                     //Northwest-upleft
             }else if(d == SE)
             {
                 _y-=_speed;
-                _x+=_speed;
+                _x+=_speed;                     //Southeast-downright
             }else if(d == SW)
             {
                 _y-=_speed;
-                _x-=_speed;
-            }
-            if (_y < 1) 
-            {
-                _y = 1;
+                _x-=_speed;                     //Southwest-downleft
             }
-            if (_y > HEIGHT - _height - 1)
+          //  boundary judging and dealing
+          
+            if (_y <= 24)                        //up
             {
-                _y = HEIGHT - _height - 1;
+                _y = 24;
             }
-             if (_x < 1) 
+            if (_y >= HEIGHT - _width - 1)       //bottom
+            {
+                _y = HEIGHT - _width - 1;
+            }
+             if (_x < 1)                         //left
             {
                 _x = 1;
             }
-            if (_x > WIDTH - _width - 1)
+            if (_x > WIDTH - _length - 1)        //right
             {
-                _x = WIDTH - _width - 1;
+                _x = WIDTH - _length - 1;
             }
 }
-            void Board::add_score()
-            {
+/*void Board::add_score()
+{
                  _score++;
-            }
-            int Board::get_score()
-            {
-                return _score;
-            }
+}
+int Board::get_score()
+{
+     return _score;
+}*/
 
-            Vector2D Board::get_pos() 
-            {
-                 Vector2D p = {_x,_y};
-                 return p;    
-            }
\ No newline at end of file
+Vector2D Board::get_pos()        //position data
+{
+    Vector2D p = {_x,_y};
+    return p;         
+}
\ No newline at end of file