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:
- 150:bd02678bfdb1
- Parent:
- 149:bd0f37008f5a
File content as of revision 150:bd02678bfdb1:
#include "Alien.h" //nothing to be done here. Alien::Alien() //constructor of class Alien { } Alien::~Alien() //Destructor of class Alien { } //intialise the prameters of class Alien void Alien::init(int x_alien,int y_alien, int speed_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; // random movment 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; //printif("alien at y_cooridante equal 0\n") } } // to get the position of the alien at x_cooridante . int Alien::get_pos_x() { return _x_alien; // retutn x_corridante of the alien in integer. } //function to get the position of the alien at y_cooridante. int Alien::get_pos_y() { 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") } // this bool function to check if the alive alien bool Alien::isAlive() { //return the alive alien in bool. return _alive; //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") }