ELEC2645 (2018/19) / Mbed 2 deprecated fy14lkaa

Dependencies:   mbed

alien/alien.cpp

Committer:
fy14lkaa
Date:
2019-04-19
Revision:
17:9da9d0d41fca
Parent:
16:cba54d0696dc
Child:
18:1c1a3fb0efae

File content as of revision 17:9da9d0d41fca:

#include "alien.h"


alien::alien()
{

}

alien::~alien()
{

}

void alien::init(int size,int speed)
{
    
    _size = size;
    
    
   
    
    
    srand(time(NULL));
    int direction = rand() % 8; // randomise initial direction. 

    // 4 possibilities. Get random modulo and set velocities accordingly
    if (direction == 0) {
        _velocity.x = speed;
        _velocity.y = speed;
    } else if (direction == 1) {
        _velocity.x = speed;
        _velocity.y = -speed;
    } else if (direction == 2) {
        _velocity.x = speed;
        _velocity.y = speed;
    } else {
        _velocity.x = -speed;
        _velocity.y = -speed;
    }
}
   
   
   void alien::draw(N5110 &lcd)
{
    lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
}
 
    void alien::update()
{
    _x += _velocity.x;
    _y += _velocity.y;
    
    void alien::set_velocity(Vector2D v)
{
    _velocity.x = v.x;
    _velocity.y = v.y;
}

Vector2D alien::get_velocity()
{
    Vector2D v = {_velocity.x,_velocity.y};
    return v;
}

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