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
item/item.cpp@3:672d4bd8225d, 2020-04-21 (annotated)
- Committer:
 - el17my
 - Date:
 - Tue Apr 21 12:31:27 2020 +0000
 - Revision:
 - 3:672d4bd8225d
 - Parent:
 - 1:ed745421d8c4
 - Child:
 - 7:88c4ba6bb37b
 
creating the line on the screen
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| el17my | 1:ed745421d8c4 | 1 | #include "item.h" | 
| el17my | 1:ed745421d8c4 | 2 | |
| el17my | 1:ed745421d8c4 | 3 | // Define sprite arrays. | 
| el17my | 3:672d4bd8225d | 4 | //this is the forward form of the item | 
| el17my | 1:ed745421d8c4 | 5 | int item_form[6][5] = { | 
| el17my | 1:ed745421d8c4 | 6 | { 0,0,1,1,0,0}, | 
| el17my | 1:ed745421d8c4 | 7 | { 0,1,0,0,1,0}, | 
| el17my | 3:672d4bd8225d | 8 | { 1,0,0,0,0,1}, | 
| el17my | 1:ed745421d8c4 | 9 | { 0,1,0,0,1,0}, | 
| el17my | 1:ed745421d8c4 | 10 | { 0,0,1,1,0,0}, | 
| el17my | 1:ed745421d8c4 | 11 | }; | 
| el17my | 3:672d4bd8225d | 12 | //this is the vertical form of the item | 
| el17my | 1:ed745421d8c4 | 13 | int item_vertical[6][5] = { | 
| el17my | 1:ed745421d8c4 | 14 | { 0,0,1,1,0,0}, | 
| el17my | 1:ed745421d8c4 | 15 | { 0,0,1,1,0,0}, | 
| el17my | 1:ed745421d8c4 | 16 | { 0,0,1,1,0,0}, | 
| el17my | 1:ed745421d8c4 | 17 | { 0,0,1,1,0,0}, | 
| el17my | 1:ed745421d8c4 | 18 | { 0,0,1,1,0,0}, | 
| el17my | 1:ed745421d8c4 | 19 | }; | 
| el17my | 1:ed745421d8c4 | 20 | |
| el17my | 1:ed745421d8c4 | 21 | // Constructor and destructor. | 
| el17my | 1:ed745421d8c4 | 22 | item::item() {} | 
| el17my | 1:ed745421d8c4 | 23 | |
| el17my | 1:ed745421d8c4 | 24 | item::~item() {} | 
| el17my | 1:ed745421d8c4 | 25 | |
| el17my | 1:ed745421d8c4 | 26 | void item::init() { | 
| el17my | 3:672d4bd8225d | 27 | // Starting position of the item. | 
| el17my | 3:672d4bd8225d | 28 | _x = 40; | 
| el17my | 3:672d4bd8225d | 29 | _y = 40; | 
| el17my | 3:672d4bd8225d | 30 | _loop = 0;//the loop must be set to zero | 
| el17my | 1:ed745421d8c4 | 31 | } | 
| el17my | 1:ed745421d8c4 | 32 | |
| el17my | 1:ed745421d8c4 | 33 | void item::generate_item() { | 
| el17my | 1:ed745421d8c4 | 34 | // make the item rotating every 4 loops | 
| el17my | 3:672d4bd8225d | 35 | for(_loop = 0; loop<4; _loop++;) { | 
| el17my | 1:ed745421d8c4 | 36 | if (_loop == 3) { | 
| el17my | 1:ed745421d8c4 | 37 | _loop = 0; | 
| el17my | 1:ed745421d8c4 | 38 | _rotate_item = !_rotate_item; | 
| el17my | 3:672d4bd8225d | 39 | } | 
| el17my | 3:672d4bd8225d | 40 | wait(0.05); | 
| el17my | 1:ed745421d8c4 | 41 | } | 
| el17my | 1:ed745421d8c4 | 42 | |
| el17my | 3:672d4bd8225d | 43 | void item::set_item(int random_x, int random_y) { | 
| el17my | 1:ed745421d8c4 | 44 | // Set the item coords based on input values. | 
| el17my | 3:672d4bd8225d | 45 | // This function must have two rules | 
| el17my | 3:672d4bd8225d | 46 | //1 the item must be generated on the surface but not in the air | 
| el17my | 3:672d4bd8225d | 47 | //2 the item must be in the srceen or the explorer can not collect them | 
| el17my | 3:672d4bd8225d | 48 | if (_x < 6 || _x > 74) { // Ensures the item does not generate off-screen. | 
| el17my | 3:672d4bd8225d | 49 | _x = 40;//go back to the intial position | 
| el17my | 3:672d4bd8225d | 50 | else if (_y < 5 || _y > 75) | 
| el17my | 3:672d4bd8225d | 51 | { | 
| el17my | 3:672d4bd8225d | 52 | _y = 50; };//go back to the intial position | 
| el17my | 3:672d4bd8225d | 53 | //according to the height of the line, the item must be generated upper the line but can not be so high | 
| el17my | 3:672d4bd8225d | 54 | //if y >40, the item need to be one the second line and if is lower it has to be one the lower line | 
| el17my | 3:672d4bd8225d | 55 | if (random_y > 40) { | 
| el17my | 3:672d4bd8225d | 56 | _y = 40; | 
| el17my | 1:ed745421d8c4 | 57 | } else { | 
| el17my | 3:672d4bd8225d | 58 | _y = 25; | 
| el17my | 1:ed745421d8c4 | 59 | } | 
| el17my | 3:672d4bd8225d | 60 | _x = random_x;//x can be every random value between 6 and 74 | 
| el17my | 1:ed745421d8c4 | 61 | } | 
| el17my | 3:672d4bd8225d | 62 | |
| el17my | 3:672d4bd8225d | 63 | int *item::get_item_form() { | 
| el17my | 3:672d4bd8225d | 64 | //by changing the form from forward to vertical each 4 loop the item can start rotating | 
| el17my | 1:ed745421d8c4 | 65 | if (_rotate_item) { | 
| el17my | 1:ed745421d8c4 | 66 | return *item_form; | 
| el17my | 3:672d4bd8225d | 67 | } else if(!_rotate_item) { | 
| el17my | 1:ed745421d8c4 | 68 | return *item_vertical; | 
| el17my | 1:ed745421d8c4 | 69 | } | 
| el17my | 1:ed745421d8c4 | 70 | } | 
| el17my | 1:ed745421d8c4 | 71 | |
| el17my | 3:672d4bd8225d | 72 | int item::get_item_x() { | 
| el17my | 1:ed745421d8c4 | 73 | return _x; | 
| el17my | 1:ed745421d8c4 | 74 | } | 
| el17my | 1:ed745421d8c4 | 75 | |
| el17my | 3:672d4bd8225d | 76 | int item::get_item_y() { | 
| el17my | 1:ed745421d8c4 | 77 | return _y; | 
| el17my | 1:ed745421d8c4 | 78 | } | 
| el17my | 3:672d4bd8225d | 79 | |
| el17my | 1:ed745421d8c4 | 80 | } |