#include "../include/my.h"
int main()
{
int width = 5;
int height = 3;
sfVideoMode mode = {512, 256, 32};
sfRenderWindow *window = sfRenderWindow_create(mode, "MY_RUNNER", sfResize | sfClose, NULL);
int lvl[] =
{
2, 2, 2, 2, 2,
2, 2, 1, 2, 1,
0, 0, 0, 0, 0,
};
sfTexture *texture = sfTexture_createFromFile("./img/social.png", NULL);
sfVertexArray *vertex = sfVertexArray_create();
sfVertexArray_setPrimitiveType(vertex, sfQuads);
sfVertexArray_resize(vertex, width * height * 4);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
int nbr = lvl[i + j * width];
sfVertex *quad = sfVertexArray_getVertex(vertex, (i + j * width) * 4);
quad[0].position = (sfVector2f){i * 32, j * 32};
quad[1].position = (sfVector2f){(i + 1) * 32, j * 32};
quad[2].position = (sfVector2f){(i + 1) * 32, (j + 1) * 32};
quad[3].position = (sfVector2f){i * 32, (j + 1) * 32};
quad[0].texCoords = (sfVector2f){nbr * 32, 0};
quad[1].texCoords = (sfVector2f){(nbr + 1) * 32, 0};
quad[2].texCoords = (sfVector2f){(nbr + 1) * 32, 32};
quad[3].texCoords = (sfVector2f){nbr * 32, 32};
}
}
sfRenderStates states;
states.texture = texture;
while (sfRenderWindow_isOpen(window))
{
sfEvent event;
while (sfRenderWindow_pollEvent(window, &event))
{
if (event.type == sfEvtClosed)
sfRenderWindow_close(window);
}
sfRenderWindow_clear(window, sfBlack);
sfRenderWindow_drawVertexArray(window, vertex, states);
sfRenderWindow_display(window);
}
sfTexture_destroy(texture);
sfVertexArray_destroy(vertex);
sfRenderWindow_destroy(window);
return (0);
}