diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..aa9c5ce --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "/usr/include/c++/8", + "/usr/include/x86_64-linux-gnu/c++/9" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu18", + "cppStandard": "gnu++14", + "intelliSenseMode": "gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..002473d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "exception": "c" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..b35e261 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "label": "C/C++: gcc build active file + SLD2", + "command": "/usr/bin/gcc", + "args": [ + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}", + "-lSDL2", + "-lSDL2main" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + "group": "build" + } + ] +} diff --git a/balle2.bmp b/balle2.bmp new file mode 100644 index 0000000..2ee83a6 Binary files /dev/null and b/balle2.bmp differ diff --git a/joueur1.bmp b/joueur1.bmp new file mode 100644 index 0000000..a29a932 Binary files /dev/null and b/joueur1.bmp differ diff --git a/joueur2.bmp b/joueur2.bmp new file mode 100644 index 0000000..deea3fe Binary files /dev/null and b/joueur2.bmp differ diff --git a/main.cpp b/main.cpp index b953bab..dec2f40 100644 --- a/main.cpp +++ b/main.cpp @@ -1,17 +1,137 @@ // Leopold Clement +#include +#include +#include #include "SDL2/SDL.h" + /*#include #include #include */ +struct timeval tv; + +const int16_t LONGUEURE_TERRAIN = 800; +const int16_t LARGEUR_TERRAIN = 600; +const int16_t LARGEUR_BUT = 200; + +const float VITESSE_TRANSLATION = 0.2; +const float VITESSE_ROTATION = 0.02; + +typedef struct +{ + int up_key; + int down_key; + int right_key; + int left_key; +} Controlleur; + +typedef struct +{ + float x; + float y; + float theta; +} Vecteur; + +typedef struct +{ + Vecteur position; + char nom[25]; + Controlleur *control; +} Robot; + +typedef struct +{ + Vecteur position; + Vecteur vitesse; + Robot *possession; +} Balle; + +typedef struct +{ + int point_vert; + int point_violet; + int balle_en_jeu; +} Score; + +void rendut_robot(Robot robot) +{ +} +void rendut_balle(Balle balle) +{ +} +void rendut_global(Robot robots[2], Balle balle) +{ +} +float distance_vecteurs(Vecteur vect1, Vecteur vect2) +{ + return (sqrtf32(powf(vect1.x - vect2.x, 2) + powf(vect1.y - vect2.y, 2))); +} +Vecteur addition_vecteur(Vecteur vect1, Vecteur vect2) +{ + Vecteur vecteur_somme = {vect1.x + vect2.y, vect1.y + vect2.y, vect1.theta + vect2.theta}; + return vecteur_somme; +} + +Vecteur projecteur_base_fixe(Vecteur vect, float theta) +{ + Vecteur vect_fixe = {0, 0, 0}; + vect_fixe.x = vect.x * cosf32(theta) - vect.y * sinf32(theta); + vect_fixe.y = vect.x * sinf32(theta) + vect.y * cosf32(theta); + return vect_fixe; +} + +void deplacement_robot(SDL_Event events, Robot robot) +{ + if (events.key.keysym.sym == robot.control->up_key) + { + Vecteur avance_ref_robot = {VITESSE_TRANSLATION, 0, 0}; + Vecteur avance_ref_fixe = projecteur_base_fixe(avance_ref_robot, -robot.position.theta); + robot.position = addition_vecteur(robot.position, avance_ref_fixe); + } + else if (events.key.keysym.sym == robot.control->down_key) + { + Vecteur avance_ref_robot = {-VITESSE_TRANSLATION, 0, 0}; + Vecteur avance_ref_fixe = projecteur_base_fixe(avance_ref_robot, -robot.position.theta); + robot.position = addition_vecteur(robot.position, avance_ref_fixe); + } + if (events.key.keysym.sym == robot.control->left_key) + { + Vecteur rotation = {0, 0, VITESSE_ROTATION}; + robot.position = addition_vecteur(robot.position, rotation); + } + else if (events.key.keysym.sym == robot.control->right_key) + { + Vecteur rotation = {0, 0, -VITESSE_ROTATION}; + robot.position = addition_vecteur(robot.position, rotation); + } +} +void pulsation_du_jeu(SDL_Renderer *prenderer, SDL_Event events, Robot robots[2], Balle balle, int *pisOpen) +{ + while (SDL_PollEvent(&events)) + { + switch (events.type) + { + case SDL_QUIT: + *pisOpen = 0; + break; + + case SDL_KEYDOWN: + char i; + for(i = 0; i<2; i++) deplacement_robot(events, robots[i]); + } + } + return; +} + int main(int argc, char *argv[]) { SDL_Window *pwindow; SDL_Renderer *prenderer; SDL_Event events; int isOpen = 1; + unsigned long long last_tic = 0; - SDL_Rect rectangle1 = {20, 20, 100, 50}; + // SDL_Rect rectangle1 = {20, 20, 100, 50}; //Initialisation de SDL avec la vidéo if (SDL_Init(SDL_INIT_VIDEO) != 0) @@ -34,30 +154,9 @@ int main(int argc, char *argv[]) while (isOpen) { + gettimeofday(&tv, NULL); + unsigned long long millisecondsSinceEpoch = (unsigned long long)(tv.tv_sec) * 1000 + (unsigned long long)(tv.tv_usec) / 1000; /* évènements de votre jeu */ - while (SDL_PollEvent(&events)) - { - - switch (events.type) - { - case SDL_QUIT: - isOpen = 0; - break; - - case SDL_KEYDOWN: - if (events.key.keysym.sym == SDLK_v) - { - SDL_SetRenderDrawColor(prenderer, 00, 255, 00, 255); - SDL_RenderFillRect(prenderer, &rectangle1); - } - if (events.key.keysym.sym == SDLK_b) - { - SDL_SetRenderDrawColor(prenderer, 00, 00, 255, 255); - SDL_RenderFillRect(prenderer, &rectangle1); - } - break; - } - } SDL_RenderPresent(prenderer); // mets à jour la fenêtre } diff --git a/sand_box b/sand_box new file mode 100755 index 0000000..828af0c Binary files /dev/null and b/sand_box differ diff --git a/sand_box.c b/sand_box.c new file mode 100644 index 0000000..58cd33a --- /dev/null +++ b/sand_box.c @@ -0,0 +1,59 @@ +#include +#include +#include "SDL2/SDL.h" + +struct timeval tv; + +typedef struct +{ + float x; + float y; + float theta; +} Vecteur; +// typedef struct {Vecteur position; Vecteur vitesse; char[25] nom} Robot; +void print_nl() +{ + printf("\n"); +} +void print_vecteur(Vecteur vec) +{ + printf("(%f;%f;%f)", vec.x, vec.y, vec.theta); +} + +Vecteur addition_vecteur(Vecteur vect1, Vecteur vect2) +{ + Vecteur vecteur_somme = {vect1.x + vect2.y, vect1.y + vect2.y, vect1.theta + vect2.theta}; + return vecteur_somme; +} + +int main(int argc, char **argv) +{ + Vecteur A = {1, 2, 3}; + Vecteur B = {1, 0, 3}; + Vecteur C; + C = addition_vecteur(A, B); + /*int i = 0; + unsigned long long last_tic = 0; + while (i <= 1000) + { + gettimeofday(&tv, NULL); + unsigned long long millisecondsSinceEpoch = (unsigned long long)(tv.tv_sec) * 1000 + (unsigned long long)(tv.tv_usec) / 1000; + if ((millisecondsSinceEpoch - last_tic) >= 10) + { + printf("%llu\n", millisecondsSinceEpoch); + last_tic = millisecondsSinceEpoch; + i++; + } + }*/ + + print_vecteur(A); + print_nl(); + print_vecteur(B); + print_nl(); + print_vecteur(C); + print_nl(); + C.x = -10; + print_vecteur(C); + print_nl(); + return 0; +} diff --git a/victoire_joueur1.bmp b/victoire_joueur1.bmp new file mode 100644 index 0000000..f92fa40 Binary files /dev/null and b/victoire_joueur1.bmp differ diff --git a/victoire_joueur2.bmp b/victoire_joueur2.bmp new file mode 100644 index 0000000..cd494a0 Binary files /dev/null and b/victoire_joueur2.bmp differ