createur de map fini
This commit is contained in:
@@ -55,5 +55,5 @@ void nullScore(score *player_score);
|
|||||||
void winOrLoseLoop(dis *display_user,score *score_user, bool win);
|
void winOrLoseLoop(dis *display_user,score *score_user, bool win);
|
||||||
unsigned int scoreCalculator(score *score_user, bool win);
|
unsigned int scoreCalculator(score *score_user, bool win);
|
||||||
int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
||||||
int nbr_targets, dis *display_user, score *score_user);
|
int nbr_targets, dis *display_user,score *score_user, int num_fichier);
|
||||||
#endif // FONCTION_H
|
#endif // FONCTION_H
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
################
|
|
||||||
# #
|
|
||||||
# IIIIIIIIIII #
|
|
||||||
# CCCCCCCCCCC #
|
|
||||||
# #
|
|
||||||
# #
|
|
||||||
# P #
|
|
||||||
################
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#############
|
|
||||||
##### I #
|
|
||||||
# C #
|
|
||||||
# #
|
|
||||||
# P #
|
|
||||||
#############
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
##########
|
|
||||||
#PC I#
|
|
||||||
# C #
|
|
||||||
#I #
|
|
||||||
##########
|
|
||||||
@@ -137,6 +137,8 @@ char canIGoDirection (char valueOfNCase, char valueOfNPlusOneCase)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Cette fonction effectue les deplacements du joueur et des boites en
|
* \brief Cette fonction effectue les deplacements du joueur et des boites en
|
||||||
* fonction de la situation.
|
* fonction de la situation.
|
||||||
@@ -428,6 +430,39 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* \brief La fonction permet de retranscrire un niveau creer du tableau vers le fichier.txt
|
||||||
|
* \param filename Le nom du fichier a remplir.
|
||||||
|
* \param tab2d Le tableau 2d carre.
|
||||||
|
*/
|
||||||
|
void save_grid_to_file(int filename, char **tab2D) {
|
||||||
|
|
||||||
|
char path[250];
|
||||||
|
snprintf(path, sizeof(path), "maps/custom_%d.txt", filename);
|
||||||
|
FILE *file = fopen(path, "w");
|
||||||
|
|
||||||
|
// Parcours et sauvegarde du tableau 2D dans le fichier
|
||||||
|
for (int i = 0; i < 20; i++) {
|
||||||
|
for (int j = 0; j < 20; j++) {
|
||||||
|
switch (tab2D[i][j]) {
|
||||||
|
case EMPTY: fputc(' ',file);break;
|
||||||
|
case WALL: fputc('#',file); break;
|
||||||
|
case BOX: fputc('C',file);break;
|
||||||
|
case TARGET: fputc('I',file); break;
|
||||||
|
case BOX_ON_TARGET: fputc(' ',file); break;
|
||||||
|
case PLAYER: fputc('P',file); break;
|
||||||
|
case PLAYER_ON_TARGET: fputc('P',file); break;
|
||||||
|
default: return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fputc('\n',file); // Nouvelle ligne pour chaque ligne du tableau
|
||||||
|
|
||||||
|
}
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* \brief La fonction permet de faire la boucle de l'éditeur.
|
* \brief La fonction permet de faire la boucle de l'éditeur.
|
||||||
@@ -440,10 +475,11 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
* \param display_user Tout les information SDL pour afficher le jeu.
|
* \param display_user Tout les information SDL pour afficher le jeu.
|
||||||
* \param score_user Toute les données nécessaire pour calculer le score fini
|
* \param score_user Toute les données nécessaire pour calculer le score fini
|
||||||
* du joueur.
|
* du joueur.
|
||||||
|
* \param num_fichier Simplement le numéro de la map actuel.
|
||||||
* \return renvoie -2 ce qui signifie l'editeur
|
* \return renvoie -2 ce qui signifie l'editeur
|
||||||
*/
|
*/
|
||||||
int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
||||||
int nbr_targets, dis *display_user, score *score_user)
|
int nbr_targets, dis *display_user,score *score_user, int num_fichier)
|
||||||
{
|
{
|
||||||
vect direction = { 0, 0 };
|
vect direction = { 0, 0 };
|
||||||
int fov = -1;
|
int fov = -1;
|
||||||
@@ -469,7 +505,7 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
|
|
||||||
|
|
||||||
int GRID_SIZE = 20;
|
int GRID_SIZE = 20;
|
||||||
int BLOCK_SIZE = 24;
|
int BLOCK_SIZE = 25;
|
||||||
int GRID_X_OFFSET =100;
|
int GRID_X_OFFSET =100;
|
||||||
int GRID_Y_OFFSET =0;
|
int GRID_Y_OFFSET =0;
|
||||||
while (!finish)
|
while (!finish)
|
||||||
@@ -478,6 +514,7 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
while (SDL_PollEvent (&event))
|
while (SDL_PollEvent (&event))
|
||||||
{
|
{
|
||||||
if (event.type == SDL_QUIT) {
|
if (event.type == SDL_QUIT) {
|
||||||
|
save_grid_to_file(num_fichier,tab2d);
|
||||||
return 0; // Quitter si l'utilisateur ferme la fenêtre
|
return 0; // Quitter si l'utilisateur ferme la fenêtre
|
||||||
}
|
}
|
||||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||||
@@ -486,7 +523,6 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
int click_x, click_y;
|
int click_x, click_y;
|
||||||
SDL_GetMouseState(&click_x, &click_y); // Récupérer la position de la souris
|
SDL_GetMouseState(&click_x, &click_y); // Récupérer la position de la souris
|
||||||
|
|
||||||
printf("Clic gauche à la position: (%d, %d)\n", click_x, click_y);
|
|
||||||
|
|
||||||
if (click_x >= GRID_X_OFFSET && click_x < GRID_X_OFFSET + GRID_SIZE * BLOCK_SIZE &&
|
if (click_x >= GRID_X_OFFSET && click_x < GRID_X_OFFSET + GRID_SIZE * BLOCK_SIZE &&
|
||||||
click_y >= GRID_Y_OFFSET && click_y < GRID_Y_OFFSET + GRID_SIZE * BLOCK_SIZE) {
|
click_y >= GRID_Y_OFFSET && click_y < GRID_Y_OFFSET + GRID_SIZE * BLOCK_SIZE) {
|
||||||
@@ -506,10 +542,6 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
}
|
}
|
||||||
// Met à jour l'affichage
|
// Met à jour l'affichage
|
||||||
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov);
|
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov);
|
||||||
|
|
||||||
printf("Clic détecté dans la case [%d][%d]. Nouvelle valeur : %d\n", row, col, tab2d[row][col]);
|
|
||||||
} else {
|
|
||||||
printf("Clic hors de la grille.\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.button.button == SDL_BUTTON_RIGHT) {
|
if (event.button.button == SDL_BUTTON_RIGHT) {
|
||||||
@@ -517,8 +549,6 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
int click_x, click_y;
|
int click_x, click_y;
|
||||||
SDL_GetMouseState(&click_x, &click_y); // Récupérer la position de la souris
|
SDL_GetMouseState(&click_x, &click_y); // Récupérer la position de la souris
|
||||||
|
|
||||||
printf("Clic droit à la position: (%d, %d)\n", click_x, click_y);
|
|
||||||
|
|
||||||
if (click_x >= GRID_X_OFFSET && click_x < GRID_X_OFFSET + GRID_SIZE * BLOCK_SIZE &&
|
if (click_x >= GRID_X_OFFSET && click_x < GRID_X_OFFSET + GRID_SIZE * BLOCK_SIZE &&
|
||||||
click_y >= GRID_Y_OFFSET && click_y < GRID_Y_OFFSET + GRID_SIZE * BLOCK_SIZE) {
|
click_y >= GRID_Y_OFFSET && click_y < GRID_Y_OFFSET + GRID_SIZE * BLOCK_SIZE) {
|
||||||
|
|
||||||
@@ -535,12 +565,9 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
{
|
{
|
||||||
tab2d[row][col] -= 1;
|
tab2d[row][col] -= 1;
|
||||||
}
|
}
|
||||||
|
printf("mtn la case est a %hd \n",tab2d[row][col]);
|
||||||
// Met à jour l'affichage
|
// Met à jour l'affichage
|
||||||
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov);
|
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov);
|
||||||
|
|
||||||
printf("Clic détecté dans la case [%d][%d]. Nouvelle valeur : %d\n", row, col, tab2d[row][col]);
|
|
||||||
} else {
|
|
||||||
printf("Clic hors de la grille.\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -551,7 +578,8 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
{
|
{
|
||||||
case SDL_SCANCODE_ESCAPE:
|
case SDL_SCANCODE_ESCAPE:
|
||||||
|
|
||||||
return -1000;
|
save_grid_to_file(num_fichier,tab2d);
|
||||||
|
return -1;
|
||||||
finish = true;
|
finish = true;
|
||||||
break;
|
break;
|
||||||
case SDL_SCANCODE_D:
|
case SDL_SCANCODE_D:
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ int main ()
|
|||||||
char **tab2d = creatArea2D (SIZE_PLAY, SIZE_PLAY);
|
char **tab2d = creatArea2D (SIZE_PLAY, SIZE_PLAY);
|
||||||
|
|
||||||
score score_user = {0, 0, 0,0};
|
score score_user = {0, 0, 0,0};
|
||||||
|
int num_fichier=0;
|
||||||
vect dim = {SIZE_PLAY, SIZE_PLAY};
|
vect dim = {SIZE_PLAY, SIZE_PLAY};
|
||||||
int output = -1;
|
int output = -1;
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ int main ()
|
|||||||
{
|
{
|
||||||
printf("editeur de map");
|
printf("editeur de map");
|
||||||
//newmap
|
//newmap
|
||||||
output = inEditorLoop(tab2d, &dim, playerPos, targets, nbr_targets, &display_user, &score_user);
|
output = inEditorLoop(tab2d, &dim, playerPos, targets, nbr_targets, &display_user,&score_user ,num_fichier);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -93,16 +94,17 @@ int main ()
|
|||||||
else{
|
else{
|
||||||
char path[256];
|
char path[256];
|
||||||
snprintf(path, sizeof(path), "maps/custom_%d.txt", output-4);
|
snprintf(path, sizeof(path), "maps/custom_%d.txt", output-4);
|
||||||
|
num_fichier = output-4;
|
||||||
FILE *src = fopen("maps/viergemap.txt", "r");
|
FILE *src = fopen("maps/viergemap.txt", "r");
|
||||||
FILE *file = fopen(path, "w");
|
FILE *file = fopen(path, "w");
|
||||||
|
|
||||||
|
|
||||||
char buffer[1024]; // Tampon pour lire le contenu
|
char tmp[1024]; // Tampon pour lire le contenu
|
||||||
size_t bytesRead;
|
size_t bytesRead;
|
||||||
|
|
||||||
// Lire le contenu du fichier source et l'écrire dans le fichier destination
|
// Lire le contenu du fichier source et l'écrire dans le fichier destination
|
||||||
while ((bytesRead = fread(buffer, 1, sizeof(buffer), src)) > 0) {
|
while ((bytesRead = fread(tmp, 1, sizeof(tmp), src)) > 0) {
|
||||||
fwrite(buffer, 1, bytesRead, file);
|
fwrite(tmp, 1, bytesRead, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(src);
|
fclose(src);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ vect *fileToTab2D (const char *name_file, char **tab,
|
|||||||
case 'C':
|
case 'C':
|
||||||
tab[x][y] = BOX;
|
tab[x][y] = BOX;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'I':
|
case 'I':
|
||||||
targets = realloc (targets, sizeof (vect) * (++nbr_targets[0]));
|
targets = realloc (targets, sizeof (vect) * (++nbr_targets[0]));
|
||||||
targets[nbr_targets[0] - 1].x = x;
|
targets[nbr_targets[0] - 1].x = x;
|
||||||
|
|||||||
Reference in New Issue
Block a user