Skip to content
Snippets Groups Projects
Commit 7de20491 authored by SmallIshMink's avatar SmallIshMink
Browse files

Rotation de l'écran quand on touche l'élement numero 2 Dans la map

parent 07938c3a
No related branches found
No related tags found
No related merge requests found
...@@ -11,48 +11,47 @@ void init_ressource(SDL_Renderer *renderer, ressources_t *textures){ ...@@ -11,48 +11,47 @@ void init_ressource(SDL_Renderer *renderer, ressources_t *textures){
textures->font = load_font("ressources/font/arial.ttf", 14); textures->font = load_font("ressources/font/arial.ttf", 14);
textures->color = (SDL_Color){255, 255, 255, 255}; textures->color = (SDL_Color){255, 255, 255, 255};
textures->center = (SDL_Point){SCREEN_WIDTH/2, SCREEN_HEIGHT/2}; 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){ 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))); //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){ if(texture != NULL){
SDL_Rect rect; 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.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(res->angle) + (sprite->y - SCREEN_HEIGHT/2) * cos(res->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.w = sprite->w;
rect.h = sprite->h; 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){ if(texture != NULL){
SDL_Rect rect; SDL_Rect rect;
rect.x = SCREEN_WIDTH/2 + (x - SCREEN_WIDTH/2) * cos(res->angle) - (y - SCREEN_HEIGHT/2) * sin(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(res->angle) + (y - SCREEN_HEIGHT/2) * cos(res->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.w = METEORITE_SIZE;
rect.h = 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"); 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 i = 0; i < world->nb_murs; i++){
for (int i3 = 0; i3 < world->murs[i]->w/METEORITE_SIZE ; i3++){ for (int i3 = 0; i3 < world->murs[i]->w/METEORITE_SIZE ; i3++){
for (int i2 = 0; i2 < world->murs[i]->h/METEORITE_SIZE ; i2++){ 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 ...@@ -64,13 +63,13 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textu
clear_renderer(renderer); clear_renderer(renderer);
//application des textures dans le 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){ if (timer_update_s(world) != 0){
world->str[0] = '\0'; world->str[0] = '\0';
......
...@@ -57,7 +57,7 @@ void init_ressource(SDL_Renderer *renderer, ressources_t *textures); ...@@ -57,7 +57,7 @@ void init_ressource(SDL_Renderer *renderer, ressources_t *textures);
* \param renderer le renderer * \param renderer le renderer
* \param texture la texture liée au fond * \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 * \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 ...@@ -66,7 +66,7 @@ void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, ressources_t
* \param renderer * \param renderer
* \param sprite * \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 * \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 ...@@ -76,7 +76,7 @@ void apply_sprite(SDL_Renderer * renderer, SDL_Texture *texture, sprite_t *sprit
* \param x * \param x
* \param y * \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 * \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 ...@@ -86,7 +86,7 @@ void apply_wall(SDL_Renderer * renderer, SDL_Texture *texture, int x, int y, res
* \param world * \param world
* \param res * \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 * \brief La fonction rafraichit l'écran en fonction de l'état des données du monde
......
No preview for this file type
...@@ -14,6 +14,9 @@ void update_data(world_t *world){ ...@@ -14,6 +14,9 @@ void update_data(world_t *world){
collide(world->vaisseau, world->murs[i], world, 0); collide(world->vaisseau, world->murs[i], world, 0);
} }
collide(world->vaisseau, world->ligneArriver, world, 1); collide(world->vaisseau, world->ligneArriver, world, 1);
allEvents(world);
world->timer = SDL_GetTicks(); world->timer = SDL_GetTicks();
} }
...@@ -36,6 +39,8 @@ void init_data(world_t * world){ ...@@ -36,6 +39,8 @@ void init_data(world_t * world){
world->startTimer = SDL_GetTicks(); world->startTimer = SDL_GetTicks();
world->timer = SDL_GetTicks(); world->timer = SDL_GetTicks();
world->str = malloc(sizeof(char)*100); world->str = malloc(sizeof(char)*100);
world->angle = 0.0;
world->isFlipping = 0;
} }
...@@ -45,7 +50,6 @@ void clean_data(world_t *world){ ...@@ -45,7 +50,6 @@ void clean_data(world_t *world){
free(world->ligneArriver); free(world->ligneArriver);
free(world->murs); free(world->murs);
free(world->str); free(world->str);
printf("clean_data"); printf("clean_data");
} }
...@@ -55,13 +59,36 @@ void collide(sprite_t *sp1, sprite_t *sp2, world_t *world, int make_disappear){ ...@@ -55,13 +59,36 @@ void collide(sprite_t *sp1, sprite_t *sp2, world_t *world, int make_disappear){
if (strcmp(sp2->id, "1") == 0){ if (strcmp(sp2->id, "1") == 0){
world->gameover = 1; world->gameover = 1;
}else if(strcmp(sp2->id, "2") == 0){ }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){ }else if(strcmp(sp2->id, "z") == 0){
world->gameover = 1; 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){ void init_walls(world_t *world){
world->nb_murs = 0; world->nb_murs = 0;
world->murs = malloc(sizeof(sprite_t) * MAX_LENGTH*MAX_LINES); world->murs = malloc(sizeof(sprite_t) * MAX_LENGTH*MAX_LINES);
...@@ -76,7 +103,6 @@ void init_walls(world_t *world){ ...@@ -76,7 +103,6 @@ void init_walls(world_t *world){
} }
} }
} }
printf("aaaa");
} }
void update_walls(world_t *world){ void update_walls(world_t *world){
...@@ -84,3 +110,9 @@ void update_walls(world_t *world){ ...@@ -84,3 +110,9 @@ void update_walls(world_t *world){
world->murs[i]->y += world->speed_h; world->murs[i]->y += world->speed_h;
} }
} }
void allEvents(world_t *world){
if (world->isFlipping != 0){
flipScreen(world);
}
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "../Sprites/sprites.h" #include "../Sprites/sprites.h"
#include "../../constante.c" #include "../../constante.c"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <stdbool.h>
/** /**
* \file world.h * \file world.h
...@@ -43,6 +44,9 @@ struct world_s{ ...@@ -43,6 +44,9 @@ struct world_s{
unsigned int startTimer; /*!< Timer de départ */ unsigned int startTimer; /*!< Timer de départ */
unsigned int timer; /*!< Timer de jeu */ unsigned int timer; /*!< Timer de jeu */
char * str; // String affichant le temps sur le 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; typedef struct world_s world_t;
...@@ -60,7 +64,6 @@ void update_data(world_t *world); ...@@ -60,7 +64,6 @@ void update_data(world_t *world);
int is_game_over(world_t *world); int is_game_over(world_t *world);
/** /**
* \brief La fonction initialise les données du monde du jeu * \brief La fonction initialise les données du monde du jeu
* \param world les données du monde * \param world les données du monde
...@@ -75,6 +78,12 @@ void init_data(world_t * world); ...@@ -75,6 +78,12 @@ void init_data(world_t * world);
*/ */
void clean_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 * \brief La fonction fais une action en fonction de la collision entre deux sprites
...@@ -101,5 +110,10 @@ void init_walls(world_t *world); ...@@ -101,5 +110,10 @@ void init_walls(world_t *world);
*/ */
void update_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 #endif
No preview for this file type
No preview for this file type
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
001001111100011100000110 001001111100011100000110
001001111100011100000110 001001111100011100000110
001001111100011100000110 001001111100011100000110
001001111100011100000110 001021111100011100000110
001001111100011100000110 001001111100011100000110
001001111100011100000110 001001111100011100000110
001001111100011100000110 001001111100011100000110
......
...@@ -52,13 +52,13 @@ SDL_Texture *load_image(const char path[], SDL_Renderer *renderer) ...@@ -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_Rect dst = {0, 0, 0, 0};
SDL_QueryTexture(texture, NULL, NULL, &dst.w, &dst.h); SDL_QueryTexture(texture, NULL, NULL, &dst.w, &dst.h);
dst.x = x; dst.y=y; 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);
} }
......
...@@ -61,7 +61,7 @@ void clean_texture(SDL_Texture *texture); ...@@ -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) * \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);
......
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment