Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Board.cpp
00001 #include "Board.h" 00002 #define LENGTH 84 00003 00004 //borad initial function 00005 void Board::init(int x,int y,int length,int width) 00006 { 00007 _x=x ; // horizontal coordinate of Board 00008 _y=y ; // vertical coordinate of board 00009 _length =length; // length 00010 _width = width; // width 00011 _speed = 1; // default speed 00012 _score = 0; // initi8al socre 00013 00014 00015 } 00016 void Board::draw(N5110 &lcd) // use N5110 series function to draw a board 00017 { 00018 lcd.drawRect(_x,_y,_length,_width,FILL_BLACK); 00019 } 00020 void Board::update(Direction d,float mag) // update position and speed increment information 00021 { 00022 _speed = int(mag*10.0f); // speed variable 00023 00024 // eight directions control 00025 if (d == N) 00026 { 00027 _y-=_speed; // North-up 00028 }else if (d == S) 00029 { 00030 _y+=_speed; // South-down 00031 }else if(d == W) 00032 { 00033 _x-=_speed; // West-left 00034 }else if(d == E) 00035 { 00036 _x+=_speed; // East-right 00037 }else if(d == NE) 00038 { 00039 _y+=_speed; 00040 _x+=_speed; //Northeast-upright 00041 }else if(d == NW) 00042 { 00043 _y+=_speed; 00044 _x-=_speed; //Northwest-upleft 00045 }else if(d == SE) 00046 { 00047 _y-=_speed; 00048 _x+=_speed; //Southeast-downright 00049 }else if(d == SW) 00050 { 00051 _y-=_speed; 00052 _x-=_speed; //Southwest-downleft 00053 } 00054 // boundary judging and dealing 00055 00056 if (_y <= 24) //up 00057 { 00058 _y = 24; 00059 } 00060 if (_y >= HEIGHT - _width - 1) //bottom 00061 { 00062 _y = HEIGHT - _width - 1; 00063 } 00064 if (_x < 1) //left 00065 { 00066 _x = 1; 00067 } 00068 if (_x > WIDTH - _length - 1) //right 00069 { 00070 _x = WIDTH - _length - 1; 00071 } 00072 } 00073 /*void Board::add_score() 00074 { 00075 _score++; 00076 } 00077 int Board::get_score() 00078 { 00079 return _score; 00080 }*/ 00081 00082 Vector2D Board::get_pos() //position data 00083 { 00084 Vector2D p = {_x,_y}; 00085 return p; 00086 }
Generated on Mon Jul 18 2022 10:48:25 by
1.7.2