
Zirui Chen 201235448
Dependencies: mbed
Board/Board.cpp
- Committer:
- ChenZirui
- Date:
- 2020-05-29
- Revision:
- 7:f61ac963eb07
- Parent:
- 6:b393cfe4e0a7
- Child:
- 9:a8420b353bb0
File content as of revision 7:f61ac963eb07:
#include "Board.h" #define LENGTH 84 //borad initial function void Board::init(int x,int y,int length,int width) { _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) // 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; // North-up }else if (d == S) { _y+=_speed; // South-down }else if(d == W) { _x-=_speed; // West-left }else if(d == E) { _x+=_speed; // East-right }else if(d == NE) { _y+=_speed; _x+=_speed; //Northeast-upright }else if(d == NW) { _y+=_speed; _x-=_speed; //Northwest-upleft }else if(d == SE) { _y-=_speed; _x+=_speed; //Southeast-downright }else if(d == SW) { _y-=_speed; _x-=_speed; //Southwest-downleft } // boundary judging and dealing if (_y <= 24) //up { _y = 24; } if (_y >= HEIGHT - _width - 1) //bottom { _y = HEIGHT - _width - 1; } if (_x < 1) //left { _x = 1; } if (_x > WIDTH - _length - 1) //right { _x = WIDTH - _length - 1; } } /*void Board::add_score() { _score++; } int Board::get_score() { return _score; }*/ Vector2D Board::get_pos() //position data { Vector2D p = {_x,_y}; return p; }