diff --git a/library/Display/Display.c b/library/Display/Display.c index d8a5b32fd1979d54126c76a48ea7f3d4e4a565ec..cf28654c231888a4e09c51f3c573f8bded4a3b58 100644 --- a/library/Display/Display.c +++ b/library/Display/Display.c @@ -9,31 +9,36 @@ void init_ressource(SDL_Renderer *renderer, ressources_t *textures){ textures->background = load_image( "ressources/Elements/backgrounds/1.png",renderer); textures->background2 = load_image( "ressources/Elements/backgrounds/3.png",renderer); textures->background3 = load_image( "ressources/Elements/backgrounds/2.png",renderer); - textures->ship = load_image( "ressources/Elements/Ship_1.png",renderer); + textures->ships = malloc(sizeof(SDL_Texture*)*4); + textures->ships[0] = load_image( "ressources/Elements/Ship_1.png",renderer); + textures->ships[1] = load_image( "ressources/Elements/Ship_2.png",renderer); + textures->ships[2] = load_image( "ressources/Elements/Ship_3.png",renderer); + textures->ships[3] = load_image( "ressources/Elements/Ship_4.png",renderer); textures->exit_shp = load_image( "ressources/exit.png",renderer); - textures->finishLine = load_image( "ressources/finish_line.bmp",renderer); textures->font = load_font("ressources/font/arial.ttf", 14); textures->color = (SDL_Color){255, 255, 255, 255}; textures->BarreProgression = load_image( "ressources/Elements/BarreProgression.png",renderer); - textures->vaisseauMini = textures->ship; + textures->vaisseauMini = textures->ships[0]; textures->soleilBarre = load_image( "ressources/Elements/soleil.png",renderer); textures->soleil = load_image( "ressources/Elements/soleil.png",renderer); - + printf("aaa"); + textures->buy = load_image( "ressources/Elements/shop/buy.png",renderer); textures->nomoney = load_image( "ressources/Elements/shop/nomoney.png",renderer); textures->sell = load_image( "ressources/Elements/shop/sell.png",renderer); + textures->selected = load_image("ressources/Elements/shop/selected.png", renderer); - textures->nb_init = 9; + textures->nb_init = 19; init_ressource_element(renderer, textures); } void init_ressource_element(SDL_Renderer *renderer, ressources_t *textures){ textures->meteorite = load_image( "ressources/meteorite.bmp",renderer); - textures->e_rotate = load_image("ressources/Elements/reverse.bmp", renderer); + textures->e_rotate = load_image("ressources/Elements/e_rotate.png", renderer); textures->coins = load_image("ressources/Elements/coin.png", renderer); textures->nb_init += 3; } @@ -72,7 +77,7 @@ void apply_sprite_fixed(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t rect.w = sprite->w; rect.h = sprite->h; - SDL_RenderCopyEx(renderer, texture, NULL, &rect, world->angle*180/M_PI, NULL, SDL_FLIP_NONE); + SDL_RenderCopyEx(renderer, texture, NULL, &rect, 0, NULL, SDL_FLIP_NONE); } } @@ -109,6 +114,7 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textu //on vide le renderer clear_renderer(renderer); if (world->gamestate == 0){ + ingame(renderer,world,textures); }else if(world ->gamestate==1){ inmenu(renderer,world,textures); @@ -128,22 +134,33 @@ void inmenu(SDL_Renderer *renderer, world_t *world,ressources_t *textures){ void inshop(SDL_Renderer *renderer, world_t *world, ressources_t *textures){ apply_background(renderer, textures->bshop, world); - apply_text(renderer, 150, 150, 50, 25, "200$", textures->font, textures->color); + apply_text(renderer, 150, 150, 50, 25, "0$", textures->font, textures->color); apply_text(renderer, 360, 145, 50, 25, "500$", textures->font, textures->color); apply_text(renderer, 560, 140, 50, 25, "1000$", textures->font, textures->color); apply_text(renderer, 370, 315, 50, 25, "2000$", textures->font, textures->color); + apply_sprite_fixed(renderer, textures->ships[0], world->vaisseau1, world); + apply_sprite_fixed(renderer, textures->ships[1], world->vaisseau2, world); + apply_sprite_fixed(renderer, textures->ships[2], world->vaisseau3, world); + apply_sprite_fixed(renderer, textures->ships[3], world->vaisseau4, world); + for (int i = 0; i<4; i++){ - if (world->shopPrice[i] <= world->money){ + if (world->isSelected[i]){ + apply_sprite_fixed(renderer, textures->selected, world->Spr_ship[i], world); + }else if(world->isBought[i]){ + apply_sprite_fixed(renderer, textures->sell, world->Spr_ship[i], world); + }else if (world->shopPrice[i] <= world->money){ apply_sprite_fixed(renderer, textures->buy, world->Spr_ship[i], world); }else{ apply_sprite_fixed(renderer, textures->nomoney, world->Spr_ship[i], world); } } - + printf("aaa"); apply_text(renderer, (SCREEN_WIDTH-90)-(25*number_of_numbers(world->money)), 20, 25*number_of_numbers(world->money), 50, world->coin_menu_str, textures->font, textures->color); - - apply_sprite(renderer, textures->exit_shp, world->exit_shp , world); + + apply_sprite(renderer, textures->exit_shp, world->exit_shop , world); + printf("aaa\n"); + } void ingame(SDL_Renderer *renderer, world_t *world,ressources_t *textures){ @@ -153,11 +170,12 @@ void ingame(SDL_Renderer *renderer, world_t *world,ressources_t *textures){ apply_background_parralax(renderer, textures->background, world, 7); apply_background_parralax(renderer, textures->background2, world, 3); apply_background_parralax(renderer, textures->background3, world, 9); - - apply_sprite(renderer, textures->ship, world->vaisseau, world); + apply_sprite(renderer, textures->ships[world->actualship], world->vaisseau, world); + apply_sprite(renderer, textures->finishLine, world->ligneArriver, world); apply_walls(renderer, textures->meteorite, world, textures); apply_sprite(renderer, textures->soleil, world->soleil, world); + apply_text(renderer, 10, 10, 100, 33, world->temps_str, textures->font, textures->color); // Temps de jeu apply_text(renderer, SCREEN_WIDTH-(60+10*number_of_numbers(world->money)), 10, 15*number_of_numbers(world->money), 30, world->coins_str, textures->font, textures->color); @@ -166,6 +184,8 @@ void ingame(SDL_Renderer *renderer, world_t *world,ressources_t *textures){ apply_sprite_fixed(renderer, textures->vaisseauMini, world->vaisseauMini, world); apply_sprite_fixed(renderer, textures->soleilBarre, world->soleilBarre, world); apply_sprite_fixed(renderer, textures->coins, world->coins, world); + draw_progressbarre(renderer, world, world->pgb); + // Update de l'écran update_screen(renderer); @@ -180,8 +200,37 @@ void clean(SDL_Window *window, SDL_Renderer * renderer, ressources_t *textures, void clean_textures(ressources_t *textures){ SDL_DestroyTexture(textures->background); - SDL_DestroyTexture(textures->ship); + SDL_DestroyTexture(textures->ships[0]); + SDL_DestroyTexture(textures->ships[1]); + SDL_DestroyTexture(textures->ships[2]); + SDL_DestroyTexture(textures->ships[3]); + SDL_DestroyTexture(textures->meteorite); SDL_DestroyTexture(textures->finishLine); + SDL_DestroyTexture(textures->BarreProgression); + SDL_DestroyTexture(textures->vaisseauMini); + SDL_DestroyTexture(textures->soleilBarre); + SDL_DestroyTexture(textures->soleil); + SDL_DestroyTexture(textures->coins); + + SDL_DestroyTexture(textures->bmenu); + SDL_DestroyTexture(textures->bshop); + SDL_DestroyTexture(textures->background2); + SDL_DestroyTexture(textures->background3); + + SDL_DestroyTexture(textures->exit_shp); + SDL_DestroyTexture(textures->buy); + SDL_DestroyTexture(textures->nomoney); + SDL_DestroyTexture(textures->sell); + SDL_DestroyTexture(textures->selected); clean_font(textures->font); +} + + +void draw_progressbarre(SDL_Renderer *renderer, world_t *world, progressBarre_t *pgb){ + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDL_RenderFillRect(renderer, pgb->Contours); + SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); + SDL_RenderFillRect(renderer, pgb->Barre); + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); } \ No newline at end of file diff --git a/library/Display/Display.h b/library/Display/Display.h index 2fe956b07d8f3efe871d2f7ba1903c97b97f2268..b3a097d882c400693ac5caf8b06419a6a1966bda 100644 --- a/library/Display/Display.h +++ b/library/Display/Display.h @@ -32,13 +32,18 @@ * \param color * */ + + + struct ressources_s{ SDL_Texture* background; /*!< Texture liée à l'image du fond de l'écran. */ SDL_Texture* bmenu;/*!< Texture liée à l'image du fond du menu. */ SDL_Texture* bshop; /*!< Texture liée à l'image du fond du gameover. */ SDL_Texture* background2; /*!< Texture liée à l'image du fond de l'écran. (effet parallax) */ SDL_Texture* background3; /*!< Texture liée à l'image du fond de l'écran. (effet parallax) */ - SDL_Texture* ship; /*!< Texture liée à l'image du vaisseau. */ + SDL_Texture** ships; + + SDL_Texture* exit_shp; SDL_Texture* meteorite; /*!< Texture liée à l'image du météorite. */ @@ -54,6 +59,9 @@ struct ressources_s{ SDL_Texture* buy; /*!< Texture liée à l'image du bouton buy. */ SDL_Texture* nomoney; /*!< Texture liée à l'image du bouton nomoney. */ SDL_Texture* sell; /*!< Texture liée à l'image du bouton sell. */ + SDL_Texture* selected; + + TTF_Font *font; // Font SDL_Color color; // Color @@ -61,8 +69,11 @@ struct ressources_s{ int nb_init; /*!< Nombre d'initialisation. */ }; + typedef struct ressources_s ressources_t; + + /** * \brief La fonction initialise les textures du jeu * @@ -181,4 +192,6 @@ void inmenu(SDL_Renderer *renderer, world_t *world,ressources_t *textures); * @param textures */ void inshop(SDL_Renderer *renderer, world_t *world, ressources_t *textures); + +void draw_progressbarre(SDL_Renderer *renderer, world_t *world, progressBarre_t *pgb); #endif \ No newline at end of file diff --git a/library/Display/Display.o b/library/Display/Display.o index db1aa70d1adadf0bddd7dd106101c3e6959a233d..b3b27d003938ae90abdaa65d174521cdca6a94ea 100644 Binary files a/library/Display/Display.o and b/library/Display/Display.o differ diff --git a/library/Sprites/sprites.o b/library/Sprites/sprites.o index 653312a1dc4daeb0f67fd0532b4c2ee660ae8145..b52ea3ebefe689154a5a3a0a5f5135bf17bea7df 100644 Binary files a/library/Sprites/sprites.o and b/library/Sprites/sprites.o differ diff --git a/library/World/world.c b/library/World/world.c index 2105b30d273261e8b537e997d26b77fa0e9a68e3..9a25960bbe1817e10451ea498fc89afe84e43f35 100644 --- a/library/World/world.c +++ b/library/World/world.c @@ -26,11 +26,10 @@ void update_data(world_t *world){ world->temps_str = strcats(world->temps_str, 3, "temps: ",int_to_str((int)world->timer/1000), "s"); } allEvents(world); - world->timer = SDL_GetTicks() - world->startTimer;; + world->timer = SDL_GetTicks() - world->startTimer; + }else if(world->gamestate == 1){ world->startTimer = SDL_GetTicks(); - }else if(world->gamestate == 2){ - printf("%d\n", world->money); } } @@ -47,9 +46,9 @@ void init_data(world_t * world){ init_shop(world); - printf("test\n"); // Initialisation du vaisseau world->vaisseau = init_sprite(world->vaisseau, SCREEN_WIDTH/2 - SHIP_SIZE/2, SCREEN_HEIGHT - SHIP_SIZE-15, SHIP_SIZE, SHIP_SIZE, '0', 0); + world->ligneArriver = init_sprite(world->ligneArriver, 0, -world->nb_lines_murs*METEORITE_REAL_SIZE-30 , SCREEN_WIDTH, FINISH_LINE_HEIGHT, 'z', 0); world->BarreProgression = init_sprite(world->BarreProgression, 10, SCREEN_HEIGHT - 500, 50, 400, 'y', 0); world->vaisseauMini = init_sprite(world->vaisseauMini, 10, SCREEN_HEIGHT - 130, 20, 20, 'x', 0); @@ -57,6 +56,8 @@ void init_data(world_t * world){ world->soleil = init_sprite(world->soleil, SCREEN_WIDTH/2-1800/2, -world->nb_lines_murs*METEORITE_REAL_SIZE-1400, 1800, 1800, 'z', 0); world->air = init_sprite(world->air, -2000, -2000, 0, 0, 'x', 0); world->coins = init_sprite(world->coins, SCREEN_WIDTH-40, 10, 30, 30, 'x', 0); + world->exit_shop = init_sprite(world->exit_shop, 670, 500, 100, 100, 'x', 0); + world->pgb = init_progressbarre(SCREEN_WIDTH-200, SCREEN_HEIGHT-30, 190, 20, 100/(INITIAL_SPEED+6)*world->speed_h); world->vaisseauMini->y = SCREEN_HEIGHT - (110); world->vaisseauMini->dy = SCREEN_HEIGHT - (110); @@ -65,7 +66,7 @@ void init_data(world_t * world){ world->coins_str = malloc(sizeof(char)*100); // Allocation de la mémoire pour le string coins world->coins_str[0] = '\0'; world->coins_str = strcats(world->coins_str, 1, "0"); - + world->actualship = 0; world->angle = 0.0; world->isFlipping = 0; @@ -81,6 +82,23 @@ void init_data(world_t * world){ print_sprite(world->vaisseau); } +void restart(world_t *world){ + + world->vaisseau->x = SCREEN_WIDTH/2 - SHIP_SIZE/2; + + world->vaisseauMini->y = SCREEN_HEIGHT - (110); + world->vaisseauMini->dy = SCREEN_HEIGHT - (110); + + world->ligneArriver->y = -world->nb_lines_murs*METEORITE_SIZE-30; + world->soleil->y = -world->nb_lines_murs*METEORITE_SIZE-1400; + world->nb_murs = 0; + world->speed_h = (float)INITIAL_SPEED; + free(world->murs); + init_walls(world); + world->angle = 0.0; + + modify_str(world->coin_menu_str, int_to_str(world->money)); +} void outBorder(world_t *world){ if (isOverScreen(world->vaisseau)){ @@ -114,12 +132,20 @@ void init_menu(world_t * world){ } void init_shop(world_t * world){ - world->ship1 = init_btn(74,145, 191, 139); - world->ship2 = init_btn(287,143, 191, 139); - world->ship3 = init_btn(491,138, 191, 139); - world->ship4 = init_btn(290,308, 191, 139); + world->ships = malloc(sizeof(btn_t*)*4); + world->ships[0] = init_btn(74,145, 191, 139); + world->ships[1] = init_btn(287,143, 191, 139); + world->ships[2] = init_btn(491,138, 191, 139); + world->ships[3] = init_btn(290,308, 191, 139); + world->exit_shp = init_btn(670,500,100,100); + world->vaisseau1 = init_sprite(world->vaisseau1, 140, 170, 60, 60, 0, 'z'); + world->vaisseau2 = init_sprite(world->vaisseau2, 350, 170, 60, 60, 0, 'z'); + world->vaisseau3 = init_sprite(world->vaisseau3, 560, 170, 60, 60, 0, 'z'); + world->vaisseau4 = init_sprite(world->vaisseau4, 360, 340, 60, 60, 0, 'z'); + + world->Spr_ship = malloc(sizeof(sprite_t*)*4); world->Spr_ship[0] = init_sprite(world->Spr_ship[0], 74,145, 191, 139, 'x', 0); world->Spr_ship[1] = init_sprite(world->Spr_ship[1], 287,143, 191, 139, 'x', 0); @@ -127,25 +153,46 @@ void init_shop(world_t * world){ world->Spr_ship[3] = init_sprite(world->Spr_ship[3], 290,308, 191, 139, 'x', 0); world->shopPrice = malloc(sizeof(int)*4); - world->shopPrice[0] = 200; + world->shopPrice[0] = 0; world->shopPrice[1] = 500; world->shopPrice[2] = 1000; world->shopPrice[3] = 2000; + + world->isBought = malloc(sizeof(bool)*4); + world->isBought[0] = true; + world->isBought[1] = false; + world->isBought[2] = false; + world->isBought[3] = false; + + world->isSelected = malloc(sizeof(bool)*4); + world->isSelected[0] = true; + world->isSelected[1] = false; + world->isSelected[2] = false; + world->isSelected[3] = false; } void collide(sprite_t *sp1, sprite_t *sp2, world_t *world){ if (sprites_collide(sp1, sp2)){ - printf("aaa: %s\n", sp2->id); if (strcmp(sp2->id, "1") == 0){ - world->gameover = 1; + world->gamestate = 1; + restart(world); }else if(strcmp(sp2->id, "2") == 0){ - if (world->isFlipping == 0){ - world->isFlipping = 1; - }else if(world->isFlipping == -2){ - world->isFlipping = -1; + switch (rand() % 3){ + case 1: + if (world->isFlipping == 0){ + world->isFlipping = 1; + }else if(world->isFlipping == -2){ + world->isFlipping = -1; + } + break; + case 2: + world->money += 10; + break; } + remove_wall(world, sp2->indice); }else if(strcmp(sp2->id, "z") == 0){ - world->gameover = 1; + world->gamestate = 1; + restart(world); }else if(strcmp(sp2->id, "3") == 0){ world->money += 1; remove_wall(world, sp2->indice); @@ -169,6 +216,7 @@ void flipScreen(world_t *world){ } } world->startTimer = SDL_GetTicks(); + } } @@ -217,8 +265,6 @@ void allEvents(world_t *world){ } } - - void clean_data(world_t *world){ /* utile uniquement si vous avez fait de l'allocation dynamique (malloc); la fonction ici doit permettre de libérer la mémoire (free) */ free(world->vaisseau); @@ -236,13 +282,38 @@ void clean_data(world_t *world){ free(world->exit); free(world->magasin); free(world->sound); - free(world->ship1); - free(world->ship2); - free(world->ship3); - free(world->ship4); + free(world->ships); free(world->Spr_ship); free(world->shopPrice); free(world->coin_menu_str); printf("clean_data"); +} + +progressBarre_t *init_progressbarre(int x, int y, int w, int h, int pourcent){ + progressBarre_t *pgb; + pgb = malloc(sizeof(progressBarre_t)); + pgb->Barre = malloc(sizeof(SDL_Rect)); + pgb->Contours = malloc(sizeof(SDL_Rect)); + pgb->Base = malloc(sizeof(SDL_Rect)); + pgb->Barre->x = x; + pgb->Barre->y = y; + pgb->Barre->w = (int)(w*((float)pourcent/100.0)); + pgb->Barre->h = h; + pgb->Contours->x = x-6; + pgb->Contours->y = y-6; + pgb->Contours->w = w+12; + pgb->Contours->h = h+12; + pgb->Base->x = x; + pgb->Base->y = y; + pgb->Base->w = w; + pgb->Base->h = h; + pgb->pourcent = pourcent; + return pgb; +} + +void updateProgressBarre (progressBarre_t *pgb, int pourcent){ + pgb->pourcent = pourcent; + + pgb->Barre->w = (int)(pgb->Base->w*((float)pourcent/100.0)); } \ No newline at end of file diff --git a/library/World/world.h b/library/World/world.h index 0a5a56bbd2fb5d97d8c80550210823606cf76cbf..9185c99d6df915322374717b9968c148cc09ec42 100644 --- a/library/World/world.h +++ b/library/World/world.h @@ -20,6 +20,15 @@ #ifndef WORLD_H #define WORLD_H +struct progressBarre_s{ + SDL_Rect* Barre; + SDL_Rect* Contours; + SDL_Rect* Base; + int pourcent; +}; + +typedef struct progressBarre_s progressBarre_t; + /** * \brief La structure qui contient les données du monde * @@ -39,15 +48,18 @@ struct world_s{ sprite_t **murs; /*<Représentation des météorites>*/ sprite_t **murs2; /*<Représentation des météorites et de l'air>*/ + sprite_t *vaisseau1; + sprite_t *vaisseau2; + sprite_t *vaisseau3; + sprite_t *vaisseau4; + btn_t *play; btn_t *exit; btn_t *magasin; btn_t *sound; - btn_t *ship1; - btn_t *ship2; - btn_t *ship3; - btn_t *ship4; + int actualship; + btn_t **ships; btn_t *exit_shp; sprite_t *BarreProgression; @@ -59,6 +71,9 @@ struct world_s{ sprite_t *exit_shop; sprite_t **Spr_ship; + progressBarre_t* pgb; + bool *isBought; + bool *isSelected; int *shopPrice; int nb_murs; // Nombre de météorites int nb_lines_murs; // Nombre de lignes de météorites @@ -190,4 +205,9 @@ void init_menu(world_t *world); * @param world */ void init_shop(world_t * world); + + +progressBarre_t *init_progressbarre(int x, int y, int w, int h, int pourcent); + +void updateProgressBarre (progressBarre_t *pgb, int pourcent); #endif diff --git a/library/World/world.o b/library/World/world.o index 0093a2f35eb4e398d00509dcfda841039868522b..e3e8fd5e7717b287851c14f3d61a813028478cf6 100644 Binary files a/library/World/world.o and b/library/World/world.o differ diff --git a/library/menu/menu.o b/library/menu/menu.o index b6cbc3e665f91e49dc9a7db7cdebb2712ead74c7..84c315fce363b5059bff8e7a368ef00fceb3c935 100644 Binary files a/library/menu/menu.o and b/library/menu/menu.o differ diff --git a/library/utility/utility.o b/library/utility/utility.o index 6609c095ef8dafdbc81576ac568e31b439ea5fff..6d8022279078ab3e448c8e8a3e13ec2d6306e722 100644 Binary files a/library/utility/utility.o and b/library/utility/utility.o differ diff --git a/main.c b/main.c index 2c228c97a91f2f253d9fc8bb6698ce383c957021..64d0ddeab01a49cbf52834be00e023dd0c281bd3 100644 --- a/main.c +++ b/main.c @@ -13,6 +13,7 @@ #include "library/World/world.h" #include "library/utility/utility.h" #include "constante.c" +#include <time.h> /** @@ -49,10 +50,20 @@ void handle_events(SDL_Event *event,world_t *world){ if (!world->gamestate){ switch (event->key.keysym.sym){ case SDLK_z: - world->speed_h = 4; + if (world->speed_h < INITIAL_SPEED+6){ + world->speed_h += 1; + printf("%f\n", world->speed_h); + updateProgressBarre(world->pgb, 100.0/(float)(INITIAL_SPEED+6)*(world->speed_h)); + + } + break; case SDLK_s: - world->speed_h = INITIAL_SPEED; + if (world->speed_h > INITIAL_SPEED){ + world->speed_h -= 1; + updateProgressBarre(world->pgb, 100.0/(float)(INITIAL_SPEED+6)*(world->speed_h)); + } + break; case SDLK_ESCAPE: world->gameover = 1; @@ -69,40 +80,39 @@ void handle_events(SDL_Event *event,world_t *world){ if (event->button.button == SDL_BUTTON_LEFT){ printf("mouse(%d, %d) world rect (%d %d %d %d)\n", world->mouseX, world->mouseY, world->play->rect.x,world->play->rect.y,world->play->rect.w,world->play->rect.h ); if (collidePoint(world->play, world->mouseX, world->mouseY)){ - printf("tesy"); + modify_str(world->coins_str, int_to_str(world->money)); world->gamestate = 0; } if (collidePoint(world->magasin, world->mouseX, world->mouseY)){ - printf("tesy"); world->gamestate = 2; } if (collidePoint(world->exit, world->mouseX, world->mouseY)){ - printf("tesy"); world->gameover = true; } } }else if(world->gamestate == 2){ if (event->button.button == SDL_BUTTON_LEFT){ - if (collidePoint(world->ship1, world->mouseX, world->mouseY)){ - printf("ship1"); - world->money -= world->shopPrice[0]; - modify_str(world->coins_str, int_to_str(world->money)); - printf("%s\n", world->coins_str); - } - if (collidePoint(world->ship2, world->mouseX, world->mouseY)){ - printf("ship2"); - world->money -= world->shopPrice[1]; - modify_str(world->coins_str, int_to_str(world->money)); - } - if (collidePoint(world->ship3, world->mouseX, world->mouseY)){ - printf("ship3"); - world->money -= world->shopPrice[2]; - modify_str(world->coins_str, int_to_str(world->money)); - } - if (collidePoint(world->ship4, world->mouseX, world->mouseY)){ - printf("ship4"); - world->money -= world->shopPrice[3]; - modify_str(world->coins_str, int_to_str(world->money)); + for (int i = 0; i < 4; i++){ + if (collidePoint(world->ships[i], world->mouseX, world->mouseY)){ + if (world->money - world->shopPrice[i] >= 0){ + if (!world->isBought[i]){ + world->money -= world->shopPrice[i]; + modify_str(world->coin_menu_str, int_to_str(world->money)); + world->isBought[i] = true; + } + + } + if(world->isBought[i]){ + for (int j = 0; j < 4; j++){ + if (j != i){ + world->isSelected[j] = false; + }else{ + world->isSelected[j] = true; + world->actualship = j; + } + } + } + } } if (collidePoint(world->exit_shp, world->mouseX, world->mouseY)){ printf("exit"); @@ -130,7 +140,7 @@ void handle_events(SDL_Event *event,world_t *world){ void init(SDL_Window **window, SDL_Renderer ** renderer, ressources_t *textures, world_t * world){ init_sdl(window,renderer,SCREEN_WIDTH, SCREEN_HEIGHT); - + srand(time(0)); init_data(world); // Initialisation du ttf init_ttf(); @@ -155,9 +165,10 @@ int main( int argc, char* args[] ) Uint32 ticks = SDL_GetTicks(); Uint32 frameTime = 0; - + //initialisation du jeu init(&window,&renderer,&textures,&world); + while(!is_game_over(&world)){ //tant que le jeu n'est pas fini frameTime = SDL_GetTicks() - ticks; //gestion des évènements @@ -165,6 +176,7 @@ int main( int argc, char* args[] ) //mise à jour des données liée à la physique du monde update_data(&world); + //rafraichissement de l'écran refresh_graphics(renderer,&world,&textures); diff --git a/main.o b/main.o index d9f97e4da37988ad1709dea0b0dd7ff05c19176a..cbde06eac5472bd47768c0720c1ec9480e22ddfc 100644 Binary files a/main.o and b/main.o differ diff --git a/ressources/Elements/e_rotate.png b/ressources/Elements/e_rotate.png new file mode 100644 index 0000000000000000000000000000000000000000..eaab9fcb8c45620165ffd2b17471c93a28331820 Binary files /dev/null and b/ressources/Elements/e_rotate.png differ diff --git a/ressources/Elements/shop/selected.png b/ressources/Elements/shop/selected.png new file mode 100644 index 0000000000000000000000000000000000000000..fbe5b16ff2dfbc93d36dc5eedbb0908e31ffcdac Binary files /dev/null and b/ressources/Elements/shop/selected.png differ diff --git a/sdl2-light.o b/sdl2-light.o index 3e6a75a3a2e00c9e5611f12a2032bd08bbe0786f..b1fb73d0112d9feb208a755bbcb6b2a0571606ef 100644 Binary files a/sdl2-light.o and b/sdl2-light.o differ diff --git a/sdl2-ttf-light.o b/sdl2-ttf-light.o index e6dbdb53a08901764f1103130b7cfe977b7bcc21..f8e682ac4d9855b2e3eea678d9470fab1084a9f1 100644 Binary files a/sdl2-ttf-light.o and b/sdl2-ttf-light.o differ diff --git a/spacecorridor.exe b/spacecorridor.exe index 353addcaac4d315dcadaf3658fad1b03db2ff94b..cc4620315b1fb76d55de0d2faa7b0a3d40587d1a 100644 Binary files a/spacecorridor.exe and b/spacecorridor.exe differ