diff --git a/library/Display/Display.c b/library/Display/Display.c index 69465d855bd1db924d5e0e27921fad970dd0542b..f2dcf114c969ac7adeb46613773233e4090b9052 100644 --- a/library/Display/Display.c +++ b/library/Display/Display.c @@ -11,48 +11,47 @@ void init_ressource(SDL_Renderer *renderer, ressources_t *textures){ textures->font = load_font("ressources/font/arial.ttf", 14); textures->color = (SDL_Color){255, 255, 255, 255}; textures->center = (SDL_Point){SCREEN_WIDTH/2, SCREEN_HEIGHT/2}; - textures->angle = 0; } -void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, ressources_t *res){ +void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world){ if(texture != NULL){ //printf("%f %f\n", (SCREEN_WIDTH/2+(0-SCREEN_WIDTH/2)*cos(angle)-(0-SCREEN_HEIGHT/2)*sin(angle)), (SCREEN_HEIGHT/2+(0-SCREEN_WIDTH/2)*sin(angle)+(0-SCREEN_HEIGHT/2)*cos(angle))); - apply_texture(texture, renderer, 0, 0, res->angle*180/M_PI, &res->center); + apply_texture(texture, renderer, 0, 0, world->angle*180/M_PI); } } -void apply_sprite(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprite, ressources_t *res){ +void apply_sprite(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(res->angle) - (sprite->y - SCREEN_HEIGHT/2) * sin(res->angle); - rect.y = SCREEN_HEIGHT/2 + (sprite->x - SCREEN_WIDTH/2) * sin(res->angle) + (sprite->y - SCREEN_HEIGHT/2) * cos(res->angle); + 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, res->angle*180/M_PI, NULL, SDL_FLIP_NONE); + SDL_RenderCopyEx(renderer, texture, NULL, &rect, world->angle*180/M_PI, NULL, SDL_FLIP_NONE); } } -void apply_wall(SDL_Renderer * renderer, SDL_Texture *texture, int x, int y, ressources_t *res){ +void apply_wall(SDL_Renderer * renderer, SDL_Texture *texture, int x, int y,world_t *world){ if(texture != NULL){ SDL_Rect rect; - rect.x = SCREEN_WIDTH/2 + (x - SCREEN_WIDTH/2) * cos(res->angle) - (y - SCREEN_HEIGHT/2) * sin(res->angle); - rect.y = SCREEN_HEIGHT/2 + (x - SCREEN_WIDTH/2) * sin(res->angle) + (y - SCREEN_HEIGHT/2) * cos(res->angle); + rect.x = SCREEN_WIDTH/2 + (x - SCREEN_WIDTH/2) * cos(world->angle) - (y - SCREEN_HEIGHT/2) * sin(world->angle); + rect.y = SCREEN_HEIGHT/2 + (x - SCREEN_WIDTH/2) * sin(world->angle) + (y - SCREEN_HEIGHT/2) * cos(world->angle); rect.w = METEORITE_SIZE; rect.h = METEORITE_SIZE; - if (SDL_RenderCopyEx(renderer, texture, NULL, &rect, res->angle*180/M_PI, NULL, SDL_FLIP_NONE) != 0){ + if (SDL_RenderCopyEx(renderer, texture, NULL, &rect, world->angle*180/M_PI, NULL, SDL_FLIP_NONE) != 0){ printf("ok\n"); } } } -void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world, ressources_t *res){ +void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world){ for (int i = 0; i < world->nb_murs; i++){ for (int i3 = 0; i3 < world->murs[i]->w/METEORITE_SIZE ; i3++){ for (int i2 = 0; i2 < world->murs[i]->h/METEORITE_SIZE ; i2++){ - apply_wall(renderer, texture, world->murs[i]->x+i3*METEORITE_SIZE, world->murs[i]->y+i2*METEORITE_SIZE, res); + apply_wall(renderer, texture, world->murs[i]->x+i3*METEORITE_SIZE, world->murs[i]->y+i2*METEORITE_SIZE, world); } } } @@ -64,13 +63,13 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textu clear_renderer(renderer); //application des textures dans le renderer - apply_background(renderer, textures->background, textures); + apply_background(renderer, textures->background, world); - apply_sprite(renderer, textures->ship, world->vaisseau, textures); + apply_sprite(renderer, textures->ship, world->vaisseau, world); - apply_sprite(renderer, textures->finishLine, world->ligneArriver, textures); + apply_sprite(renderer, textures->finishLine, world->ligneArriver, world); - apply_walls(renderer, textures->meteorite, world, textures); + apply_walls(renderer, textures->meteorite, world); if (timer_update_s(world) != 0){ world->str[0] = '\0'; diff --git a/library/Display/Display.h b/library/Display/Display.h index f535cbce8c53af52d570419b7cf53e9a74cb7f69..90b6f5479a4ddd21e6ded1208f291d1c5bb7d6f4 100644 --- a/library/Display/Display.h +++ b/library/Display/Display.h @@ -57,7 +57,7 @@ void init_ressource(SDL_Renderer *renderer, ressources_t *textures); * \param renderer le renderer * \param texture la texture liée au fond */ -void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, ressources_t *res); +void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, 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 @@ -66,7 +66,7 @@ void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, ressources_t * \param renderer * \param sprite */ -void apply_sprite(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprite, ressources_t *res); +void apply_sprite(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 @@ -76,7 +76,7 @@ void apply_sprite(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprit * \param x * \param y */ -void apply_wall(SDL_Renderer * renderer, SDL_Texture *texture, int x, int y, ressources_t *res); +void apply_wall(SDL_Renderer * renderer, SDL_Texture *texture, int x, int y, world_t *world); /** * \brief La fonction qui applique les textures des murs sur le renderer \a renderer en fonction des données du monde \a world @@ -86,7 +86,7 @@ void apply_wall(SDL_Renderer * renderer, SDL_Texture *texture, int x, int y, res * \param world * \param res */ -void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world, ressources_t *res); +void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world); /** * \brief La fonction rafraichit l'écran en fonction de l'état des données du monde diff --git a/library/Display/Display.o b/library/Display/Display.o index 5e770405a1658dd3711a9eda4836cf29edde849f..cbeb5ddd3ea0298fb3c7e8596062e609a20dc529 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 2290b2c429b7fec19a033f1e296f2bc2167c4227..cd156c51c3416d3e4e3c3eeb4b848dc1a9279b02 100644 --- a/library/World/world.c +++ b/library/World/world.c @@ -14,6 +14,9 @@ void update_data(world_t *world){ collide(world->vaisseau, world->murs[i], world, 0); } collide(world->vaisseau, world->ligneArriver, world, 1); + + allEvents(world); + world->timer = SDL_GetTicks(); } @@ -36,6 +39,8 @@ void init_data(world_t * world){ world->startTimer = SDL_GetTicks(); world->timer = SDL_GetTicks(); world->str = malloc(sizeof(char)*100); + world->angle = 0.0; + world->isFlipping = 0; } @@ -45,7 +50,6 @@ void clean_data(world_t *world){ free(world->ligneArriver); free(world->murs); free(world->str); - printf("clean_data"); } @@ -55,13 +59,36 @@ void collide(sprite_t *sp1, sprite_t *sp2, world_t *world, int make_disappear){ if (strcmp(sp2->id, "1") == 0){ world->gameover = 1; }else if(strcmp(sp2->id, "2") == 0){ - printf("Changement de sens"); + if (world->isFlipping == 0){ + world->isFlipping = 1; + }else if(world->isFlipping == -2){ + world->isFlipping = -1; + } }else if(strcmp(sp2->id, "z") == 0){ world->gameover = 1; } } } +void flipScreen(world_t *world){ + if (world->timer - world->startTimer > 10){ + if (world->isFlipping == 1){ + world->angle += M_PI/20; + if (world->angle > M_PI){ + world->angle = M_PI; + world->isFlipping = -2; + } + }else if(world->isFlipping == -1){ + world->angle -= M_PI/20; + if (world->angle < 0){ + world->angle = 0; + world->isFlipping = 0; + } + } + world->startTimer = SDL_GetTicks(); + } +} + void init_walls(world_t *world){ world->nb_murs = 0; world->murs = malloc(sizeof(sprite_t) * MAX_LENGTH*MAX_LINES); @@ -76,7 +103,6 @@ void init_walls(world_t *world){ } } } - printf("aaaa"); } void update_walls(world_t *world){ @@ -84,3 +110,9 @@ void update_walls(world_t *world){ world->murs[i]->y += world->speed_h; } } + +void allEvents(world_t *world){ + if (world->isFlipping != 0){ + flipScreen(world); + } +} diff --git a/library/World/world.h b/library/World/world.h index b89e47b05490485938daf30b111d6b8210895954..ae0ee801f094d9ddbde3ae30401e0e5099260766 100644 --- a/library/World/world.h +++ b/library/World/world.h @@ -3,6 +3,7 @@ #include "../Sprites/sprites.h" #include "../../constante.c" #include <SDL2/SDL.h> +#include <stdbool.h> /** * \file world.h @@ -43,6 +44,9 @@ struct world_s{ unsigned int startTimer; /*!< Timer de départ */ unsigned int timer; /*!< Timer de jeu */ char * str; // String affichant le temps sur le jeu + double angle; // Angle de rotation de la map + int isFlipping; // Indique si l'on est en train de faire une rotation de l'écran et dans quelle sens (0 : non droite, 1 : vers la droite, -1 : vers la gauche, -2 : non gauche) + }; typedef struct world_s world_t; @@ -60,7 +64,6 @@ void update_data(world_t *world); int is_game_over(world_t *world); - /** * \brief La fonction initialise les données du monde du jeu * \param world les données du monde @@ -75,6 +78,12 @@ void init_data(world_t * world); */ void clean_data(world_t * world); +/** + * \brief La fonction qui retounre le monde + * + * \param world + */ +void flipScreen(world_t *world); /** * \brief La fonction fais une action en fonction de la collision entre deux sprites @@ -101,5 +110,10 @@ void init_walls(world_t *world); */ void update_walls(world_t *world); - +/** + * \brief La fonction qui execute toutes les actions du jeu + * + * \param world + */ +void allEvents(world_t *world); #endif diff --git a/library/World/world.o b/library/World/world.o index eb906c738d5f8cbfd81ee47b2e5ac4796d8bdfde..df966a89887b259d602a9222d52e62f6360f4d9a 100644 Binary files a/library/World/world.o and b/library/World/world.o differ diff --git a/main.o b/main.o index e9257108b45be6160b70ccc6e098b75bc18ab630..59f2c5613bb826a9e7a166ab5896bf0d0d1f223b 100644 Binary files a/main.o and b/main.o differ diff --git a/maps/default.txt b/maps/default.txt index cb0c728479c7f0fa82a9d044d8927cdd5ce19af3..fdbbf21886dfeaf2f9949d7ce2f3aa59d38c7405 100644 --- a/maps/default.txt +++ b/maps/default.txt @@ -21,7 +21,7 @@ 001001111100011100000110 001001111100011100000110 001001111100011100000110 -001001111100011100000110 +001021111100011100000110 001001111100011100000110 001001111100011100000110 001001111100011100000110 diff --git a/sdl2-light.c b/sdl2-light.c index c50e484cf4e76b4dc4713c0bc41fa2c893e52cb7..1d64ca87d4155e0a7803d223bb4657bf2189f1b0 100644 --- a/sdl2-light.c +++ b/sdl2-light.c @@ -52,13 +52,13 @@ SDL_Texture *load_image(const char path[], SDL_Renderer *renderer) } -void apply_texture(SDL_Texture *texture,SDL_Renderer *renderer,int x, int y, int angle, SDL_Point *center){ +void apply_texture(SDL_Texture *texture,SDL_Renderer *renderer,int x, int y, int angle){ SDL_Rect dst = {0, 0, 0, 0}; SDL_QueryTexture(texture, NULL, NULL, &dst.w, &dst.h); dst.x = x; dst.y=y; - SDL_RenderCopyEx(renderer, texture, NULL, &dst, angle, center, SDL_FLIP_NONE); + SDL_RenderCopyEx(renderer, texture, NULL, &dst, angle, NULL, SDL_FLIP_NONE); } diff --git a/sdl2-light.h b/sdl2-light.h index 861dfb885e908aee040c2c75b98597f81fea98e5..a7715caea7dde7e3d8a56455f5adecb97f28866f 100644 --- a/sdl2-light.h +++ b/sdl2-light.h @@ -61,7 +61,7 @@ void clean_texture(SDL_Texture *texture); * \param y l'ordonnée sur le renderer de l'endroit où est appliquée texture (point en haut à gauche de la surface) */ -void apply_texture(SDL_Texture *texture,SDL_Renderer *renderer,int x, int y, int angle, SDL_Point *center); +void apply_texture(SDL_Texture *texture,SDL_Renderer *renderer,int x, int y, int angle); diff --git a/sdl2-light.o b/sdl2-light.o index 01450226850a60cb6c6dc2ff5cef821c7d1e1486..c96f2fbbd092f6d2d8d49e75754cc20f9c81150b 100644 Binary files a/sdl2-light.o and b/sdl2-light.o differ diff --git a/spacecorridor.exe b/spacecorridor.exe index fc931b72b38ef4bcbe43ccb371aaa6012e954b96..8c5dded8800ff4842b25ea0081f834881d63cb7b 100644 Binary files a/spacecorridor.exe and b/spacecorridor.exe differ