Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.
Dependencies: mbed
Spaceship/Spaceship.cpp@105:b206078335a3, 2019-05-05 (annotated)
- Committer:
- fy14lkaa
- Date:
- Sun May 05 13:17:31 2019 +0000
- Revision:
- 105:b206078335a3
- Parent:
- spaceship/spaceship.cpp@102:d5c235fb27fd
- Child:
- 106:73d5d818ae7d
added private member in Spaceship.h speed_spaceship.
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 | 105:b206078335a3 | 3 | Space_ship::Space_ship() |
fy14lkaa | 83:a55e77dfee5a | 4 | { |
fy14lkaa | 83:a55e77dfee5a | 5 | |
fy14lkaa | 83:a55e77dfee5a | 6 | } |
fy14lkaa | 83:a55e77dfee5a | 7 | |
fy14lkaa | 105:b206078335a3 | 8 | Space_ship::~Space_ship() |
fy14lkaa | 83:a55e77dfee5a | 9 | { |
fy14lkaa | 83:a55e77dfee5a | 10 | |
fy14lkaa | 83:a55e77dfee5a | 11 | } |
fy14lkaa | 84:d875c6e87398 | 12 | |
fy14lkaa | 87:4635d00ffe9d | 13 | |
fy14lkaa | 87:4635d00ffe9d | 14 | |
fy14lkaa | 87:4635d00ffe9d | 15 | |
fy14lkaa | 105:b206078335a3 | 16 | const int Space_ship[10][12]= { |
fy14lkaa | 87:4635d00ffe9d | 17 | {0,0,0,0,0,0,0,0,0,0,0,0}, |
fy14lkaa | 87:4635d00ffe9d | 18 | {0,0,0,1,1,0,0,0,0,0,0,0}, |
fy14lkaa | 87:4635d00ffe9d | 19 | {0,0,0,1,1,0,0,0,0,0,0,0}, |
fy14lkaa | 87:4635d00ffe9d | 20 | {0,1,1,1,1,1,1,1,0,0,0,0}, |
fy14lkaa | 87:4635d00ffe9d | 21 | {0,1,1,1,1,1,1,1,1,0,0,0}, |
fy14lkaa | 87:4635d00ffe9d | 22 | {0,1,1,1,1,1,1,1,1,1,1,0}, |
fy14lkaa | 87:4635d00ffe9d | 23 | {0,1,1,1,1,1,1,1,1,0,0,0}, |
fy14lkaa | 87:4635d00ffe9d | 24 | {0,1,1,1,1,1,1,1,0,0,0,0}, |
fy14lkaa | 87:4635d00ffe9d | 25 | {0,0,0,1,1,0,0,0,0,0,0,0}, |
fy14lkaa | 87:4635d00ffe9d | 26 | {0,0,0,1,1,0,0,0,0,0,0,0}, |
fy14lkaa | 87:4635d00ffe9d | 27 | |
fy14lkaa | 87:4635d00ffe9d | 28 | }; |
fy14lkaa | 87:4635d00ffe9d | 29 | |
fy14lkaa | 105:b206078335a3 | 30 | void Space_ship::init(int x,int height,int width) |
fy14lkaa | 85:0094d33fb1da | 31 | { |
fy14lkaa | 85:0094d33fb1da | 32 | _x = x; // x value on screen is fixed |
fy14lkaa | 105:b206078335a3 | 33 | _y = HEIGHT/2 - height/2; // y depends on height of screen and height of Space_ship |
fy14lkaa | 85:0094d33fb1da | 34 | _height = height; |
fy14lkaa | 85:0094d33fb1da | 35 | _width = width; |
fy14lkaa | 85:0094d33fb1da | 36 | _speed = 1; // default speed |
fy14lkaa | 85:0094d33fb1da | 37 | _score = 0; // start score from zero |
fy14lkaa | 85:0094d33fb1da | 38 | |
fy14lkaa | 91:f9e2ff484014 | 39 | |
fy14lkaa | 91:f9e2ff484014 | 40 | |
fy14lkaa | 85:0094d33fb1da | 41 | } |
fy14lkaa | 86:79cfe806a11d | 42 | |
fy14lkaa | 105:b206078335a3 | 43 | void Space_ship::draw(N5110 &lcd) |
fy14lkaa | 86:79cfe806a11d | 44 | { |
fy14lkaa | 105:b206078335a3 | 45 | // draw Space_ship in screen buffer. |
fy14lkaa | 105:b206078335a3 | 46 | lcd.drawSprite(x_Space_ship,y_Space_ship,10,12,(int *) Space_ship); |
fy14lkaa | 86:79cfe806a11d | 47 | } |
fy14lkaa | 88:a19f315551ea | 48 | |
fy14lkaa | 105:b206078335a3 | 49 | void Space_ship::add_score() |
fy14lkaa | 88:a19f315551ea | 50 | { |
fy14lkaa | 88:a19f315551ea | 51 | _score++; |
fy14lkaa | 89:2eb3b6624117 | 52 | } |
fy14lkaa | 89:2eb3b6624117 | 53 | |
fy14lkaa | 105:b206078335a3 | 54 | int Space_ship::get_score() |
fy14lkaa | 89:2eb3b6624117 | 55 | { |
fy14lkaa | 89:2eb3b6624117 | 56 | return _score; |
fy14lkaa | 89:2eb3b6624117 | 57 | } |
fy14lkaa | 90:a992605aeb8d | 58 | |
fy14lkaa | 105:b206078335a3 | 59 | Vector2D Space_ship::get_pos() |
fy14lkaa | 91:f9e2ff484014 | 60 | { |
fy14lkaa | 90:a992605aeb8d | 61 | Vector2D p = {_x,_y}; |
fy14lkaa | 91:f9e2ff484014 | 62 | return p; |
fy14lkaa | 90:a992605aeb8d | 63 | } |