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
Platforms/Platforms.cpp@29:bdc4138b5171, 2019-05-07 (annotated)
- Committer:
- lewisgw
- Date:
- Tue May 07 17:21:00 2019 +0000
- Revision:
- 29:bdc4138b5171
- Parent:
- 27:c920c5ec31af
Final Submission. I have read and agreed with the Statement of Academic Integrity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lewisgw | 18:304700b5d8f8 | 1 | #include "Platforms.h" |
lewisgw | 6:8741d2011692 | 2 | |
lewisgw | 21:20478f086bc2 | 3 | // Constructor and destructor. |
lewisgw | 18:304700b5d8f8 | 4 | Platforms::Platforms() {} |
lewisgw | 6:8741d2011692 | 5 | |
lewisgw | 18:304700b5d8f8 | 6 | Platforms::~Platforms() {} |
lewisgw | 6:8741d2011692 | 7 | |
lewisgw | 18:304700b5d8f8 | 8 | void Platforms::init(int y) { |
lewisgw | 21:20478f086bc2 | 9 | // Starting values for the platforms. |
lewisgw | 9:fff2009f826e | 10 | _line_1.x_start = 0; |
lewisgw | 9:fff2009f826e | 11 | _line_1.x_end = 15; |
lewisgw | 10:8bf3713d9e9c | 12 | _line_1.y = y; |
lewisgw | 9:fff2009f826e | 13 | _line_2.x_start = 25; |
lewisgw | 18:304700b5d8f8 | 14 | _line_2.x_end = 60; |
lewisgw | 10:8bf3713d9e9c | 15 | _line_2.y = y; |
lewisgw | 9:fff2009f826e | 16 | _line_3.x_start = 60; |
lewisgw | 9:fff2009f826e | 17 | _line_3.x_end = 80; |
lewisgw | 10:8bf3713d9e9c | 18 | _line_3.y = y; |
lewisgw | 9:fff2009f826e | 19 | } |
lewisgw | 6:8741d2011692 | 20 | |
lewisgw | 21:20478f086bc2 | 21 | void Platforms::set_line_1(int length) { |
lewisgw | 27:c920c5ec31af | 22 | // Lines move from R to L via de-incrementing. |
lewisgw | 14:9861fe85c803 | 23 | _line_1.x_start--; |
lewisgw | 21:20478f086bc2 | 24 | if (_line_1.x_start < 80 - length) _line_1.x_end--; // Only move end of the |
lewisgw | 21:20478f086bc2 | 25 | // line if the line length is fully on the screen. |
lewisgw | 21:20478f086bc2 | 26 | if (_line_1.x_start <= 0) _line_1.x_start = 0; // Terminate line 1 start at 0 |
lewisgw | 21:20478f086bc2 | 27 | // when it reaches LHS of screen so it does not go negative. |
lewisgw | 21:20478f086bc2 | 28 | if (_line_1.x_end <= 0) { // Start Drawing line again from start once the end |
lewisgw | 21:20478f086bc2 | 29 | // has reaches LHS of screen. |
lewisgw | 9:fff2009f826e | 30 | _line_1.x_start = 80; |
lewisgw | 9:fff2009f826e | 31 | _line_1.x_end = 80; |
lewisgw | 9:fff2009f826e | 32 | } |
lewisgw | 9:fff2009f826e | 33 | } |
lewisgw | 14:9861fe85c803 | 34 | |
lewisgw | 21:20478f086bc2 | 35 | void Platforms::set_line_2(int length) { |
lewisgw | 29:bdc4138b5171 | 36 | // Same as set_line_1. |
lewisgw | 9:fff2009f826e | 37 | _line_2.x_start--; |
lewisgw | 21:20478f086bc2 | 38 | if (_line_2.x_start < 80 - length) _line_2.x_end--; |
lewisgw | 21:20478f086bc2 | 39 | if (_line_2.x_start <= 0) _line_2.x_start = 0; |
lewisgw | 21:20478f086bc2 | 40 | if (_line_2.x_end <= 0) { |
lewisgw | 9:fff2009f826e | 41 | _line_2.x_start = 80; |
lewisgw | 9:fff2009f826e | 42 | _line_2.x_end = 80; |
lewisgw | 9:fff2009f826e | 43 | } |
lewisgw | 9:fff2009f826e | 44 | } |
lewisgw | 6:8741d2011692 | 45 | |
lewisgw | 21:20478f086bc2 | 46 | void Platforms::set_line_3(int length) { |
lewisgw | 29:bdc4138b5171 | 47 | // Same as set_line_1. |
lewisgw | 9:fff2009f826e | 48 | _line_3.x_start--; |
lewisgw | 21:20478f086bc2 | 49 | if (_line_3.x_start < 80 - length) _line_3.x_end--; |
lewisgw | 21:20478f086bc2 | 50 | if (_line_3.x_start <= 0) _line_3.x_start = 0; |
lewisgw | 21:20478f086bc2 | 51 | if (_line_3.x_end <= 0) { |
lewisgw | 9:fff2009f826e | 52 | _line_3.x_start = 80; |
lewisgw | 9:fff2009f826e | 53 | _line_3.x_end = 80; |
lewisgw | 9:fff2009f826e | 54 | } |
lewisgw | 9:fff2009f826e | 55 | } |
lewisgw | 9:fff2009f826e | 56 | |
lewisgw | 18:304700b5d8f8 | 57 | Line Platforms::get_line_1() { |
lewisgw | 9:fff2009f826e | 58 | return _line_1; |
lewisgw | 9:fff2009f826e | 59 | } |
lewisgw | 6:8741d2011692 | 60 | |
lewisgw | 18:304700b5d8f8 | 61 | Line Platforms::get_line_2() { |
lewisgw | 9:fff2009f826e | 62 | return _line_2; |
lewisgw | 9:fff2009f826e | 63 | } |
lewisgw | 9:fff2009f826e | 64 | |
lewisgw | 18:304700b5d8f8 | 65 | Line Platforms::get_line_3() { |
lewisgw | 9:fff2009f826e | 66 | return _line_3; |
lewisgw | 9:fff2009f826e | 67 | } |
lewisgw | 6:8741d2011692 | 68 | |
lewisgw | 6:8741d2011692 | 69 | |
lewisgw | 15:876c047a6ec9 | 70 | |
lewisgw | 21:20478f086bc2 | 71 |