/
main.c
122 lines (102 loc) · 3.27 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
main.c
------
Par Sarcadent Tp du site du Zéro
R�le : menu du jeu. Permet de choisir entre l'�diteur et le jeu lui-m�me.
*/
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "constantes.h"
#include "jeu.h"
#include "editeur.h"
#include "niveau.h"
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *menu = NULL, *manuel = NULL;
SDL_Rect positionMenu;
SDL_Event event;
int continuer = 1, afficherManuel = 0;
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetIcon(IMG_Load("caisse.jpg"), NULL); // L'ic�ne doit �tre charg�e avant SDL_SetVideoMode
ecran = SDL_SetVideoMode(408, 408, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
//ecran = SDL_SetVideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Naruto Sokoban", NULL);
menu = IMG_Load("menu.png");
manuel = IMG_Load("GFX/manuel.png");
positionMenu.x = 0;
positionMenu.y = 0;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE: // Veut arr�ter le jeu
if (afficherManuel != 1)
{
continuer = 0;
}
else
{
afficherManuel = 0;
}
break;
case SDLK_1: // Demande � jouer
if (afficherManuel != 1)
{
menuNiveau(ecran, 1);
}
else
{
afficherManuel = 0;
}
break;
case SDLK_2: // Demande l'�diteur de niveaux
if (afficherManuel != 1)
{
menuNiveau(ecran, 0);
}
else
{
afficherManuel = 0;
}
break;
case SDLK_3:
//afficher image avec les r�gles
if (afficherManuel == 0)
{
afficherManuel = 1;
}
else
{
afficherManuel = 0;
}
break;
}
break;
}
// Effacement de l'�cran
ecran = SDL_SetVideoMode(408, 408, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
if (afficherManuel == 1)
{
SDL_BlitSurface(manuel, NULL, ecran, &positionMenu);
}
else
{
SDL_BlitSurface(menu, NULL, ecran, &positionMenu);
}
SDL_Flip(ecran);
}
SDL_FreeSurface(menu);
SDL_FreeSurface(manuel);
SDL_Quit();
return EXIT_SUCCESS;
}