Skip to content
Snippets Groups Projects
Commit 3f5d903f authored by IKHRICHI Soumaya's avatar IKHRICHI Soumaya
Browse files

depot du projet fait avec Rawan

parent ff9b52c5
Branches
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ LIBS = -L /SDL2_ttf/.libs -L /SDL2_image/.libs ...@@ -4,7 +4,7 @@ LIBS = -L /SDL2_ttf/.libs -L /SDL2_image/.libs
LDFLAGS = `sdl2-config --cflags --libs` -lSDL2_ttf LDFLAGS = `sdl2-config --cflags --libs` -lSDL2_ttf
INCLUDES = -I ./SDL2_ttf -I ./SDL2_image INCLUDES = -I ./SDL2_ttf -I ./SDL2_image
EXEC = main 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) OBJ = $(SRC:.c=.o)
all: $(EXEC) all: $(EXEC)
... ...
......
# Maze_Game # 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
...@@ -61,19 +61,19 @@ void affichage_bricks(SDL_Renderer* ecran,walls_t* walls,char** map,int nbc,int ...@@ -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++) for (int j = 0; j< nbc; j++)
{ {
if(map[i][j]=='L'){ 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)); SDL_RenderCopy(ecran,walls->texture_brick,&(walls->DestR),&(walls->Src));
} }
else if(map[i][j]=='#'){ 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)); SDL_RenderCopy(ecran,walls->texture_brick,&(walls->DestR),&(walls->Src));
} }
else if (map[i][j]=='S'){ 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)); SDL_RenderCopy(ecran,walls->texture_brick,&(walls->DestR),&(walls->Src));
} }
else if (map[i][j]=='T'){ 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)); 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){ ...@@ -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){ void gameover(player_t* player,char** tab, int nbc,int nbl){
TTF_Font* font=TTF_OpenFont("ressources/angelina.TTF",14); for (int i = 0; i<nbl ; i++)
SDL_Color white={255,255,255,255}; {
SDL_Surface* surfaceText=TTF_RenderText_Solid(font,message,white); for (int j = 0; j<nbc; j++)
SDL_Texture* text=SDL_CreateTextureFromSurface(ecran,surfaceText); {
SDL_Rect textRect; if(tab[i][j]=='S'){
textRect.h=height; if(player->x==j&& player->y==i){
textRect.w=width; player->gameover=1;
textRect.x=x; }
textRect.y=y; }
TTF_CloseFont(font); }
SDL_RenderCopy(ecran,text,NULL,&textRect); }
SDL_FreeSurface(surfaceText); if (player->lives==0){
SDL_DestroyTexture(text); player->gameover=1;
}*/ }
}
void clean_walls(walls_t* walls){ void clean_walls(walls_t* walls){
SDL_DestroyTexture(walls->texture_joueur); SDL_DestroyTexture(walls->texture_joueur);
... ...
......
...@@ -25,6 +25,6 @@ void affichage_bricks(SDL_Renderer* ecran,walls_t* walls,char** map,int nbc,int ...@@ -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 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 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 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); void clean_walls(walls_t* walls);
#endif #endif
\ No newline at end of file
No preview for this file type
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
int main() int main()
{ {
trap_t trap1= {{"The capital of Yemen","Sanaa","Riyadh","Aden"}}; trap_t trap1= {{"The capital of Yemen:","Sanaa","Riyadh","Aden"}};
//trap_t trap2= {"light bulb inventor","tesla"}; trap_t trap2= {{"Light bulb inventor:","Edison","Tesla","Stern"}};
//trap_t trap3={"the origin of the frensh language","latin"}; trap_t trap3={{"Origin of the frensh language:","Frisian","Peninsula","Latin"}};
//trap_t trap4={"Who won the world cup in 2006","italy"}; trap_t* traps=init_trap(trap1,trap2,trap3);
int nbl = 0,nbc = 0,i=0; int nbl = 0,nbc = 0,i=0;
char** map =lire_map("ressources/maze_map.txt");//lire le fichier char** map =lire_map("ressources/maze_map.txt");//lire le fichier
taille_map("ressources/maze_map.txt",&nbl,&nbc); taille_map("ressources/maze_map.txt",&nbl,&nbc);
...@@ -21,24 +21,25 @@ int main() ...@@ -21,24 +21,25 @@ int main()
SDL_Event event; SDL_Event event;
// Boucle principale // Boucle principale
while(!player->gameover){ while(!player->gameover){
gameover(player,map,nbc,nbl);
if (map[player->y][player->x]=='T'){ if (map[player->y][player->x]=='T'){
showTrap(trap1,player,&event,0); showTrap(traps[i],player,&event,i);
map[player->y][player->x]='L'; map[player->y][player->x]='L';
i++;
} }
handle_events(&event,walls,player,map); handle_events(&event,walls,player,map);
gameover(player,map,nbc,nbl);
SDL_RenderClear(ecran); SDL_RenderClear(ecran);
affichage_bricks(ecran,walls,map,nbc,nbl); affichage_bricks(ecran,walls,map,nbc,nbl);
affichage_joueur(player,walls,ecran); affichage_joueur(player,walls,ecran);
SDL_RenderPresent(ecran); SDL_RenderPresent(ecran);
SDL_UpdateWindowSurface(fenetre); SDL_UpdateWindowSurface(fenetre);
} }
// Libérer de la mémoire // Libérer de la mémoire
SDL_DestroyRenderer(ecran); SDL_DestroyRenderer(ecran);
desallouer_tab_2D(map,nbl); desallouer_tab_2D(map,nbl);
free_player(player); free_player(player);
clean_walls(walls); clean_walls(walls);
clean_trap(traps);
// Quitter SDL // Quitter SDL
SDL_DestroyWindow(fenetre); SDL_DestroyWindow(fenetre);
SDL_Quit(); SDL_Quit();
... ...
......
...@@ -9,27 +9,10 @@ player_t* init_player(int posc,int posl){ ...@@ -9,27 +9,10 @@ player_t* init_player(int posc,int posl){
player->posl=posl; player->posl=posl;
player->lives=3; player->lives=3;
player->gameover=0; player->gameover=0;
player->lose=0;
return player; 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) 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'){ if (tab[player->y-1][player->x]=='L'|| tab[player->y-1][player->x]=='S' || tab[player->y-1][player->x]=='T'){
... ...
......
...@@ -14,6 +14,7 @@ typedef struct player_s ...@@ -14,6 +14,7 @@ typedef struct player_s
int posl; int posl;
int score; int score;
int lives; int lives;
int lose;
int gameover; int gameover;
}player_t; }player_t;
...@@ -24,7 +25,6 @@ bool handle_movement_left(char** tab,player_t*player); ...@@ -24,7 +25,6 @@ bool handle_movement_left(char** tab,player_t*player);
bool handle_movement_right(char** tab,player_t*player); bool handle_movement_right(char** tab,player_t*player);
bool handle_mouvement_trap(char** tab,player_t* player); bool handle_mouvement_trap(char** tab,player_t* player);
void movement(char** tab,player_t *player,char deplacement); 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); void free_player(player_t* player);
#endif #endif
\ No newline at end of file
########################################### ###########################################
#LTLLLLLLLLLLLLLLLLLLLLLLL#LLLLLLLLLLLLLLL# #LLLLLLLLLLT#LLLL###LLLLLLLLLLLLLLL#LLL#LL#
#L#########################L#########L###L# #L#########LLLL#LLLLL###########L##LL#LLLL#
#L#LLLLLLLLLLLLLLLLLLLLLLLLL#############L# #LLLLLLLLL#L##L##L###LLLLLLLLLL#L###LL#L#L#
#L#L#####################################L# #########L#L#LLL#LLLLL##LL#L##L##LLL#L#####
#L#L##################################L##L# #LLLLLLLLL#L#L#L#####LLL#LLL##L#L##L#LLLL##
#L####################################L##L# #L#########L#L#LLLLLLLLLLLLLLLL#L##L####LL#
#L####################################L##L# #LLLLLLLLL#L#LLT################L#LL#LLL#L#
#L####################################L##L# ###########L#L#L##LLLLLLLL####LLL#L#LL#LLL#
#L#################L######L##############L# #LLLLLLLLLLL###LLLL######LLLLLL#L#L######L#
#L#################L######L##############L# #####L########################L#L#LLLLLLLL#
#L##L##############L######L#########L####L# #LLLLL#LLLLLLLLLLLLLLLLLLLLLLLL###L#####L##
#L##L###############################L####L# #L#####L##########################LLLLL#LL#
#L##L#L######L######################LLL##L# #LLLLL#LLL###LLLLLL###LLLLLLLLLLLL####L##L#
#L###########L#####L##L#####LLL####LL####L# #L###L###L###L#L##L###L##########L#LLL#LLL#
#T###########L#####L##L###########LL#####L# #L#L#L#LLLLLLL#LL#LLLLL#LLLLLLLLLLLL#L#L#L#
#L#################L##L##LLLLLLLLLLLLLL##L# #L#L#L#L#############################L#L#L#
#L#################L##LLLL######L###T####L# #L#L#L#LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL##L#L#
#L#################L##L#LL######L###S####L# #L#LLL##############################L#LL#L#
#L#LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLTLLL#L# #L#####LLL###LLLLL#LLL#LLLLLLLLLLLLLL######
#L############L##########################L# #LLLLLLL#LLLLL###LLL#L#L############LTLLLS#
#LLLLLLLLLLLLLLLLLLL#LLLLLLLLLLLLLLLLLLLLL#
########################################### ###########################################
ressources/ok_button.bmp

9.43 KiB

...@@ -23,40 +23,48 @@ trap_t* init_trap(trap_t trap1,trap_t trap2,trap_t trap3){ ...@@ -23,40 +23,48 @@ 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){ void showTrap(trap_t trap,player_t* player,SDL_Event* event,int j){
int y=30; int y=30;
int px,py; int px,py;
//SDL_Surface* textSurfQ;
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
SDL_Window *fenetre=SDL_CreateWindow("Trap",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,400,400,SDL_WINDOW_OPENGL); 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); SDL_Renderer *renderer=SDL_CreateRenderer(fenetre,-1,0);
TTF_Init(); 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_Color color={255,255,255,255};
SDL_Rect position[4]; SDL_Rect position[4];
SDL_Texture* textTextureQ[4]; SDL_Texture* textTextureQ[4];
SDL_Texture* bg=charger_image("ressources/bg_trap.bmp",renderer);
for(int i=0;i<4;i++){ for(int i=0;i<4;i++){
textTextureQ[i]= createText(renderer,font,trap,color,&position[i],(i+1)*y,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); TTF_CloseFont(font);
bool end=false; player->lose=0;
while(!end){ while(!player->lose){
SDL_RenderCopy(renderer,bg,NULL,NULL);
while (SDL_PollEvent(event)) while (SDL_PollEvent(event))
{ {
if (event->type ==SDL_QUIT){ 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. 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->type== SDL_MOUSEBUTTONDOWN){
if (event->button.state==SDL_PRESSED){ 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)))){ 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->score += 50;
end=true; player->lose=1;
}else{ }else{
player->lives--; player->lives -=1;
}
}else{
player->lives -=1;
}
} }
} }
if (player->lives==0){
player->lose=1;
} }
} }
...@@ -70,6 +78,7 @@ void showTrap(trap_t trap,player_t* player,SDL_Event* event,int j){ ...@@ -70,6 +78,7 @@ void showTrap(trap_t trap,player_t* player,SDL_Event* event,int j){
SDL_DestroyTexture(textTextureQ[i]); SDL_DestroyTexture(textTextureQ[i]);
} }
// Quitter SDL // Quitter SDL
SDL_DestroyTexture(bg);
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(fenetre); SDL_DestroyWindow(fenetre);
TTF_Quit(); TTF_Quit();
... ...
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
#define TRAP_H #define TRAP_H
#include "graphics.h" #include "graphics.h"
#define TRAPHT 60
#define TRAPWT 120
typedef struct trap_s{ typedef struct trap_s{
const char* text[4]; const char* text[4];
}trap_t; }trap_t;
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment