Mochu Yao explorer game
Dependencies: mbed
Diff: item/item.cpp
- Revision:
- 3:672d4bd8225d
- Parent:
- 1:ed745421d8c4
- Child:
- 7:88c4ba6bb37b
--- a/item/item.cpp Mon Apr 20 08:31:02 2020 +0000 +++ b/item/item.cpp Tue Apr 21 12:31:27 2020 +0000 @@ -1,24 +1,15 @@ #include "item.h" // Define sprite arrays. -int barrier_form[7][7] = { - { 0,0,0,0,0,0,0 }, - { 0,1,1,1,1,1,0 }, - { 0,1,0,0,0,1,0 }, - { 0,1,0,0,0,1,0 }, - { 0,1,0,0,0,1,0 }, - { 0,1,0,0,0,1,0 }, - { 0,1,1,1,1,1,0 }, -}; - +//this is the forward form of the item int item_form[6][5] = { { 0,0,1,1,0,0}, { 0,1,0,0,1,0}, - { 1,0,1,0,0,1}, + { 1,0,0,0,0,1}, { 0,1,0,0,1,0}, { 0,0,1,1,0,0}, }; - +//this is the vertical form of the item int item_vertical[6][5] = { { 0,0,1,1,0,0}, { 0,0,1,1,0,0}, @@ -33,73 +24,57 @@ item::~item() {} void item::init() { - // Starting position of the coin. - _x = 30; - _y = 35; - _bx = 60; - _by = 30; - _counter = 0; + // Starting position of the item. + _x = 40; + _y = 40; + _loop = 0;//the loop must be set to zero } void item::generate_item() { // make the item rotating every 4 loops + for(_loop = 0; loop<4; _loop++;) { if (_loop == 3) { _loop = 0; _rotate_item = !_rotate_item; - } - _loop++; -} - -void item::set_item(int rand_x, int rand_y) { - // Set the item coords based on input values. - if (rand_y < 40) { - _y = 35; - } else { - _y = 20; - } - _x = rand_x; - if (_x < 5 || _x > 75) { // Ensures the item does not generate off-screen. - _x = 45; - } + } + wait(0.05); } -void item::set_barrier(int rand_x, int rand_y) { +void item::set_item(int random_x, int random_y) { // Set the item coords based on input values. - if (rand_dy < 35) { - _dy = 40; + // This function must have two rules + //1 the item must be generated on the surface but not in the air + //2 the item must be in the srceen or the explorer can not collect them + if (_x < 6 || _x > 74) { // Ensures the item does not generate off-screen. + _x = 40;//go back to the intial position + else if (_y < 5 || _y > 75) + { + _y = 50; };//go back to the intial position + //according to the height of the line, the item must be generated upper the line but can not be so high + //if y >40, the item need to be one the second line and if is lower it has to be one the lower line + if (random_y > 40) { + _y = 40; } else { - _dy = 15; + _y = 25; } - _dx = rand_dx; - if (_dx < 5 || _dx > 75) { // Ensures the item does not generate off-screen. - _dx = 50; - } + _x = random_x;//x can be every random value between 6 and 74 } -int *item::get_barrier_sprite() { - // Return different coin sprites. + +int *item::get_item_form() { + //by changing the form from forward to vertical each 4 loop the item can start rotating if (_rotate_item) { return *item_form; - } else { + } else if(!_rotate_item) { return *item_vertical; } } -int *item::get_item_sprite() { - - return *barrier_form; - } -} - -int Coin::get_coin_x() { +int item::get_item_x() { return _x; } -int Coin::get_coin_y() { +int item::get_item_y() { return _y; } -int item::get_barrier_bx() { - return _bx; -} -int Coin::get_barrier_by() { - return _by; + } \ No newline at end of file