Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.
Dependencies: mbed
Diff: Spaceship/Spaceship.cpp
- Revision:
- 149:bd0f37008f5a
- Parent:
- 145:e060e890c725
--- a/Spaceship/Spaceship.cpp Thu May 09 12:09:59 2019 +0000 +++ b/Spaceship/Spaceship.cpp Thu May 09 14:13:43 2019 +0000 @@ -1,65 +1,57 @@ #include "Spaceship.h" +// nothing to be done here. Spaceship::Spaceship() //constructor of class Spaceship { + } Spaceship::~Spaceship() //Destructor of class Spaceship { -} -////////////////////////////////////////////////////////// - - -void Spaceship::init(int x_spaceship,int y_spaceship, int speed_spaceship) -{ - //intialise the prameters of class Spaceship - - _x_spaceship= x_spaceship; // the position of spaceship at x-cooridante. - _y_spaceship= y_spaceship; // the position of spaceship at y-cooridante. - _speed_spaceship= speed_spaceship; // the speed of the alien. -} - -/////////////////////////////////////////////////////////////////////////// - - // void function to draw the spaceship by using N5110 library -void Spaceship::draw(N5110 &lcd) -{ - //drawing the spaceship by using lcd.drawSprite. - lcd.drawSprite(_x_spaceship,_y_spaceship,32,32,(int *) spaceship2); } +//intialise the prameters of class Spaceship +void Spaceship::init(int x_spaceship,int y_spaceship, int speed_spaceship) +{ + _x_spaceship= x_spaceship; // the position of spaceship at x-cooridante. + _y_spaceship= y_spaceship; // the position of spaceship at y-cooridante. + _speed_spaceship= speed_spaceship; // the speed of the alien. +} +// void function to draw the spaceship by using N5110 library +void Spaceship::draw(N5110 &lcd) +{ + //drawing the spaceship by using lcd.drawSprite. + lcd.drawSprite(_x_spaceship,_y_spaceship,32,32,(int *) spaceship2); +} + +// void function to update the direction and the magnitude of the spaceship. void Spaceship::update(Direction d,float mag) { _speed_spaceship = int(mag*10.0f); -///////////////////////////////////////////////////////////////// - if(d==N) { //if statment to check if the joystic's direction moves to the north - - _y_spaceship-=2; // the position of the spaceship at y-coordiante decrement by two - -// printf("North\n"); //printf statment. - } else if(d==S) { // else if condition to check if the joystic's direction moves to the south - - _y_spaceship+=2; // the position of the spaceship at y-coordiante increment by two - - // printf("North\n"); //printf statment - + if(d==N) { // if statment to check if the joystic's direction moves to the north + _y_spaceship-=2; // the position of the spaceship at y-coordiante decrement by two + //printf("North\n"); // printf statment. + } else if(d==S) { // else if condition to check if the joystic's direction moves to the south + _y_spaceship+=2; // the position of the spaceship at y-coordiante increment by two + // printf("North\n"); // printf statment } - - if(_y_spaceship>=30) { //if statment to check the position of the spaceship at y_cooridante. - _y_spaceship=30; // y_cooridante of the spaceship equals 30 - //printif("alien at y_cooridante equal 30\n") // printif statment + if(_y_spaceship>=30) { // if statment to check the position of the spaceship at y_cooridante. + _y_spaceship=30; // y_cooridante of the spaceship equals 30 + //printif("alien at y_cooridante equal 30\n") // printif statment } else if(_y_spaceship<=0) { _y_spaceship=0; } - } -int Spaceship::get_pos_x() // to get the position of the spaceship at x_cooridante. +// this function to get the position of the spaceship at x_cooridante. +int Spaceship::get_pos_x() { return _x_spaceship; // return the value of x_corridante of the spaceship in integer. } -int Spaceship::get_pos_y()//function to get the position of the alien at y_cooridante. + +//function to get the position of the alien at y_cooridante. +int Spaceship::get_pos_y() { return _y_spaceship; // return the value of y_corridante of the spaceship in integer. } @@ -67,16 +59,18 @@ //void function to set the position of the spaceship in x-cooridante and y_cooridante. void Spaceship::set_pos(int x, int y) { - _x_spaceship = x; //the position of the spaceship at x-coordniate is equal to x. - _y_spaceship = y; //the position of the spaceship at y-coordniate is equal to y. + _x_spaceship = x; //the position of the spaceship at x-coordniate is equal to x. + _y_spaceship = y; //the position of the spaceship at y-coordniate is equal to y. } +//void function to add the scores of the spaceship. void Spaceship::add_score() { _score++; // increment the scores by 1. - //printf("scores increament by 1\n") + //printf("scores increament by 1\n") } +//this function is to get the scores of the spaceship int Spaceship::get_score() { return _score; //return the numbers of the scores which achived by the spaceship.