XJEL2645 (19/20) / Mbed 2 deprecated Explorer

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers item.cpp Source File

item.cpp

00001 #include "item.h"
00002 
00003 // Define sprite arrays.
00004 //this is the forward form of the item
00005 int item_form[5][6] = {
00006   { 0,0,1,1,0,0},
00007   { 0,1,1,1,1,0},
00008   { 1,1,1,1,1,1},
00009   { 0,1,1,1,1,0},
00010   { 0,0,1,1,0,0},
00011 };
00012 //this is the vertical form of the item
00013 
00014 // Constructor and destructor.
00015 item::item() {} 
00016 
00017 item::~item() {}
00018 
00019 void item::init() {
00020   // Starting position of the item.
00021   _x = 40;
00022   _y = 15;
00023 }
00024 
00025 void item::set_item(int random_x, int random_y) {
00026   // Set the item coords based on input values.
00027   // This function must have two rules
00028   //1 the item must be generated on the surface but not in the air
00029   //2 the item must be in the srceen or the explorer can not collect them
00030   if (_x < 6 || _x > 74) {  // Ensures the item does not generate off-screen.
00031     _x = 40; }//go back to the intial position
00032   else if (_y < 5 || _y > 75) 
00033   {
00034     _y = 15; };//go back to the intial position
00035   //according to the height of the line, the item must be generated upper the line but can not be so high
00036   //if y >40, the item need to be one the second line and if is lower it has to be one the lower line
00037   if (random_y > 40) {  
00038     _y = 45; 
00039   } else {
00040     _y = 15;
00041   }
00042   _x = random_x;//x can be every random value between 6 and 74
00043 }
00044 
00045 int *item::get_item_form() {
00046     return *item_form;
00047 }
00048 
00049 int item::get_item_x() {
00050   return _x;
00051 }
00052 
00053 int item::get_item_y() {
00054   return _y;
00055 } 
00056 
00057