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
Spaceship/Spaceship.cpp@139:c46a2cef7e09, 2019-05-09 (annotated)
- Committer:
- fy14lkaa
- Date:
- Thu May 09 05:50:57 2019 +0000
- Revision:
- 139:c46a2cef7e09
- Parent:
- 138:66befaefb27e
- Child:
- 140:e389918735a7
adding printf statement.
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 | 138:66befaefb27e | 9 | |
| fy14lkaa | 138:66befaefb27e | 10 | void Spaceship::init(int x_spaceship,int y_spaceship, int speed_spaceship) |
| fy14lkaa | 138:66befaefb27e | 11 | { |
| fy14lkaa | 139:c46a2cef7e09 | 12 | //intialise the prameters of class Spaceship |
| fy14lkaa | 138:66befaefb27e | 13 | |
| fy14lkaa | 139:c46a2cef7e09 | 14 | _x_spaceship= x_spaceship; // the position of spaceship at x-cooridante. |
| fy14lkaa | 139:c46a2cef7e09 | 15 | _y_spaceship= y_spaceship; // the position of spaceship at y-cooridante. |
| fy14lkaa | 139:c46a2cef7e09 | 16 | _speed_spaceship= speed_spaceship; // the speed of the alien. |
| fy14lkaa | 138:66befaefb27e | 17 | } |
| fy14lkaa | 138:66befaefb27e | 18 | |
| fy14lkaa | 139:c46a2cef7e09 | 19 | |
| fy14lkaa | 139:c46a2cef7e09 | 20 | // void function to draw the spaceship by using N5110 library |
| fy14lkaa | 138:66befaefb27e | 21 | void Spaceship::draw(N5110 &lcd) |
| fy14lkaa | 138:66befaefb27e | 22 | { |
| fy14lkaa | 139:c46a2cef7e09 | 23 | . //drawing the spaceship by using lcd.drawSprite. |
| fy14lkaa | 138:66befaefb27e | 24 | lcd.drawSprite(_x_spaceship,_y_spaceship,32,32,(int *) spaceship2); |
| fy14lkaa | 138:66befaefb27e | 25 | |
| fy14lkaa | 138:66befaefb27e | 26 | } |
| fy14lkaa | 138:66befaefb27e | 27 | |
| fy14lkaa | 138:66befaefb27e | 28 | |
| 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 | 138:66befaefb27e | 32 | |
| fy14lkaa | 138:66befaefb27e | 33 | if(d==N){ |
| fy14lkaa | 139:c46a2cef7e09 | 34 | |
| fy14lkaa | 138:66befaefb27e | 35 | _y_spaceship-=2; |
| fy14lkaa | 139:c46a2cef7e09 | 36 | |
| fy14lkaa | 139:c46a2cef7e09 | 37 | // printf("North\n"); |
| fy14lkaa | 138:66befaefb27e | 38 | } |
| fy14lkaa | 138:66befaefb27e | 39 | else |
| fy14lkaa | 138:66befaefb27e | 40 | if(d==S){ |
| fy14lkaa | 138:66befaefb27e | 41 | // printf("North\n"); |
| fy14lkaa | 138:66befaefb27e | 42 | _y_spaceship+=2; |
| fy14lkaa | 138:66befaefb27e | 43 | |
| fy14lkaa | 138:66befaefb27e | 44 | } |
| fy14lkaa | 138:66befaefb27e | 45 | |
| fy14lkaa | 138:66befaefb27e | 46 | if(_y_spaceship>=30){ |
| fy14lkaa | 138:66befaefb27e | 47 | _y_spaceship=30; |
| fy14lkaa | 138:66befaefb27e | 48 | } |
| fy14lkaa | 138:66befaefb27e | 49 | else |
| fy14lkaa | 138:66befaefb27e | 50 | if(_y_spaceship<=0){ |
| fy14lkaa | 138:66befaefb27e | 51 | _y_spaceship=0; |
| fy14lkaa | 138:66befaefb27e | 52 | } |
| fy14lkaa | 138:66befaefb27e | 53 | |
| fy14lkaa | 138:66befaefb27e | 54 | } |
| fy14lkaa | 138:66befaefb27e | 55 | |
| fy14lkaa | 138:66befaefb27e | 56 | int Spaceship::get_pos_x() |
| fy14lkaa | 138:66befaefb27e | 57 | { |
| fy14lkaa | 138:66befaefb27e | 58 | return _x_spaceship; |
| fy14lkaa | 138:66befaefb27e | 59 | } |
| fy14lkaa | 138:66befaefb27e | 60 | int Spaceship::get_pos_y() |
| fy14lkaa | 138:66befaefb27e | 61 | { |
| fy14lkaa | 138:66befaefb27e | 62 | return _y_spaceship; |
| fy14lkaa | 138:66befaefb27e | 63 | } |
| fy14lkaa | 138:66befaefb27e | 64 | |
| fy14lkaa | 138:66befaefb27e | 65 | void Spaceship::set_pos(int x, int y) |
| fy14lkaa | 138:66befaefb27e | 66 | { |
| fy14lkaa | 138:66befaefb27e | 67 | _x_spaceship = x; |
| fy14lkaa | 138:66befaefb27e | 68 | _y_spaceship = y; |
| fy14lkaa | 138:66befaefb27e | 69 | } |
| fy14lkaa | 138:66befaefb27e | 70 | |
| fy14lkaa | 138:66befaefb27e | 71 | void Spaceship::add_score() |
| fy14lkaa | 138:66befaefb27e | 72 | { |
| fy14lkaa | 138:66befaefb27e | 73 | _score++; |
| fy14lkaa | 138:66befaefb27e | 74 | } |
| fy14lkaa | 138:66befaefb27e | 75 | |
| fy14lkaa | 138:66befaefb27e | 76 | int Spaceship::get_score() |
| fy14lkaa | 138:66befaefb27e | 77 | { |
| fy14lkaa | 138:66befaefb27e | 78 | return _score; |
| fy14lkaa | 138:66befaefb27e | 79 | } |