touche (pas fini encore un bug

This commit is contained in:
2024-12-14 16:16:13 +01:00
parent fa7d5ce51a
commit e82ffb51be

View File

@@ -1,7 +1,10 @@
#include "function.h"
#include "display.h"
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_keycode.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_scancode.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -183,48 +186,52 @@ void move (unsigned short int **tab, vect *playerPos, vect direction)
void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
vect *targets, int nbr_targets, dis *display_user)
{
char last = SDL_SCANCODE_1;
vect direction = { 0, 0 };
char input;
bool finish = false;
SDL_Event event;
while (!finish)
{
printf ("Utilisez Z/Q/S/D pour bouger, X pour quitter : ");
//printf ("Utilisez Z/Q/S/D pour bouger, X pour quitter : ");
SDL_PollEvent (&event);
input = getchar ();
if (input == 'x')
if (event.type == SDL_KEYDOWN)
{
break; // Quitter le jeu
}
input = event.key.keysym.scancode;
printf ("%c\n", input);
switch (input)
{
case 'd':
case SDL_SCANCODE_ESCAPE:
finish = true;
break;
case SDL_SCANCODE_D:
direction.y = 1;
direction.x = 0;
break;
case 'q':
case SDL_SCANCODE_A:
direction.y = -1;
direction.x = 0;
break;
case 'z':
case SDL_SCANCODE_W:
direction.x = -1;
direction.y = 0;
break;
case 's':
case SDL_SCANCODE_S:
direction.x = 1;
direction.y = 0;
break;
default:
direction.x = 0;
direction.y = 0;
last = SDL_SCANCODE_1;
}
}
system ("clear");
move (tab2d, playerPos, direction);
printf ("\n");
//system ("clear");
if (last != input) move (tab2d, playerPos, direction);
last = input;
if (isWin (tab2d, targets, nbr_targets))
{
puts ("Win!");
@@ -235,8 +242,9 @@ void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
puts ("lose!");
finish = true;
}
screenDisplay (tab2d, N);
//screenDisplay (tab2d, N);
screenDisplaySDL (tab2d, display_user);
//SDL_Delay (1000);
}
}