I now have the program reading the coordinates for the mirrors to be placed from a text file.
In Main(), the program opens the file, reads the coordinates for the mirror to be drawn, the colour of the mirror, and where it is to be placed on the screen. This means that for different levels, I can specify how many mirrors there will be, what kind of mirrors they will be, and where they are to be placed. There is a bar at the side of the screen where the mirrors for each level are placed, and the user drags them on to the grid and places them where they want.
I already had the mirror draw coordinates and colour in place, so to add the screen position coordinates, I added the variables posx and posy to the mirror function, which are then passed to main(). The Vector positions are assigned to posx and posy in the mirror function.
The mirror function:
Mirror45::Mirror45(float x1, float y1, float x2, float y2, float x3, float y3,float posx, float posy, int color)
{
myBitmap=create_bitmap(25,25);
clear_to_color(myBitmap,makecol(255,0,255));
triangle(myBitmap,x1,y1,x2,y2,x3,y3, color);
//rectfill(myBitmap,0,0,20,20,color);
position.x = posx;
position.y = posy;
}
The text file:
The values being passed to main, and main reading from a text file:
string astring, anotherstring, color;
float x1,y1,x2,y2,x3,y3,posx,posy;
while(!mirrors.eof())
{
getline(mirrors,astring);
stringstream ss(astring);
ss >> anotherstring;
if(anotherstring == "box")
{
ss >> x1;
ss >> y1;
ss >> x2;
ss >> y2;
ss >> x3;
ss >> y3;
ss >> color;
ss >> posx;
ss >> posy;
listOfShapes.push_back(new Mirror45(x1,y1,x2,y2,x3,y3,posx,posy,colorFunction(color)));
}
}
mirrors.close();
No comments:
Post a Comment