Mochu Yao explorer game
Dependencies: mbed
item/item.h
- Committer:
- el17my
- Date:
- 2020-04-15
- Revision:
- 1:ed745421d8c4
- Child:
- 2:89f04cd3bf45
File content as of revision 1:ed745421d8c4:
#ifndef ITEM_H #define ITEM_H #include "mbed.h" /** item Class * @the item class has three functions 1 generate an item in random position after one disappear 2 build the item's structer 3 build a barrier to increase difficulty * @date April 13th 2020 * @author Yaomochu @code #include "mbed.h" #include "item.h" #include "Gamepad.h" #include "N5110.h" #include <cstdlib> #include <ctime> N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad gamepad; item _item; int _explorer_x; int _explorer_y; int _score; bool _collision_flag; int main() { _item.init(); _explorer_x = 40; _explorer_y = 15; _player_score = 0; srand(time(NULL));%this srand comment reqire the coin to get a random location value while(1){ // If the player collides with the item,a flag will be set to run the interruprtion. player's score will be +1 if (_explorer_x == _item.get_x()&&(_explorer_y == _item.get_y() - 5)) { _collision_flag = true; _score++; // the item will have a new random position and make a noise. _item.set_item((rand()%100),(abs(rand()%100 - 10))); // Place item on a constrained random position. gamepad.tone(2000, 0.05); // Make collection noise on buzzer. // If the player collides with the barrier,a flag will be set to run the interruprtion. player's score will be -1 if (_explorer_x == _barrier.get_x()&&(_explorer_y == _barrier.get_y() - 5)) { _collision_flag = true; _score--; // the barrier will have a new random position and make a noise. _item.set_barrier((rand()%100),(abs(rand()%100 - 10))); // Place barrier on a constrained random position. gamepad.tone(3000, 0.05); // Make collection noise on buzzer. } // than draw the next item on the lcd. lcd.drawSprite(_item.get_x(),_item.get_y(),6,5,(int*)_item.get_item_sprite()); lcd.drawSprite(_barrier.get_x(),_barrier.get_y(),7,7,(int*)_barrier.get_barrier_sprite()); } } @endcode */ class item { public: // Constructor and Destructor. item(); ~item(); // Initialises Coin object.*/ void init(); //Generates the item and barrier. void generate_item(); //Sets the item coordinates. //rand_x = a random number that determines the x coordinate //rand_y = a random number that determines if the item's generated level void set_item(int rand_x, int rand_y); void set_barrier(int rand_dx, int rand_dy); int *get_item_sprite(); int get_item_x(); int get_item_y(); int *get_barrier_sprite(); int get_barrier_bx(); int get_barrier_by(); private: int _x; int _y; int _bx; int _by; int _loop; bool _rotate_item; }; #endif