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
spase_ship/space_ship.cpp@90:a992605aeb8d, 2019-04-28 (annotated)
- Committer:
- fy14lkaa
- Date:
- Sun Apr 28 15:21:54 2019 +0000
- Revision:
- 90:a992605aeb8d
- Parent:
- 89:2eb3b6624117
- Child:
- 91:f9e2ff484014
added an accessor method to return the position of the spaceship in Vector2D.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fy14lkaa | 83:a55e77dfee5a | 1 | #include "space_ship.h" |
fy14lkaa | 83:a55e77dfee5a | 2 | |
fy14lkaa | 83:a55e77dfee5a | 3 | space_ship::space_ship() |
fy14lkaa | 83:a55e77dfee5a | 4 | { |
fy14lkaa | 83:a55e77dfee5a | 5 | |
fy14lkaa | 83:a55e77dfee5a | 6 | } |
fy14lkaa | 83:a55e77dfee5a | 7 | |
fy14lkaa | 83:a55e77dfee5a | 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 | 87:4635d00ffe9d | 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 | 85:0094d33fb1da | 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 | 85:0094d33fb1da | 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 | 85:0094d33fb1da | 39 | } |
fy14lkaa | 86:79cfe806a11d | 40 | |
fy14lkaa | 86:79cfe806a11d | 41 | void space_ship::draw(N5110 &lcd) |
fy14lkaa | 86:79cfe806a11d | 42 | { |
fy14lkaa | 88:a19f315551ea | 43 | // draw space_ship in screen buffer. |
fy14lkaa | 88:a19f315551ea | 44 | lcd.drawSprite(x_space_ship,y_space_ship,10,12,(int *) space_ship); |
fy14lkaa | 86:79cfe806a11d | 45 | } |
fy14lkaa | 88:a19f315551ea | 46 | |
fy14lkaa | 88:a19f315551ea | 47 | void space_ship::add_score() |
fy14lkaa | 88:a19f315551ea | 48 | { |
fy14lkaa | 88:a19f315551ea | 49 | _score++; |
fy14lkaa | 89:2eb3b6624117 | 50 | } |
fy14lkaa | 89:2eb3b6624117 | 51 | |
fy14lkaa | 89:2eb3b6624117 | 52 | int space_ship::get_score() |
fy14lkaa | 89:2eb3b6624117 | 53 | { |
fy14lkaa | 89:2eb3b6624117 | 54 | return _score; |
fy14lkaa | 89:2eb3b6624117 | 55 | } |
fy14lkaa | 90:a992605aeb8d | 56 | |
fy14lkaa | 90:a992605aeb8d | 57 | Vector2D space_ship::get_pos() { |
fy14lkaa | 90:a992605aeb8d | 58 | Vector2D p = {_x,_y}; |
fy14lkaa | 90:a992605aeb8d | 59 | return p; |
fy14lkaa | 90:a992605aeb8d | 60 | } |