runner

Dependencies:   mbed

Obstacle/Obstacle.cpp

Committer:
kamtas
Date:
2019-05-09
Revision:
3:59e67155e2dd
Child:
4:7fca66882a00

File content as of revision 3:59e67155e2dd:

#include "Obstacle.h"

// nothing doing in the constructor and destructor
Obstacle::Obstacle()
{

}

Obstacle::~Obstacle()
{

}

void Obstacle::init(int y,int height,int width)
{
    _x = WIDTH - 5;  // x value on screen is fixed
    _y = y;
    _height = height;
    _width = width;

}

void Obstacle::draw(N5110 &lcd)
{
    lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
}

void Obstacle::update()
{
    _speed = 3;
    _x -= _speed;
    // check the x origin to ensure that the obstacle doesn't go beyond screen
    if (_x < 0) {
        _x = 1;
    }
}


Vector2D Obstacle::get_pos() {
    Vector2D p = {_x,_y};
    return p;    
}