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.
Dependencies: mbed
Board/Board.cpp
- Committer:
- ChenZirui
- Date:
- 2020-05-27
- Revision:
- 5:7207c9b70108
- Child:
- 6:b393cfe4e0a7
File content as of revision 5:7207c9b70108:
#include "Board.h"
// nothing doing in the constructor and destructor
Board::Board()
{
}
Board::~Board()
{
}
void Board::init(int x,int y,int height,int width,N5110 &lcd)
{
_x=x ; // horizontal coordinate of Board
//_y=48-height/2 ; // vertical coordinate of fighte
_y=y ;
_height =height;
_width = width;
_speed = 1; // default speed
_score = 0;
//lcd.drawRect(0,0,84,24,FILL_BLACK);
}
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,N5110 &lcd)
{
_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
if (d == N)
{
_y-=_speed;
}else if (d == S)
{
_y+=_speed;
}else if(d == W)
{
_x-=_speed;
}else if(d == E)
{
_x+=_speed;
}else if(d == NE)
{
_y+=_speed;
_x+=_speed;
}else if(d == NW)
{
_y+=_speed;
_x-=_speed;
}else if(d == SE)
{
_y-=_speed;
_x+=_speed;
}else if(d == SW)
{
_y-=_speed;
_x-=_speed;
}
if (_y < 1)
{
_y = 1;
}
if (_y > HEIGHT - _height - 1)
{
_y = HEIGHT - _height - 1;
}
if (_x < 1)
{
_x = 1;
}
if (_x > WIDTH - _width - 1)
{
_x = WIDTH - _width - 1;
}
}
void Board::add_score()
{
_score++;
}
int Board::get_score()
{
return _score;
}
Vector2D Board::get_pos()
{
Vector2D p = {_x,_y};
return p;
}