touche (pas fini encore un bug
This commit is contained in:
42
function.c
42
function.c
@@ -1,7 +1,10 @@
|
|||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
|
#include <SDL2/SDL_events.h>
|
||||||
|
#include <SDL2/SDL_keycode.h>
|
||||||
#include <SDL2/SDL_render.h>
|
#include <SDL2/SDL_render.h>
|
||||||
|
#include <SDL2/SDL_scancode.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.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,
|
void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
|
||||||
vect *targets, int nbr_targets, dis *display_user)
|
vect *targets, int nbr_targets, dis *display_user)
|
||||||
{
|
{
|
||||||
|
char last = SDL_SCANCODE_1;
|
||||||
vect direction = { 0, 0 };
|
vect direction = { 0, 0 };
|
||||||
char input;
|
char input;
|
||||||
bool finish = false;
|
bool finish = false;
|
||||||
|
SDL_Event event;
|
||||||
while (!finish)
|
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 (event.type == SDL_KEYDOWN)
|
||||||
|
|
||||||
if (input == 'x')
|
|
||||||
{
|
{
|
||||||
break; // Quitter le jeu
|
input = event.key.keysym.scancode;
|
||||||
}
|
printf ("%c\n", input);
|
||||||
|
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
case 'd':
|
case SDL_SCANCODE_ESCAPE:
|
||||||
|
finish = true;
|
||||||
|
break;
|
||||||
|
case SDL_SCANCODE_D:
|
||||||
direction.y = 1;
|
direction.y = 1;
|
||||||
direction.x = 0;
|
direction.x = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case SDL_SCANCODE_A:
|
||||||
direction.y = -1;
|
direction.y = -1;
|
||||||
direction.x = 0;
|
direction.x = 0;
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case SDL_SCANCODE_W:
|
||||||
direction.x = -1;
|
direction.x = -1;
|
||||||
direction.y = 0;
|
direction.y = 0;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case SDL_SCANCODE_S:
|
||||||
direction.x = 1;
|
direction.x = 1;
|
||||||
direction.y = 0;
|
direction.y = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
direction.x = 0;
|
direction.x = 0;
|
||||||
direction.y = 0;
|
direction.y = 0;
|
||||||
|
last = SDL_SCANCODE_1;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
system ("clear");
|
//system ("clear");
|
||||||
move (tab2d, playerPos, direction);
|
if (last != input) move (tab2d, playerPos, direction);
|
||||||
|
last = input;
|
||||||
printf ("\n");
|
|
||||||
if (isWin (tab2d, targets, nbr_targets))
|
if (isWin (tab2d, targets, nbr_targets))
|
||||||
{
|
{
|
||||||
puts ("Win!");
|
puts ("Win!");
|
||||||
@@ -235,8 +242,9 @@ void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos,
|
|||||||
puts ("lose!");
|
puts ("lose!");
|
||||||
finish = true;
|
finish = true;
|
||||||
}
|
}
|
||||||
screenDisplay (tab2d, N);
|
//screenDisplay (tab2d, N);
|
||||||
screenDisplaySDL (tab2d, display_user);
|
screenDisplaySDL (tab2d, display_user);
|
||||||
|
//SDL_Delay (1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user