Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.
Dependencies: mbed
Spaceship/Spaceship.cpp@145:e060e890c725, 2019-05-09 (annotated)
- Committer:
- fy14lkaa
- Date:
- Thu May 09 09:27:32 2019 +0000
- Revision:
- 145:e060e890c725
- Parent:
- 142:92f277a3e7e6
- Child:
- 149:bd0f37008f5a
formatting the SpaceEngine.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fy14lkaa | 138:66befaefb27e | 1 | #include "Spaceship.h" |
fy14lkaa | 138:66befaefb27e | 2 | |
fy14lkaa | 139:c46a2cef7e09 | 3 | Spaceship::Spaceship() //constructor of class Spaceship |
fy14lkaa | 138:66befaefb27e | 4 | { |
fy14lkaa | 138:66befaefb27e | 5 | } |
fy14lkaa | 139:c46a2cef7e09 | 6 | Spaceship::~Spaceship() //Destructor of class Spaceship |
fy14lkaa | 138:66befaefb27e | 7 | { |
fy14lkaa | 138:66befaefb27e | 8 | } |
fy14lkaa | 142:92f277a3e7e6 | 9 | ////////////////////////////////////////////////////////// |
fy14lkaa | 142:92f277a3e7e6 | 10 | |
fy14lkaa | 138:66befaefb27e | 11 | |
fy14lkaa | 138:66befaefb27e | 12 | void Spaceship::init(int x_spaceship,int y_spaceship, int speed_spaceship) |
fy14lkaa | 138:66befaefb27e | 13 | { |
fy14lkaa | 139:c46a2cef7e09 | 14 | //intialise the prameters of class Spaceship |
fy14lkaa | 138:66befaefb27e | 15 | |
fy14lkaa | 139:c46a2cef7e09 | 16 | _x_spaceship= x_spaceship; // the position of spaceship at x-cooridante. |
fy14lkaa | 139:c46a2cef7e09 | 17 | _y_spaceship= y_spaceship; // the position of spaceship at y-cooridante. |
fy14lkaa | 139:c46a2cef7e09 | 18 | _speed_spaceship= speed_spaceship; // the speed of the alien. |
fy14lkaa | 138:66befaefb27e | 19 | } |
fy14lkaa | 138:66befaefb27e | 20 | |
fy14lkaa | 145:e060e890c725 | 21 | /////////////////////////////////////////////////////////////////////////// |
fy14lkaa | 145:e060e890c725 | 22 | |
fy14lkaa | 139:c46a2cef7e09 | 23 | // void function to draw the spaceship by using N5110 library |
fy14lkaa | 138:66befaefb27e | 24 | void Spaceship::draw(N5110 &lcd) |
fy14lkaa | 138:66befaefb27e | 25 | { |
fy14lkaa | 142:92f277a3e7e6 | 26 | //drawing the spaceship by using lcd.drawSprite. |
fy14lkaa | 138:66befaefb27e | 27 | lcd.drawSprite(_x_spaceship,_y_spaceship,32,32,(int *) spaceship2); |
fy14lkaa | 138:66befaefb27e | 28 | |
fy14lkaa | 138:66befaefb27e | 29 | } |
fy14lkaa | 138:66befaefb27e | 30 | |
fy14lkaa | 138:66befaefb27e | 31 | |
fy14lkaa | 138:66befaefb27e | 32 | void Spaceship::update(Direction d,float mag) |
fy14lkaa | 138:66befaefb27e | 33 | { |
fy14lkaa | 138:66befaefb27e | 34 | _speed_spaceship = int(mag*10.0f); |
fy14lkaa | 142:92f277a3e7e6 | 35 | ///////////////////////////////////////////////////////////////// |
fy14lkaa | 140:e389918735a7 | 36 | if(d==N) { //if statment to check if the joystic's direction moves to the north |
fy14lkaa | 140:e389918735a7 | 37 | |
fy14lkaa | 140:e389918735a7 | 38 | _y_spaceship-=2; // the position of the spaceship at y-coordiante decrement by two |
fy14lkaa | 138:66befaefb27e | 39 | |
fy14lkaa | 141:02858e82c9cc | 40 | // printf("North\n"); //printf statment. |
fy14lkaa | 141:02858e82c9cc | 41 | } else if(d==S) { // else if condition to check if the joystic's direction moves to the south |
fy14lkaa | 140:e389918735a7 | 42 | |
fy14lkaa | 145:e060e890c725 | 43 | _y_spaceship+=2; // the position of the spaceship at y-coordiante increment by two |
fy14lkaa | 141:02858e82c9cc | 44 | |
fy14lkaa | 141:02858e82c9cc | 45 | // printf("North\n"); //printf statment |
fy14lkaa | 138:66befaefb27e | 46 | |
fy14lkaa | 140:e389918735a7 | 47 | } |
fy14lkaa | 140:e389918735a7 | 48 | |
fy14lkaa | 141:02858e82c9cc | 49 | if(_y_spaceship>=30) { //if statment to check the position of the spaceship at y_cooridante. |
fy14lkaa | 141:02858e82c9cc | 50 | _y_spaceship=30; // y_cooridante of the spaceship equals 30 |
fy14lkaa | 141:02858e82c9cc | 51 | //printif("alien at y_cooridante equal 30\n") // printif statment |
fy14lkaa | 140:e389918735a7 | 52 | } else if(_y_spaceship<=0) { |
fy14lkaa | 140:e389918735a7 | 53 | _y_spaceship=0; |
fy14lkaa | 140:e389918735a7 | 54 | } |
fy14lkaa | 138:66befaefb27e | 55 | |
fy14lkaa | 138:66befaefb27e | 56 | } |
fy14lkaa | 138:66befaefb27e | 57 | |
fy14lkaa | 141:02858e82c9cc | 58 | int Spaceship::get_pos_x() // to get the position of the spaceship at x_cooridante. |
fy14lkaa | 138:66befaefb27e | 59 | { |
fy14lkaa | 141:02858e82c9cc | 60 | return _x_spaceship; // return the value of x_corridante of the spaceship in integer. |
fy14lkaa | 138:66befaefb27e | 61 | } |
fy14lkaa | 141:02858e82c9cc | 62 | int Spaceship::get_pos_y()//function to get the position of the alien at y_cooridante. |
fy14lkaa | 138:66befaefb27e | 63 | { |
fy14lkaa | 141:02858e82c9cc | 64 | return _y_spaceship; // return the value of y_corridante of the spaceship in integer. |
fy14lkaa | 138:66befaefb27e | 65 | } |
fy14lkaa | 138:66befaefb27e | 66 | |
fy14lkaa | 141:02858e82c9cc | 67 | //void function to set the position of the spaceship in x-cooridante and y_cooridante. |
fy14lkaa | 138:66befaefb27e | 68 | void Spaceship::set_pos(int x, int y) |
fy14lkaa | 138:66befaefb27e | 69 | { |
fy14lkaa | 141:02858e82c9cc | 70 | _x_spaceship = x; //the position of the spaceship at x-coordniate is equal to x. |
fy14lkaa | 141:02858e82c9cc | 71 | _y_spaceship = y; //the position of the spaceship at y-coordniate is equal to y. |
fy14lkaa | 138:66befaefb27e | 72 | } |
fy14lkaa | 138:66befaefb27e | 73 | |
fy14lkaa | 138:66befaefb27e | 74 | void Spaceship::add_score() |
fy14lkaa | 138:66befaefb27e | 75 | { |
fy14lkaa | 141:02858e82c9cc | 76 | _score++; // increment the scores by 1. |
fy14lkaa | 141:02858e82c9cc | 77 | //printf("scores increament by 1\n") |
fy14lkaa | 138:66befaefb27e | 78 | } |
fy14lkaa | 138:66befaefb27e | 79 | |
fy14lkaa | 138:66befaefb27e | 80 | int Spaceship::get_score() |
fy14lkaa | 138:66befaefb27e | 81 | { |
fy14lkaa | 141:02858e82c9cc | 82 | return _score; //return the numbers of the scores which achived by the spaceship. |
fy14lkaa | 141:02858e82c9cc | 83 | //printf("returned scores\n") |
fy14lkaa | 138:66befaefb27e | 84 | } |