Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.
Dependencies: mbed
Spaceship/Spaceship.cpp@135:cf08bb4bdee9, 2019-05-08 (annotated)
- Committer:
- fy14lkaa
- Date:
- Wed May 08 19:06:19 2019 +0000
- Revision:
- 135:cf08bb4bdee9
- Parent:
- 133:eed60548d170
- Child:
- 136:58f393968aa3
deleted the shape of the spaceship(rectangle) and added the sprite instead to make it more attractive.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fy14lkaa | 105:b206078335a3 | 1 | #include "Spaceship.h" |
fy14lkaa | 83:a55e77dfee5a | 2 | |
fy14lkaa | 106:73d5d818ae7d | 3 | Spaceship::Spaceship() |
fy14lkaa | 83:a55e77dfee5a | 4 | { |
fy14lkaa | 83:a55e77dfee5a | 5 | } |
fy14lkaa | 106:73d5d818ae7d | 6 | Spaceship::~Spaceship() |
fy14lkaa | 83:a55e77dfee5a | 7 | { |
fy14lkaa | 83:a55e77dfee5a | 8 | } |
fy14lkaa | 84:d875c6e87398 | 9 | |
fy14lkaa | 106:73d5d818ae7d | 10 | void Spaceship::init(int x_spaceship,int y_spaceship, int speed_spaceship) |
fy14lkaa | 85:0094d33fb1da | 11 | { |
fy14lkaa | 106:73d5d818ae7d | 12 | |
fy14lkaa | 106:73d5d818ae7d | 13 | _x_spaceship= x_spaceship; |
fy14lkaa | 106:73d5d818ae7d | 14 | _y_spaceship= y_spaceship; |
fy14lkaa | 106:73d5d818ae7d | 15 | _speed_spaceship= speed_spaceship; |
fy14lkaa | 106:73d5d818ae7d | 16 | } |
fy14lkaa | 85:0094d33fb1da | 17 | |
fy14lkaa | 107:83b0bc100600 | 18 | void Spaceship::draw(N5110 &lcd) |
fy14lkaa | 107:83b0bc100600 | 19 | { |
fy14lkaa | 135:cf08bb4bdee9 | 20 | |
fy14lkaa | 133:eed60548d170 | 21 | lcd.drawSprite(_x_spaceship,_y_spaceship,32,32,(int *) spaceship2); |
fy14lkaa | 107:83b0bc100600 | 22 | |
fy14lkaa | 107:83b0bc100600 | 23 | } |
fy14lkaa | 108:ca888bb3ed54 | 24 | |
fy14lkaa | 108:ca888bb3ed54 | 25 | |
fy14lkaa | 108:ca888bb3ed54 | 26 | void Spaceship::update(Direction d,float mag) |
fy14lkaa | 108:ca888bb3ed54 | 27 | { |
fy14lkaa | 108:ca888bb3ed54 | 28 | _speed_spaceship = int(mag*10.0f); |
fy14lkaa | 108:ca888bb3ed54 | 29 | |
fy14lkaa | 130:4ce67451d0c1 | 30 | if(d==N){ |
fy14lkaa | 130:4ce67451d0c1 | 31 | // printf("North\n"); |
fy14lkaa | 109:2137a6a63840 | 32 | _y_spaceship-=2; |
fy14lkaa | 130:4ce67451d0c1 | 33 | } |
fy14lkaa | 109:2137a6a63840 | 34 | else |
fy14lkaa | 130:4ce67451d0c1 | 35 | if(d==S){ |
fy14lkaa | 133:eed60548d170 | 36 | // printf("North\n"); |
fy14lkaa | 109:2137a6a63840 | 37 | _y_spaceship+=2; |
fy14lkaa | 133:eed60548d170 | 38 | |
fy14lkaa | 130:4ce67451d0c1 | 39 | } |
fy14lkaa | 108:ca888bb3ed54 | 40 | |
fy14lkaa | 130:4ce67451d0c1 | 41 | if(_y_spaceship>=30){ |
fy14lkaa | 109:2137a6a63840 | 42 | _y_spaceship=30; |
fy14lkaa | 130:4ce67451d0c1 | 43 | } |
fy14lkaa | 109:2137a6a63840 | 44 | else |
fy14lkaa | 130:4ce67451d0c1 | 45 | if(_y_spaceship<=0){ |
fy14lkaa | 109:2137a6a63840 | 46 | _y_spaceship=0; |
fy14lkaa | 130:4ce67451d0c1 | 47 | } |
fy14lkaa | 108:ca888bb3ed54 | 48 | |
fy14lkaa | 108:ca888bb3ed54 | 49 | } |
fy14lkaa | 110:755a3a75d9b0 | 50 | |
fy14lkaa | 133:eed60548d170 | 51 | int Spaceship::get_pos_x() |
fy14lkaa | 110:755a3a75d9b0 | 52 | { |
fy14lkaa | 110:755a3a75d9b0 | 53 | return _x_spaceship; |
fy14lkaa | 110:755a3a75d9b0 | 54 | } |
fy14lkaa | 133:eed60548d170 | 55 | int Spaceship::get_pos_y() |
fy14lkaa | 110:755a3a75d9b0 | 56 | { |
fy14lkaa | 110:755a3a75d9b0 | 57 | return _y_spaceship; |
fy14lkaa | 110:755a3a75d9b0 | 58 | } |
fy14lkaa | 111:e9a048d06690 | 59 | |
fy14lkaa | 111:e9a048d06690 | 60 | void Spaceship::set_pos(int x, int y) |
fy14lkaa | 111:e9a048d06690 | 61 | { |
fy14lkaa | 111:e9a048d06690 | 62 | _x_spaceship = x; |
fy14lkaa | 111:e9a048d06690 | 63 | _y_spaceship = y; |
fy14lkaa | 111:e9a048d06690 | 64 | } |
fy14lkaa | 131:2084e4a8338f | 65 | |
fy14lkaa | 133:eed60548d170 | 66 | void Spaceship::add_score() |
fy14lkaa | 131:2084e4a8338f | 67 | { |
fy14lkaa | 131:2084e4a8338f | 68 | _score++; |
fy14lkaa | 131:2084e4a8338f | 69 | } |
fy14lkaa | 133:eed60548d170 | 70 | |
fy14lkaa | 133:eed60548d170 | 71 | int Spaceship::get_score() |
fy14lkaa | 131:2084e4a8338f | 72 | { |
fy14lkaa | 133:eed60548d170 | 73 | return _score; |
fy14lkaa | 133:eed60548d170 | 74 | } |