ajout du createur de niveau + mouvement du joueur dans le createur de niveau
This commit is contained in:
@@ -445,6 +445,7 @@ int inGameLoop (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)
|
||||
{
|
||||
vect direction = { 0, 0 };
|
||||
int fov = -1;
|
||||
int indice_button = -1;
|
||||
|
||||
@@ -465,6 +466,12 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
||||
bool finish = false;
|
||||
SDL_Event event;
|
||||
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos, fov);
|
||||
|
||||
|
||||
int GRID_SIZE = 20;
|
||||
int BLOCK_SIZE = 24;
|
||||
int GRID_X_OFFSET =100;
|
||||
int GRID_Y_OFFSET =0;
|
||||
while (!finish)
|
||||
{
|
||||
|
||||
@@ -476,10 +483,65 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
// Lorsque le clic gauche est effectué
|
||||
int x, y;
|
||||
SDL_GetMouseState(&x, &y); // Récupérer la position de la souris
|
||||
int click_x, click_y;
|
||||
SDL_GetMouseState(&click_x, &click_y); // Récupérer la position de la souris
|
||||
|
||||
printf("Clic gauche à la position: (%d, %d)\n", x, y);
|
||||
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 &&
|
||||
click_y >= GRID_Y_OFFSET && click_y < GRID_Y_OFFSET + GRID_SIZE * BLOCK_SIZE) {
|
||||
|
||||
// Calcul des indices de la case
|
||||
int col = (click_x - GRID_X_OFFSET) / BLOCK_SIZE;
|
||||
int row = (click_y - GRID_Y_OFFSET) / BLOCK_SIZE;
|
||||
|
||||
// Met à jour la case correspondante
|
||||
if(tab2d[row][col] ==3)
|
||||
{
|
||||
tab2d[row][col] =0;
|
||||
}
|
||||
else if(tab2d[row][col] <3)
|
||||
{
|
||||
tab2d[row][col] += 1;
|
||||
}
|
||||
// Met à jour l'affichage
|
||||
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) {
|
||||
// Lorsque le clic gauche est effectué
|
||||
int click_x, click_y;
|
||||
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 &&
|
||||
click_y >= GRID_Y_OFFSET && click_y < GRID_Y_OFFSET + GRID_SIZE * BLOCK_SIZE) {
|
||||
|
||||
// Calcul des indices de la case
|
||||
int col = (click_x - GRID_X_OFFSET) / BLOCK_SIZE;
|
||||
int row = (click_y - GRID_Y_OFFSET) / BLOCK_SIZE;
|
||||
|
||||
// Met à jour la case correspondante
|
||||
if(tab2d[row][col] ==0)
|
||||
{
|
||||
tab2d[row][col] =3;
|
||||
}
|
||||
else if(tab2d[row][col] <=3)
|
||||
{
|
||||
tab2d[row][col] -= 1;
|
||||
}
|
||||
// Met à jour l'affichage
|
||||
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.type == SDL_KEYDOWN)
|
||||
@@ -493,19 +555,30 @@ int inEditorLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
||||
finish = true;
|
||||
break;
|
||||
case SDL_SCANCODE_D:
|
||||
direction.y = 1;
|
||||
direction.x = 0;
|
||||
break;
|
||||
case SDL_SCANCODE_A:
|
||||
direction.y = -1;
|
||||
direction.x = 0;
|
||||
break;
|
||||
case SDL_SCANCODE_W:
|
||||
direction.x = -1;
|
||||
direction.y = 0;
|
||||
break;
|
||||
case SDL_SCANCODE_S:
|
||||
direction.x = 1;
|
||||
direction.y = 0;
|
||||
break;
|
||||
case SDL_SCANCODE_RETURN:
|
||||
if (tab2d[playerPos->x][playerPos->y] == PLAYER_ON_BUTTON)
|
||||
return indice_button;
|
||||
break;
|
||||
default:
|
||||
direction.x = 0;
|
||||
direction.y = 0;
|
||||
}
|
||||
move (tab2d, playerPos, direction, score_user);
|
||||
screenDisplayGameSDL (tab2d, *dim_tab, display_user, playerPos,
|
||||
fov);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user