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

Dependencies:   mbed

Committer:
fy14lkaa
Date:
Thu May 09 14:23:44 2019 +0000
Revision:
150:bd02678bfdb1
Parent:
149:bd0f37008f5a
finished the games and the last formatting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fy14lkaa 138:66befaefb27e 1 #include "Spaceship.h"
fy14lkaa 138:66befaefb27e 2
fy14lkaa 149:bd0f37008f5a 3 // nothing to be done here.
fy14lkaa 139:c46a2cef7e09 4 Spaceship::Spaceship() //constructor of class Spaceship
fy14lkaa 138:66befaefb27e 5 {
fy14lkaa 149:bd0f37008f5a 6
fy14lkaa 138:66befaefb27e 7 }
fy14lkaa 139:c46a2cef7e09 8 Spaceship::~Spaceship() //Destructor of class Spaceship
fy14lkaa 138:66befaefb27e 9 {
fy14lkaa 138:66befaefb27e 10
fy14lkaa 138:66befaefb27e 11 }
fy14lkaa 138:66befaefb27e 12
fy14lkaa 149:bd0f37008f5a 13 //intialise the prameters of class Spaceship
fy14lkaa 149:bd0f37008f5a 14 void Spaceship::init(int x_spaceship,int y_spaceship, int speed_spaceship)
fy14lkaa 149:bd0f37008f5a 15 {
fy14lkaa 149:bd0f37008f5a 16 _x_spaceship= x_spaceship; // the position of spaceship at x-cooridante.
fy14lkaa 149:bd0f37008f5a 17 _y_spaceship= y_spaceship; // the position of spaceship at y-cooridante.
fy14lkaa 149:bd0f37008f5a 18 _speed_spaceship= speed_spaceship; // the speed of the alien.
fy14lkaa 149:bd0f37008f5a 19 }
fy14lkaa 138:66befaefb27e 20
fy14lkaa 149:bd0f37008f5a 21 // void function to draw the spaceship by using N5110 library
fy14lkaa 149:bd0f37008f5a 22 void Spaceship::draw(N5110 &lcd)
fy14lkaa 149:bd0f37008f5a 23 {
fy14lkaa 149:bd0f37008f5a 24 //drawing the spaceship by using lcd.drawSprite.
fy14lkaa 149:bd0f37008f5a 25 lcd.drawSprite(_x_spaceship,_y_spaceship,32,32,(int *) spaceship2);
fy14lkaa 149:bd0f37008f5a 26 }
fy14lkaa 149:bd0f37008f5a 27
fy14lkaa 149:bd0f37008f5a 28 // void function to update the direction and the magnitude of the spaceship.
fy14lkaa 138:66befaefb27e 29 void Spaceship::update(Direction d,float mag)
fy14lkaa 138:66befaefb27e 30 {
fy14lkaa 138:66befaefb27e 31 _speed_spaceship = int(mag*10.0f);
fy14lkaa 149:bd0f37008f5a 32 if(d==N) { // if statment to check if the joystic's direction moves to the north
fy14lkaa 149:bd0f37008f5a 33 _y_spaceship-=2; // the position of the spaceship at y-coordiante decrement by two
fy14lkaa 149:bd0f37008f5a 34 //printf("North\n"); // printf statment.
fy14lkaa 149:bd0f37008f5a 35 } else if(d==S) { // else if condition to check if the joystic's direction moves to the south
fy14lkaa 149:bd0f37008f5a 36 _y_spaceship+=2; // the position of the spaceship at y-coordiante increment by two
fy14lkaa 149:bd0f37008f5a 37 // printf("North\n"); // printf statment
fy14lkaa 140:e389918735a7 38 }
fy14lkaa 149:bd0f37008f5a 39 if(_y_spaceship>=30) { // if statment to check the position of the spaceship at y_cooridante.
fy14lkaa 149:bd0f37008f5a 40 _y_spaceship=30; // y_cooridante of the spaceship equals 30
fy14lkaa 149:bd0f37008f5a 41 //printif("alien at y_cooridante equal 30\n") // printif statment
fy14lkaa 140:e389918735a7 42 } else if(_y_spaceship<=0) {
fy14lkaa 140:e389918735a7 43 _y_spaceship=0;
fy14lkaa 140:e389918735a7 44 }
fy14lkaa 138:66befaefb27e 45 }
fy14lkaa 138:66befaefb27e 46
fy14lkaa 149:bd0f37008f5a 47 // this function to get the position of the spaceship at x_cooridante.
fy14lkaa 149:bd0f37008f5a 48 int Spaceship::get_pos_x()
fy14lkaa 138:66befaefb27e 49 {
fy14lkaa 141:02858e82c9cc 50 return _x_spaceship; // return the value of x_corridante of the spaceship in integer.
fy14lkaa 138:66befaefb27e 51 }
fy14lkaa 149:bd0f37008f5a 52
fy14lkaa 149:bd0f37008f5a 53 //function to get the position of the alien at y_cooridante.
fy14lkaa 149:bd0f37008f5a 54 int Spaceship::get_pos_y()
fy14lkaa 138:66befaefb27e 55 {
fy14lkaa 141:02858e82c9cc 56 return _y_spaceship; // return the value of y_corridante of the spaceship in integer.
fy14lkaa 138:66befaefb27e 57 }
fy14lkaa 138:66befaefb27e 58
fy14lkaa 141:02858e82c9cc 59 //void function to set the position of the spaceship in x-cooridante and y_cooridante.
fy14lkaa 138:66befaefb27e 60 void Spaceship::set_pos(int x, int y)
fy14lkaa 138:66befaefb27e 61 {
fy14lkaa 149:bd0f37008f5a 62 _x_spaceship = x; //the position of the spaceship at x-coordniate is equal to x.
fy14lkaa 149:bd0f37008f5a 63 _y_spaceship = y; //the position of the spaceship at y-coordniate is equal to y.
fy14lkaa 138:66befaefb27e 64 }
fy14lkaa 138:66befaefb27e 65
fy14lkaa 149:bd0f37008f5a 66 //void function to add the scores of the spaceship.
fy14lkaa 138:66befaefb27e 67 void Spaceship::add_score()
fy14lkaa 138:66befaefb27e 68 {
fy14lkaa 141:02858e82c9cc 69 _score++; // increment the scores by 1.
fy14lkaa 149:bd0f37008f5a 70 //printf("scores increament by 1\n")
fy14lkaa 138:66befaefb27e 71 }
fy14lkaa 138:66befaefb27e 72
fy14lkaa 149:bd0f37008f5a 73 //this function is to get the scores of the spaceship
fy14lkaa 138:66befaefb27e 74 int Spaceship::get_score()
fy14lkaa 138:66befaefb27e 75 {
fy14lkaa 141:02858e82c9cc 76 return _score; //return the numbers of the scores which achived by the spaceship.
fy14lkaa 141:02858e82c9cc 77 //printf("returned scores\n")
fy14lkaa 138:66befaefb27e 78 }