ELEC2645 (2017/18) / Mbed 2 deprecated fy15raf

Dependencies:   mbed

Asteroids/Asteroid.cpp

Committer:
RehamFaqehi
Date:
2018-05-03
Revision:
11:cb48d596aa3e
Parent:
8:13cef7cb872e
Child:
12:4d7f1349d796

File content as of revision 11:cb48d596aa3e:

#include "Asteroid.h"

Asteroid::Asteroid()
{

}

Asteroid::~Asteroid()
{

}

void Asteroid::init(float speed)
{
    _size = 5;
    _x = WIDTH - _size;

   // srand(time(NULL));
    _y1 = rand()%(HEIGHT); // random initial position on y-axis.
//_y1 =22;
    _velocity.x = speed;
}

void Asteroid::draw(N5110 &lcd)
{

    int sprite[6][11] =   {

        
        { 0,0,1,1,0,1,0,0,1,1,0, },
        { 0,1,1,1,1,1,1,0,0,0,0, },
        { 1,1,0,1,1,1,0,1,0,0,0, },
        { 1,1,1,1,1,1,1,1,0,1,1, },
        { 0,1,1,1,0,1,1,0,0,0,0, },
        { 0,0,0,1,1,1,0,0,1,1,0, },
         
    };
    lcd.drawSprite(_x,_y1,6,11,(int *)sprite);
}

void Asteroid::update()
{
    if(_x>0) {
        _x -= _velocity.x;
    } else {
        _x = WIDTH - _size; //start from the begining again
        _y1= rand()%(HEIGHT);
        //_y1 =22;
    }
}

Vector2D Asteroid::get_pos()
{
    Vector2D p = {_x,_y1};
    return p;
}