diff --git a/library/Display/Display.c b/library/Display/Display.c index 4c890d6718b3c3696b3d2d012737d2633200ca37..a908b1760bc936b54ee2f09e7d9f65417c387491 100644 --- a/library/Display/Display.c +++ b/library/Display/Display.c @@ -2,7 +2,7 @@ #include "../../constante.c" #include "../utility/utility.h" -void init_ressource(SDL_Renderer *renderer, textures_t *textures){ +void init_ressource(SDL_Renderer *renderer, ressources_t *textures){ textures->background = load_image( "ressources/space-background.bmp",renderer); textures->ship = load_image( "ressources/spaceship.bmp",renderer); textures->meteorite = load_image( "ressources/meteorite.bmp",renderer); @@ -50,7 +50,7 @@ void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world){ } -void refresh_graphics(SDL_Renderer *renderer, world_t *world,textures_t *textures){ +void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textures){ char * str = malloc(sizeof(char)*100); //on vide le renderer clear_renderer(renderer); @@ -70,14 +70,13 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,textures_t *texture } -void clean(SDL_Window *window, SDL_Renderer * renderer, textures_t *textures, world_t * world){ +void clean(SDL_Window *window, SDL_Renderer * renderer, ressources_t *textures, world_t * world){ clean_data(world); clean_textures(textures); clean_sdl(renderer,window); - } -void clean_textures(textures_t *textures){ +void clean_textures(ressources_t *textures){ SDL_DestroyTexture(textures->background); SDL_DestroyTexture(textures->ship); SDL_DestroyTexture(textures->meteorite); diff --git a/library/Display/Display.h b/library/Display/Display.h index 3aec0d4d01f3dde939869c6a12d743c4ce439ff5..36a2d85ddef1c273ba66c357d976e8f3101a37a2 100644 --- a/library/Display/Display.h +++ b/library/Display/Display.h @@ -31,7 +31,7 @@ * \param color * */ -struct textures_s{ +struct ressources_s{ SDL_Texture* background; /*!< Texture liée à l'image du fond de l'écran. */ SDL_Texture* ship; /*!< Texture liée à l'image du vaisseau. */ SDL_Texture* meteorite; /*!< Texture liée à l'image du météorite. */ @@ -41,7 +41,7 @@ struct textures_s{ /* A COMPLETER */ }; -typedef struct textures_s textures_t; +typedef struct ressources_s ressources_t; /** * \brief La fonction initialise les textures du jeu @@ -49,7 +49,7 @@ typedef struct textures_s textures_t; * \param renderer * \param textures */ -void init_ressource(SDL_Renderer *renderer, textures_t *textures); +void init_ressource(SDL_Renderer *renderer, ressources_t *textures); /** * \brief La fonction applique la texture du fond sur le renderer lié à l'écran de jeu @@ -84,13 +84,13 @@ void apply_wall(SDL_Renderer * renderer, SDL_Texture *texture, int x, int y); * \param world les données du monde * \param textures les textures */ -void refresh_graphics(SDL_Renderer *renderer, world_t *world,textures_t *textures); +void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textures); /** * \brief La fonction nettoie les textures * \param textures les textures */ -void clean_textures(textures_t *textures); +void clean_textures(ressources_t *textures); /** * \brief fonction qui nettoie le jeu: nettoyage de la partie graphique (SDL), nettoyage des textures, nettoyage des données @@ -99,6 +99,6 @@ void clean_textures(textures_t *textures); * \param textures les textures * \param world le monde */ -void clean(SDL_Window *window, SDL_Renderer * renderer, textures_t *textures, world_t * world); +void clean(SDL_Window *window, SDL_Renderer * renderer, ressources_t *textures, world_t * world); #endif \ No newline at end of file diff --git a/library/Display/Display.o b/library/Display/Display.o index 5b005b2d58b3d3c30b4df923be545f3c15ad64ae..8d84e1021647c5cffad8470d0f89af7124b68d16 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 1524feee9b7b2be0b30f1354e0ba1823b072ca71..a0bcec589963c7ba110f9f0a248d4b9fc13e5763 100644 --- a/library/World/world.c +++ b/library/World/world.c @@ -2,7 +2,7 @@ void update_data(world_t *world){ - world->ligneArriver->y += world->speed_h; + world->ligneArriver->y += (int)world->speed_h; update_walls(world); if (isOverScreen(world->vaisseau)){ if (world->vaisseau->x < 0) world->vaisseau->x = 0; @@ -15,6 +15,10 @@ void update_data(world_t *world){ break; } } + + if (handle_sprite_collide(world->vaisseau, world->ligneArriver, world, 0) == 1){ // si le vaisseau touche la ligne d'arrivée + world->gameover = 1; + } world->timer = SDL_GetTicks(); } @@ -25,10 +29,9 @@ int is_game_over(world_t *world){ void init_data(world_t * world){ - //on n'est pas à la fin du jeu world->gameover = 0; - world->speed_h = INITIAL_SPEED; + world->speed_h = (float)INITIAL_SPEED; // Initialisation du vaisseau world->vaisseau = init_sprite(world->vaisseau, SCREEN_WIDTH/2 - SHIP_SIZE/2, SCREEN_HEIGHT - SHIP_SIZE, SHIP_SIZE, SHIP_SIZE); // world->mur = init_sprite(world->mur, 0, 0, 3*METEORITE_SIZE, 7*METEORITE_SIZE); @@ -43,18 +46,19 @@ void init_data(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); - free(world->mur); free(world->ligneArriver); + free(world->murs); + printf("clean_data"); } int handle_sprite_collide(sprite_t *sp1, sprite_t *sp2, world_t *world, int make_disappear){ if (sprites_collide(sp1, sp2)){ - world->speed_h = 0; + world->gameover = 1; + printf("collision"); return 1; }else{ - world->speed_h = INITIAL_SPEED; return 0; } } @@ -63,7 +67,6 @@ int handle_sprite_collide(sprite_t *sp1, sprite_t *sp2, world_t *world, int make void init_walls(world_t *world){ world->nb_murs = 6; world->murs = malloc(sizeof(sprite_t) * 10); - world->murs[0] = init_sprite(world->murs[0], 48, 0, 3*METEORITE_SIZE, 6*METEORITE_SIZE); world->murs[1] = init_sprite(world->murs[1], 252, 0, 3*METEORITE_SIZE, 6*METEORITE_SIZE); world->murs[2] = init_sprite(world->murs[2], 16, -352, 1*METEORITE_SIZE, 5*METEORITE_SIZE); diff --git a/library/World/world.h b/library/World/world.h index 1c1009f3ba85d03a0e814a13878d53aa8315f92c..6f0fafa6e47e3021b0b3f9443d6ed9d78fff791d 100644 --- a/library/World/world.h +++ b/library/World/world.h @@ -34,12 +34,11 @@ */ struct world_s{ sprite_t *vaisseau ; /*!< Représentation du vaisseau */ - sprite_t *mur; /*!< Représentation du météorite */ - sprite_t **murs; + sprite_t **murs; /*<Représentation des météorites>*/ int nb_murs; sprite_t *ligneArriver; int gameover; /*!< Champ indiquant si l'on est à la fin du jeu */ - int speed_h; /*!< Vitesse de déplacement horizontal des éléments du jeu */ + float speed_h; /*!< Vitesse de déplacement horizontal des éléments du jeu */ unsigned int startTimer; /*!< Timer de départ */ unsigned int timer; /*!< Timer de jeu */ }; @@ -73,7 +72,6 @@ void init_data(world_t * world); * \param world les données du monde */ void clean_data(world_t * world); - /** * \brief La fonction indique si le sprite est en collision avec un autre sprite * diff --git a/library/World/world.o b/library/World/world.o index f7361aad0ad43ce08e649923cc373c144eb4db59..060c0decb47e2b855d20b5afc654f6b2f57a1521 100644 Binary files a/library/World/world.o and b/library/World/world.o differ diff --git a/main.c b/main.c index 18b741753fb8789e2f0eb2c44fa3523c05bd9d0c..308c20058a753135c7cbfb59254b84cec83541b9 100644 --- a/main.c +++ b/main.c @@ -44,10 +44,12 @@ void handle_events(SDL_Event *event,world_t *world){ world->vaisseau->x -= MOVING_STEP; break; case SDLK_z: - world->speed_h = 3; + world->speed_h = 4; + + printf("%f\n", world->speed_h); break; case SDLK_s: - world->speed_h = -3; + world->speed_h = INITIAL_SPEED; break; case SDLK_ESCAPE: world->gameover = 1; @@ -56,11 +58,7 @@ void handle_events(SDL_Event *event,world_t *world){ break; } // print_sprite(world->vaisseau); - - }else if(event->type == SDL_KEYUP){ - world->speed_h = 0; } - } } @@ -70,9 +68,6 @@ void handle_events(SDL_Event *event,world_t *world){ * \param textures les textures du jeu */ - - - /** * \brief fonction qui initialise le jeu: initialisation de la partie graphique (SDL), chargement des textures, initialisation des données * \param window la fenêtre du jeu @@ -81,7 +76,7 @@ void handle_events(SDL_Event *event,world_t *world){ * \param world le monde */ -void init(SDL_Window **window, SDL_Renderer ** renderer, textures_t *textures, 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); init_data(world); // Initialisation du ttf @@ -100,7 +95,7 @@ int main( int argc, char* args[] ) { SDL_Event event; world_t world; - textures_t textures; + ressources_t textures; SDL_Renderer *renderer; SDL_Window *window; @@ -108,16 +103,16 @@ int main( int argc, char* args[] ) init(&window,&renderer,&textures,&world); while(!is_game_over(&world)){ //tant que le jeu n'est pas fini - + //gestion des évènements handle_events(&event,&world); - + //mise à jour des données liée à la physique du monde update_data(&world); - + //rafraichissement de l'écran refresh_graphics(renderer,&world,&textures); - + // pause de 10 ms pour controler la vitesse de rafraichissement pause(10); } diff --git a/main.o b/main.o index 71db079ab2b4e40f24c2ab9cd1eb3ff47a1cda31..84c2058808654c80d41f952bd3f7398e50847781 100644 Binary files a/main.o and b/main.o differ diff --git a/spacecorridor.exe b/spacecorridor.exe index 27eb5b0dd98acf0724495cc192d510efac766708..7b741295f5dbf25ab6e5b4520d2b0818900af73d 100644 Binary files a/spacecorridor.exe and b/spacecorridor.exe differ