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@102:d5c235fb27fd, 2019-05-05 (annotated)
- Committer:
- fy14lkaa
- Date:
- Sun May 05 13:08:51 2019 +0000
- Revision:
- 102:d5c235fb27fd
- Parent:
- spaceship/space_ship.cpp@93:ab36428d0152
change file's name from space_ship.cpp to spaceship.cpp
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 | 91:f9e2ff484014 | 39 | |
| fy14lkaa | 91:f9e2ff484014 | 40 | |
| fy14lkaa | 85:0094d33fb1da | 41 | } |
| fy14lkaa | 86:79cfe806a11d | 42 | |
| fy14lkaa | 86:79cfe806a11d | 43 | void space_ship::draw(N5110 &lcd) |
| fy14lkaa | 86:79cfe806a11d | 44 | { |
| fy14lkaa | 88:a19f315551ea | 45 | // draw space_ship in screen buffer. |
| fy14lkaa | 88:a19f315551ea | 46 | lcd.drawSprite(x_space_ship,y_space_ship,10,12,(int *) space_ship); |
| fy14lkaa | 86:79cfe806a11d | 47 | } |
| fy14lkaa | 88:a19f315551ea | 48 | |
| fy14lkaa | 88:a19f315551ea | 49 | void space_ship::add_score() |
| fy14lkaa | 88:a19f315551ea | 50 | { |
| fy14lkaa | 88:a19f315551ea | 51 | _score++; |
| fy14lkaa | 89:2eb3b6624117 | 52 | } |
| fy14lkaa | 89:2eb3b6624117 | 53 | |
| fy14lkaa | 89:2eb3b6624117 | 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 | 91:f9e2ff484014 | 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 | } |