diff --git a/Makefile b/Makefile index 29ec9b185226cd0ad695ce866f9eab65e05a9f34..ee70b3a621913a7ac3b741d4609542a7fd7351ae 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ LIBS = -L /SDL2_ttf/.libs -L /SDL2_image/.libs LDFLAGS = `sdl2-config --cflags --libs` -lSDL2_ttf INCLUDES = -I ./SDL2_ttf -I ./SDL2_image EXEC = main -SRC = main.c player.c map.c graphics.c trap.c sdl2-ttf-light.c +SRC = main.c player.c map.c graphics.c trap.c OBJ = $(SRC:.c=.o) all: $(EXEC) diff --git a/README.md b/README.md index 42dd527b99544f4ba1a1cdab423dd682ef6744d6..70b81109ba1ebd94fbc811e25c289799758ed7a1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # Maze_Game +La compilation du jeu se fait dans le treminal avec la commande : make +L'execution: ./main + +C'est un jeu labyrinthe avec des traps sous forme de QCM. Pour choisir la répose il suffit de cliquer avec la souris. +Les mouvements du joueur se fait avec les flèches du clavier.Le joueur a trois chance et à chaque fausse réponse du trap ses chances diminues + diff --git a/graphics.c b/graphics.c index cdf0f39df829f0a4619c8f16245ee1e9d11e366f..5a699e74abc154c689f1e2363208f23f345f5d9d 100644 --- a/graphics.c +++ b/graphics.c @@ -61,19 +61,19 @@ void affichage_bricks(SDL_Renderer* ecran,walls_t* walls,char** map,int nbc,int for (int j = 0; j< nbc; j++) { if(map[i][j]=='L'){ - init_wall(walls,j,i,9,3); + init_wall(walls,j,i,11,0); SDL_RenderCopy(ecran,walls->texture_brick,&(walls->DestR),&(walls->Src)); } else if(map[i][j]=='#'){ - init_wall(walls,j,i,10,3); + init_wall(walls,j,i,6,9); SDL_RenderCopy(ecran,walls->texture_brick,&(walls->DestR),&(walls->Src)); } else if (map[i][j]=='S'){ - init_wall(walls,j,i,13,3); + init_wall(walls,j,i,5,2); SDL_RenderCopy(ecran,walls->texture_brick,&(walls->DestR),&(walls->Src)); } else if (map[i][j]=='T'){ - init_wall(walls,j,i,13,4); + init_wall(walls,j,i,0,7); SDL_RenderCopy(ecran,walls->texture_brick,&(walls->DestR),&(walls->Src)); } } @@ -133,22 +133,24 @@ void handle_events(SDL_Event *event,walls_t* walls,player_t* player,char** map){ } } -/* -void apply_text(SDL_Renderer* ecran,int x,int y,int width,int height,const char* message){ - TTF_Font* font=TTF_OpenFont("ressources/angelina.TTF",14); - SDL_Color white={255,255,255,255}; - SDL_Surface* surfaceText=TTF_RenderText_Solid(font,message,white); - SDL_Texture* text=SDL_CreateTextureFromSurface(ecran,surfaceText); - SDL_Rect textRect; - textRect.h=height; - textRect.w=width; - textRect.x=x; - textRect.y=y; - TTF_CloseFont(font); - SDL_RenderCopy(ecran,text,NULL,&textRect); - SDL_FreeSurface(surfaceText); - SDL_DestroyTexture(text); -}*/ + +void gameover(player_t* player,char** tab, int nbc,int nbl){ + for (int i = 0; i<nbl ; i++) + { + for (int j = 0; j<nbc; j++) + { + if(tab[i][j]=='S'){ + if(player->x==j&& player->y==i){ + player->gameover=1; + } + } + } + } + if (player->lives==0){ + player->gameover=1; + } +} + void clean_walls(walls_t* walls){ SDL_DestroyTexture(walls->texture_joueur); diff --git a/graphics.h b/graphics.h index bf28212ce65e4e78c59b4ce8191709e0c697d189..3e39e63786ed131f5d11e95c2a68de7a795a50b8 100644 --- a/graphics.h +++ b/graphics.h @@ -25,6 +25,6 @@ void affichage_bricks(SDL_Renderer* ecran,walls_t* walls,char** map,int nbc,int void affichage_joueur(player_t* player,walls_t* walls,SDL_Renderer* ecran); void change_movement_player(player_t* player,walls_t* walls,int posc,int posl); void handle_events(SDL_Event *event,walls_t* walls,player_t* player,char** map); -//void apply_text(SDL_Renderer* ecran,int x,int y,int width,int height,const char* message); +void gameover(player_t* player,char** tab, int nbc,int nbl); void clean_walls(walls_t* walls); #endif \ No newline at end of file diff --git a/main b/main index 685436504e224007a3fb86201a25c1d7f67eb16f..b0ae605909517d23507a06e85fd5aaa77b9a257e 100644 Binary files a/main and b/main differ diff --git a/main.c b/main.c index bc46e38ed0052b2115ecf3d56f8fadb3a1e29efa..36a9b08fd59d1a79feea655e37e9f80e0751474d 100644 --- a/main.c +++ b/main.c @@ -3,10 +3,10 @@ int main() { - trap_t trap1= {{"The capital of Yemen","Sanaa","Riyadh","Aden"}}; - //trap_t trap2= {"light bulb inventor","tesla"}; - //trap_t trap3={"the origin of the frensh language","latin"}; - //trap_t trap4={"Who won the world cup in 2006","italy"}; + trap_t trap1= {{"The capital of Yemen:","Sanaa","Riyadh","Aden"}}; + trap_t trap2= {{"Light bulb inventor:","Edison","Tesla","Stern"}}; + trap_t trap3={{"Origin of the frensh language:","Frisian","Peninsula","Latin"}}; + trap_t* traps=init_trap(trap1,trap2,trap3); int nbl = 0,nbc = 0,i=0; char** map =lire_map("ressources/maze_map.txt");//lire le fichier taille_map("ressources/maze_map.txt",&nbl,&nbc); @@ -21,24 +21,25 @@ int main() SDL_Event event; // Boucle principale while(!player->gameover){ + gameover(player,map,nbc,nbl); if (map[player->y][player->x]=='T'){ - showTrap(trap1,player,&event,0); + showTrap(traps[i],player,&event,i); map[player->y][player->x]='L'; + i++; } handle_events(&event,walls,player,map); - gameover(player,map,nbc,nbl); SDL_RenderClear(ecran); affichage_bricks(ecran,walls,map,nbc,nbl); affichage_joueur(player,walls,ecran); SDL_RenderPresent(ecran); SDL_UpdateWindowSurface(fenetre); } - // Libérer de la mémoire SDL_DestroyRenderer(ecran); desallouer_tab_2D(map,nbl); free_player(player); clean_walls(walls); + clean_trap(traps); // Quitter SDL SDL_DestroyWindow(fenetre); SDL_Quit(); diff --git a/player.c b/player.c index ce3d32adfee096d8390c6c36e1e2fc569632e779..92df2dd3639f3166ff5efed4c2510cdde8594c40 100644 --- a/player.c +++ b/player.c @@ -9,27 +9,10 @@ player_t* init_player(int posc,int posl){ player->posl=posl; player->lives=3; player->gameover=0; + player->lose=0; return player; } - -void gameover(player_t* player,char** tab, int nbc,int nbl){ - for (int i = 0; i<nbl ; i++) - { - for (int j = 0; j<nbc; j++) - { - if(tab[i][j]=='S'){ - if(player->x==j&& player->y==i){ - player->gameover=1; - } - } - } - } - if (player->lives==0){ - player->gameover=1; - } -} - bool handle_movement_up(char** tab,player_t*player) { if (tab[player->y-1][player->x]=='L'|| tab[player->y-1][player->x]=='S' || tab[player->y-1][player->x]=='T'){ diff --git a/player.h b/player.h index c3ed96d26ab087d73be9d34d106c8da5358dc2f9..8c624ba8b59483f178040ae6629cf6a036bf6538 100644 --- a/player.h +++ b/player.h @@ -14,6 +14,7 @@ typedef struct player_s int posl; int score; int lives; + int lose; int gameover; }player_t; @@ -24,7 +25,6 @@ bool handle_movement_left(char** tab,player_t*player); bool handle_movement_right(char** tab,player_t*player); bool handle_mouvement_trap(char** tab,player_t* player); void movement(char** tab,player_t *player,char deplacement); -void gameover(player_t* player,char** tab, int nbc,int nbl); void free_player(player_t* player); #endif \ No newline at end of file diff --git a/ressources/maze_map.txt b/ressources/maze_map.txt index 6494410fea68ee9ae9fb6263630daaa59c28a8ad..2018788b89d022b0bcc7973adfbea14c73c3b186 100644 --- a/ressources/maze_map.txt +++ b/ressources/maze_map.txt @@ -1,24 +1,23 @@ ########################################### -#LTLLLLLLLLLLLLLLLLLLLLLLL#LLLLLLLLLLLLLLL# -#L#########################L#########L###L# -#L#LLLLLLLLLLLLLLLLLLLLLLLLL#############L# -#L#L#####################################L# -#L#L##################################L##L# -#L####################################L##L# -#L####################################L##L# -#L####################################L##L# -#L#################L######L##############L# -#L#################L######L##############L# -#L##L##############L######L#########L####L# -#L##L###############################L####L# -#L##L#L######L######################LLL##L# -#L###########L#####L##L#####LLL####LL####L# -#T###########L#####L##L###########LL#####L# -#L#################L##L##LLLLLLLLLLLLLL##L# -#L#################L##LLLL######L###T####L# -#L#################L##L#LL######L###S####L# -#L#LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLTLLL#L# -#L############L##########################L# -#LLLLLLLLLLLLLLLLLLL#LLLLLLLLLLLLLLLLLLLLL# +#LLLLLLLLLLT#LLLL###LLLLLLLLLLLLLLL#LLL#LL# +#L#########LLLL#LLLLL###########L##LL#LLLL# +#LLLLLLLLL#L##L##L###LLLLLLLLLL#L###LL#L#L# +#########L#L#LLL#LLLLL##LL#L##L##LLL#L##### +#LLLLLLLLL#L#L#L#####LLL#LLL##L#L##L#LLLL## +#L#########L#L#LLLLLLLLLLLLLLLL#L##L####LL# +#LLLLLLLLL#L#LLT################L#LL#LLL#L# +###########L#L#L##LLLLLLLL####LLL#L#LL#LLL# +#LLLLLLLLLLL###LLLL######LLLLLL#L#L######L# +#####L########################L#L#LLLLLLLL# +#LLLLL#LLLLLLLLLLLLLLLLLLLLLLLL###L#####L## +#L#####L##########################LLLLL#LL# +#LLLLL#LLL###LLLLLL###LLLLLLLLLLLL####L##L# +#L###L###L###L#L##L###L##########L#LLL#LLL# +#L#L#L#LLLLLLL#LL#LLLLL#LLLLLLLLLLLL#L#L#L# +#L#L#L#L#############################L#L#L# +#L#L#L#LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL##L#L# +#L#LLL##############################L#LL#L# +#L#####LLL###LLLLL#LLL#LLLLLLLLLLLLLL###### +#LLLLLLL#LLLLL###LLL#L#L############LTLLLS# ########################################### diff --git a/ressources/ok_button.bmp b/ressources/ok_button.bmp deleted file mode 100644 index 67369bfe83f2fd40e2a1be105ca8e1535b8fe63d..0000000000000000000000000000000000000000 Binary files a/ressources/ok_button.bmp and /dev/null differ diff --git a/trap.c b/trap.c index 51e8bed39494e688113fa51a70951dd8e187804a..e719221014e0d790a0d3bed576548f827ede6341 100644 --- a/trap.c +++ b/trap.c @@ -23,41 +23,49 @@ trap_t* init_trap(trap_t trap1,trap_t trap2,trap_t trap3){ void showTrap(trap_t trap,player_t* player,SDL_Event* event,int j){ int y=30; int px,py; - //SDL_Surface* textSurfQ; SDL_Init(SDL_INIT_VIDEO); SDL_Window *fenetre=SDL_CreateWindow("Trap",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,400,400,SDL_WINDOW_OPENGL); SDL_Renderer *renderer=SDL_CreateRenderer(fenetre,-1,0); TTF_Init(); - TTF_Font* font= TTF_OpenFont("ressources/arial.ttf",24); + TTF_Font* font= TTF_OpenFont("ressources/arial.ttf",20); SDL_Color color={255,255,255,255}; SDL_Rect position[4]; SDL_Texture* textTextureQ[4]; + SDL_Texture* bg=charger_image("ressources/bg_trap.bmp",renderer); for(int i=0;i<4;i++){ textTextureQ[i]= createText(renderer,font,trap,color,&position[i],(i+1)*y,i); } - px=position[j+1].x; - py=position[j+1].y; - TTF_CloseFont(font); - bool end=false; - while(!end){ + TTF_CloseFont(font); + player->lose=0; + while(!player->lose){ + SDL_RenderCopy(renderer,bg,NULL,NULL); while (SDL_PollEvent(event)) { if (event->type ==SDL_QUIT){ - end=true; + player->lose=1; } if (event->key.keysym.sym==SDLK_ESCAPE){ //si on appui sur la touche Echap, on quitte le jeu. - end=true; + player->lose=1; } if (event->type== SDL_MOUSEBUTTONDOWN){ if (event->button.state==SDL_PRESSED){ - if(((event->button.x>=px) && (event->button.x<=( px +position[j+1].w)))&&((event->button.y>=py)&&(event->button.y<=(py+position[j+1].h)))){ - player->score += 50; - end=true; + px=position[j+1].x; + py=position[j+1].y; + if((event->button.x>=px) && (event->button.x<=( px +position[j+1].w))){ + if((event->button.y>=py)&&(event->button.y<=(py+position[j+1].h))){ + player->score += 50; + player->lose=1; + }else{ + player->lives -=1; + } }else{ - player->lives--; + player->lives -=1; } } } + if (player->lives==0){ + player->lose=1; + } } for(int i=0;i<4;i++){ @@ -70,6 +78,7 @@ void showTrap(trap_t trap,player_t* player,SDL_Event* event,int j){ SDL_DestroyTexture(textTextureQ[i]); } // Quitter SDL + SDL_DestroyTexture(bg); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(fenetre); TTF_Quit(); diff --git a/trap.h b/trap.h index bb8a10c5743db605191bc6428a1a1cd25f9a1236..8f4c03bdff743fb698bc30b20202dc44adcd70db 100644 --- a/trap.h +++ b/trap.h @@ -2,9 +2,6 @@ #define TRAP_H #include "graphics.h" -#define TRAPHT 60 -#define TRAPWT 120 - typedef struct trap_s{ const char* text[4]; }trap_t;