diff --git a/constante.c b/constante.c index bd2ee450ee5967343de2dc532fcf42ec07e493b8..b82d014a6035146ea7a6fba5e602fdddb196da3a 100644 --- a/constante.c +++ b/constante.c @@ -1,12 +1,12 @@ /** * \brief Largeur de l'écran de jeu */ -#define SCREEN_WIDTH 300 +#define SCREEN_WIDTH 768 /** * \brief Hauteur de l'écran de jeu */ -#define SCREEN_HEIGHT 480 +#define SCREEN_HEIGHT 600 /** @@ -35,7 +35,7 @@ * \brief Pas de déplacement horizontal du vaisseau */ -#define MOVING_STEP 10 +#define MOVING_STEP 5 /** diff --git a/library/Display/Display.c b/library/Display/Display.c index f2dcf114c969ac7adeb46613773233e4090b9052..6a7134b9682837d6ac590e18a10e4cd1ea90afb5 100644 --- a/library/Display/Display.c +++ b/library/Display/Display.c @@ -4,13 +4,19 @@ #include <math.h> void init_ressource(SDL_Renderer *renderer, ressources_t *textures){ - textures->background = load_image( "ressources/space-background.bmp",renderer); + textures->background = load_image( "ressources/Elements/background2.bmp",renderer); textures->ship = load_image( "ressources/spaceship.bmp",renderer); - textures->meteorite = load_image( "ressources/meteorite.bmp",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->center = (SDL_Point){SCREEN_WIDTH/2, SCREEN_HEIGHT/2}; + + 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); } void apply_background(SDL_Renderer *renderer, SDL_Texture *texture, world_t *world){ @@ -47,11 +53,15 @@ void apply_wall(SDL_Renderer * renderer, SDL_Texture *texture, int x, int y,worl } } -void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world){ +void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world, ressources_t *res){ 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, world); + if (strcmp(world->murs[i]->id, "1") == 0){ + apply_wall(renderer, res->meteorite, world->murs[i]->x+i3*METEORITE_SIZE, world->murs[i]->y+i2*METEORITE_SIZE, world); + }else if(strcmp(world->murs[i]->id, "2") == 0){ + apply_wall(renderer, res->e_rotate, world->murs[i]->x+i3*METEORITE_SIZE, world->murs[i]->y+i2*METEORITE_SIZE, world); + } } } } @@ -69,7 +79,7 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textu apply_sprite(renderer, textures->finishLine, world->ligneArriver, world); - apply_walls(renderer, textures->meteorite, world); + apply_walls(renderer, textures->meteorite, world, textures); if (timer_update_s(world) != 0){ world->str[0] = '\0'; diff --git a/library/Display/Display.h b/library/Display/Display.h index 90b6f5479a4ddd21e6ded1208f291d1c5bb7d6f4..5a651004932c4c296c821a7a6b51fa9f3e45d493 100644 --- a/library/Display/Display.h +++ b/library/Display/Display.h @@ -35,10 +35,10 @@ 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. */ + SDL_Texture* e_rotate; /*!< Texture liée à l'image de l'élément de rotation. */ SDL_Texture* finishLine; /*!< Texture liée à l'image de la ligne d'arrivée. */ TTF_Font *font; // Font SDL_Color color; // Color - SDL_Point center; /*!< Point central de la fenetre. */ long double angle; /*!< Angle de rotation de l'image. */ }; @@ -52,6 +52,14 @@ typedef struct ressources_s ressources_t; */ void init_ressource(SDL_Renderer *renderer, ressources_t *textures); +/** + * \brief La fonction initialise les textures des elements du jeu + * + * \param renderer + * \param textures + */ +void init_ressource_element(SDL_Renderer *renderer, ressources_t *textures); + /** * \brief La fonction applique la texture du fond sur le renderer lié à l'écran de jeu * \param renderer le renderer @@ -86,7 +94,7 @@ void apply_wall(SDL_Renderer * renderer, SDL_Texture *texture, int x, int y, wor * \param world * \param res */ -void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world); +void apply_walls(SDL_Renderer * renderer, SDL_Texture *texture, world_t *world, ressources_t *res); /** * \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 cbeb5ddd3ea0298fb3c7e8596062e609a20dc529..854c7794d2432bc604814da3d85ca44cb80e5a48 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 d8e0fd254cad4fc891329be08d5932ed1edb1160..ffdda1429f76936fee3fbd83332bf3faf04a06db 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 cd156c51c3416d3e4e3c3eeb4b848dc1a9279b02..078224c58d9c87126b0203b1e4f38e5c0ddad0ab 100644 --- a/library/World/world.c +++ b/library/World/world.c @@ -17,7 +17,7 @@ void update_data(world_t *world){ allEvents(world); - world->timer = SDL_GetTicks(); + world->timer = SDL_GetTicks(); } @@ -71,7 +71,7 @@ void collide(sprite_t *sp1, sprite_t *sp2, world_t *world, int make_disappear){ } void flipScreen(world_t *world){ - if (world->timer - world->startTimer > 10){ + if (world->timer - world->startTimer > 1){ if (world->isFlipping == 1){ world->angle += M_PI/20; if (world->angle > M_PI){ @@ -98,11 +98,11 @@ void init_walls(world_t *world){ for (int i = 0; i < world->nb_lines_murs; i++) { for (int j = 0; j < MAX_LENGTH; j++) { if (txt[i][j] != '0'){ - world->murs[world->nb_murs] = init_sprite(world->murs[world->nb_murs], j*METEORITE_SIZE, (i*METEORITE_SIZE)-(METEORITE_SIZE*world->nb_lines_murs), METEORITE_SIZE, METEORITE_SIZE, txt[i][j]); + world->murs[world->nb_murs] = init_sprite(world->murs[world->nb_murs], j*METEORITE_SIZE+2, (i*METEORITE_SIZE)-(METEORITE_SIZE*world->nb_lines_murs), METEORITE_SIZE, METEORITE_SIZE, txt[i][j]); world->nb_murs++; } } - } + } } void update_walls(world_t *world){ diff --git a/library/World/world.o b/library/World/world.o index df966a89887b259d602a9222d52e62f6360f4d9a..9ebfc49ffead55bf0dc3b69241610fb0695f02b0 100644 Binary files a/library/World/world.o and b/library/World/world.o differ diff --git a/main.c b/main.c index 4be00d67ed2760da1fe0609648380ff04cc1f657..8f120972d55e4f24282bf1c6906be5a8a5e374ed 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,7 @@ #include "library/Display/Display.h" #include "library/World/world.h" #include "library/utility/utility.h" +#include "constante.c" /** @@ -21,7 +22,15 @@ */ void handle_events(SDL_Event *event,world_t *world){ - Uint8 *keystates; + const Uint8 *keystates = SDL_GetKeyboardState(NULL); + + if (keystates[SDL_SCANCODE_A]){ + world->vaisseau->x -= MOVING_STEP; + } + if(keystates[SDL_SCANCODE_D]){ + world->vaisseau->x += MOVING_STEP; + } + while( SDL_PollEvent( event ) ) { //Si l'utilisateur a cliqué sur le X de la fenêtre @@ -33,29 +42,21 @@ void handle_events(SDL_Event *event,world_t *world){ //si une touche est appuyée if(event->type == SDL_KEYDOWN){ //si la touche appuyée est 'D' - - switch (event->key.keysym.sym) - { - case SDLK_d: - - world->vaisseau->x += MOVING_STEP; - break; - case SDLK_q: - world->vaisseau->x -= MOVING_STEP; - break; - case SDLK_z: - world->speed_h = 4; - - printf("%f\n", world->speed_h); - break; - case SDLK_s: - world->speed_h = INITIAL_SPEED; - break; - case SDLK_ESCAPE: - world->gameover = 1; - break; - default: - break; + + switch (event->key.keysym.sym){ + case SDLK_z: + world->speed_h = 4; + + printf("%f\n", world->speed_h); + break; + case SDLK_s: + world->speed_h = INITIAL_SPEED; + break; + case SDLK_ESCAPE: + world->gameover = 1; + break; + default: + break; } // print_sprite(world->vaisseau); } @@ -99,11 +100,13 @@ int main( int argc, char* args[] ) SDL_Renderer *renderer; SDL_Window *window; + 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 handle_events(&event,&world); @@ -113,8 +116,11 @@ int main( int argc, char* args[] ) //rafraichissement de l'écran refresh_graphics(renderer,&world,&textures); - // pause de 10 ms pour controler la vitesse de rafraichissement - pause(10); + if (frameTime < 16) { + SDL_Delay(16 - frameTime); // 16 ms = 60 fps + } + + ticks = SDL_GetTicks(); } //nettoyage final diff --git a/main.o b/main.o index 59f2c5613bb826a9e7a166ab5896bf0d0d1f223b..d1c17724200b1476c11f0182cd3982547306fbb3 100644 Binary files a/main.o and b/main.o differ diff --git a/maps/default.txt b/maps/default.txt index fdbbf21886dfeaf2f9949d7ce2f3aa59d38c7405..75f4839a3c89fc28a71fd50e17b8428fe1d5d5e6 100644 --- a/maps/default.txt +++ b/maps/default.txt @@ -1,47 +1,159 @@ -010000000011110000000000 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -000000000000000000000000 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001021111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001001111100011100000110 -001201111100011100000110 -001001111100011100000110 \ No newline at end of file +0100000000111100000000001 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0000000000000000000000001 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111020111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010211111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111111111101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0012011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +2012011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111000111000001101 +0010011111020111000001101 +0010011111000111000001101 +0010011111000111000001101 diff --git a/ressources/Elements/Ship_1.png b/ressources/Elements/Ship_1.png new file mode 100644 index 0000000000000000000000000000000000000000..d82bb188f4240f2b4d741fd5ddb4cf300d5e7e13 Binary files /dev/null and b/ressources/Elements/Ship_1.png differ diff --git a/ressources/Elements/Ship_2.png b/ressources/Elements/Ship_2.png new file mode 100644 index 0000000000000000000000000000000000000000..2db91174336ba1b922ddf16debeb68cc83a530ec Binary files /dev/null and b/ressources/Elements/Ship_2.png differ diff --git a/ressources/Elements/Ship_3.png b/ressources/Elements/Ship_3.png new file mode 100644 index 0000000000000000000000000000000000000000..13b2b50c48d01fc2975289cc2b75ee0bc4dbe4c1 Binary files /dev/null and b/ressources/Elements/Ship_3.png differ diff --git a/ressources/Elements/Ship_4.png b/ressources/Elements/Ship_4.png new file mode 100644 index 0000000000000000000000000000000000000000..0ce40ee95907dec39bcb97d1e9144cf1b2fc27bd Binary files /dev/null and b/ressources/Elements/Ship_4.png differ diff --git a/ressources/Elements/Ship_5.png b/ressources/Elements/Ship_5.png new file mode 100644 index 0000000000000000000000000000000000000000..254630882c4370dc981dbb330519105f92f1b5c5 Binary files /dev/null and b/ressources/Elements/Ship_5.png differ diff --git a/ressources/Elements/background2.bmp b/ressources/Elements/background2.bmp new file mode 100644 index 0000000000000000000000000000000000000000..f94c8a91524888b9143ad1f7497ada315a76f478 Binary files /dev/null and b/ressources/Elements/background2.bmp differ diff --git a/ressources/Elements/reverse.bmp b/ressources/Elements/reverse.bmp new file mode 100644 index 0000000000000000000000000000000000000000..8a67dd2121e33df78a63543c1926ab92da54ec82 Binary files /dev/null and b/ressources/Elements/reverse.bmp differ diff --git a/spacecorridor.exe b/spacecorridor.exe index 8c5dded8800ff4842b25ea0081f834881d63cb7b..42963cd69cdc4b82be9d0238233ed74f5af8ab39 100644 Binary files a/spacecorridor.exe and b/spacecorridor.exe differ