deemo1

Dependencies:   mbed

Laser/Laser.cpp

Committer:
haoyan
Date:
2020-05-14
Revision:
6:b59bc5e15cf3
Parent:
1:8c48fb8ca5e0

File content as of revision 6:b59bc5e15cf3:

#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;
}