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 28:4786e81ce3e3 1 #include "Alien.h"
fy14lkaa 130:4ce67451d0c1 2
fy14lkaa 149:bd0f37008f5a 3 //nothing to be done here.
fy14lkaa 137:fe80c0f2da9d 4 Alien::Alien() //constructor of class Alien
fy14lkaa 28:4786e81ce3e3 5 {
fy14lkaa 28:4786e81ce3e3 6
fy14lkaa 28:4786e81ce3e3 7 }
fy14lkaa 28:4786e81ce3e3 8
fy14lkaa 137:fe80c0f2da9d 9 Alien::~Alien() //Destructor of class Alien
fy14lkaa 28:4786e81ce3e3 10 {
fy14lkaa 28:4786e81ce3e3 11
fy14lkaa 28:4786e81ce3e3 12 }
fy14lkaa 28:4786e81ce3e3 13
fy14lkaa 149:bd0f37008f5a 14 //intialise the prameters of class Alien
fy14lkaa 137:fe80c0f2da9d 15 void Alien::init(int x_alien,int y_alien, int speed_alien)
fy14lkaa 137:fe80c0f2da9d 16 {
fy14lkaa 149:bd0f37008f5a 17 _x_alien = x_alien; // the position of alien at x-cooridante.
fy14lkaa 137:fe80c0f2da9d 18 _y_alien = y_alien; // the position of alien at y-cooridante.
fy14lkaa 149:bd0f37008f5a 19 _speed_alien = speed_alien; // the speed of the alien.
fy14lkaa 137:fe80c0f2da9d 20 _alive = true; //intialise the alive alien.
fy14lkaa 137:fe80c0f2da9d 21
fy14lkaa 137:fe80c0f2da9d 22 }
fy14lkaa 137:fe80c0f2da9d 23
fy14lkaa 149:bd0f37008f5a 24 // void function to draw the alien by using N5110 library
fy14lkaa 97:58e5b454931f 25 void Alien::draw(N5110 &lcd)
fy14lkaa 97:58e5b454931f 26 {
fy14lkaa 137:fe80c0f2da9d 27 //drawing the alien by using lcd.drawSprite.
fy14lkaa 149:bd0f37008f5a 28 lcd.drawSprite(_x_alien,_y_alien,32,32,(int *)alien2);
fy14lkaa 134:2da2db5871bd 29 }
fy14lkaa 133:eed60548d170 30
fy14lkaa 98:663e584183bf 31 void Alien::update(Direction d,float mag)
fy14lkaa 98:663e584183bf 32 {
fy14lkaa 98:663e584183bf 33 _speed_alien = int(mag*10.0f);
fy14lkaa 137:fe80c0f2da9d 34
fy14lkaa 149:bd0f37008f5a 35 srand(time(NULL)); // lets the alien move randomly.
fy14lkaa 149:bd0f37008f5a 36 _y_alien += rand() % 17 - 8; // random movment
fy14lkaa 149:bd0f37008f5a 37 if(_y_alien>=30) { //if statment to check the position of the alien at y_cooridante.
fy14lkaa 149:bd0f37008f5a 38 _y_alien=30;
fy14lkaa 149:bd0f37008f5a 39 //printif("alien at y_cooridante equal 30\n")
fy14lkaa 149:bd0f37008f5a 40 } else if(_y_alien<=0) {
fy14lkaa 149:bd0f37008f5a 41 _y_alien=0;
fy14lkaa 149:bd0f37008f5a 42 //printif("alien at y_cooridante equal 0\n")
fy14lkaa 149:bd0f37008f5a 43 }
fy14lkaa 134:2da2db5871bd 44 }
fy14lkaa 134:2da2db5871bd 45
fy14lkaa 149:bd0f37008f5a 46 // to get the position of the alien at x_cooridante .
fy14lkaa 149:bd0f37008f5a 47 int Alien::get_pos_x()
fy14lkaa 133:eed60548d170 48 {
fy14lkaa 141:02858e82c9cc 49 return _x_alien; // retutn x_corridante of the alien in integer.
fy14lkaa 98:663e584183bf 50 }
fy14lkaa 133:eed60548d170 51
fy14lkaa 149:bd0f37008f5a 52 //function to get the position of the alien at y_cooridante.
fy14lkaa 149:bd0f37008f5a 53 int Alien::get_pos_y()
fy14lkaa 133:eed60548d170 54 {
fy14lkaa 141:02858e82c9cc 55 return _y_alien; // retutn y_corridante of the alien in integer.
fy14lkaa 133:eed60548d170 56 }
fy14lkaa 133:eed60548d170 57
fy14lkaa 137:fe80c0f2da9d 58 //void function to set the position of the alien in x-cooridante and y_cooridante.
fy14lkaa 133:eed60548d170 59 void Alien::set_pos(int x, int y)
fy14lkaa 133:eed60548d170 60 {
fy14lkaa 149:bd0f37008f5a 61 _x_alien = x; //the position of the alien at x-coordniate is equal to x.
fy14lkaa 149:bd0f37008f5a 62 _y_alien = y; //the position of the alien at y-coordniate is equal to y.
fy14lkaa 133:eed60548d170 63 }
fy14lkaa 133:eed60548d170 64
fy14lkaa 142:92f277a3e7e6 65 //void function to add the scores of the alien.
fy14lkaa 133:eed60548d170 66 void Alien::add_score()
fy14lkaa 133:eed60548d170 67 {
fy14lkaa 137:fe80c0f2da9d 68 _score++; // increment the scores by 1.
fy14lkaa 137:fe80c0f2da9d 69 //printf("scores increament by 1\n")
fy14lkaa 133:eed60548d170 70 }
fy14lkaa 142:92f277a3e7e6 71
fy14lkaa 142:92f277a3e7e6 72 //void function to get the scores of the alien.
fy14lkaa 149:bd0f37008f5a 73 int Alien::get_score()
fy14lkaa 149:bd0f37008f5a 74 {
fy14lkaa 137:fe80c0f2da9d 75 return _score; //return the numbers of the scores which achived by the alien.
fy14lkaa 137:fe80c0f2da9d 76 //printf("returned scores\n")
fy14lkaa 134:2da2db5871bd 77 }
fy14lkaa 133:eed60548d170 78
fy14lkaa 149:bd0f37008f5a 79 // this bool function to check if the alive alien
fy14lkaa 133:eed60548d170 80 bool Alien::isAlive()
fy14lkaa 133:eed60548d170 81 {
fy14lkaa 149:bd0f37008f5a 82 //return the alive alien in bool.
fy14lkaa 149:bd0f37008f5a 83 return _alive;
fy14lkaa 149:bd0f37008f5a 84 //printf("alive alien is true\n")
fy14lkaa 133:eed60548d170 85 }
fy14lkaa 149:bd0f37008f5a 86
fy14lkaa 142:92f277a3e7e6 87 //void function to set up the alive alien.
fy14lkaa 149:bd0f37008f5a 88 void Alien::setAlive(bool alive)
fy14lkaa 149:bd0f37008f5a 89 {
fy14lkaa 133:eed60548d170 90 _alive = alive;
fy14lkaa 149:bd0f37008f5a 91 //printf("alive alien is set up\n")
fy14lkaa 134:2da2db5871bd 92 }
fy14lkaa 134:2da2db5871bd 93
fy14lkaa 133:eed60548d170 94
fy14lkaa 134:2da2db5871bd 95
fy14lkaa 133:eed60548d170 96
fy14lkaa 134:2da2db5871bd 97