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.
Laser/Laser.cpp
- Committer:
- haoyan
- Date:
- 2020-05-11
- Revision:
- 1:8c48fb8ca5e0
File content as of revision 1:8c48fb8ca5e0:
#include "Laser.h"
Laser::Laser()
{
}
Laser::~Laser()
{
}
void Laser::init(int height,int width,int speed)
{
Vector2D Battleship_pos = _Battleship.get_pos();
_width = width;
_height = height;
// Set laser's position
_x = Battleship_pos.x + 3;
_y = Battleship_pos.y - 1;
srand(time(NULL));
_velocity.x = 0;
_velocity.y = 2*speed;
}
void Laser::draw(N5110 &lcd)
{
lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
}
void Laser::update()
{
_x += _velocity.x;
_y -= _velocity.y;
}
void Laser::set_velocity(Vector2D v)
{
_velocity.x = v.x;
_velocity.y = v.y;
}
Vector2D Laser::get_velocity()
{
Vector2D v = {_velocity.x,_velocity.y};
return v;
}
Vector2D Laser::get_pos()
{
Vector2D p = {_x,_y};
return p;
}
void Laser::set_pos(Vector2D p)
{
_x = p.x;
_y = p.y;
}