Skip to content

Commit 4afc9ef

Browse files
committed
menu
1 parent 3a77009 commit 4afc9ef

8 files changed

+62
-32
lines changed

bin/prog.exe

953 Bytes
Binary file not shown.

format

Whitespace-only changes.

src/acceuil.bmp

1.3 MB
Binary file not shown.
Binary file not shown.

src/jouer.c

+37-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,46 @@
44
#include <stdbool.h>
55
#include "jouer.h"
66

7-
void jouer(SDL_Surface* s){
7+
void jouer(SDL_Surface *fond){
88
SDL_Event event;
9-
int continuer=1;
10-
int i=0, j=0;
11-
while(continuer==1){
12-
SDL_WaitEvent(&event);
13-
switch(event.type){
9+
printf("jouer");
10+
int continuer = 1;
11+
int i = 0, j = 0;
12+
13+
fond = SDL_LoadBMP("src/zeldamap.bmp");
14+
if (SDL_CreateWindowAndRenderer(WINDOW_WITDH, WINDOW_HEIGHT, 0, &window, &rendu) != 0)
15+
ExitWithError("impossible de creer la fenêtre et le rendu");
16+
texture = SDL_CreateTextureFromSurface(rendu, fond);
17+
SDL_FreeSurface(fond);
18+
if (SDL_QueryTexture(texture, NULL, NULL, &positionfond.w, &positionfond.h) != 0)
19+
ExitChargement("impossible charger le conteneur du fond", rendu, window);
20+
positionfond.x = (791 - positionfond.w) / 2;
21+
positionfond.x = (575 - positionfond.h) / 2;
22+
if (SDL_RenderCopy(rendu, texture, NULL, &positionfond) != 0)
23+
ExitChargement("impossible d'afficher la texture", rendu, window);
24+
SDL_RenderPresent(rendu);
25+
while (continuer != 0)
26+
{
27+
while (SDL_PollEvent(&event))
28+
{
29+
switch (event.type)
30+
{
31+
case SDL_KEYDOWN:
32+
switch (event.key.keysym.sym)
33+
{
34+
case SDLK_ESCAPE:
35+
continuer = 0;
36+
break;
37+
default:
38+
continue;
39+
}
40+
break;
1441
case SDL_QUIT:
15-
continuer=0;
42+
continuer = 0;
43+
break;
44+
default:
1645
break;
46+
}
1747
}
18-
SDL_FillRect(s,NULL,SDL_MapRGB(s->format,255,255,255));
19-
SDL_Flip(s);
2048
}
2149
}

src/jouer.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#ifndef JOUER_H_INCLUED
2-
#define JOUER_H_INCLUED
1+
#define WINDOW_WITDH 791
2+
#define WINDOW_HEIGHT 575
33

4-
void jouer(SDL_Surface* s);
4+
SDL_Texture *texture;
5+
SDL_Renderer *rendu;
6+
SDL_Window *window;
7+
SDL_Rect positionfond;
58

6-
7-
#endif
9+
void jouer(SDL_Surface *fond);

src/main.c

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* gcc src/main.c -o bin/prog -I include -L lib -lmingw32 -lSDL2main -lSDL2
1+
/* gcc src/*.c -o bin/prog -I include -L lib -lmingw32 -lSDL2main -lSDL2
22
bin\prog.exe
33
*/
44

@@ -7,42 +7,42 @@
77
#include <SDL.h>
88
#include <stdbool.h>
99
#include "main.h"
10+
#include "jouer.h"
11+
1012

1113
int main(int argc, char **argv){
1214

1315
if(SDL_Init(SDL_INIT_EVERYTHING)!=0)
1416
ExitWithError("impossible d'initialiser");
1517

16-
//Création fenêtre + rendu
1718
if (SDL_CreateWindowAndRenderer(WINDOW_WITDH, WINDOW_HEIGHT, 0, &window, &renderer) != 0)
1819
ExitWithError("impossible de creer la fenêtre et le rendu");
1920

2021
unsigned int fram_limit = 0;
2122
fram_limit = SDL_GetTicks() + 16; //delai pr limiter à 60fps
2223
limit_fps(fram_limit);
23-
24+
2425
/*---------------------------------------------*/
2526

26-
fond = SDL_LoadBMP("src/zeldamap.bmp");
27-
if (fond == NULL)
27+
menu = SDL_LoadBMP("src/acceuil.bmp");
28+
if (menu == NULL)
2829
ExitChargement("impossiblde de charger le fond", renderer, window);
2930

30-
texture = SDL_CreateTextureFromSurface(renderer, fond);
31-
SDL_FreeSurface(fond);
31+
texture = SDL_CreateTextureFromSurface(renderer, menu);
32+
SDL_FreeSurface(menu);
3233
if (texture == NULL)
3334
ExitChargement("impossible de créer la texture", renderer, window);
3435

35-
if (SDL_QueryTexture(texture, NULL, NULL, &conteneurfond.w, &conteneurfond.h) != 0)
36+
if (SDL_QueryTexture(texture, NULL, NULL, &positionMenu.w, &positionMenu.h) != 0)
3637
ExitChargement("impossible charger le conteneur du fond", renderer, window);
3738

38-
conteneurfond.x = (WINDOW_WITDH - conteneurfond.w) / 2;
39-
conteneurfond.x = (WINDOW_HEIGHT - conteneurfond.h) / 2;
40-
if (SDL_RenderCopy(renderer, texture, NULL, &conteneurfond) != 0)
39+
positionMenu.x = (WINDOW_WITDH - positionMenu.w) / 2;
40+
positionMenu.x = (WINDOW_HEIGHT - positionMenu.h) / 2;
41+
if (SDL_RenderCopy(renderer, texture, NULL, &positionMenu) != 0)
4142
ExitChargement("impossible d'afficher la texture", renderer, window);
4243

4344
SDL_RenderPresent(renderer);
4445
/*----------------------------------------------*/
45-
4646

4747
/*----------------------------------------------*/
4848

@@ -60,9 +60,9 @@ int main(int argc, char **argv){
6060
case SDLK_ESCAPE:
6161
continuer=0;
6262
break;
63-
case SDLK_z:
63+
case SDLK_1:
6464
continuer=1;
65-
//jouer(fond);
65+
jouer(fond);
6666
break;
6767
default:
6868
continue;
@@ -76,6 +76,7 @@ int main(int argc, char **argv){
7676
}
7777
}
7878
}
79+
7980
/*---------------------------------------------*/
8081
SDL_DestroyRenderer(renderer);
8182
SDL_DestroyWindow(window);

src/main.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11

2-
32
#define WINDOW_WITDH 791
43
#define WINDOW_HEIGHT 575
54

65
SDL_Window *window = NULL;
76
SDL_Renderer *renderer = NULL;
8-
97
SDL_Surface *fond = NULL;
8+
SDL_Surface *menu = NULL;
109
SDL_Texture *texture = NULL;
11-
SDL_Rect conteneurfond;
10+
SDL_Rect positionMenu;
1211

1312
void ExitWithError(const char *message)
1413
{
@@ -33,4 +32,4 @@ void limit_fps(unsigned int limit)
3332
SDL_Delay(16);
3433
else
3534
SDL_Delay(limit - ticks);
36-
}
35+
}

0 commit comments

Comments
 (0)