Mochu Yao explorer game
Dependencies: mbed
item/item.cpp@39:0debc17bad29, 2020-05-15 (annotated)
- Committer:
- el17my
- Date:
- Fri May 15 09:03:36 2020 +0000
- Revision:
- 39:0debc17bad29
- Parent:
- 31:8e92b65e0779
the final version
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 | 9:e11bb7cef050 | 5 | int item_form[5][6] = { |
el17my | 1:ed745421d8c4 | 6 | { 0,0,1,1,0,0}, |
el17my | 8:201ef0618b7d | 7 | { 0,1,1,1,1,0}, |
el17my | 8:201ef0618b7d | 8 | { 1,1,1,1,1,1}, |
el17my | 8:201ef0618b7d | 9 | { 0,1,1,1,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 | |
el17my | 1:ed745421d8c4 | 14 | // Constructor and destructor. |
el17my | 1:ed745421d8c4 | 15 | item::item() {} |
el17my | 1:ed745421d8c4 | 16 | |
el17my | 1:ed745421d8c4 | 17 | item::~item() {} |
el17my | 1:ed745421d8c4 | 18 | |
el17my | 1:ed745421d8c4 | 19 | void item::init() { |
el17my | 3:672d4bd8225d | 20 | // Starting position of the item. |
el17my | 3:672d4bd8225d | 21 | _x = 40; |
el17my | 31:8e92b65e0779 | 22 | _y = 15; |
el17my | 1:ed745421d8c4 | 23 | } |
el17my | 1:ed745421d8c4 | 24 | |
el17my | 3:672d4bd8225d | 25 | void item::set_item(int random_x, int random_y) { |
el17my | 1:ed745421d8c4 | 26 | // Set the item coords based on input values. |
el17my | 3:672d4bd8225d | 27 | // This function must have two rules |
el17my | 3:672d4bd8225d | 28 | //1 the item must be generated on the surface but not in the air |
el17my | 3:672d4bd8225d | 29 | //2 the item must be in the srceen or the explorer can not collect them |
el17my | 3:672d4bd8225d | 30 | if (_x < 6 || _x > 74) { // Ensures the item does not generate off-screen. |
el17my | 9:e11bb7cef050 | 31 | _x = 40; }//go back to the intial position |
el17my | 3:672d4bd8225d | 32 | else if (_y < 5 || _y > 75) |
el17my | 3:672d4bd8225d | 33 | { |
el17my | 31:8e92b65e0779 | 34 | _y = 15; };//go back to the intial position |
el17my | 3:672d4bd8225d | 35 | //according to the height of the line, the item must be generated upper the line but can not be so high |
el17my | 3:672d4bd8225d | 36 | //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 | 37 | if (random_y > 40) { |
el17my | 31:8e92b65e0779 | 38 | _y = 45; |
el17my | 1:ed745421d8c4 | 39 | } else { |
el17my | 31:8e92b65e0779 | 40 | _y = 15; |
el17my | 1:ed745421d8c4 | 41 | } |
el17my | 3:672d4bd8225d | 42 | _x = random_x;//x can be every random value between 6 and 74 |
el17my | 1:ed745421d8c4 | 43 | } |
el17my | 3:672d4bd8225d | 44 | |
el17my | 3:672d4bd8225d | 45 | int *item::get_item_form() { |
el17my | 1:ed745421d8c4 | 46 | return *item_form; |
el17my | 1:ed745421d8c4 | 47 | } |
el17my | 1:ed745421d8c4 | 48 | |
el17my | 3:672d4bd8225d | 49 | int item::get_item_x() { |
el17my | 1:ed745421d8c4 | 50 | return _x; |
el17my | 1:ed745421d8c4 | 51 | } |
el17my | 1:ed745421d8c4 | 52 | |
el17my | 3:672d4bd8225d | 53 | int item::get_item_y() { |
el17my | 1:ed745421d8c4 | 54 | return _y; |
el17my | 1:ed745421d8c4 | 55 | } |
el17my | 3:672d4bd8225d | 56 | |
el17my | 9:e11bb7cef050 | 57 |