From cbeebfb1d49e2b3cf68e8f08d3395518191d1527 Mon Sep 17 00:00:00 2001 From: antoinemeyer5 <antoine.meyer54@gmail.com> Date: Mon, 27 Jun 2022 22:38:59 +0200 Subject: [PATCH] ligne en 2d top view + zone canon + finish : zone point de chute --- .../antoi_render_2d/source/canon.c | 24 +++++++ .../antoi_render_2d/source/canon.h | 2 + .../antoi_render_2d/source/gest_event.c | 2 + .../antoi_render_2d/source/render.c | 62 +++++++++++++++---- .../antoi_render_2d/source/render.h | 6 ++ 5 files changed, 84 insertions(+), 12 deletions(-) diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/canon.c b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/canon.c index d896d1c..e0041d2 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/canon.c +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/canon.c @@ -8,4 +8,28 @@ void initCanon(){ canon.length = 20; canon.x = 100; canon.y = 20; + canon.zone = 1; +} + +int getZone(int terrainX, int terrainY, int terrainW, int terrainH){ + int z = -1; + int xCanonTopView = terrainX + canon.x; + int yCanonTopView = terrainY + canon.y; + //en haut à gauche => 1 + if(canon.x >= 0 && canon.x<terrainW/2 && yCanonTopView>=0 && canon.y<terrainH/4){ + z = 1; + } + //en haut à droite => 2 + else if(xCanonTopView>=terrainX+terrainW/2 && xCanonTopView<=terrainX+terrainW && yCanonTopView>=terrainY && yCanonTopView<terrainX+terrainH/4){ + z = 2; + } + //en bas à gauche => 3 + else if(xCanonTopView >= terrainX && xCanonTopView<terrainX+terrainW/2 && yCanonTopView>=terrainY+terrainH/4 && yCanonTopView<=terrainH+terrainH/2){ + z = 3; + } + //en bas à droite => 4 + else{ + z = 4; + } + return z; } \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/canon.h b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/canon.h index 5b292f9..1191da9 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/canon.h +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/canon.h @@ -7,10 +7,12 @@ typedef struct canon{ int width; int height; int length; + int zone; } canon_t; extern canon_t canon; void initCanon(); +int getZone(int, int, int, int); #endif \ No newline at end of file diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/gest_event.c b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/gest_event.c index 45f5d81..98c449f 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/gest_event.c +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/gest_event.c @@ -32,10 +32,12 @@ void manageGame(){ case SDLK_e: initPointDeChute(); + zone_chute = getZoneChute(terrain.x, terrain.y, terrain.w, terrain.h); break; case SDLK_r: newCanon(); + zone_canon = getZone(terrain.x, terrain.y, terrain.w, terrain.h); break; default: diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c index ba6a252..3bbe988 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.c @@ -17,6 +17,9 @@ SDL_Rect point_de_chute; int point_x_rand; int point_y_rand; +int zone_canon = -1; +int zone_chute = -1; + void createWindow(){ if (SDL_Init(SDL_INIT_VIDEO) != 0){ printf("Couldn't create window."); @@ -67,6 +70,33 @@ void initPointDeChute(){ point_y_rand = (int)rand()%(terrain.h/2); } + +int getZoneChute(int terrainX, int terrainY, int terrainW, int terrainH){ + int z = -1; + // pdc = point de chute + int pdc_x = terrainX + point_x_rand; + int pdc_y = terrainY + terrainH/2 + point_y_rand; + //en haut à gauche => 1 + if(point_x_rand>=0 && point_x_rand<terrainW/2 && pdc_y<terrainY+(3*terrainH)/4){ + z = 1; + } + //en haut à droite => 2 + /*else if(){ + z = 2; + } + //en bas à gauche => 3 + else if(point_x_rand>=0 && point_x_rand<terrainW/2 && ){ + z = 3; + } + //en bas à droite => 4 + */else{ + z = -6; + } + printf("point_x_rand : %d, terrainW/2: %d\n", point_x_rand, terrainW/2); + printf("pdc_x : %d, pdc_y : %d, tX : %d, tY : %d\n", pdc_x, pdc_y, terrainX, terrainY); + return z; +} + void newCanon(){ initTerrain(); srand(time(NULL)); @@ -190,18 +220,23 @@ void drawInformations(){ int texte_width = 200; int texte_height = 40; char str[20]; - char zone_canon[20] = "zone canon : "; - int zone_ca = 4; + char str2[20]; + char zoneChuteChaine[20] = "zone chute :"; + char zoneCanonChaine[20] = "zone canon :"; drawString("informations :", window_width-texte_width, texte_height*0, texte_width, texte_height, 255, 255, 255, 255); - drawString("e : new ball", window_width-texte_width, texte_height*1, texte_width, texte_height, 255, 255, 255, 255); - drawString("posBallX", window_width-texte_width, texte_height*2, texte_width, texte_height, 255, 255, 255, 255); - drawString("zone de chute : %d", window_width-texte_width, texte_height*3, texte_width, texte_height, 255, 255, 255, 255); + drawString("e : new point chute", window_width-texte_width, texte_height*1, texte_width, texte_height, 255, 255, 255, 255); + sprintf(str2, "%d", zone_chute); + strcat(zoneChuteChaine, str2); + drawString(zoneChuteChaine, window_width-texte_width, texte_height*2, texte_width, texte_height, 255, 255, 255, 255); drawString("r : new canon", window_width-texte_width, texte_height*4, texte_width, texte_height, 255, 255, 255, 255); - drawString("position canon (%d, %d)", window_width-texte_width, texte_height*5, texte_width, texte_height, 255, 255, 255, 255); + sprintf(str, "%d", zone_canon); + strcat(zoneCanonChaine, str); + drawString(zoneCanonChaine, window_width-texte_width, texte_height*5, texte_width, texte_height, 255, 255, 255, 255); +} - sprintf(str, "%d", zone_ca); - strcat(zone_canon, str); - drawString(zone_canon, window_width-texte_width, texte_height*6, texte_width, texte_height, 255, 255, 255, 255); +void drawTrajectoireTopView(){ + SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); + SDL_RenderDrawLine(renderer, terrain.x+canon.x, terrain.y+canon.y, point_de_chute.x, point_de_chute.y); } void drawBall(){ @@ -238,8 +273,7 @@ void drawBall(){ void mainLoop(){ createWindow(); initCanon(); - initPointDeChute(terrain); - //trouveZoneDeChute(); + initPointDeChute(); pthread_t eventThread; if (pthread_create(&eventThread, NULL, eventLoop, NULL) != 0){ @@ -255,12 +289,16 @@ void mainLoop(){ drawTerrainTopView(); drawCanonTopView(); drawPointDeChuteTopView(); + drawTrajectoireTopView(); + initTerrain(); + zone_canon = getZone(terrain.x, terrain.y, terrain.w, terrain.h); + zone_chute = getZoneChute(terrain.x, terrain.y, terrain.w, terrain.h); //side view drawTerrainSideView(); drawCanonSideView(); drawPointDeChuteSideView(); - + // drawInformations(); diff --git a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.h b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.h index 6661516..88255aa 100644 --- a/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.h +++ b/travail_de_groupe/jeu_appren_par_renfo/antoi_render_2d/source/render.h @@ -5,12 +5,18 @@ #include "ball.h" #include "canon.h" +extern int zone_canon; +extern int zone_chute; +extern SDL_Rect terrain; + void createWindow(); void endSDL(); void drawString(char *, int, int, int, int, int, int, int, int); void drawTerrainTopView(); void initPointDeChute(); void newCanon(); +int getZoneChute(int, int, int, int); +void initTerrain(); //tofinish void mainLoop(); -- GitLab