This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
141 lines (116 loc) · 3.62 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
main.c
programme principal
charge le menu, et lance le jeu
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include "player.h"
#include "obstacles.h"
#include "constantes.h"
#include "jeu.h"
#include "stats.h"
#include "menu.h"
int main(int argc, char *argv[])
{
// Initialisation de la SDL
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
fprintf(stderr, "Erreur d'initialisation de la SDL");
exit(EXIT_FAILURE);
}
// Initialisation de TTF
if (TTF_Init() == -1)
{
fprintf(stderr, "Erreur d'initialisation de TTF");
exit(EXIT_FAILURE);
}
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
// Creation des surfaces
SDL_Surface *screen = NULL, *menu = NULL, *text = NULL, *ver = NULL;
// Police
TTF_Font *font = NULL, *font2 = NULL;
font = TTF_OpenFont(FONT_ECRAN_TITRE, 30);
font2 = TTF_OpenFont(FONT_ECRAN_TITRE, 10);
// Couleur
SDL_Color couleur = {255, 255, 255, 0};
// Position du texte
SDL_Rect posText = newRect(300, 500, 0, 0);
SDL_Rect posVer = newRect(1140, 700, 0, 0);
// Textes
text = TTF_RenderText_Blended(font, "Appuyez sur la touche RETURN", couleur);
ver = TTF_RenderText_Solid(font2, VERSION, couleur);
//
int temps = 0, tempsIni = 0, aff = 0;
// Creation du rect et surface du menu
SDL_Rect posMenu;
posMenu.x = 0; posMenu.y = 0;
menu = IMG_Load("res/menu.png");
// Variable de boucle
int continuer = 1;
// Ouverture de l'ecran
screen = SDL_SetVideoMode(WIDTH_GAME, HEIGHT_GAME, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format, 255, 255, 255));
SDL_WM_SetCaption(TITLE_GAME, NULL);
SDL_Event event;
while(continuer)
{
SDL_PollEvent(&event);
switch(event.type)
{
case SDL_QUIT:
// On arrete
continuer = 0;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
// On arrete
continuer = 0;
break;
case SDLK_RETURN:
realMenu(screen);
SDL_BlitSurface(menu, NULL, screen, &posMenu);
SDL_BlitSurface(ver, NULL, screen, &posVer);
SDL_Flip(screen);
SDL_Delay(200);
break;
default:
break;
}
break;
}
// On affiche le menu (si le jeu n'est pas lance)
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
SDL_BlitSurface(menu, NULL, screen, &posMenu);
SDL_BlitSurface(ver, NULL, screen, &posVer);
// Clignotement du texte
tempsIni = SDL_GetTicks();
if (tempsIni - temps > 500 && aff == 0)
{
aff = 1;
temps = tempsIni;
}
if (tempsIni - temps > 500 && aff == 1)
{
SDL_BlitSurface(text, NULL, screen, &posText);
if(tempsIni - temps > 1500)
{
aff = 0;
temps = tempsIni;
}
}
// Affichage
SDL_Flip(screen);
}
// Quit
TTF_Quit();
SDL_Quit();
return EXIT_SUCCESS;
}