00001
00002
00009
00010
#include "affichage.h"
00011
#include "ctrl_fenetre.h"
00012
#include "ctrl_son.h"
00013
#include "ctrl_jeu.h"
00014
#include "window_sdl.h"
00015
#include "texture_manager.h"
00016
#include <stdlib.h>
00017
00018
#ifdef _DEBUG
00019
#define FULLSCREEN false
00020
#else
00021 #define FULLSCREEN true
00022
#endif //_DEBUG
00023
00024 CFenetre::CFenetre ()
00025 {
00026
00027
CWindowSDL::Instance ()->
Create (
FENETRE_NOM,
FENETRE_LARGEUR,
FENETRE_HAUTEUR,
FENETRE_COULEUR,
FULLSCREEN);
00028
00029
00030
CSoundManager::Instance ()->
Jouer (
FICHIER_MUSIQUE_MENU,
CANAL_MUSIQUE,
true);
00031
00032
00033 MenuInit ();
00034
00035 m_Page =
PAGE_PRINCIPALE;
00036 m_bEnd =
false;
00037
00038
00039
while (!m_bEnd)
00040 {
00041
00042
switch (m_Page)
00043 {
00044
default:
00045
case PAGE_NULL:
00046 m_Page =
PAGE_QUITTER;
00047
break;
00048
case PAGE_JEU_CHARGEMENT:
00049
if (!PageJeuChargement ())
00050 m_Page =
PAGE_JEU_CHARGEMENT_ERREUR;
00051
break;
00052
case PAGE_JEU_CHARGEMENT_ERREUR:
00053 PageJeuChargementErreur ();
00054
break;
00055
case PAGE_JEU_ENCOURS:
00056 PageJeuEnCours ();
00057
break;
00058
case PAGE_PRINCIPALE:
00059 PagePrincipale ();
00060
break;
00061
case PAGE_JEU_COMMENCER:
00062 PageJeuCommencer ();
00063
break;
00064
case PAGE_SCORE:
00065 PageScore ();
00066
break;
00067
case PAGE_QUITTER:
00068 PageQuitter ();
00069
break;
00070 }
00071 }
00072 }
00073
00074 CFenetre::~CFenetre ()
00075 {
00076
00077
00078
00079
00080
00081
CTextureManager::Kill ();
00082
CGameManager::Kill ();
00083
CAffichage::Kill ();
00084
CSoundManager::Kill ();
00085
CWindowSDL::Kill ();
00086
00087 SDL_Quit ();
00088 }
00089
00090
void CFenetre::MenuInit ()
00091 {
00092 m_uiMenuPrincipal =
PAGE_PRINCIPALE_JEU_COMMENCER;
00093 m_uiMenuCommencer =
PAGE_JEU_COMMENCER_NOMBRE_JOUEUR;
00094 m_uiNombreJoueur = 1;
00095
00096 m_pTextureMenuFond =
CTextureManager::Instance ()->
Texture2D (FICHIER_TEXTURE_FOND_MENU);
00097
00098
00099
00100
00101
00102 }
00103
00104
bool CFenetre::PageJeuChargement ()
00105 {
00106
00107
CAffichage *pAffichage =
CAffichage::Instance ();
00108 pAffichage->
Debut ();
00109
00110 pAffichage->
MenuImageFond (m_pTextureMenuFond);
00111 pAffichage->
MenuChargement ();
00112 pAffichage->
Fin ();
00113
00114
00115 m_EntreeSouris =
CEntreeSouris (FENETRE_LARGEUR * 1 / 3, FENETRE_HAUTEUR / 6);
00116 m_EntreeClavier =
CEntreeClavier (FENETRE_LARGEUR * 2 / 3, FENETRE_HAUTEUR / 6);
00117
00118
00119
00120
CGameManager::Kill ();
00121
00122
CGameManager *pJeu =
CGameManager::Instance ();
00123
00124
00125
if (!pJeu->
Init (m_uiNombreJoueur, m_szNomJoueur1.c_str (), m_szNomJoueur2.c_str ()))
00126 {
00127 pJeu->
Kill ();
00128
return false;
00129 }
00130
00131
00132
CSoundManager::Instance ()->
Jouer (FICHIER_MUSIQUE_JEU, CANAL_MUSIQUE,
true);
00133
00134 m_Page =
PAGE_JEU_ENCOURS;
00135
return true;
00136 }
00137
00138
void CFenetre::PageJeuChargementErreur ()
00139 {
00140 SDL_Event event;
00141
bool bFin =
false;
00142
00143
00144
CAffichage *pAffichage =
CAffichage::Instance ();
00145 pAffichage->
Debut ();
00146 pAffichage->
MenuImageFond (m_pTextureMenuFond);
00147 pAffichage->
MenuChargementErreur ();
00148 pAffichage->
Fin ();
00149
00150
while (!bFin)
00151 {
00152
00153
while (SDL_PollEvent (&event))
00154 {
00155
switch (event.type)
00156 {
00157
case SDL_QUIT:
00158
case SDL_KEYDOWN:
00159 m_Page =
PAGE_PRINCIPALE;
00160 bFin =
true;
00161
break;
00162
default:
00163
break;
00164 }
00165 }
00166 }
00167 }
00168
00169
void CFenetre::PageJeuEnCours ()
00170 {
00171 SDL_Event event;
00172
00173
00174
while (SDL_PollEvent (&event))
00175 {
00176
switch (event.type)
00177 {
00178
case SDL_QUIT:
00179 m_Page =
PAGE_PRINCIPALE;
00180
break;
00181
case SDL_KEYUP:
00182
case SDL_KEYDOWN:
00183
if (event.key.keysym.sym == SDLK_ESCAPE)
00184 {
00185
00186
CSoundManager::Instance ()->
Jouer (FICHIER_MUSIQUE_MENU, CANAL_MUSIQUE,
true);
00187 m_Page =
PAGE_PRINCIPALE;
00188 }
00189 m_EntreeClavier.
Event ((SDL_KeyboardEvent*) &event);
00190
break;
00191
case SDL_MOUSEMOTION:
00192 m_EntreeSouris.
Event ((SDL_MouseMotionEvent*) &event);
00193
break;
00194
case SDL_MOUSEBUTTONDOWN:
00195
case SDL_MOUSEBUTTONUP:
00196 m_EntreeSouris.
Event ((SDL_MouseButtonEvent*) &event);
00197
break;
00198
default:
00199
break;
00200 }
00201 }
00202
00203
CGameManager *pJeu =
CGameManager::Instance ();
00204
00205
00206 pJeu->
Tirer (JOUEUR_1, m_EntreeSouris.
Tirer ());
00207
00208 pJeu->
PositionnerJoueur (JOUEUR_1, m_EntreeSouris.
GetPosition ());
00209
00210
00211 pJeu->
Tirer (JOUEUR_2, m_EntreeClavier.
Tirer ());
00212
00213 pJeu->
PositionnerJoueur (JOUEUR_2, m_EntreeClavier.
GetPosition ());
00214
00215
00216 pJeu->
Update ();
00217 }
00218
00219
void CFenetre::PagePrincipale ()
00220 {
00221 SDL_Event event;
00222
bool bAction =
false;
00223
00224
while (SDL_PollEvent (&event))
00225 {
00226
00227
switch (event.type)
00228 {
00229
case SDL_QUIT:
00230 m_Page =
PAGE_QUITTER;
00231
break;
00232
case SDL_KEYDOWN:
00233
00234
if (event.key.keysym.sym == SDLK_KP8 || event.key.keysym.sym == SDLK_UP)
00235 {
00236
unsigned int iMax =
CGameManager::IsCreate () != 0 ?
PAGE_PRINCIPALE_JEU_REPRENDRE :
PAGE_PRINCIPALE_JEU_COMMENCER;
00237 m_uiMenuPrincipal++;
00238
if (m_uiMenuPrincipal > iMax)
00239 m_uiMenuPrincipal = iMax;
00240 }
00241
00242
if (event.key.keysym.sym == SDLK_KP2 || event.key.keysym.sym == SDLK_DOWN)
00243 {
00244 m_uiMenuPrincipal--;
00245
if (m_uiMenuPrincipal <
PAGE_PRINCIPALE_QUITTER)
00246 m_uiMenuPrincipal =
PAGE_PRINCIPALE_QUITTER;
00247 }
00248
00249
if (event.key.keysym.sym == SDLK_SPACE
00250 || event.key.keysym.sym == SDLK_RETURN
00251 || event.key.keysym.sym == SDLK_KP_ENTER)
00252 {
00253 bAction =
true;
00254 }
00255
if (event.key.keysym.sym == SDLK_ESCAPE)
00256 m_Page =
PAGE_QUITTER;
00257
break;
00258
default:
00259
break;
00260 }
00261 }
00262
00263
00264
if (bAction)
00265 {
00266
switch (m_uiMenuPrincipal)
00267 {
00268
default:
00269
break;
00270
case PAGE_PRINCIPALE_QUITTER:
00271 m_Page =
PAGE_QUITTER;
00272
break;
00273
case PAGE_PRINCIPALE_SCORES:
00274 m_Page =
PAGE_SCORE;
00275
break;
00276
case PAGE_PRINCIPALE_JEU_COMMENCER:
00277 m_Page =
PAGE_JEU_COMMENCER;
00278
break;
00279
case PAGE_PRINCIPALE_JEU_REPRENDRE:
00280 m_Page =
PAGE_JEU_ENCOURS;
00281
break;
00282 }
00283 }
00284
00285
00286
CAffichage *pAffichage =
CAffichage::Instance ();
00287 pAffichage->
Debut ();
00288 pAffichage->
MenuImageFond (m_pTextureMenuFond);
00289 pAffichage->
MenuPrincipal (m_uiMenuPrincipal, CGameManager::IsCreate ());
00290 pAffichage->
Fin ();
00291 }
00292
00293
void CFenetre::PageJeuCommencer ()
00294 {
00295 SDL_Event event;
00296
bool bAction =
false;
00297
00298
00299
00300 SDL_EnableUNICODE (1);
00301 SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
00302
00303
00304
while (SDL_PollEvent (&event))
00305 {
00306
switch (event.type)
00307 {
00308
default:
00309
break;
00310
case SDL_QUIT:
00311 m_Page =
PAGE_PRINCIPALE;
00312 SDL_EnableUNICODE (0);
00313
break;
00314
case SDL_KEYDOWN:
00315
if (event.key.keysym.sym == SDLK_ESCAPE)
00316 {
00317 m_Page =
PAGE_PRINCIPALE;
00318 SDL_EnableUNICODE (0);
00319 }
00320
00321
else if (event.key.keysym.sym == SDLK_BACKSPACE)
00322 {
00323
if (m_uiMenuCommencer ==
PAGE_JEU_COMMENCER_JOUEUR1)
00324 m_szNomJoueur1.clear ();
00325
if (m_uiMenuCommencer ==
PAGE_JEU_COMMENCER_JOUEUR2)
00326 m_szNomJoueur2.clear ();
00327 }
00328
00329
else if (event.key.keysym.sym == SDLK_KP8 || event.key.keysym.sym == SDLK_UP)
00330 {
00331
if (m_uiNombreJoueur ==
PAGE_JEU_COMMENCER_JOUEUR2 || m_uiMenuCommencer !=
PAGE_JEU_COMMENCER_CHARGEMENT)
00332 {
00333 m_uiMenuCommencer++;
00334
if (m_uiMenuCommencer >
PAGE_JEU_COMMENCER_NOMBRE_JOUEUR)
00335 m_uiMenuCommencer =
PAGE_JEU_COMMENCER_NOMBRE_JOUEUR;
00336 }
00337
else
00338 m_uiMenuCommencer =
PAGE_JEU_COMMENCER_JOUEUR1;
00339 }
00340
00341
else if (event.key.keysym.sym == SDLK_KP2 || event.key.keysym.sym == SDLK_DOWN)
00342 {
00343
if (m_uiNombreJoueur ==
PAGE_JEU_COMMENCER_JOUEUR2 || m_uiMenuCommencer !=
PAGE_JEU_COMMENCER_JOUEUR1)
00344 {
00345 m_uiMenuCommencer--;
00346
if (m_uiMenuCommencer <
PAGE_JEU_COMMENCER_CHARGEMENT)
00347 m_uiMenuCommencer =
PAGE_JEU_COMMENCER_CHARGEMENT;
00348 }
00349
else
00350 m_uiMenuCommencer =
PAGE_JEU_COMMENCER_CHARGEMENT;
00351 }
00352
00353
else if (event.key.keysym.sym == SDLK_SPACE
00354 || event.key.keysym.sym == SDLK_RETURN
00355 || event.key.keysym.sym == SDLK_KP_ENTER)
00356 {
00357 bAction =
true;
00358 }
00359
else if (event.key.keysym.unicode > 32 && event.key.keysym.unicode <= 160)
00360 {
00361
00362
if (m_uiMenuCommencer ==
PAGE_JEU_COMMENCER_JOUEUR1)
00363 m_szNomJoueur1.push_back (static_cast<char> (event.key.keysym.unicode));
00364
if (m_uiMenuCommencer ==
PAGE_JEU_COMMENCER_JOUEUR2 && m_uiNombreJoueur == 2)
00365 m_szNomJoueur2.push_back (static_cast<char> (event.key.keysym.unicode));
00366 }
00367
break;
00368 }
00369 }
00370
00371
if (bAction)
00372 {
00373
switch (m_uiMenuCommencer)
00374 {
00375
case PAGE_JEU_COMMENCER_CHARGEMENT:
00376 m_Page =
PAGE_JEU_CHARGEMENT;
00377 SDL_EnableUNICODE (0);
00378
break;
00379
case 4:
00380
00381 m_uiNombreJoueur = m_uiNombreJoueur == 1 ? 2 : 1;
00382
break;
00383 }
00384 }
00385
00386
00387
CAffichage *pAffichage =
CAffichage::Instance ();
00388 pAffichage->
Debut ();
00389
00390 pAffichage->
MenuImageFond (m_pTextureMenuFond);
00391
00392 pAffichage->
MenuCommencer (m_uiMenuCommencer, m_uiNombreJoueur, m_szNomJoueur1, m_szNomJoueur2);
00393 pAffichage->
Fin ();
00394 }
00395
00396
void CFenetre::PageScore ()
00397 {
00398 SDL_Event event;
00399
bool bFin =
false;
00400
00401
00402
CAffichage *pAffichage =
CAffichage::Instance ();
00403 pAffichage->
Debut ();
00404
00405 pAffichage->
MenuImageFond (m_pTextureMenuFond);
00406
00407 pAffichage->
MenuScore ();
00408 pAffichage->
Fin ();
00409
00410
00411
while (!bFin)
00412 {
00413
00414
while (SDL_PollEvent (&event))
00415 {
00416
switch (event.type)
00417 {
00418
case SDL_QUIT:
00419
case SDL_KEYDOWN:
00420 m_Page =
PAGE_PRINCIPALE;
00421 bFin =
true;
00422
break;
00423
default:
00424
break;
00425 }
00426 }
00427 }
00428 }
00429
00430
void CFenetre::PageQuitter ()
00431 {
00432 SDL_Event event;
00433
00434
CTextureManager *pTextureManager =
CTextureManager::Instance ();
00435 m_pTextureMenuQuitter = pTextureManager->
Texture2D (FICHIER_TEXTURE_FOND_QUITTER);
00436
00437
00438
CAffichage *pAffichage =
CAffichage::Instance ();
00439 pAffichage->
Debut ();
00440
00441 pAffichage->
MenuImageFond (m_pTextureMenuQuitter);
00442 pAffichage->
Fin ();
00443
00444 pTextureManager->
Delete (m_pTextureMenuQuitter);
00445
00446
00447
CSoundManager::Instance ()->
Jouer (FICHIER_MUSIQUE_QUITTER, CANAL_MUSIQUE,
true);
00448
00449
00450
if (
CGameManager::IsCreate ())
00451
CGameManager::Instance ()->
Kill ();
00452
00453
bool bEnd =
false;
00454
00455
while (!bEnd)
00456 {
00457
00458
while (SDL_PollEvent (&event))
00459 {
00460
switch (event.type)
00461 {
00462
case SDL_KEYDOWN:
00463
00464 bEnd =
true;
00465 m_bEnd =
true;
00466
break;
00467
default:
00468
break;
00469 }
00470 }
00471 }
00472 }