So in an attempt to move out of the console environment I have set up an SFML poject in Visual Studio. I am currently trying to draw a stage from a vector within a vector (Matrix?), and the results are not exactly what I was hoping for.
First i tried mapping out everything as '0's representing empty space, changing the top and bottom vector to '1's, representing objects, thus drawing what essentially would be a rectangle covering the bottom and a rectangle covering the top, everything inbetween ignored.
bool stage::load()
{
vector<int> tempvec;
for (int i = 0; i != 30; i++)
{
for (int j = 0; j != 40; j++)
{
tempvec.push_back(0);
}
hitbox.push_back(tempvec);
tempvec.clear();
}
for (int i = 40 - 1; i != -1; i--)
{
hitbox[29][i] = 1;
}
for (int i = 30 - 1; i != -1; i--)
{
hitbox[i][0] = 1;
}
return true; //Will use this more efficently once I get the function to work
}
So this is how I set up the stage variable-wise, hitbox being defined as:
vector <vector<int>> stage::hitbox;
I then try to map out the individual blocks, so every time it finds a '1' in the vector, it should print out a square (quad).
vector<VertexArray> tilesetrender;
VertexArray tmp(Quads, 4);
tmp.resize(4);
level.load();
for (int y = level.hitbox.size() - 1; y >= 0; y--)
{
for (int x = level.hitbox.at(y).size() - 1; x >= 0; x--)
{
switch(level.hitbox[y][x]) //Switch case allows me to expand on this function in the future
{
case 1:
tmp[0].position = Vector2f(y * 20 - 10, x * 20 - 10);
tmp[1].position = Vector2f(y * 20 - 10, x * 20 + 10);
tmp[2].position = Vector2f(y * 20 + 10, x * 20 + 10);
tmp[3].position = Vector2f(y * 20 + 10, x * 20 - 10);
tilesetrender.push_back(tmp);
}
}
}
With all the variables created, I proceed to draw the level.
for (int count = tilesetrender.size() - 1; count >= 0; count--)
{
renderWindow.draw(tilesetrender.at(count));
}
And what I get is this...
The vertices being white, and the background being red. As I have said, I hoped for drawing two rectangles, one at the top and one at the bottom. I have no real idea regarding what part of my code is causing the error, but I've played around with the position commands the most, to no avail.
Thanks in advance.
EDIT: Code partially corrected (Thanks Alayric), thus rendering this image instead:
White being the vertices, red the background and blue the player (previously not visible).
Although it is a whole lot better, something is still incorrect, as the upper rectangle does not reach all the way, and the lower rectangle does not mirror the upper. I do belive the main problem has been solved, and thus I am able to continue on my own.