Haoyan Zhang
/
el17h2z1
deemo1
Diff: Laser/Laser.cpp
- Revision:
- 1:8c48fb8ca5e0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Laser/Laser.cpp Mon May 11 06:50:18 2020 +0000 @@ -0,0 +1,73 @@ +#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; +} + + + + + + + + + + + \ No newline at end of file