std::vector<Tile> env;
sf::VertexArray tiles;
bool Game::LoadTileMap(double SCR_WIDTH, double SCR_HEIGHT)
{
float size = 60;
int ytiles = (int)SCR_HEIGHT / (int)size;
int xtiles = (int)SCR_WIDTH / (int)size;
int tilesnum = ytiles * xtiles;
for (int i = 0; i <= ytiles; i++)
{
for (int j = 0; j < xtiles; j++)
{
sf::Vector2f vec0 = sf::Vector2f(0 + (j * size), 0+(i*size));
sf::Vector2f vec1 = sf::Vector2f(size + (size * j), 0 + (i * size));
sf::Vector2f vec2 = sf::Vector2f(size + (j*size), size + (i*size));
sf::Vector2f vec3 = sf::Vector2f(0 + (j*size), size+(i*size));
Tile tile(size, vec0, vec1, vec2, vec3);
env.push_back(tile);
}
}
tiles.setPrimitiveType(sf::Quads);
tiles.resize(tilesnum * 4);
sf::Vector2f v0;
sf::Vector2f v1;
sf::Vector2f v2;
sf::Vector2f v3;
std::cout << tilesnum << std::endl;
int numofvertex = 0;
for (int i = 0, j=0; i < tilesnum; i++, j+=4)
{
sf::Vector2f v0 = env.at(i).getVec0();
sf::Vector2f v1 = env.at(i).getVec1();
sf::Vector2f v2 = env.at(i).getVec2();
sf::Vector2f v3 = env.at(i).getVec3();
sf::Color newcolor = env.at(i).getColor();
tiles[j].position = v0;
tiles[j + 1].position = v1;
tiles[j + 2].position = v2;
tiles[j + 3].position = v3;
tiles[j].color = newcolor;
tiles[j + 1].color = newcolor;
tiles[j + 2].color = newcolor;
tiles[j+3].color = newcolor;
numofvertex += 4;
}
vertexnumber = numofvertex;
std::cout << "numofvertex: " << numofvertex << std::endl;
std::cout << "ntiles: " << tilesnum << std::endl;
return true;
}