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

mise en place du menu (bouton play fonctionne) (actuellement en 0 0 de taille 100 100)

parent b0302904
No related branches found
No related tags found
No related merge requests found
......@@ -87,9 +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);
}else{
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);
apply_text(renderer, 100, 100, 100, 33, "Jouer", textures->font, textures->color);
apply_text(renderer, 100, 200, 100, 33, "Magasin", textures->font, textures->color);
apply_text(renderer, 100, 300, 100, 33, "Exit", textures->font, textures->color);
}
update_screen(renderer);
......
No preview for this file type
......@@ -19,10 +19,6 @@ void update_data(world_t *world){
allEvents(world);
world->timer = SDL_GetTicks();
}else{
if (collidePoint(world->play, world->mouseX, world->mouseY)){
world->isMenu = false;
}
}
}
......
No preview for this file type
......@@ -3,17 +3,17 @@
#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;
bool 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 true;
return false;
}
\ No newline at end of file
......@@ -5,17 +5,15 @@
#ifndef DEF_CONSTANTES
#define DEF_CONSTANTES
#define LARGEUR_FENETRE 704
#define HAUTEUR_FENETRE 704
#include <stdbool.h>
struct btn{
SDL_Rect rect;
}
};
typedef struct btn_t ;
typedef struct btn btn_t;
btn_t *init_btn(int x, int y, int w, int h);
int collidePoint(btn_t *btn, int x, int y);
bool collidePoint(btn_t *btn, int x, int y);
#endif
\ No newline at end of file
File added
......@@ -44,7 +44,7 @@ void handle_events(SDL_Event *event,world_t *world){
}
//si une touche est appuyée
if(event->type == SDL_KEYDOWN){
if(event->type == SDL_KEYDOWN){
//si la touche appuyée est 'D'
if (!world->isMenu){
switch (event->key.keysym.sym){
......@@ -63,8 +63,21 @@ void handle_events(SDL_Event *event,world_t *world){
break;
}
}
// print_sprite(world->vaisseau);
}
if (event->type == SDL_MOUSEBUTTONDOWN){
printf("aaa");
if (world->isMenu){
if (event->button.button == SDL_BUTTON_LEFT){
printf("mouse(%d, %d) world rect (%d %d %d %d)\n", world->mouseX, world->mouseY, world->play->rect.x,world->play->rect.y,world->play->rect.w,world->play->rect.h );
if (collidePoint(world->play, world->mouseX, world->mouseY)){
printf("tesy");
world->isMenu = false;
}
}
}
}
}
}
......
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