0

problem that I've got is that, so I'm creating blocks in my game in block class:

void Block::CreateBlocks() {
int count = 0;
coordinateX[0] = START_FLOOR_X;
coordinateY[0] = START_FLOOR_Y;
width[0] = al_get_bitmap_width(floorbmp);
for (int i = 1; i < MAX_BLOCKS; i++) {
    width[i] = (rand() % MAX_RANDOM_X_SIZE) + MIN_RANDOM_X_SIZE;
    while (width[i] > MAX_RANDOM_X_SIZE) {
        width[i] = (rand() % MAX_RANDOM_X_SIZE) + MIN_RANDOM_X_SIZE;
    }
}
for (int i = 1; i < MAX_BLOCKS; i++) {
            coordinateX[i] = rand() % START_OF_RIGHT_WALL;
            while (coordinateX[i] < WALL_WIDTH || coordinateX[i] + width[i] >= START_OF_RIGHT_WALL) {
                coordinateX[i] = rand() % START_OF_RIGHT_WALL;
            }
        coordinateY[i] = 430 - count * 116;
        count++;
    }

} Now, I'd like to create class Bonus, where I'll read X,Y position of single block, and then i'll create a Bonus on it. The question is, how I can read these arrays: coordinateX, coordinateY, width from block class in bonus class?

Thanks!

  • 1
    Please have a look at this [C++ books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) list. – Ron Nov 26 '17 at 15:28
  • If you need info about a Block, perhaps you should pass the Block as a parameter to Bonus? – Bo Persson Nov 26 '17 at 15:35
  • Huh, yeah thanks, I was very confused, because I thought, that I have to pass whole arrays, I mean *CoordinateX[MAX_BLOCKS]* from Block to Bonus, but this works well. Thanks for your answer – Maciej Wroński Nov 26 '17 at 15:44
  • BTW, passing `std::vector` is easier than passing arrays. With arrays, you need to pass the array, the capacity and the number of valid elements in the array. Also, remember to pass the vector by constant reference if you are not modifying it or by reference. – Thomas Matthews Nov 26 '17 at 18:08
  • Thanks for answer, yeah I've seen another threads, where people suggested to use **std::vector**, but I've got already arrays so... Anyway, thanks for answer, cheers! – Maciej Wroński Nov 26 '17 at 20:12

0 Answers0