I'm trying to make a tilebased map.
I made a texture for water,grass,lava.
Then I made a rectagle shapes:
sf::RectangleShape grass;
grass.setTexture(&grassTexture);
grass.setSize(sf::Vector2f(50, 50));
sf::RectangleShape water;
water.setTexture(&waterTexture);
water.setSize(sf::Vector2f(50, 50));
sf::RectangleShape lava;
lava.setTexture(&lavaTexture);
lava.setSize(sf::Vector2f(50, 50));
Then and array for tiles:
sf::RectangleShape map[16][12];
And I put like this:
map[0][0] = grass;
map[0][1] = grass;
.....
map[15][11] = lava;
It takes a lot of space for all this.
Next I made and array for water collision and put in it all water tiles:
sf::RectangleShape waterCollision[56] = {map[1][1] , map[1][2] ,map[1][4]...};
And the at the end I draw them:
for(int d=0; d < 16; d++)
{
for(int f=0; f < 12; f++)
{
window.draw(map[d][f]);
}
}
All this works but is there any easier way to assign water,lava,grass to tiles?
And is there any easier way to do water collision?
Sorry for my english.