This is starting to read more like diary entries than a thread...
Dear Diary,
Today I found out about a nifty little function: random_shuffle. I used it and to my delight I found that it accomplished exactly what I was trying to do without all of that messy math stuff. That is just swell but it does feel a little like cheating since my ultimate goal is to better understand programming in c++ vs. piggybacking off the work of others; but it works for now. It works too well. Not only are my two little sprites randomly drawing to locations within my defined ranges, they just won't stop redrawing. Its sprites run amok! Hmmm...?
void Levels::BrickLocations( )
{
using std::time;
using std::srand;
using std::rand;
using std::random_shuffle;
shuffled = false;
// Stores the X axis coordinates for the bricks in all levels
int row [7] = {75, 175, 275, 375, 475, 575, 675};
// Stores the Y axis coordinates for the bricks in all levels
int column[7] = {125, 175, 225, 275, 325, 375, 425};
// Shuffles the elements of each array
if (!shuffled)
{
random_shuffle(&row[0], &row[6]);
random_shuffle(&column[0], &column[6]);
shuffled;
}
r1 = row[0], r2 = row[1], r3 = row[2], r4 = row[3],
r5 = row[4], r6 = row[5], r7 = row[6];
c1= column[0], c2 = column[1], c3 = column[2],
c4 = column[3],c5 = column[4], c6 = column[5],
c7 = column[6];
return;
}
void Levels::LevelOne( )
{
// Sets up the bricks
dbSprite (REDBRICK, r4, c1, 30);
dbOffsetSprite (REDBRICK, 25, 50);
dbRotateSprite (REDBRICK, 0);
dbSetSpritePriority (REDBRICK, 9);
dbSprite (GLASS, r1, c3, 31);
dbOffsetSprite (GLASS, 25, 50);
dbRotateSprite (GLASS, 0);
dbSetSpritePriority (GLASS, 9);
return;
}
Well, at the least I have figured out how to structure my code to call on class functions in a way that I already understand, so that counts for something, this bit is just a little frustrating. I wonder if hurling a javaline at my computer monitor will help?
P.S. If there are any helpful souls out there, "srand (time (0))" is located at the first line of my main loop but outside of this class and all variables used here are publically declared in my class header. I only initialize the variables at the time of use. It feels more organized to do it this way but I fear that I may be forming a bad habit.
Haikus are easy; But sometimes they don’t make sense; Pteredactyl pie