diff --git a/Makefile b/Makefile index cafac6919451c2280977318487945ef85fd99012..19bad3ad0edadedfc367306dcbbd5dd97ad9a84a 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ $(PROG): $(OBJ) test: gcc -O3 -Dmain=SDL_main -c test.c -I src/include -o test.o - gcc -O3 -Dmain=SDL_main test.o sdl2-light.o sdl2-ttf-light.o library/Display/Display.o library/World/world.o library/Sprites/sprites.o library/utility/utility.o library/menu/menu.o -lm -lmingw32 -lSDL2main -lSDL2 -lSDL2_ttf -lSDL2_image -o test.exe -L src/lib + gcc -O3 -Dmain=SDL_main test.o sdl2-light.o sdl2-ttf-light.o library/Display/Display.o library/World/world.o library/Sprites/sprites.o library/utility/utility.o library/menu/menu.o library/mixer/mixer.o -lm -lmingw32 -lSDL2main -lSDL2 -lSDL2_ttf -lSDL2_image -lSDL2_mixer -o test.exe -L src/lib doc: $(PROG) doxygen $(PROG) diff --git a/constante.c b/constante.c index 496dcc5dcdc2cdefb1e8787ee635525bb4582b05..e60d936c249a7bb2beb24eb1f09907c525ec09dd 100644 --- a/constante.c +++ b/constante.c @@ -43,7 +43,7 @@ * \brief Vitesse initiale de déplacement vertical des éléments du jeu */ -#define INITIAL_SPEED 2 +#define INITIAL_SPEED 6 /** * \brief Nombre de lignes de météorites diff --git a/library/Display/Display.c b/library/Display/Display.c index cf28654c231888a4e09c51f3c573f8bded4a3b58..5946be2f1421fe74b737dd7cd60178b4d2097562 100644 --- a/library/Display/Display.c +++ b/library/Display/Display.c @@ -20,7 +20,7 @@ void init_ressource(SDL_Renderer *renderer, ressources_t *textures){ textures->color = (SDL_Color){255, 255, 255, 255}; textures->BarreProgression = load_image( "ressources/Elements/BarreProgression.png",renderer); - textures->vaisseauMini = textures->ships[0]; + textures->soleilBarre = load_image( "ressources/Elements/soleil.png",renderer); textures->soleil = load_image( "ressources/Elements/soleil.png",renderer); @@ -33,7 +33,7 @@ void init_ressource(SDL_Renderer *renderer, ressources_t *textures){ textures->nb_init = 19; init_ressource_element(renderer, textures); - + printf("aaa"); } void init_ressource_element(SDL_Renderer *renderer, ressources_t *textures){ @@ -45,7 +45,7 @@ void init_ressource_element(SDL_Renderer *renderer, ressources_t *textures){ void apply_background_parralax(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world, int parallax){ if(texture != NULL){ - apply_texture(texture, renderer, 0, (int)(-1800+(world->parallax/parallax)), world->angle*180/M_PI); + apply_texture(texture, renderer, 0, (int)(-1800+(world->parallax/parallax)), 0); } } @@ -64,10 +64,24 @@ void apply_sprite(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprit rect.w = sprite->w; rect.h = sprite->h; + SDL_RenderCopyEx(renderer, texture, NULL, &rect, world->angle*180/M_PI, NULL, SDL_FLIP_NONE); } } +void apply_sprite_without_rotation(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprite, world_t *world){ + if(texture != NULL){ + SDL_Rect rect; + rect.x = SCREEN_WIDTH/2 + (sprite->x - SCREEN_WIDTH/2) * cos(world->angle) - (sprite->y - SCREEN_HEIGHT/2) * sin(world->angle); + rect.y = SCREEN_HEIGHT/2 + (sprite->x - SCREEN_WIDTH/2) * sin(world->angle) + (sprite->y - SCREEN_HEIGHT/2) * cos(world->angle); + + rect.w = sprite->w; + rect.h = sprite->h; + + SDL_RenderCopyEx(renderer, texture, NULL, &rect, 0, NULL, SDL_FLIP_NONE); + } +} + void apply_sprite_fixed(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprite, world_t *world){ if(texture != NULL){ SDL_Rect rect; @@ -181,7 +195,7 @@ void ingame(SDL_Renderer *renderer, world_t *world,ressources_t *textures){ // HUD apply_sprite_fixed(renderer, textures->BarreProgression, world->BarreProgression, world); - apply_sprite_fixed(renderer, textures->vaisseauMini, world->vaisseauMini, world); + apply_sprite_fixed(renderer, textures->ships[world->actualship], 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); @@ -208,7 +222,7 @@ void clean_textures(ressources_t *textures){ 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); diff --git a/library/Display/Display.h b/library/Display/Display.h index b3a097d882c400693ac5caf8b06419a6a1966bda..cff990a5edd4098e40a91886cebd00cb71a1d4c7 100644 --- a/library/Display/Display.h +++ b/library/Display/Display.h @@ -51,7 +51,6 @@ struct ressources_s{ SDL_Texture* coins; /*!< Texture liée à l'image des pièces. */ SDL_Texture* finishLine; /*!< Texture liée à l'image de la ligne d'arrivée. */ SDL_Texture* BarreProgression; /*!< Texture liée à l'image de l'air. */ - SDL_Texture* vaisseauMini; /*!< Texture liée à l'image du vaisseau. */ SDL_Texture* soleilBarre; /*!< Texture liée à l'image du soleil. */ SDL_Texture* soleil; /*!< Texture liée à l'image du soleil. */ @@ -123,6 +122,16 @@ void apply_sprite(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprit * @param world */ void apply_sprite_fixed(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprite, world_t *world); + +/** + * @brief La fonction qui applique la texture \a texture sur le renderer \a renderer en fonction des données du sprite \a sprite (sans rotation sur lui meme) + * + * @param renderer + * @param texture + * @param sprite + * @param world + */ +void apply_sprite_without_rotation(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprite, world_t *world); /** * \brief La fonction qui applique la texture \a texture sur le renderer \a renderer en fonction des coordonnées \a x et \a y * @@ -193,5 +202,11 @@ void inmenu(SDL_Renderer *renderer, world_t *world,ressources_t *textures); */ void inshop(SDL_Renderer *renderer, world_t *world, ressources_t *textures); +/** + * @brief La fonction qui affiche la barre de progression + * @param renderer + * @param world + * @param pgb + */ 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 9103c4b1bd5d808b72dc7de38be6acd697153192..80271e4243045ef0677cb2c58db0a4a22342ce61 100644 Binary files a/library/Display/Display.o and b/library/Display/Display.o differ diff --git a/library/World/world.c b/library/World/world.c index 9d99f7559dc7a80e548d07ccd3c7b8a8733cb9cc..6c9a357cae0bac302212eb7d86866121accf83cf 100644 --- a/library/World/world.c +++ b/library/World/world.c @@ -22,18 +22,22 @@ void update_data(world_t *world){ } } collide(world->vaisseau, world->ligneArriver, world); + if (world->vaisseau->y < world->ligneArriver->y){ + world->gamestate = 1; + } if (timer_update_s(world) != 0){ world->temps_str[0] = '\0'; 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; - + allEvents(world); }else if(world->gamestate == 1){ world->startTimer = SDL_GetTicks(); } } +/// @brief +/// @param world void init_data(world_t * world){ //on n'est pas à la fin du jeu world->gameover = 0; @@ -50,7 +54,7 @@ void init_data(world_t * world){ // 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->ligneArriver = init_sprite(world->ligneArriver, 0, -world->nb_lines_murs*METEORITE_REAL_SIZE-30 , SCREEN_WIDTH, FINISH_LINE_HEIGHT, 'z', 0); // Place la ligne d'arriver correctement a la fin du jeu 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); world->soleilBarre = init_sprite(world->soleilBarre, 0, SCREEN_HEIGHT - 510, 40, 40, 'x', 0); @@ -82,7 +86,6 @@ void init_data(world_t * world){ world->parallax = 0; world->invicibility = false; - print_sprite(world->vaisseau); } @@ -93,14 +96,17 @@ void restart(world_t *world){ world->vaisseauMini->y = SCREEN_HEIGHT - (110); world->vaisseauMini->dy = SCREEN_HEIGHT - (110); - world->ligneArriver->y = -world->nb_lines_murs*METEORITE_SIZE-30; + world->ligneArriver->y = -world->nb_lines_murs*METEORITE_SIZE-30; // Place la ligne d'arriver correctement a la fin du jeu + world->ligneArriver->x = 0; world->soleil->y = -world->nb_lines_murs*METEORITE_SIZE-1400; + world->soleil->x = SCREEN_WIDTH/2-1800/2; world->nb_murs = 0; world->speed_h = (float)INITIAL_SPEED; free(world->murs); init_walls(world); world->angle = 0.0; - + world->parallax = 0; + updateProgressBarre(world->pgb, 100/(INITIAL_SPEED+6)*world->speed_h); modify_str(world->coin_menu_str, int_to_str(world->money)); } @@ -181,7 +187,7 @@ void collide(sprite_t *sp1, sprite_t *sp2, world_t *world){ world->gamestate = 1; restart(world); }else if(strcmp(sp2->id, "2") == 0){ - switch (rand() % 3){ // random entre 1 et 2 + switch (rand() % 3){ // random entre 0 et 2 case 1: if (world->isFlipping == 0){ world->isFlipping = 1; @@ -205,12 +211,16 @@ void collide(sprite_t *sp1, sprite_t *sp2, world_t *world){ } void flipScreen(world_t *world){ - if (world->timer - world->startTimer > 1){ + if (world->timer - world->startTimer2 > 1){ if (world->isFlipping == 1){ world->angle += M_PI/20; + world->speed_h = 0.0; if (world->angle > M_PI){ + world->speed_h = (float)INITIAL_SPEED; world->angle = M_PI; world->isFlipping = -2; + world->soleil->x = SCREEN_WIDTH/2; + world->ligneArriver->x = SCREEN_WIDTH; } }else if(world->isFlipping == -1){ world->angle -= M_PI/20; @@ -219,7 +229,7 @@ void flipScreen(world_t *world){ world->isFlipping = 0; } } - world->startTimer = SDL_GetTicks(); + world->startTimer2 = SDL_GetTicks(); } } diff --git a/library/World/world.h b/library/World/world.h index 4c79bca112183e5d5f4ad8dc8019d18dd94f9160..abb2e66077b500adb389bc992153a993163c1609 100644 --- a/library/World/world.h +++ b/library/World/world.h @@ -21,6 +21,10 @@ #ifndef WORLD_H #define WORLD_H +/** + * @brief La structure qui contient les données d'une progression barre + * + */ struct progressBarre_s{ SDL_Rect* Barre; SDL_Rect* Contours; @@ -84,6 +88,7 @@ struct world_s{ int gameover; /*!< Champ indiquant si l'on est à la fin du jeu */ float speed_h; /*!< Vitesse de déplacement horizontal des éléments du jeu */ unsigned int startTimer; /*!< Timer de départ */ + unsigned int startTimer2; /*!< Timer de départ (flip) */ unsigned int timer; /*!< Timer de jeu */ char * temps_str; // String affichant le temps sur le jeu char * coins_str; @@ -209,8 +214,23 @@ void init_menu(world_t *world); */ void init_shop(world_t * world); - +/** + * @brief La fonction qui initialise la progression barre + * + * @param x + * @param y + * @param w + * @param h + * @param pourcent + * @return progressBarre_t* + */ progressBarre_t *init_progressbarre(int x, int y, int w, int h, int pourcent); +/** + * @brief La fonction qui met à jour la progression barre + * + * @param pgb + * @param pourcent + */ void updateProgressBarre (progressBarre_t *pgb, int pourcent); #endif diff --git a/library/World/world.o b/library/World/world.o index 85ba36e125f23c39da9b9d44e0eb02c10477a071..f44466a0cfb20b27ccab08bdcdc428e9760236ee 100644 Binary files a/library/World/world.o and b/library/World/world.o differ diff --git a/library/menu/menu.h b/library/menu/menu.h index c3c7a2629cb8359c06e4bfe52a13dce3786f30fb..210aff128ed4fa4bc4092d8b08aa05c55c4014a8 100644 --- a/library/menu/menu.h +++ b/library/menu/menu.h @@ -1,3 +1,15 @@ +/** + * \file menu.h + * \author M Moulias + * \brief Fichier qui contient les fonctions liées au menu + * \version 0.1 + * \date 2023-04-05 + * + * @copyright Copyright (c) 2023 + * + */ + + #include <stdio.h> #include <stdlib.h> #include "../../src/include/SDL2/SDL.h" diff --git a/library/mixer/mixer.h b/library/mixer/mixer.h index cb25d25eb7ff8ba0de8cd9bcea533b7952e32ff5..250fbf98a34563b629c497eee45c1caee6f084e7 100644 --- a/library/mixer/mixer.h +++ b/library/mixer/mixer.h @@ -1,7 +1,34 @@ +/** + * \file Display.h + * \author M Moulias + * \brief Fichier qui contient les fonctions liées au son du jeu + * \version 0.1 + * \date 2023-04-05 + * + * @copyright Copyright (c) 2023 + * + */ + #include "../../src/include/SDL2/SDL_mixer.h" +/** + * @brief Initialise le mixer + * + */ void init_mixer(); +/** + * @brief Initialise la musique donnée en paramètre + * + * @param path + * @return Mix_Music* + */ Mix_Music* init_music(char * path); +/** + * @brief Joue la musique donnée en paramètr, -1 pour jouer a l'infini + * + * @param music + * @param loop + */ void play_music(Mix_Music* music, int loop); \ No newline at end of file diff --git a/library/utility/utility.h b/library/utility/utility.h index 3d462b128a118657b2a850e0f021b2f956f30379..5cddddc62835342ee6bab7669f119b3b71333411 100644 --- a/library/utility/utility.h +++ b/library/utility/utility.h @@ -24,6 +24,12 @@ */ char * strcats(char* dest, int num_args, ...); +/** + * @brief Modify un str par un autre + * + * @param str + * @param str2 + */ void modify_str(char *str, char *str2); /** * \brief Convertit un entier en chaine de caractère diff --git a/main.o b/main.o index 11ea1fb29f182fec31481e77ca503b4fb0abf873..698b9ed955e32c71e4f4594e7ef9a076b8f50b5a 100644 Binary files a/main.o and b/main.o differ diff --git a/spacecorridor.exe b/spacecorridor.exe index 50ee6f833c339e7b2ad07d39e3317854d6c9d238..7d24cf169dcd63f6da1f4b14f7e2b046650f958e 100644 Binary files a/spacecorridor.exe and b/spacecorridor.exe differ diff --git a/test.c b/test.c index 24fdf7c2276a2da4706c4e15cea4901a58ed6eb4..730f177d2663b71fed53c3d4b17c2a33e7c3a0bd 100644 --- a/test.c +++ b/test.c @@ -81,7 +81,10 @@ int test_init_data(world_t * world){ } int test_update_data(world_t * world){ + world->gamestate = 0; + printf(" world->ligneArriver->y : %d\n", world->ligneArriver->y); update_data(world); + printf(" world->ligneArriver->y : %d\n", world->ligneArriver->y); return 1; // Pas d'erreur } @@ -140,6 +143,53 @@ int test_InitMenu(world_t *world){ return 1; // Pas d'erreur } +int test_strcats(){ + char *str = malloc(sizeof(char)*100); + strcats(str, 3, "test", "test2", "test3"); + printf("strcats : %s\n", str); + free(str); + return 1; // Pas d'erreur +} + +int test_modify_str(){ + char *str = malloc(sizeof(char)*100); + modify_str(str, "test"); + printf("modify_str : %s\n", str); + free(str); + return 1; // Pas d'erreur +} + +int test_int_to_str(){ + char *str = int_to_str(123); + printf("int_to_str : %s\n", str); + free(str); + return 1; // Pas d'erreur +} + +int test_lire_file(){ + printf("Trop compliquer a test"); + return 1; // Pas d'erreur +} + +int test_number_of_numbers(){ + printf("number_of_numbers : %d\n", number_of_numbers(123)); + return 1; // Pas d'erreur +} + +int test_init_btn(){ + btn_t *btn = init_btn(0, 0, 0, 0); + printf("test_init_btn : %d\n", btn->rect.x); + free(btn); + return 1; // Pas d'erreur +} + +int test_collidePoint(){ + btn_t *btn = init_btn(0, 0, 0, 0); + printf("test_collidePoint : %d\n", collidePoint(btn, 0, 0)); + free(btn); + return 1; // Pas d'erreur +} + int main( int argc, char* args[] ){ printf("Nombre de test : 23\n"); SDL_Event event; @@ -160,10 +210,10 @@ int main( int argc, char* args[] ){ compteur_test += test_init_ressource(renderer, &textures); compteur_test += test_apply_background_parralax(renderer, textures.background, &world, 1); compteur_test += test_apply_background(renderer, textures.background, &world); - compteur_test += test_apply_sprite(renderer, textures.ship, world.vaisseau, &world); - compteur_test += test_apply_sprite_fixed(renderer, textures.ship, world.vaisseau, &world); - compteur_test += test_apply_walls(renderer, textures.ship, &world, &textures); - compteur_test += test_apply_wall(renderer, textures.ship, 0, 0, &world); + compteur_test += test_apply_sprite(renderer, textures.ships[0], world.vaisseau, &world); + compteur_test += test_apply_sprite_fixed(renderer, textures.ships[0], world.vaisseau, &world); + compteur_test += test_apply_walls(renderer, textures.ships[0], &world, &textures); + compteur_test += test_apply_wall(renderer, textures.ships[0], 0, 0, &world); compteur_test += test_refresh_graphics(renderer, &world, &textures); compteur_test += test_inmenu(renderer, &world, &textures); compteur_test += test_ingame(renderer, &world, &textures); @@ -182,10 +232,20 @@ int main( int argc, char* args[] ){ compteur_test += test_allEvents(&world); compteur_test += test_InitMenu(&world); /*--------------------------Sprite--------------------------*/ - + //Compliquer a faire vu que c'est des sprites /*--------------------------Utility--------------------------*/ + + compteur_test += test_strcats(); + compteur_test += test_modify_str(); + compteur_test += test_int_to_str(); + compteur_test += test_lire_file(); + compteur_test += test_number_of_numbers(); /*--------------------------menu--------------------------*/ + compteur_test += test_init_btn(); + compteur_test += test_collidePoint(); + /*--------------------------mixer--------------------------*/ + //Compliquer a faire vu que c'est du son //mise à jour des données liée à la physique du monde update_data(&world); diff --git a/test.exe b/test.exe index 41f8a1a53a23cafa4f9bc3c3dfe8719e911ca4c2..46f9d35560eca443a97c5582312a46d18917ce92 100644 Binary files a/test.exe and b/test.exe differ diff --git a/test.o b/test.o index 6c64885833d69c700b81838bcc628bb9189dce9c..bcc2bbc1792c6d2a357c31c7873564a0922741c8 100644 Binary files a/test.o and b/test.o differ