Advertisement

Rects and arrays

Started by February 07, 2000 12:30 AM
0 comments, last by Zombie 24 years, 10 months ago
I have 84 inventory slots, which are all RECTs. I should write their coordinates, but because they are all same size, there has to be another way to do it. First one begins at 25,25 and ends at 75,75. So all rects are 50*50 size in pixels. They are aligned as 6*14: six in each col, and 14 in each row. So 84 total. What I need to know is- how can I write their coordinates from a loop or by any other way than writing them myself? All the slots are in one array, ItemSlots().
I'm too tired to do it all right now, but all you have to do is set up some nested for loops, and do something like this:
for(int x = 0; x < NUM_ROWS; x++)  for(int y = 0; y < NUM_COLS; y++)  {    rects[x][y].top = y * HEIGHT;    rects[x][y].bottom = (y*HEIGHT) + HEIGHT;    rects[x][y].left = x * WIDTH;    rects[x][y].right = (x*WIDTH) + WIDTH;  }  


Something like that should work. If I got the orientation wrong, or anything like that (because I think I might have messed up on the orientation of the indexes), then it's because I'm really tired right now so be sure to go over what you're trying to do on paper, with diagrams or something before you take the code I wrote too seriously. That always helps me

Hope this helped!

------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge

Edited by - Qoy on 2/7/00 3:07:27 AM

This topic is closed to new replies.

Advertisement