Mochu Yao explorer game
Dependencies: mbed
item/item.cpp
- Committer:
- el17my
- Date:
- 2020-04-15
- Revision:
- 1:ed745421d8c4
- Child:
- 3:672d4bd8225d
File content as of revision 1:ed745421d8c4:
#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 }, }; int item_form[6][5] = { { 0,0,1,1,0,0}, { 0,1,0,0,1,0}, { 1,0,1,0,0,1}, { 0,1,0,0,1,0}, { 0,0,1,1,0,0}, }; int item_vertical[6][5] = { { 0,0,1,1,0,0}, { 0,0,1,1,0,0}, { 0,0,1,1,0,0}, { 0,0,1,1,0,0}, { 0,0,1,1,0,0}, }; // Constructor and destructor. item::item() {} item::~item() {} void item::init() { // Starting position of the coin. _x = 30; _y = 35; _bx = 60; _by = 30; _counter = 0; } void item::generate_item() { // make the item rotating every 4 loops 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; } } void item::set_barrier(int rand_x, int rand_y) { // Set the item coords based on input values. if (rand_dy < 35) { _dy = 40; } else { _dy = 15; } _dx = rand_dx; if (_dx < 5 || _dx > 75) { // Ensures the item does not generate off-screen. _dx = 50; } } int *item::get_barrier_sprite() { // Return different coin sprites. if (_rotate_item) { return *item_form; } else { return *item_vertical; } } int *item::get_item_sprite() { return *barrier_form; } } int Coin::get_coin_x() { return _x; } int Coin::get_coin_y() { return _y; } int item::get_barrier_bx() { return _bx; } int Coin::get_barrier_by() { return _by; }