Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Alien.cpp
00001 #include "Alien.h" 00002 00003 //nothing to be done here. 00004 Alien::Alien() //constructor of class Alien 00005 { 00006 00007 } 00008 00009 Alien::~Alien() //Destructor of class Alien 00010 { 00011 00012 } 00013 00014 //intialise the prameters of class Alien 00015 void Alien::init(int x_alien,int y_alien, int speed_alien) 00016 { 00017 _x_alien = x_alien; // the position of alien at x-cooridante. 00018 _y_alien = y_alien; // the position of alien at y-cooridante. 00019 _speed_alien = speed_alien; // the speed of the alien. 00020 _alive = true; //intialise the alive alien. 00021 00022 } 00023 00024 // void function to draw the alien by using N5110 library 00025 void Alien::draw(N5110 &lcd) 00026 { 00027 //drawing the alien by using lcd.drawSprite. 00028 lcd.drawSprite(_x_alien,_y_alien,32,32,(int *)alien2); 00029 } 00030 00031 void Alien::update(Direction d,float mag) 00032 { 00033 _speed_alien = int(mag*10.0f); 00034 00035 srand(time(NULL)); // lets the alien move randomly. 00036 _y_alien += rand() % 17 - 8; // random movment 00037 if(_y_alien>=30) { //if statment to check the position of the alien at y_cooridante. 00038 _y_alien=30; 00039 //printif("alien at y_cooridante equal 30\n") 00040 } else if(_y_alien<=0) { 00041 _y_alien=0; 00042 //printif("alien at y_cooridante equal 0\n") 00043 } 00044 } 00045 00046 // to get the position of the alien at x_cooridante . 00047 int Alien::get_pos_x() 00048 { 00049 return _x_alien; // retutn x_corridante of the alien in integer. 00050 } 00051 00052 //function to get the position of the alien at y_cooridante. 00053 int Alien::get_pos_y() 00054 { 00055 return _y_alien; // retutn y_corridante of the alien in integer. 00056 } 00057 00058 //void function to set the position of the alien in x-cooridante and y_cooridante. 00059 void Alien::set_pos(int x, int y) 00060 { 00061 _x_alien = x; //the position of the alien at x-coordniate is equal to x. 00062 _y_alien = y; //the position of the alien at y-coordniate is equal to y. 00063 } 00064 00065 //void function to add the scores of the alien. 00066 void Alien::add_score() 00067 { 00068 _score++; // increment the scores by 1. 00069 //printf("scores increament by 1\n") 00070 } 00071 00072 //void function to get the scores of the alien. 00073 int Alien::get_score() 00074 { 00075 return _score; //return the numbers of the scores which achived by the alien. 00076 //printf("returned scores\n") 00077 } 00078 00079 // this bool function to check if the alive alien 00080 bool Alien::isAlive() 00081 { 00082 //return the alive alien in bool. 00083 return _alive; 00084 //printf("alive alien is true\n") 00085 } 00086 00087 //void function to set up the alive alien. 00088 void Alien::setAlive(bool alive) 00089 { 00090 _alive = alive; 00091 //printf("alive alien is set up\n") 00092 } 00093 00094 00095 00096 00097
Generated on Sat Aug 6 2022 12:54:46 by
