Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.
Dependencies: mbed
Spaceship/Spaceship.cpp@130:4ce67451d0c1, 2019-05-06 (annotated)
- Committer:
- fy14lkaa
- Date:
- Mon May 06 13:47:06 2019 +0000
- Revision:
- 130:4ce67451d0c1
- Parent:
- 111:e9a048d06690
- Child:
- 131:2084e4a8338f
added printf statement to the spaceship.cpp
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 | 87:4635d00ffe9d | 10 | |
fy14lkaa | 87:4635d00ffe9d | 11 | |
fy14lkaa | 106:73d5d818ae7d | 12 | void Spaceship::init(int x_spaceship,int y_spaceship, int speed_spaceship) |
fy14lkaa | 85:0094d33fb1da | 13 | { |
fy14lkaa | 106:73d5d818ae7d | 14 | |
fy14lkaa | 106:73d5d818ae7d | 15 | _x_spaceship= x_spaceship; |
fy14lkaa | 106:73d5d818ae7d | 16 | _y_spaceship= y_spaceship; |
fy14lkaa | 106:73d5d818ae7d | 17 | _speed_spaceship= speed_spaceship; |
fy14lkaa | 106:73d5d818ae7d | 18 | } |
fy14lkaa | 85:0094d33fb1da | 19 | |
fy14lkaa | 107:83b0bc100600 | 20 | void Spaceship::draw(N5110 &lcd) |
fy14lkaa | 107:83b0bc100600 | 21 | { |
fy14lkaa | 107:83b0bc100600 | 22 | lcd.drawRect(_x_spaceship,_y_spaceship,_x_spaceship+5,_y_spaceship+10,FILL_BLACK); |
fy14lkaa | 107:83b0bc100600 | 23 | //lcd.drawSprite(_x_spaceship,_y_spaceship,10,12,(int *) spaceship_2); |
fy14lkaa | 107:83b0bc100600 | 24 | |
fy14lkaa | 107:83b0bc100600 | 25 | } |
fy14lkaa | 108:ca888bb3ed54 | 26 | |
fy14lkaa | 108:ca888bb3ed54 | 27 | |
fy14lkaa | 108:ca888bb3ed54 | 28 | void Spaceship::update(Direction d,float mag) |
fy14lkaa | 108:ca888bb3ed54 | 29 | { |
fy14lkaa | 108:ca888bb3ed54 | 30 | _speed_spaceship = int(mag*10.0f); |
fy14lkaa | 108:ca888bb3ed54 | 31 | |
fy14lkaa | 130:4ce67451d0c1 | 32 | if(d==N){ |
fy14lkaa | 130:4ce67451d0c1 | 33 | // printf("North\n"); |
fy14lkaa | 109:2137a6a63840 | 34 | _y_spaceship-=2; |
fy14lkaa | 130:4ce67451d0c1 | 35 | } |
fy14lkaa | 109:2137a6a63840 | 36 | else |
fy14lkaa | 130:4ce67451d0c1 | 37 | if(d==S){ |
fy14lkaa | 109:2137a6a63840 | 38 | _y_spaceship+=2; |
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 | 110:755a3a75d9b0 | 51 | int Spaceship::get_pos_x() |
fy14lkaa | 110:755a3a75d9b0 | 52 | { |
fy14lkaa | 110:755a3a75d9b0 | 53 | return _x_spaceship; |
fy14lkaa | 110:755a3a75d9b0 | 54 | } |
fy14lkaa | 110:755a3a75d9b0 | 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 | } |