Skip to content
Snippets Groups Projects
Commit 4e10a5d2 authored by maberet's avatar maberet
Browse files

Changement du nom de dossier (1exercice->x_fenetre), modification du README et...

Changement du nom de dossier (1exercice->x_fenetre), modification du README et ajout du dossier snakes (+Makefile)
parent 2ff3a5b1
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,8 @@ Trello : https://trello.com/b/YGhNeYX3/projet-apprentissage-par-renforcement ...@@ -16,7 +16,8 @@ Trello : https://trello.com/b/YGhNeYX3/projet-apprentissage-par-renforcement
│ ├── Belkhiri │ ├── Belkhiri
│ │ ├── x_fenetre │ │ ├── x_fenetre
│ │ └── snakes │ │ └── snakes
│ ├── Beret │ ├── Beret
│ │ └── x_fenetre
│ └── Meyer │ └── Meyer
│ └── x_fenetre │ └── x_fenetre
└── travail_de_groupe └── travail_de_groupe
......
CC=gcc
main:main.o
$(CC) -o main main.o -lm -lSDL2
@echo "=> Lancer le programme avec ./main"
main.o:main.c
$(CC) -c main.c -g -Wall -Wextra
clean:
rm -rf main main.o
\ No newline at end of file
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
int main(int argc, char **argv) { int main(int argc, char **argv) {
(void)argc; (void)argc;
(void)argv; (void)argv;
int x=0; int x=0;
SDL_Window SDL_Window
*window_1 = NULL,*window_2=NULL, *window_3=NULL,*window_4=NULL; // Future fenêtre de gauche *window_1 = NULL,*window_2=NULL, *window_3=NULL,*window_4=NULL; // Future fenêtre de gauche
/* Initialisation de la SDL + gestion de l'échec possible */ /* Initialisation de la SDL + gestion de l'échec possible */
if (SDL_Init(SDL_INIT_VIDEO) != 0) { if (SDL_Init(SDL_INIT_VIDEO) != 0) {
SDL_Log("Error : SDL initialisation - %s\n", SDL_Log("Error : SDL initialisation - %s\n",
SDL_GetError()); // l'initialisation de la SDL a échoué SDL_GetError()); // l'initialisation de la SDL a échoué
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
SDL_DisplayMode DM; SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &DM); SDL_GetCurrentDisplayMode(0, &DM);
int Width = DM.w; int Width = DM.w;
/* Création de la fenêtre de gauche */ /* Création de la fenêtre de gauche */
window_1 = SDL_CreateWindow( window_1 = SDL_CreateWindow(
"Vague", // codage en utf8, donc accents possibles "Vague", // codage en utf8, donc accents possibles
x,300 + 100*cos(x/10), x,300 + 100*cos(x/10),
100,100, 100,100,
SDL_WINDOW_RESIZABLE); SDL_WINDOW_RESIZABLE);
if (window_1 == NULL) { if (window_1 == NULL) {
SDL_Log("Error : SDL window 1 creation - %s\n", SDL_Log("Error : SDL window 1 creation - %s\n",
SDL_GetError()); // échec de la création de la fenêtre SDL_GetError()); // échec de la création de la fenêtre
SDL_Quit(); // On referme la SDL SDL_Quit(); // On referme la SDL
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
window_2 = SDL_CreateWindow( window_2 = SDL_CreateWindow(
"vague2", // codage en utf8, donc accents possibles "vague2", // codage en utf8, donc accents possibles
x-10,300 + 110*cos((x-10)/10), // à droite de la fenêtre de gauche x-10,300 + 110*cos((x-10)/10), // à droite de la fenêtre de gauche
80, 80, // largeur = 500, hauteur = 300 80, 80, // largeur = 500, hauteur = 300
0); 0);
if (window_2 == NULL) { if (window_2 == NULL) {
SDL_Log("Error : SDL window 2 creation - %s\n", SDL_Log("Error : SDL window 2 creation - %s\n",
SDL_GetError()); // échec de la création de la deuxième fenêtre SDL_GetError()); // échec de la création de la deuxième fenêtre
SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite
SDL_Quit(); SDL_Quit();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
window_3 = SDL_CreateWindow( window_3 = SDL_CreateWindow(
"vague3", // codage en utf8, donc accents possibles "vague3", // codage en utf8, donc accents possibles
x-20,300 + 130*cos((x-20)/10), // à droite de la fenêtre de gauche x-20,300 + 130*cos((x-20)/10), // à droite de la fenêtre de gauche
60, 60, // largeur = 500, hauteur = 300 60, 60, // largeur = 500, hauteur = 300
0); 0);
if (window_3 == NULL) { if (window_3 == NULL) {
SDL_Log("Error : SDL window 3 creation - %s\n", SDL_Log("Error : SDL window 3 creation - %s\n",
SDL_GetError()); // échec de la création de la deuxième fenêtre SDL_GetError()); // échec de la création de la deuxième fenêtre
SDL_DestroyWindow(window_2); SDL_DestroyWindow(window_2);
SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite
SDL_Quit(); SDL_Quit();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
window_4 = SDL_CreateWindow( window_4 = SDL_CreateWindow(
"vague4", // codage en utf8, donc accents possibles "vague4", // codage en utf8, donc accents possibles
x-30,300 + 150*cos((x-30)/10), // à droite de la fenêtre de gauche x-30,300 + 150*cos((x-30)/10), // à droite de la fenêtre de gauche
40, 40, // largeur = 500, hauteur = 300 40, 40, // largeur = 500, hauteur = 300
0); 0);
if (window_4 == NULL) { if (window_4 == NULL) {
SDL_Log("Error : SDL window 4 creation - %s\n", SDL_Log("Error : SDL window 4 creation - %s\n",
SDL_GetError()); // échec de la création de la deuxième fenêtre SDL_GetError()); // échec de la création de la deuxième fenêtre
SDL_DestroyWindow(window_3); SDL_DestroyWindow(window_3);
SDL_DestroyWindow(window_2); SDL_DestroyWindow(window_2);
SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite SDL_DestroyWindow(window_1); // la première fenétre (qui elle a été créée) doit être détruite
SDL_Quit(); SDL_Quit();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while (x<Width){ while (x<Width){
SDL_SetWindowPosition(window_1,x,300 + 100*cos((x)/10)); SDL_SetWindowPosition(window_1,x,300 + 100*cos((x)/10));
SDL_SetWindowPosition(window_2,x-10,300 + 100*cos((x-10)/10)); SDL_SetWindowPosition(window_2,x-10,300 + 100*cos((x-10)/10));
SDL_SetWindowPosition(window_3,x-20,300 + 100*cos((x-20)/10)); SDL_SetWindowPosition(window_3,x-20,300 + 100*cos((x-20)/10));
SDL_SetWindowPosition(window_4,x-30,300 + 100*cos((x-30)/10)); SDL_SetWindowPosition(window_4,x-30,300 + 100*cos((x-30)/10));
x=x+10; x=x+10;
SDL_Delay(150); // Pause exprimée en ms SDL_Delay(150); // Pause exprimée en ms
} }
SDL_DestroyWindow(window_4); SDL_DestroyWindow(window_4);
SDL_DestroyWindow(window_3); SDL_DestroyWindow(window_3);
SDL_DestroyWindow(window_2); SDL_DestroyWindow(window_2);
SDL_DestroyWindow(window_1); SDL_DestroyWindow(window_1);
SDL_Quit(); // la SDL SDL_Quit(); // la SDL
return 0; return 0;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment