Mochu Yao explorer game

Dependencies:   mbed

item/item.cpp

Committer:
el17my
Date:
2020-05-15
Revision:
39:0debc17bad29
Parent:
31:8e92b65e0779

File content as of revision 39:0debc17bad29:

#include "item.h"

// Define sprite arrays.
//this is the forward form of the item
int item_form[5][6] = {
  { 0,0,1,1,0,0},
  { 0,1,1,1,1,0},
  { 1,1,1,1,1,1},
  { 0,1,1,1,1,0},
  { 0,0,1,1,0,0},
};
//this is the vertical form of the item

// Constructor and destructor.
item::item() {} 

item::~item() {}

void item::init() {
  // Starting position of the item.
  _x = 40;
  _y = 15;
}

void item::set_item(int random_x, int random_y) {
  // Set the item coords based on input values.
  // 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 = 15; };//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 = 45; 
  } else {
    _y = 15;
  }
  _x = random_x;//x can be every random value between 6 and 74
}

int *item::get_item_form() {
    return *item_form;
}

int item::get_item_x() {
  return _x;
}

int item::get_item_y() {
  return _y;
}