1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
// Here is a small helper for you ! Have a look.
// #include "ResourcePath.hpp"
#include <SFML/Graphics.hpp>
#include <iostream>
#define LARGEUR_TILE 24 /// hauteur et largeur des tiles.
#define HAUTEUR_TILE 16
#define NOMBRE_BLOCS_LARGEUR 15 /// nombre a afficher en x et y
#define NOMBRE_BLOCS_HAUTEUR 13
int table[15][13] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,0,1,1,1,1,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,3,4,0,0,0,2,2,2,2,0,0,2,2,
0,0,5,6,0,0,0,0,0,0,0,0,0,0,0,
0,0,5,6,0,0,0,0,0,0,0,0,0,0,0,
0,0,5,6,0,0,0,0,0,0,0,0,0,0,0,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
using namespace sf;
void Afficher(sf::RenderTarget &App, sf::Texture & tileset, int table[15][13],int nombre_blocs_largeur,int nombre_blocs_hauteur)
{
sf::Sprite Rect_source;
Rect_source.setTexture(tileset);
for (int i=0;i<nombre_blocs_largeur;i++)
{
for (int j = 0; j<nombre_blocs_hauteur; j++)
{
Rect_source.setTextureRect(sf::IntRect((table[j][i]) * LARGEUR_TILE, 0, (table[i][j]) * LARGEUR_TILE + LARGEUR_TILE, HAUTEUR_TILE));
Rect_source.setPosition(i * LARGEUR_TILE, j * HAUTEUR_TILE);
App.draw(Rect_source);
}
}
}
int main()
{
sf::RenderWindow app(sf::VideoMode(LARGEUR_TILE*NOMBRE_BLOCS_LARGEUR, HAUTEUR_TILE*NOMBRE_BLOCS_HAUTEUR), "Tile Mapping - Test");
sf::Texture tileset; tileset.loadFromFile("tileset1.bmp");
while (app.isOpen())
{
sf::Event event;
while (app.pollEvent(event))
{
if (event.type == sf::Event::Closed)
app.close();
}
app.clear();
Afficher(app, tileset, table, NOMBRE_BLOCS_LARGEUR, NOMBRE_BLOCS_HAUTEUR);
app.display();
}
return EXIT_SUCCESS;
} |
Partager