Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.

Dependencies:   mbed

Alien/Alien.cpp

Committer:
fy14lkaa
Date:
2019-05-09
Revision:
142:92f277a3e7e6
Parent:
141:02858e82c9cc
Child:
149:bd0f37008f5a

File content as of revision 142:92f277a3e7e6:

#include "Alien.h"


Alien::Alien()  //constructor of class Alien
{

}

Alien::~Alien() //Destructor of class Alien
{

}


void Alien::init(int x_alien,int y_alien, int speed_alien)
{
   //intialise the prameters of class Alien 
    _x_alien = x_alien; // the position of alien at x-cooridante.
    _y_alien = y_alien; //  the position of alien at y-cooridante.
    _speed_alien = speed_alien; // the speed of the alien. 
    _alive = true;             //intialise the alive alien.

}


// void function to draw the alien by using N5110 library 
void Alien::draw(N5110 &lcd)
{
    //drawing the alien by using lcd.drawSprite.

    lcd.drawSprite(_x_alien,_y_alien,32,32,(int *)alien2); 
}



void  Alien::update(Direction d,float mag)
{
    _speed_alien = int(mag*10.0f);


  srand(time(NULL));   // lets the alien move randomly.
_y_alien += rand() % 17 - 8;



if(_y_alien>=30)   //if statment to check the position of the alien at y_cooridante.
{
    _y_alien=30;
    
    //printif("alien at y_cooridante equal 30\n")
} else if(_y_alien<=0)
{
    _y_alien=0;
}

}



int  Alien::get_pos_x() // to get the position of the alien at x_cooridante .
{
    return _x_alien;   // retutn x_corridante of the alien in integer.
}

int Alien::get_pos_y() //function to get the position of the alien at y_cooridante.
{
    return _y_alien; // retutn y_corridante of the alien in integer.
}


//void function to set the position of the alien in x-cooridante and y_cooridante.
void Alien::set_pos(int x, int y)
{
    _x_alien = x;    //the position of the alien at x-coordniate is equal to x. 
    _y_alien = y;    //the position of the alien at y-coordniate is equal to y. 
}

//void function to add the scores of the alien.
void Alien::add_score()

{
    _score++;     // increment the scores by 1.
    //printf("scores increament by 1\n")
}

//void function to get the scores of the alien.
int Alien::get_score()  
{              
    return _score;    //return the numbers of the scores which achived by the alien.
    //printf("returned scores\n")
}



bool Alien::isAlive()
{
    return _alive;    //return the alive alien in bool.
    
    //printf("alive alien is true\n")
}
//void function to set up the alive alien.

void Alien::setAlive(bool alive){  
    _alive = alive;
     //printf("alive alien is set up\n")
}