Skip to content
Snippets Groups Projects
Commit 2bfd1b85 authored by antoinemeyer5's avatar antoinemeyer5
Browse files

nettoyage code canon

parent 68b53ddf
No related branches found
No related tags found
No related merge requests found
...@@ -13,18 +13,16 @@ void initCanon(){ ...@@ -13,18 +13,16 @@ void initCanon(){
int getZone(int terrainX, int terrainY, int terrainW, int terrainH){ int getZone(int terrainX, int terrainY, int terrainW, int terrainH){
int z = -1; int z = -1;
int xCanonTopView = terrainX + canon.x;
int yCanonTopView = terrainY + canon.y;
//en haut à gauche => 1 //en haut à gauche => 1
if(canon.x >= 0 && canon.x<terrainW/2 && yCanonTopView>=0 && canon.y<terrainH/4){ if(canon.x<terrainW/2 && canon.y<terrainH/4){
z = 1; z = 1;
} }
//en haut à droite => 2 //en haut à droite => 2
else if(xCanonTopView>=terrainX+terrainW/2 && xCanonTopView<=terrainX+terrainW && yCanonTopView>=terrainY && yCanonTopView<terrainX+terrainH/4){ else if(canon.x>=terrainW/2 && canon.y<terrainH/4){
z = 2; z = 2;
} }
//en bas à gauche => 3 //en bas à gauche => 3
else if(xCanonTopView >= terrainX && xCanonTopView<terrainX+terrainW/2 && yCanonTopView>=terrainY+terrainH/4 && yCanonTopView<=terrainH+terrainH/2){ else if(canon.x<terrainW/2 && canon.y>=terrainH/4){
z = 3; z = 3;
} }
//en bas à droite => 4 //en bas à droite => 4
......
...@@ -8,7 +8,11 @@ int window_height = 700; ...@@ -8,7 +8,11 @@ int window_height = 700;
TTF_Font *robotoFont; TTF_Font *robotoFont;
int zoom = 40; int zoom = 40;
//terrain devrait etre un .c et .h comme canon
// on aurait un SDL_Rect en terrain TopView et SideView
//là mélange bizarre mais fonctionnel
SDL_Rect terrain; SDL_Rect terrain;
SDL_Rect drawerTerrainSideView;
SDL_Rect filet; SDL_Rect filet;
SDL_Rect canon_rect; SDL_Rect canon_rect;
...@@ -64,7 +68,6 @@ void initTerrain(){ ...@@ -64,7 +68,6 @@ void initTerrain(){
} }
void initPointDeChute(){ void initPointDeChute(){
initTerrain();
srand(time(NULL)); srand(time(NULL));
point_x_rand = (int)rand()%terrain.w; point_x_rand = (int)rand()%terrain.w;
point_y_rand = (int)rand()%(terrain.h/2); point_y_rand = (int)rand()%(terrain.h/2);
...@@ -73,7 +76,6 @@ void initPointDeChute(){ ...@@ -73,7 +76,6 @@ void initPointDeChute(){
int getZoneChute(int terrainX, int terrainY, int terrainW, int terrainH){ int getZoneChute(int terrainX, int terrainY, int terrainW, int terrainH){
int z = -1; int z = -1;
// pdc = point de chute // pdc = point de chute
int pdc_x = terrainX + point_x_rand;
int pdc_y = terrainY + terrainH/2 + point_y_rand; int pdc_y = terrainY + terrainH/2 + point_y_rand;
//en haut à gauche => 1 //en haut à gauche => 1
if(point_x_rand>=0 && point_x_rand<terrainW/2 && pdc_y<terrainY+(3*terrainH)/4){ if(point_x_rand>=0 && point_x_rand<terrainW/2 && pdc_y<terrainY+(3*terrainH)/4){
...@@ -95,7 +97,6 @@ int getZoneChute(int terrainX, int terrainY, int terrainW, int terrainH){ ...@@ -95,7 +97,6 @@ int getZoneChute(int terrainX, int terrainY, int terrainW, int terrainH){
} }
void newCanon(){ void newCanon(){
initTerrain();
srand(time(NULL)); srand(time(NULL));
canon.x = (int)rand()%terrain.w; canon.x = (int)rand()%terrain.w;
canon.y = (int)rand()%(terrain.h/2); canon.y = (int)rand()%(terrain.h/2);
...@@ -112,9 +113,6 @@ void drawString(char *text, int x, int y, int w, int h, int r, int g, int b, int ...@@ -112,9 +113,6 @@ void drawString(char *text, int x, int y, int w, int h, int r, int g, int b, int
} }
void drawTerrainTopView(){ void drawTerrainTopView(){
//terrain
initTerrain();
//filet //filet
filet.x = terrain.x; filet.x = terrain.x;
filet.h = 4; filet.h = 4;
...@@ -145,21 +143,20 @@ void drawTerrainTopView(){ ...@@ -145,21 +143,20 @@ void drawTerrainTopView(){
void drawTerrainSideView(){ void drawTerrainSideView(){
//terrain //terrain
//PAS BIEN A CHANGE !!!!!!!!!!!!!!! drawerTerrainSideView.x = terrain.x + terrain.w + 50;
terrain.x = terrain.x + terrain.w + 50; drawerTerrainSideView.y = terrain.y + terrain.h;
terrain.y = terrain.y + terrain.h; drawerTerrainSideView.h = 4;
terrain.h = 4; drawerTerrainSideView.w = 13.40 * zoom;
terrain.w = 13.40 * zoom;
//filet //filet
filet.w = 4; filet.w = 4;
filet.x = terrain.x + terrain.w/2 - filet.w/2; filet.x = drawerTerrainSideView.x + drawerTerrainSideView.w/2 - filet.w/2;
filet.h = -1.55 * zoom; filet.h = -1.55 * zoom;
filet.y = terrain.y; filet.y = drawerTerrainSideView.y;
//terrain en blanc //terrain en blanc
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderFillRect(renderer, &terrain); SDL_RenderFillRect(renderer, &drawerTerrainSideView);
//filet en vert //filet en vert
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
...@@ -194,8 +191,8 @@ void drawCanonSideView(){ ...@@ -194,8 +191,8 @@ void drawCanonSideView(){
//canon //canon
canon_rect.w = canon.length; canon_rect.w = canon.length;
canon_rect.h = canon.height; canon_rect.h = canon.height;
canon_rect.x = terrain.x + canon.y; canon_rect.x = drawerTerrainSideView.x + canon.y;
canon_rect.y = terrain.y - canon.height; canon_rect.y = drawerTerrainSideView.y - canon.height;
//canon en noir //canon en noir
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
...@@ -206,8 +203,8 @@ void drawPointDeChuteSideView(){ ...@@ -206,8 +203,8 @@ void drawPointDeChuteSideView(){
//point de chute de la balle //point de chute de la balle
point_de_chute.w = 5; point_de_chute.w = 5;
point_de_chute.h = 5; point_de_chute.h = 5;
point_de_chute.x = terrain.x + terrain.w/2 + point_y_rand; point_de_chute.x = drawerTerrainSideView.x + drawerTerrainSideView.w/2 + point_y_rand;
point_de_chute.y = terrain.y; point_de_chute.y = drawerTerrainSideView.y;
//point de chute de la balle //point de chute de la balle
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
...@@ -259,11 +256,7 @@ void drawBall(){ ...@@ -259,11 +256,7 @@ void drawBall(){
} }
//draw hero mana //draw hero mana
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); */
for(i=0; i<hero.mana; i++){
SDL_RenderFillRect(renderer, &rect_mana);
rect_mana.x = rect_mana.x + rect_mana.w + 20;
}*/
} }
...@@ -271,6 +264,7 @@ void drawBall(){ ...@@ -271,6 +264,7 @@ void drawBall(){
void mainLoop(){ void mainLoop(){
createWindow(); createWindow();
initCanon(); initCanon();
initTerrain();
initPointDeChute(); initPointDeChute();
pthread_t eventThread; pthread_t eventThread;
...@@ -288,7 +282,6 @@ void mainLoop(){ ...@@ -288,7 +282,6 @@ void mainLoop(){
drawCanonTopView(); drawCanonTopView();
drawPointDeChuteTopView(); drawPointDeChuteTopView();
drawTrajectoireTopView(); drawTrajectoireTopView();
initTerrain();
zone_canon = getZone(terrain.x, terrain.y, terrain.w, terrain.h); zone_canon = getZone(terrain.x, terrain.y, terrain.w, terrain.h);
zone_chute = getZoneChute(terrain.x, terrain.y, terrain.w, terrain.h); zone_chute = getZoneChute(terrain.x, terrain.y, terrain.w, terrain.h);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment