Skip to content
Snippets Groups Projects
Commit b0302904 authored by Samibenzid's avatar Samibenzid
Browse files

Ajout du menu

parent 7c545ff5
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,8 @@ LDFLAGS = -lm -lmingw32 -lSDL2main -lSDL2 -lSDL2_ttf ...@@ -3,8 +3,8 @@ LDFLAGS = -lm -lmingw32 -lSDL2main -lSDL2 -lSDL2_ttf
SDL2_INCLUDE_DIR = src/include SDL2_INCLUDE_DIR = src/include
SDL2_LIBRARIES_DIR = src/lib SDL2_LIBRARIES_DIR = src/lib
INC = sdl2-light.h sdl2-ttf-light.h library/Display/Display.h library/World/world.h library/Sprites/sprites.h library/utility/utility.h INC = sdl2-light.h sdl2-ttf-light.h library/Display/Display.h library/World/world.h library/Sprites/sprites.h library/utility/utility.h library/menu/menu.h
SRC = main.c sdl2-light.c sdl2-ttf-light.c library/Display/Display.c library/World/world.c library/Sprites/sprites.c library/utility/utility.c SRC = main.c sdl2-light.c sdl2-ttf-light.c library/Display/Display.c library/World/world.c library/Sprites/sprites.c library/utility/utility.c library/menu/menu.c
OBJ = $(SRC:%.c=%.o) OBJ = $(SRC:%.c=%.o)
......
...@@ -87,6 +87,9 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textu ...@@ -87,6 +87,9 @@ void refresh_graphics(SDL_Renderer *renderer, world_t *world,ressources_t *textu
apply_text(renderer, 10, 10, 100, 33, world->str, textures->font, textures->color); apply_text(renderer, 10, 10, 100, 33, world->str, textures->font, textures->color);
}else{ }else{
apply_text(renderer, 10, 10, 100, 33, "Menu", textures->font, textures->color); apply_text(renderer, 10, 10, 100, 33, "Menu", textures->font, textures->color);
apply_text(renderer, 10, 10, 100, 33, "Jouer", textures->font, textures->color);
apply_text(renderer, 10, 10, 100, 33, "Magasin", textures->font, textures->color);
apply_text(renderer, 10, 10, 100, 33, "Exit", textures->font, textures->color);
} }
update_screen(renderer); update_screen(renderer);
......
...@@ -19,6 +19,10 @@ void update_data(world_t *world){ ...@@ -19,6 +19,10 @@ void update_data(world_t *world){
allEvents(world); allEvents(world);
world->timer = SDL_GetTicks(); world->timer = SDL_GetTicks();
}else{
if (collidePoint(world->play, world->mouseX, world->mouseY)){
world->isMenu = false;
}
} }
} }
...@@ -37,6 +41,8 @@ void init_data(world_t * world){ ...@@ -37,6 +41,8 @@ void init_data(world_t * world){
init_walls(world); init_walls(world);
world->ligneArriver = init_sprite(world->ligneArriver, 0, -world->nb_lines_murs*METEORITE_SIZE-30 , SCREEN_WIDTH, FINISH_LINE_HEIGHT, 'z'); world->ligneArriver = init_sprite(world->ligneArriver, 0, -world->nb_lines_murs*METEORITE_SIZE-30 , SCREEN_WIDTH, FINISH_LINE_HEIGHT, 'z');
world->play = init_btn(0, 0, 100, 100);
print_sprite(world->vaisseau); print_sprite(world->vaisseau);
world->startTimer = SDL_GetTicks(); world->startTimer = SDL_GetTicks();
world->timer = SDL_GetTicks(); world->timer = SDL_GetTicks();
...@@ -44,6 +50,9 @@ void init_data(world_t * world){ ...@@ -44,6 +50,9 @@ void init_data(world_t * world){
world->angle = 0.0; world->angle = 0.0;
world->isFlipping = 0; world->isFlipping = 0;
world->isMenu = true; world->isMenu = true;
world->mouseX = 0;
world->mouseY = 0;
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "../../constante.c" #include "../../constante.c"
#include "../../src/include/SDL2/SDL.h" #include "../../src/include/SDL2/SDL.h"
#include <stdbool.h> #include <stdbool.h>
#include "../menu/menu.h"
/** /**
* \file world.h * \file world.h
...@@ -37,6 +38,9 @@ struct world_s{ ...@@ -37,6 +38,9 @@ struct world_s{
sprite_t *vaisseau ; /*!< Représentation du vaisseau */ sprite_t *vaisseau ; /*!< Représentation du vaisseau */
sprite_t **murs; /*<Représentation des météorites>*/ sprite_t **murs; /*<Représentation des météorites>*/
sprite_t **murs2; /*<Représentation des météorites et de l'air>*/ sprite_t **murs2; /*<Représentation des météorites et de l'air>*/
btn_t *play;
int nb_murs; // Nombre de météorites int nb_murs; // Nombre de météorites
int nb_lines_murs; // Nombre de lignes de météorites int nb_lines_murs; // Nombre de lignes de météorites
sprite_t *ligneArriver; sprite_t *ligneArriver;
...@@ -48,6 +52,9 @@ struct world_s{ ...@@ -48,6 +52,9 @@ struct world_s{
double angle; // Angle de rotation de la map 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) 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)
bool isMenu; bool isMenu;
int mouseX;
int mouseY;
}; };
typedef struct world_s world_t; typedef struct world_s world_t;
......
#include "menu.h"
#include <stdio.h>
#include <stdlib.h>
btn_t *init_btn(int x, int y, int w, int h){
btn_t *btn = malloc(sizeof(btn_t));
btn->rect.x = x;
btn->rect.y = y;
btn->rect.w = w;
btn->rect.h = h;
return btn;
}
int collidePoint(btn_t *btn, int x, int y){
if (btn->rect.x > x && btn->rect.x + btn->rect.w < x && btn->rect.y > y && btn->rect.y + btn->rect.h < y;) return 1;
return 0;
}
\ No newline at end of file
...@@ -2,7 +2,20 @@ ...@@ -2,7 +2,20 @@
#include <stdlib.h> #include <stdlib.h>
#include "../../src/include/SDL2/SDL.h" #include "../../src/include/SDL2/SDL.h"
#ifndef DEF_CONSTANTES
#define DEF_CONSTANTES
#define LARGEUR_FENETRE 704
#define HAUTEUR_FENETRE 704
struct btn{ struct btn{
SDL_Rect rect; SDL_Rect rect;
SDL_Texture *texture; }
}
\ No newline at end of file typedef struct btn_t ;
btn_t *init_btn(int x, int y, int w, int h);
int collidePoint(btn_t *btn, int x, int y);
#endif
\ No newline at end of file
...@@ -32,6 +32,8 @@ void handle_events(SDL_Event *event,world_t *world){ ...@@ -32,6 +32,8 @@ void handle_events(SDL_Event *event,world_t *world){
world->vaisseau->x += MOVING_STEP; world->vaisseau->x += MOVING_STEP;
} }
} }
SDL_GetMouseState(&world->mouseX, &world->mouseY);
while( SDL_PollEvent( event ) ) { while( SDL_PollEvent( event ) ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment