| 1 | // (_||_/ |
| 2 | // ( ) |
| 3 | // ( o 0 ) |
| 4 | //-OOO°--(_)---°OOO--------------------------------------- |
| 5 | // Copyright (C) 2006 By Dominique Roux-Serret |
| 6 | // .OOOo oOOO. [email protected] |
| 7 | //-( )------( )--------------------------------------- |
| 8 | // ( ( ) / Copyright (C) 2023 By Johnny Jazeix |
| 9 | // (_) (_/ [email protected] |
| 10 | |
| 11 | // This program is free software; you can redistribute it and/or modify |
| 12 | // it under the terms of the GNU General Public License as published by |
| 13 | // the Free Software Foundation; either version 2 or version 3 of the License. |
| 14 | |
| 15 | // This program is distributed in the hope that it will be useful, |
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | // GNU General Public License for more details. |
| 19 | |
| 20 | // You should have received a copy of the GNU General Public License along |
| 21 | // with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 23 | |
| 24 | #include <cstdio> |
| 25 | #include <cstdlib> |
| 26 | #include <cstring> |
| 27 | |
| 28 | #include <SDL2/SDL_audio.h> // for SDL_MIX_MAXVOLUME |
| 29 | #include <SDL2/SDL_events.h> // for SDL_PollEvent, SDL_Event, SDL_KEYDOWN |
| 30 | #include <SDL2/SDL_keyboard.h> // for SDL_StopTextInput, SDL_StartTextInput |
| 31 | #include <SDL2/SDL_keycode.h> // for SDLK_F12, SDLK_RETURN, SDLK_ESCAPE |
| 32 | #include <SDL2/SDL_mouse.h> // for SDL_ShowCursor |
| 33 | #include <SDL2/SDL_rect.h> // for SDL_Rect |
| 34 | #include <SDL2/SDL_render.h> // for SDL_RenderPresent, SDL_RenderClear |
| 35 | #include <SDL2/SDL_stdinc.h> // for Uint32 |
| 36 | #include <SDL2/SDL_timer.h> // for SDL_GetTicks, SDL_Delay |
| 37 | #include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_ENTER, SDL_SetWindowF... |
| 38 | |
| 39 | #include <array> |
| 40 | #include <utility> |
| 41 | #include "preference.h" |
| 42 | #include "menu.h" |
| 43 | #include "sprite.h" |
| 44 | #include "screen.h" |
| 45 | #include "gamepad.h" |
| 46 | #include "mouse.h" |
| 47 | #include "audio.h" |
| 48 | #include "utils.h" |
| 49 | |
| 50 | #define PY 180 |
| 51 | |
| 52 | /*** Variables globales ***/ |
| 53 | /**************************/ |
| 54 | extern int Horloge; |
| 55 | extern int HorlogeAvant; |
| 56 | extern SDL_Window *sdlWindow; |
| 57 | extern SDL_Renderer *sdlRenderer; |
| 58 | extern Sprite *Sprites; |
| 59 | extern Screen Ec; |
| 60 | extern sNewPreference Pref; |
| 61 | |
| 62 | static char Points[] = ". . . . . . . . . . . . . ."; |
| 63 | static struct mPy Menu_Py[20]; |
| 64 | |
| 65 | /*** Fait une attente pour 50fps ***/ |
| 66 | /***********************************/ |
| 67 | void Sleeping() |
| 68 | { |
| 69 | int delay; |
| 70 | |
| 71 | if ((Horloge - HorlogeAvant) < (1000 / 60)) { |
| 72 | delay = 1000 / 60 - (Horloge - HorlogeAvant); |
| 73 | SDL_Delay(delay); |
| 74 | Horloge = SDL_GetTicks(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /*** Ajoute une entrée dans le tableau des boutons ***/ |
| 79 | /*****************************************************/ |
| 80 | void AddBouton(int Num, e_Sprite NumSp, int X, int Y) |
| 81 | { |
| 82 | int const NumS = (int)NumSp; |
| 83 | |
| 84 | Menu_Py[Num].DepX = X - Sprites[NumS].Dim[0].L / 2; |
| 85 | Menu_Py[Num].DepY = Y - Sprites[NumS].Dim[0].H / 2; |
| 86 | Menu_Py[Num].FinX = X + Sprites[NumS].Dim[0].L / 2; |
| 87 | Menu_Py[Num].FinY = Y + Sprites[NumS].Dim[0].H / 2; |
| 88 | Menu_Py[Num].Py = Num; |
| 89 | Menu_Py[Num].Valide = true; |
| 90 | } |
| 91 | |
| 92 | /*** Change le vidéo ***/ |
| 93 | /***********************/ |
| 94 | void ChangeVideo() |
| 95 | { |
| 96 | Uint32 flag = SDL_WINDOW_RESIZABLE; |
| 97 | if (Pref.FullScreen) { |
| 98 | flag = SDL_WINDOW_FULLSCREEN_DESKTOP; |
| 99 | } |
| 100 | SDL_SetWindowFullscreen(sdlWindow, flag); |
| 101 | SDL_ShowCursor(0); // Cache le curseur |
| 102 | } |
| 103 | |
| 104 | /*** SDL Main Menu principale ***/ |
| 105 | /********************************/ |
| 106 | eMenu Menu::SDLMain() |
| 107 | { |
| 108 | int i; |
| 109 | char MCode[5] = { 0, 0, 0, 0, 0 }; |
| 110 | char key; |
| 111 | |
| 112 | // Initialisations Divers |
| 113 | m_mouse.Init(Menu_Py); // Initialise la sourie |
| 114 | PyE = 0; |
| 115 | |
| 116 | // Prend les evenements |
| 117 | do { |
| 118 | SDL_RenderClear(sdlRenderer); |
| 119 | // Prend l'image du fond et fait l'affichage |
| 120 | Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); |
| 121 | Sprites[menu].Affiche(400, 340, 0, Sprites[fmenu].Image[0]); |
| 122 | Sprites[titre].Affiche(400, 65, 0, Sprites[fmenu].Image[0]); |
| 123 | Sprites[copyright].Affiche(400, 587, 0, Sprites[fmenu].Image[0]); |
| 124 | |
| 125 | AfficheText(400, 229, T_play, Sprites[fmenu].Image[0]); |
| 126 | AddBouton(0, T_play, 400, 229); |
| 127 | AfficheText(400, 306, T_scores, Sprites[fmenu].Image[0]); |
| 128 | AddBouton(1, T_scores, 400, 306); |
| 129 | AfficheText(400, 384, T_moptions, Sprites[fmenu].Image[0]); |
| 130 | AddBouton(2, T_moptions, 400, 384); |
| 131 | AfficheText(400, 461, T_quit, Sprites[fmenu].Image[0]); |
| 132 | AddBouton(3, T_quit, 400, 461); |
| 133 | Menu_Py[4].DepX = -1; |
| 134 | SDL_Event event; |
| 135 | while (SDL_PollEvent(&event)) { |
| 136 | m_mouse.GetEvent(event, PyE); // Handle mouse |
| 137 | m_gamepad.GetEvent(event); // Handle gamepad |
| 138 | switch (event.type) { |
| 139 | case SDL_KEYDOWN: |
| 140 | if (event.key.state == SDL_PRESSED) { |
| 141 | m_audio.Play(sClic); |
| 142 | switch (event.key.keysym.sym) { |
| 143 | case SDLK_ESCAPE: |
| 144 | case SDLK_AC_BACK: // Android back button |
| 145 | return mQuit; |
| 146 | case SDLK_UP: |
| 147 | PyE--; |
| 148 | if (PyE < 0) { |
| 149 | PyE = 3; |
| 150 | } |
| 151 | break; |
| 152 | case SDLK_DOWN: |
| 153 | PyE++; |
| 154 | if (PyE > 3) { |
| 155 | PyE = 0; |
| 156 | } |
| 157 | break; |
| 158 | case SDLK_F12: // Save screenshot |
| 159 | if (event.key.repeat == 0) { |
| 160 | Utils::doScreenshot(sdlRenderer); |
| 161 | } |
| 162 | break; |
| 163 | case ' ': |
| 164 | case SDLK_RETURN: |
| 165 | case SDLK_KP_ENTER: |
| 166 | switch (PyE) { |
| 167 | case 0: |
| 168 | return mMenuSpeed; |
| 169 | case 1: |
| 170 | return mScore; |
| 171 | case 2: |
| 172 | return mOption; |
| 173 | case 3: |
| 174 | return mQuit; |
| 175 | } |
| 176 | break; |
| 177 | default: |
| 178 | key = event.key.keysym.sym & 0x7F; // Prend le caracataire correspondant à la touche |
| 179 | if (CharExiste(key) == true) { // Si la caractaire existe bien |
| 180 | for (i = 2; i >= 0; i--) { |
| 181 | MCode[i + 1] = MCode[i]; // décale le code |
| 182 | } |
| 183 | MCode[0] = key; |
| 184 | if (strcmp(MCode, "tide") == 0 || strcmp(MCode, "TIDE") == 0) { |
| 185 | return mEdit; // Si editeur de niveau |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | break; |
| 191 | case SDL_QUIT: |
| 192 | return mQuit; |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Gère les variables |
| 198 | HorlogeAvant = Horloge; |
| 199 | Horloge = SDL_GetTicks(); |
| 200 | Sleeping(); |
| 201 | |
| 202 | // Gère l'Affichage |
| 203 | Ec.ClearSprite(fmenu); |
| 204 | Print_Main(); |
| 205 | m_mouse.Print(); |
| 206 | |
| 207 | // Echange les buffets video |
| 208 | SDL_RenderPresent(sdlRenderer); |
| 209 | |
| 210 | } while (true); |
| 211 | |
| 212 | return mQuit; |
| 213 | } |
| 214 | |
| 215 | /*** SDL Main Menu Choix de la langue ***/ |
| 216 | /****************************************/ |
| 217 | eMenu Menu::SDLMain_Language() |
| 218 | { |
| 219 | int NCol = 1; |
| 220 | int NL; |
| 221 | int Ecart; |
| 222 | int i; |
| 223 | int x, y; |
| 224 | int const OldLangue = Pref.Langue; |
| 225 | |
| 226 | // Initialisations Divers |
| 227 | m_mouse.Init(Menu_Py); // Initialise la sourie |
| 228 | PyE = Pref.Langue; |
| 229 | if (PyE == -1) { |
| 230 | PyE = 1; |
| 231 | } |
| 232 | |
| 233 | SDL_RenderClear(sdlRenderer); |
| 234 | // Prend l'image du fond et fait l'affichage |
| 235 | Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); |
| 236 | |
| 237 | // Affiche les langues possibles |
| 238 | NCol = 3; |
| 239 | if (Pref.NLangues % NCol == 0) { |
| 240 | NL = Pref.NLangues / NCol; |
| 241 | } |
| 242 | else { |
| 243 | NL = Pref.NLangues / NCol + 1; |
| 244 | } |
| 245 | Ecart = 600 / (NL + 1); |
| 246 | |
| 247 | for (i = 0; i < Pref.NLangues; i++) { |
| 248 | x = (i / NL) * (800 / 3) + (800 / 6); |
| 249 | y = (i % NL) * Ecart + Ecart; |
| 250 | |
| 251 | Sprites[T_Langue + i].Affiche(x, y, 0, Sprites[fmenu].Image[0]); |
| 252 | AddBouton(i, (e_Sprite)(T_Langue + i), x, y); |
| 253 | } |
| 254 | |
| 255 | Menu_Py[Pref.NLangues].DepX = -1; |
| 256 | |
| 257 | // Efface le fond |
| 258 | SDL_RenderPresent(sdlRenderer); |
| 259 | |
| 260 | // Prend les evenements |
| 261 | do { |
| 262 | SDL_RenderClear(sdlRenderer); |
| 263 | Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); |
| 264 | for (i = 0; i < Pref.NLangues; i++) { |
| 265 | x = (i / NL) * (800 / 3) + (800 / 6); |
| 266 | y = (i % NL) * Ecart + Ecart; |
| 267 | |
| 268 | Sprites[T_Langue + i].Affiche(x, y, 0, Sprites[fmenu].Image[0]); |
| 269 | AddBouton(i, (e_Sprite)(T_Langue + i), x, y); |
| 270 | } |
| 271 | |
| 272 | SDL_Event event; |
| 273 | while (SDL_PollEvent(&event)) { |
| 274 | |
| 275 | m_mouse.GetEvent(event, PyE); // Handle mouse |
| 276 | m_gamepad.GetEvent(event); // Handle gamepad |
| 277 | switch (event.type) { |
| 278 | case SDL_WINDOWEVENT: |
| 279 | if (event.window.event == SDL_WINDOWEVENT_ENTER) { |
| 280 | SDL_RenderPresent(sdlRenderer); |
| 281 | } |
| 282 | break; |
| 283 | case SDL_KEYDOWN: |
| 284 | if (event.key.state == SDL_PRESSED) { |
| 285 | m_audio.Play(sClic); |
| 286 | switch (event.key.keysym.sym) { |
| 287 | case SDLK_ESCAPE: |
| 288 | case SDLK_AC_BACK: // Android back button |
| 289 | if (Pref.Langue == -1) { |
| 290 | Pref.Langue = PyE; |
| 291 | } |
| 292 | return mMenu; |
| 293 | case SDLK_UP: |
| 294 | PyE--; |
| 295 | if (PyE < 0) { |
| 296 | PyE = Pref.NLangues - 1; |
| 297 | } |
| 298 | break; |
| 299 | case SDLK_DOWN: |
| 300 | PyE++; |
| 301 | if (PyE >= Pref.NLangues) { |
| 302 | PyE = 0; |
| 303 | } |
| 304 | break; |
| 305 | case SDLK_LEFT: |
| 306 | if (PyE - NL >= 0) { |
| 307 | PyE -= NL; |
| 308 | } |
| 309 | break; |
| 310 | case SDLK_RIGHT: |
| 311 | if (PyE + NL < Pref.NLangues) { |
| 312 | PyE += NL; |
| 313 | } |
| 314 | break; |
| 315 | case SDLK_F12: // Save screenshot |
| 316 | if (event.key.repeat == 0) { |
| 317 | Utils::doScreenshot(sdlRenderer); |
| 318 | } |
| 319 | break; |
| 320 | case ' ': |
| 321 | case SDLK_RETURN: |
| 322 | case SDLK_KP_ENTER: |
| 323 | Pref.Langue = PyE; |
| 324 | if (Pref.Langue != OldLangue) { |
| 325 | LoadLangue(); |
| 326 | } |
| 327 | return mMenu; |
| 328 | default: |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | break; |
| 333 | case SDL_QUIT: |
| 334 | return mQuit; |
| 335 | break; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | // Gère les variables |
| 340 | HorlogeAvant = Horloge; |
| 341 | Horloge = SDL_GetTicks(); |
| 342 | Sleeping(); |
| 343 | |
| 344 | // Gère l'Affichage |
| 345 | Ec.ClearSprite(fmenu); // Something is done in the Efface that prevents a crash (or maybe more computation)! |
| 346 | Affiche_Main_Centre(); |
| 347 | |
| 348 | m_mouse.Print(); |
| 349 | |
| 350 | // Echange les buffets video |
| 351 | SDL_RenderPresent(sdlRenderer); |
| 352 | |
| 353 | } while (true); |
| 354 | |
| 355 | return mQuit; |
| 356 | } |
| 357 | |
| 358 | /*** SDL Main Menu Choix des Options ***/ |
| 359 | /***************************************/ |
| 360 | void Menu::InitMain_Options() |
| 361 | { |
| 362 | // Initialisations Divers |
| 363 | m_mouse.Init(Menu_Py); // Initialise la sourie |
| 364 | // PyE=4; |
| 365 | |
| 366 | // Prend l'image du fond et fait l'affichage |
| 367 | Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); |
| 368 | Sprites[gmenu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); |
| 369 | Sprites[keys].Affiche(610, 455, 0, Sprites[fmenu].Image[0]); |
| 370 | |
| 371 | AddBouton(0, bruitage, 140, 110); |
| 372 | AddBouton(1, music, 160, 200); |
| 373 | |
| 374 | AddBouton(2, fscreen, 190, 300); |
| 375 | Menu_Py[2].DepX -= 40; |
| 376 | Menu_Py[2].FinX = 625 + 40 + Sprites[fscreen].Dim[0].L / 2; |
| 377 | Sprites[fscreen].Affiche(185, 300, 0, Sprites[fmenu].Image[0]); |
| 378 | Sprites[window].Affiche(625, 300, 0, Sprites[fmenu].Image[0]); |
| 379 | |
| 380 | AddBouton(3, monde, 180, 400); |
| 381 | |
| 382 | // Centre à gauche le text de menu |
| 383 | CentreM = 120 + Sprites[T_menu].Dim[0].L / 2; |
| 384 | AfficheText(CentreM, 490, T_menu, Sprites[fmenu].Image[0]); |
| 385 | AddBouton(4, T_menu, CentreM, 490); |
| 386 | |
| 387 | // Boutons des bruitages |
| 388 | Sprites[fleches].Affiche(250, 110, 1, Sprites[fmenu].Image[0]); |
| 389 | Sprites[fleches].Affiche(700, 110, 4, Sprites[fmenu].Image[0]); |
| 390 | Menu_Py[5].DepX = 230; |
| 391 | Menu_Py[5].DepY = 70; |
| 392 | Menu_Py[5].FinX = 475; |
| 393 | Menu_Py[5].FinY = 145; |
| 394 | Menu_Py[5].Py = 5; |
| 395 | Menu_Py[5].Valide = true; |
| 396 | |
| 397 | Menu_Py[6].DepX = 476; |
| 398 | Menu_Py[6].DepY = 70; |
| 399 | Menu_Py[6].FinX = 720; |
| 400 | Menu_Py[6].FinY = 145; |
| 401 | Menu_Py[6].Py = 6; |
| 402 | Menu_Py[6].Valide = true; |
| 403 | |
| 404 | // Boutons de musics |
| 405 | Sprites[fleches].Affiche(250, 200, 1, Sprites[fmenu].Image[0]); |
| 406 | Sprites[fleches].Affiche(700, 200, 4, Sprites[fmenu].Image[0]); |
| 407 | Menu_Py[7].DepX = 230; |
| 408 | Menu_Py[7].DepY = 155; |
| 409 | Menu_Py[7].FinX = 475; |
| 410 | Menu_Py[7].FinY = 245; |
| 411 | Menu_Py[7].Py = 7; |
| 412 | Menu_Py[7].Valide = true; |
| 413 | |
| 414 | Menu_Py[8].DepX = 476; |
| 415 | Menu_Py[8].DepY = 155; |
| 416 | Menu_Py[8].FinX = 720; |
| 417 | Menu_Py[8].FinY = 245; |
| 418 | Menu_Py[8].Py = 8; |
| 419 | Menu_Py[8].Valide = true; |
| 420 | |
| 421 | Menu_Py[9].DepX = -1; |
| 422 | } |
| 423 | |
| 424 | /*** Gestion du menu Options ***/ |
| 425 | /*******************************/ |
| 426 | eMenu Menu::SDLMain_Options() |
| 427 | { |
| 428 | int i, N; |
| 429 | int NumSp; |
| 430 | |
| 431 | PyE = 4; |
| 432 | // Prend les evenements |
| 433 | do { |
| 434 | Ec.CleanSpriteAndScreen(fmenu); // To not crash... |
| 435 | SDL_RenderClear(sdlRenderer); |
| 436 | InitMain_Options(); // Prépare le menu |
| 437 | SDL_Event event; |
| 438 | while (SDL_PollEvent(&event)) { |
| 439 | m_mouse.GetEvent(event, PyE); // Handle mouse |
| 440 | m_gamepad.GetEvent(event); // Handle gamepad |
| 441 | |
| 442 | switch (event.type) { |
| 443 | case SDL_WINDOWEVENT: |
| 444 | if (event.window.event == SDL_WINDOWEVENT_ENTER) { |
| 445 | SDL_RenderPresent(sdlRenderer); |
| 446 | } |
| 447 | break; |
| 448 | case SDL_KEYDOWN: |
| 449 | if (event.key.state == SDL_PRESSED) { |
| 450 | m_audio.Play(sClic); |
| 451 | switch (event.key.keysym.sym) { |
| 452 | case SDLK_ESCAPE: |
| 453 | case SDLK_AC_BACK: // Android back button |
| 454 | return mMenu; |
| 455 | case SDLK_LEFT: |
| 456 | switch (PyE) { |
| 457 | case 2: |
| 458 | if (Pref.FullScreen == false) { |
| 459 | Pref.FullScreen = true; |
| 460 | ChangeVideo(); |
| 461 | PyE = 2; |
| 462 | } |
| 463 | break; |
| 464 | case 0: |
| 465 | case 5: // Diminue volume sons |
| 466 | case 6: |
| 467 | Pref.Volume -= SDL_MIX_MAXVOLUME / 10.0; |
| 468 | if (Pref.Volume < 0) { |
| 469 | Pref.Volume = 0; |
| 470 | } |
| 471 | m_audio.DoVolume(); |
| 472 | m_audio.Play(sLive); |
| 473 | break; |
| 474 | case 1: |
| 475 | case 7: // Diminue volume music |
| 476 | case 8: |
| 477 | Pref.VolumeM -= SDL_MIX_MAXVOLUME / 10.0; |
| 478 | if (Pref.VolumeM < 0) { |
| 479 | Pref.VolumeM = 0; |
| 480 | } |
| 481 | m_audio.DoVolume(); |
| 482 | break; |
| 483 | } |
| 484 | break; |
| 485 | case SDLK_RIGHT: |
| 486 | switch (PyE) { |
| 487 | case 2: |
| 488 | if (Pref.FullScreen == true) { |
| 489 | Pref.FullScreen = false; |
| 490 | ChangeVideo(); |
| 491 | PyE = 2; |
| 492 | } |
| 493 | break; |
| 494 | case 0: |
| 495 | case 5: |
| 496 | case 6: |
| 497 | Pref.Volume += SDL_MIX_MAXVOLUME / 10.0; |
| 498 | if (Pref.Volume > SDL_MIX_MAXVOLUME) { |
| 499 | Pref.Volume = SDL_MIX_MAXVOLUME; |
| 500 | } |
| 501 | m_audio.DoVolume(); |
| 502 | m_audio.Play(sLive); |
| 503 | break; |
| 504 | case 1: |
| 505 | case 7: |
| 506 | case 8: |
| 507 | Pref.VolumeM += SDL_MIX_MAXVOLUME / 10.0; |
| 508 | if (Pref.VolumeM > SDL_MIX_MAXVOLUME) { |
| 509 | Pref.VolumeM = SDL_MIX_MAXVOLUME; |
| 510 | } |
| 511 | m_audio.DoVolume(); |
| 512 | break; |
| 513 | } |
| 514 | break; |
| 515 | case SDLK_UP: |
| 516 | PyE--; |
| 517 | if (PyE < 0) { |
| 518 | PyE = 4; |
| 519 | } |
| 520 | break; |
| 521 | case SDLK_DOWN: |
| 522 | PyE++; |
| 523 | if (PyE >= 5) { |
| 524 | PyE = 0; |
| 525 | } |
| 526 | break; |
| 527 | case SDLK_F12: // Save screenshot |
| 528 | if (event.key.repeat == 0) { |
| 529 | Utils::doScreenshot(sdlRenderer); |
| 530 | } |
| 531 | break; |
| 532 | case ' ': |
| 533 | case SDLK_RETURN: |
| 534 | case SDLK_KP_ENTER: |
| 535 | switch (PyE) { |
| 536 | case 0: |
| 537 | case 1: |
| 538 | break; |
| 539 | case 2: // Type d'affichage |
| 540 | Pref.FullScreen = (Pref.FullScreen + 1) & 1; |
| 541 | ChangeVideo(); |
| 542 | PyE = 2; |
| 543 | break; |
| 544 | case 3: // Choix de la langue |
| 545 | SDLMain_Language(); |
| 546 | PyE = 3; |
| 547 | break; |
| 548 | case 5: // Diminue volume sons |
| 549 | Pref.Volume -= SDL_MIX_MAXVOLUME / 10.0; |
| 550 | if (Pref.Volume < 0) { |
| 551 | Pref.Volume = 0; |
| 552 | } |
| 553 | m_audio.DoVolume(); |
| 554 | m_audio.Play(sLive); |
| 555 | break; |
| 556 | case 6: |
| 557 | Pref.Volume += SDL_MIX_MAXVOLUME / 10.0; |
| 558 | if (Pref.Volume > SDL_MIX_MAXVOLUME) { |
| 559 | Pref.Volume = SDL_MIX_MAXVOLUME; |
| 560 | } |
| 561 | m_audio.DoVolume(); |
| 562 | m_audio.Play(sLive); |
| 563 | break; |
| 564 | case 7: // Diminue volume music |
| 565 | Pref.VolumeM -= SDL_MIX_MAXVOLUME / 10.0; |
| 566 | if (Pref.VolumeM < 0) { |
| 567 | Pref.VolumeM = 0; |
| 568 | } |
| 569 | m_audio.DoVolume(); |
| 570 | break; |
| 571 | case 8: |
| 572 | Pref.VolumeM += SDL_MIX_MAXVOLUME / 10.0; |
| 573 | if (Pref.VolumeM > SDL_MIX_MAXVOLUME) { |
| 574 | Pref.VolumeM = SDL_MIX_MAXVOLUME; |
| 575 | } |
| 576 | m_audio.DoVolume(); |
| 577 | break; |
| 578 | default: |
| 579 | return mMenu; |
| 580 | } |
| 581 | default: |
| 582 | break; |
| 583 | } |
| 584 | } |
| 585 | break; |
| 586 | case SDL_QUIT: |
| 587 | return mQuit; |
| 588 | break; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | // SDL_RenderClear(sdlRenderer); |
| 593 | // Gère les variables |
| 594 | HorlogeAvant = Horloge; |
| 595 | Horloge = SDL_GetTicks(); |
| 596 | Sleeping(); |
| 597 | |
| 598 | // Gère l'Affichage |
| 599 | // Ec.Efface(fmenu); |
| 600 | |
| 601 | if (Pref.FullScreen) { |
| 602 | Ec.PrintSprite(fleches, 1, 350, 300); |
| 603 | Ec.PrintSprite(fleches, 3, 450, 300); |
| 604 | } |
| 605 | else { |
| 606 | Ec.PrintSprite(fleches, 0, 350, 300); |
| 607 | Ec.PrintSprite(fleches, 4, 450, 300); |
| 608 | } |
| 609 | |
| 610 | NumSp = (Horloge / 30) % 25; |
| 611 | Ec.PrintSprite(bruitage, NumSp, 150, 110); |
| 612 | NumSp = (Horloge / 30) % 25; |
| 613 | Ec.PrintSprite(music, NumSp, 150, 200); |
| 614 | NumSp = (Horloge / 50) % 50; |
| 615 | Ec.PrintSprite(monde, NumSp, 180, 400); |
| 616 | |
| 617 | N = (int)(Pref.Volume * 10 + 1) / SDL_MIX_MAXVOLUME; |
| 618 | NumSp = (Horloge / 50) % 40 + 120; |
| 619 | for (i = 0; i < N; i++) { |
| 620 | if (i == N - 1) { |
| 621 | Ec.PrintSprite(locomotive, NumSp, (690 - 300) / 10 * i + 300, 110); |
| 622 | } |
| 623 | else { |
| 624 | Ec.PrintSprite(buches, NumSp, (690 - 300) / 10 * i + 300, 110); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | N = (int)(Pref.VolumeM * 10 + 1) / SDL_MIX_MAXVOLUME; |
| 629 | for (i = 0; i < N; i++) { |
| 630 | if (i == N - 1) { |
| 631 | Ec.PrintSprite(locomotive, NumSp, (690 - 300) / 10 * i + 300, 200); |
| 632 | } |
| 633 | else { |
| 634 | Ec.PrintSprite(buches, NumSp, (690 - 300) / 10 * i + 300, 200); |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | switch (PyE) { |
| 639 | case 3: |
| 640 | Print_Main(180); |
| 641 | break; |
| 642 | case 4: |
| 643 | Print_Main(CentreM); |
| 644 | break; |
| 645 | case 5: |
| 646 | PyE = 0; |
| 647 | Print_Main(); |
| 648 | PyE = 5; |
| 649 | break; |
| 650 | case 6: |
| 651 | PyE = 0; |
| 652 | Print_Main(); |
| 653 | PyE = 6; |
| 654 | break; |
| 655 | case 7: |
| 656 | PyE = 1; |
| 657 | Print_Main(); |
| 658 | PyE = 7; |
| 659 | break; |
| 660 | case 8: |
| 661 | PyE = 1; |
| 662 | Print_Main(); |
| 663 | PyE = 8; |
| 664 | break; |
| 665 | default: |
| 666 | Print_Main(); |
| 667 | } |
| 668 | |
| 669 | m_mouse.Print(); |
| 670 | |
| 671 | // Echange les buffets video |
| 672 | SDL_RenderPresent(sdlRenderer); |
| 673 | |
| 674 | } while (true); |
| 675 | |
| 676 | return mQuit; |
| 677 | } |
| 678 | |
| 679 | /*** SDL Main Menu Choix de la difficulté ***/ |
| 680 | /********************************************/ |
| 681 | eMenu Menu::SDLMain_Speed() |
| 682 | { |
| 683 | // Initialisations Divers |
| 684 | m_mouse.Init(Menu_Py); // Initialise la sourie |
| 685 | PyE = 1; |
| 686 | |
| 687 | // Prend les evenements |
| 688 | do { |
| 689 | Ec.CleanSpriteAndScreen(fmenu); |
| 690 | SDL_RenderClear(sdlRenderer); |
| 691 | // Prend l'image du fond et fait l'affichage |
| 692 | Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); |
| 693 | Sprites[menu].Affiche(400, 340, 0, Sprites[fmenu].Image[0]); |
| 694 | Sprites[titre].Affiche(400, 65, 0, Sprites[fmenu].Image[0]); |
| 695 | |
| 696 | AfficheText(400, 225, T_easy, Sprites[fmenu].Image[0]); |
| 697 | AddBouton(0, T_easy, 400, 225); |
| 698 | AfficheText(400, 340, T_normal, Sprites[fmenu].Image[0]); |
| 699 | AddBouton(1, T_normal, 400, 340); |
| 700 | AfficheText(400, 455, T_hard, Sprites[fmenu].Image[0]); |
| 701 | AddBouton(2, T_hard, 400, 455); |
| 702 | Menu_Py[3].DepX = -1; |
| 703 | |
| 704 | SDL_Event event; |
| 705 | while (SDL_PollEvent(&event)) { |
| 706 | m_mouse.GetEvent(event, PyE); // Handle mouse |
| 707 | m_gamepad.GetEvent(event); // Handle gamepad |
| 708 | |
| 709 | switch (event.type) { |
| 710 | case SDL_WINDOWEVENT: |
| 711 | if (event.window.event == SDL_WINDOWEVENT_ENTER) { |
| 712 | SDL_RenderPresent(sdlRenderer); |
| 713 | } |
| 714 | break; |
| 715 | case SDL_KEYDOWN: |
| 716 | if (event.key.state == SDL_PRESSED) { |
| 717 | m_audio.Play(sClic); |
| 718 | switch (event.key.keysym.sym) { |
| 719 | case SDLK_ESCAPE: |
| 720 | case SDLK_AC_BACK: // Android back button |
| 721 | return mMenu; |
| 722 | case SDLK_UP: |
| 723 | PyE--; |
| 724 | if (PyE < 0) { |
| 725 | PyE = 2; |
| 726 | } |
| 727 | break; |
| 728 | case SDLK_DOWN: |
| 729 | PyE++; |
| 730 | if (PyE > 2) { |
| 731 | PyE = 0; |
| 732 | } |
| 733 | break; |
| 734 | case SDLK_F12: // Save screenshot |
| 735 | if (event.key.repeat == 0) { |
| 736 | Utils::doScreenshot(sdlRenderer); |
| 737 | } |
| 738 | break; |
| 739 | case ' ': |
| 740 | case SDLK_RETURN: |
| 741 | case SDLK_KP_ENTER: |
| 742 | switch (PyE) { |
| 743 | case 0: |
| 744 | Pref.Difficulte = Easy; |
| 745 | return Pref.NiveauMax[Pref.Difficulte] > 0 ? mMenuNiveau : mGame; |
| 746 | case 1: |
| 747 | Pref.Difficulte = Normal; |
| 748 | return Pref.NiveauMax[Pref.Difficulte] > 0 ? mMenuNiveau : mGame; |
| 749 | case 2: |
| 750 | Pref.Difficulte = Hard; |
| 751 | return Pref.NiveauMax[Pref.Difficulte] > 0 ? mMenuNiveau : mGame; |
| 752 | } |
| 753 | break; |
| 754 | default: |
| 755 | break; |
| 756 | } |
| 757 | } |
| 758 | break; |
| 759 | case SDL_QUIT: |
| 760 | return mQuit; |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | // Gère les variables |
| 766 | HorlogeAvant = Horloge; |
| 767 | Horloge = SDL_GetTicks(); |
| 768 | Sleeping(); |
| 769 | |
| 770 | // Gère l'Affichage |
| 771 | Ec.ClearSprite(fmenu); |
| 772 | Print_Main(); |
| 773 | m_mouse.Print(); |
| 774 | |
| 775 | // Echange les buffets video |
| 776 | SDL_RenderPresent(sdlRenderer); |
| 777 | |
| 778 | } while (true); |
| 779 | |
| 780 | return mQuit; |
| 781 | } |
| 782 | |
| 783 | /*** SDL Main Menu Choix du niveau ***/ |
| 784 | /*************************************/ |
| 785 | eMenu Menu::SDLMain_Level() |
| 786 | { |
| 787 | // Initialisations Divers |
| 788 | m_mouse.Init(Menu_Py); // Initialise la sourie |
| 789 | PyE = 0; |
| 790 | Niv = Pref.NiveauMax[Pref.Difficulte]; |
| 791 | Pref.Niveau = 0; |
| 792 | |
| 793 | // Prend les evenements |
| 794 | do { |
| 795 | // Efface le fond |
| 796 | SDL_RenderClear(sdlRenderer); |
| 797 | // Prend l'image du fond et fait l'affichage |
| 798 | Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); |
| 799 | Sprites[menu].Affiche(400, 340, 0, Sprites[fmenu].Image[0]); |
| 800 | Sprites[titre].Affiche(400, 65, 0, Sprites[fmenu].Image[0]); |
| 801 | |
| 802 | AfficheText(400, 225, T_new_game, Sprites[fmenu].Image[0]); |
| 803 | AddBouton(0, T_new_game, 400, 225); |
| 804 | AfficheText(400, 320, T_old_level, Sprites[fmenu].Image[0]); |
| 805 | AddBouton(1, T_old_level, 400, 320); |
| 806 | AfficheText(400, 455, T_menu, Sprites[fmenu].Image[0]); |
| 807 | AddBouton(2, T_menu, 400, 455); |
| 808 | |
| 809 | AddBouton(3, fleches, 330, 380); |
| 810 | AddBouton(4, fleches, 470, 380); |
| 811 | |
| 812 | Menu_Py[5].DepX = -1; |
| 813 | |
| 814 | SDL_Event event; |
| 815 | while (SDL_PollEvent(&event)) { |
| 816 | m_mouse.GetEvent(event, PyE); // Handle mouse |
| 817 | m_gamepad.GetEvent(event); // Handle gamepad |
| 818 | |
| 819 | switch (event.type) { |
| 820 | case SDL_WINDOWEVENT: |
| 821 | if (event.window.event == SDL_WINDOWEVENT_ENTER) { |
| 822 | SDL_RenderPresent(sdlRenderer); |
| 823 | } |
| 824 | break; |
| 825 | case SDL_KEYDOWN: |
| 826 | if (event.key.state == SDL_PRESSED) { |
| 827 | m_audio.Play(sClic); |
| 828 | switch (event.key.keysym.sym) { |
| 829 | case SDLK_ESCAPE: |
| 830 | case SDLK_AC_BACK: // Android back button |
| 831 | return mMenu; |
| 832 | case SDLK_UP: |
| 833 | PyE--; |
| 834 | if (PyE < 0 || PyE > 2) { |
| 835 | PyE = 2; |
| 836 | } |
| 837 | break; |
| 838 | case SDLK_DOWN: |
| 839 | PyE++; |
| 840 | if (PyE > 2) { |
| 841 | PyE = 0; |
| 842 | } |
| 843 | break; |
| 844 | case SDLK_LEFT: |
| 845 | if (Niv > 0) { |
| 846 | Niv--; |
| 847 | } |
| 848 | PyE = 1; |
| 849 | break; |
| 850 | case SDLK_RIGHT: |
| 851 | if (Niv < Pref.NiveauMax[Pref.Difficulte]) { |
| 852 | Niv++; |
| 853 | } |
| 854 | PyE = 1; |
| 855 | break; |
| 856 | case SDLK_F12: // Save screenshot |
| 857 | if (event.key.repeat == 0) { |
| 858 | Utils::doScreenshot(sdlRenderer); |
| 859 | } |
| 860 | break; |
| 861 | case ' ': |
| 862 | case SDLK_RETURN: |
| 863 | case SDLK_KP_ENTER: |
| 864 | switch (PyE) { |
| 865 | case 0: |
| 866 | return mGame; |
| 867 | case 1: |
| 868 | Pref.Niveau = Niv; |
| 869 | return mGame; |
| 870 | case 2: |
| 871 | return mMenu; |
| 872 | case 3: |
| 873 | if (Niv > 0) { |
| 874 | Niv--; |
| 875 | } |
| 876 | break; |
| 877 | case 4: |
| 878 | if (Niv < Pref.NiveauMax[Pref.Difficulte]) { |
| 879 | Niv++; |
| 880 | } |
| 881 | break; |
| 882 | } |
| 883 | break; |
| 884 | default: |
| 885 | break; |
| 886 | } |
| 887 | } |
| 888 | break; |
| 889 | case SDL_QUIT: |
| 890 | return mQuit; |
| 891 | break; |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | // Gère les variables |
| 896 | HorlogeAvant = Horloge; |
| 897 | Horloge = SDL_GetTicks(); |
| 898 | Sleeping(); |
| 899 | |
| 900 | // Gère l'Affichage |
| 901 | Ec.ClearSprite(fmenu); |
| 902 | |
| 903 | // Affiche les flèches |
| 904 | if (Niv > 0) { |
| 905 | if (PyE == 3) { |
| 906 | Ec.PrintSprite(fleches, 2, 330, 380); |
| 907 | } |
| 908 | else { |
| 909 | Ec.PrintSprite(fleches, 1, 330, 380); |
| 910 | } |
| 911 | } |
| 912 | else { |
| 913 | Ec.PrintSprite(fleches, 0, 330, 380); |
| 914 | } |
| 915 | |
| 916 | if (Niv < Pref.NiveauMax[Pref.Difficulte]) { |
| 917 | if (PyE == 4) { |
| 918 | Ec.PrintSprite(fleches, 5, 470, 380); |
| 919 | } |
| 920 | else { |
| 921 | Ec.PrintSprite(fleches, 4, 470, 380); |
| 922 | } |
| 923 | } |
| 924 | else { |
| 925 | Ec.PrintSprite(fleches, 3, 470, 380); |
| 926 | } |
| 927 | |
| 928 | AfficheChiffre(400, 380, Niv + 1); |
| 929 | |
| 930 | if (PyE != 3 && PyE != 4) { |
| 931 | Print_Main(); |
| 932 | } |
| 933 | m_mouse.Print(); |
| 934 | |
| 935 | // Echange les buffets video |
| 936 | SDL_RenderPresent(sdlRenderer); |
| 937 | |
| 938 | } while (true); |
| 939 | |
| 940 | return mQuit; |
| 941 | } |
| 942 | |
| 943 | /*** SDL Main questions sur les droits de l'homme ***/ |
| 944 | /****************************************************/ |
| 945 | #ifndef DCHILDREN |
| 946 | eMenu Menu::SDLMain_HR() |
| 947 | { |
| 948 | int Fini = -1; |
| 949 | int N1, N2, Ordre; |
| 950 | SDL_Rect Position; |
| 951 | |
| 952 | // InitialisationsDivers |
| 953 | m_mouse.Init(Menu_Py); // Initialise la sourie |
| 954 | PyE = rand() % 2; |
| 955 | |
| 956 | // Choix de la question N1=reponse |
| 957 | N1 = rand() % 30; |
| 958 | do { |
| 959 | N2 = rand() % 30; |
| 960 | } while (N2 == N1); |
| 961 | Ordre = rand() % 2; // Si 0=bonne ordre, 1=inverse |
| 962 | |
| 963 | // Prend l'image du fond et fait l'affichage |
| 964 | Position.x = Position.y = 0; |
| 965 | Position.w = Sprites[fmenu].Dim[0].L; |
| 966 | Position.h = Sprites[fmenu].Dim[0].H; |
| 967 | SDL_RenderCopy(sdlRenderer, Sprites[fmenu].Image[0], &Position, &Position); |
| 968 | |
| 969 | Sprites[menu].Affiche(340, 300, 0, Sprites[fmenu].Image[0]); |
| 970 | Sprites[fond_hr].Affiche(340, 74, 0, Sprites[fmenu].Image[0]); |
| 971 | AfficheText(338, 70, e_Sprite(T_question), Sprites[fmenu].Image[0]); |
| 972 | |
| 973 | Sprites[locomotive].Affiche(115, 110, rand() % 320, Sprites[fmenu].Image[0]); |
| 974 | Sprites[deco].Affiche(100, 160 + (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); |
| 975 | Sprites[deco].Affiche(100, 470 - (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); |
| 976 | Sprites[deco].Affiche(580, 100 + (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); |
| 977 | Sprites[deco].Affiche(580, 470 - (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); |
| 978 | |
| 979 | AfficheText(340, 300, e_Sprite(T_art1 + N1), Sprites[fmenu].Image[0]); |
| 980 | |
| 981 | if (Ordre) { |
| 982 | AddBouton(0, e_Sprite(T_tart1 + N1), 240, 492); |
| 983 | AddBouton(1, e_Sprite(T_tart1 + N2), 440, 492); |
| 984 | } |
| 985 | else { |
| 986 | AddBouton(0, e_Sprite(T_tart1 + N1), 440, 492); |
| 987 | AddBouton(1, e_Sprite(T_tart1 + N2), 240, 492); |
| 988 | } |
| 989 | Menu_Py[0].DepY -= 20; |
| 990 | Menu_Py[0].FinY += 20; |
| 991 | Menu_Py[1].DepY -= 20; |
| 992 | Menu_Py[1].FinY += 20; |
| 993 | |
| 994 | Menu_Py[2].DepX = -1; |
| 995 | |
| 996 | std::array<std::pair<int, int>, 4> posDeco = { std::make_pair(rand() % 130, rand() % 18), std::make_pair(rand() % 130, rand() % 18), std::make_pair(rand() % 130, rand() % 18), std::make_pair(rand() % 130, rand() % 18) }; |
| 997 | int const locoPosition = rand() % 320; |
| 998 | |
| 999 | // Prend les evenements |
| 1000 | do { |
| 1001 | // Efface le fond |
| 1002 | SDL_RenderClear(sdlRenderer); |
| 1003 | |
| 1004 | SDL_RenderCopy(sdlRenderer, Sprites[fmenu].Image[0], &Position, &Position); |
| 1005 | |
| 1006 | // Sprites[fond].Affiche(400,300,0,Sprites[fjeu].Image[0]); |
| 1007 | Sprites[menu].Affiche(340, 300, 0, Sprites[fmenu].Image[0]); |
| 1008 | Sprites[fond_hr].Affiche(340, 74, 0, Sprites[fmenu].Image[0]); |
| 1009 | AfficheText(338, 70, e_Sprite(T_question), Sprites[fmenu].Image[0]); |
| 1010 | |
| 1011 | Sprites[locomotive].Affiche(115, 110, locoPosition, Sprites[fmenu].Image[0]); |
| 1012 | Sprites[deco].Affiche(100, 160 + posDeco[0].first, posDeco[0].second, Sprites[fmenu].Image[0]); |
| 1013 | Sprites[deco].Affiche(100, 470 - (posDeco[1].first), posDeco[1].second, Sprites[fmenu].Image[0]); |
| 1014 | Sprites[deco].Affiche(580, 100 + (posDeco[2].first), posDeco[2].second, Sprites[fmenu].Image[0]); |
| 1015 | Sprites[deco].Affiche(580, 470 - (posDeco[3].first), posDeco[3].second, Sprites[fmenu].Image[0]); |
| 1016 | |
| 1017 | AfficheText(340, 300, e_Sprite(T_art1 + N1), Sprites[fmenu].Image[0]); |
| 1018 | /* |
| 1019 | if(Ordre) { |
| 1020 | AddBouton(0,e_Sprite(T_tart1+N1),240,492); |
| 1021 | AddBouton(1,e_Sprite(T_tart1+N2),440,492); |
| 1022 | } |
| 1023 | else { |
| 1024 | AddBouton(0,e_Sprite(T_tart1+N1),440,492); |
| 1025 | AddBouton(1,e_Sprite(T_tart1+N2),240,492); |
| 1026 | } |
| 1027 | Menu_Py[0].DepY-=20; |
| 1028 | Menu_Py[0].FinY+=20; |
| 1029 | Menu_Py[1].DepY-=20; |
| 1030 | Menu_Py[1].FinY+=20; |
| 1031 | |
| 1032 | Menu_Py[2].DepX=-1; |
| 1033 | */ |
| 1034 | SDL_Event event; |
| 1035 | while (SDL_PollEvent(&event)) { |
| 1036 | m_mouse.GetEvent(event, PyE); // Handle mouse |
| 1037 | m_gamepad.GetEvent(event); // Handle gamepad |
| 1038 | |
| 1039 | switch (event.type) { |
| 1040 | case SDL_WINDOWEVENT: |
| 1041 | if (event.window.event == SDL_WINDOWEVENT_ENTER) { |
| 1042 | } |
| 1043 | break; |
| 1044 | case SDL_KEYDOWN: |
| 1045 | if (Fini == -1 && event.key.state == SDL_PRESSED) { |
| 1046 | m_audio.Play(sClic); |
| 1047 | switch (event.key.keysym.sym) { |
| 1048 | case SDLK_ESCAPE: |
| 1049 | case SDLK_AC_BACK: // Android back button |
| 1050 | return mGame; |
| 1051 | case SDLK_UP: |
| 1052 | PyE--; |
| 1053 | if (PyE < 0) { |
| 1054 | PyE = 1; |
| 1055 | } |
| 1056 | break; |
| 1057 | case SDLK_DOWN: |
| 1058 | PyE++; |
| 1059 | if (PyE > 1) { |
| 1060 | PyE = 0; |
| 1061 | } |
| 1062 | break; |
| 1063 | case SDLK_LEFT: |
| 1064 | if (Ordre) { |
| 1065 | PyE = 0; |
| 1066 | } |
| 1067 | else { |
| 1068 | PyE = 1; |
| 1069 | } |
| 1070 | break; |
| 1071 | case SDLK_RIGHT: |
| 1072 | if (Ordre) { |
| 1073 | PyE = 1; |
| 1074 | } |
| 1075 | else { |
| 1076 | PyE = 0; |
| 1077 | } |
| 1078 | break; |
| 1079 | case SDLK_F12: // Save screenshot |
| 1080 | if (event.key.repeat == 0) { |
| 1081 | Utils::doScreenshot(sdlRenderer); |
| 1082 | } |
| 1083 | break; |
| 1084 | case ' ': |
| 1085 | case SDLK_RETURN: |
| 1086 | case SDLK_KP_ENTER: |
| 1087 | switch (PyE) { |
| 1088 | case 0: |
| 1089 | m_audio.Play(sEnd); |
| 1090 | Pref.Score += 50; |
| 1091 | Fini = Horloge + 2000; |
| 1092 | break; |
| 1093 | case 1: |
| 1094 | m_audio.Play(sLose); |
| 1095 | Fini = Horloge + 2000; |
| 1096 | break; |
| 1097 | } |
| 1098 | break; |
| 1099 | default: |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
| 1103 | break; |
| 1104 | case SDL_QUIT: |
| 1105 | return mQuit; |
| 1106 | break; |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | // Test si fini |
| 1111 | if (Fini != -1 && Fini < Horloge) { |
| 1112 | return mGame; |
| 1113 | } |
| 1114 | |
| 1115 | // Gère les variables |
| 1116 | HorlogeAvant = Horloge; |
| 1117 | Horloge = SDL_GetTicks(); |
| 1118 | Sleeping(); |
| 1119 | |
| 1120 | // Gère l'Affichage |
| 1121 | Ec.ClearSprite(fmenu); |
| 1122 | |
| 1123 | if (Ordre) { |
| 1124 | Ec.PrintSprite(fond_hrr, 0, 240, 492); |
| 1125 | AfficheText(240, 492, e_Sprite(T_tart1 + N1)); |
| 1126 | } |
| 1127 | else { |
| 1128 | Ec.PrintSprite(fond_hrr, 0, 440, 492); |
| 1129 | AfficheText(440, 492, e_Sprite(T_tart1 + N1)); |
| 1130 | } |
| 1131 | |
| 1132 | if (Fini == -1) { |
| 1133 | if (Ordre) { |
| 1134 | Ec.PrintSprite(fond_hrr, 0, 440, 492); |
| 1135 | AfficheText(440, 492, e_Sprite(T_tart1 + N2)); |
| 1136 | if (PyE == 0) { |
| 1137 | Print_Main(240); |
| 1138 | } |
| 1139 | else { |
| 1140 | Print_Main(440); |
| 1141 | } |
| 1142 | } |
| 1143 | else { |
| 1144 | Ec.PrintSprite(fond_hrr, 0, 240, 492); |
| 1145 | AfficheText(240, 492, e_Sprite(T_tart1 + N2)); |
| 1146 | if (PyE == 1) { |
| 1147 | Print_Main(240); |
| 1148 | } |
| 1149 | else { |
| 1150 | Print_Main(440); |
| 1151 | } |
| 1152 | } |
| 1153 | m_mouse.Print(); |
| 1154 | } |
| 1155 | |
| 1156 | // Echange les buffets video |
| 1157 | SDL_RenderPresent(sdlRenderer); |
| 1158 | |
| 1159 | } while (true); |
| 1160 | |
| 1161 | return mQuit; |
| 1162 | } |
| 1163 | #endif |
| 1164 | |
| 1165 | /*** SDL Main dans la partie ***/ |
| 1166 | /*******************************/ |
| 1167 | void Menu::Print_InGame() |
| 1168 | { |
| 1169 | SDL_Rect Position; |
| 1170 | |
| 1171 | // InitialisationsDivers |
| 1172 | m_mouse.Init(Menu_Py); // Initialise la sourie |
| 1173 | // PyE=0; |
| 1174 | |
| 1175 | // Prend l'image du fond et fait l'affichage |
| 1176 | Position.x = Position.y = 0; |
| 1177 | Position.w = Sprites[fmenu].Dim[0].L; |
| 1178 | Position.h = Sprites[fmenu].Dim[0].H; |
| 1179 | SDL_RenderCopy(sdlRenderer, Sprites[fmenu].Image[0], &Position, &Position); |
| 1180 | |
| 1181 | Sprites[menu].Affiche(340, 300, 0, Sprites[fmenu].Image[0]); |
| 1182 | |
| 1183 | AfficheText(340, 185, T_continue, Sprites[fmenu].Image[0]); |
| 1184 | AddBouton(0, T_continue, 340, 185); |
| 1185 | AfficheText(340, 300, T_moptions, Sprites[fmenu].Image[0]); |
| 1186 | AddBouton(1, T_moptions, 340, 300); |
| 1187 | AfficheText(340, 415, T_exit_game, Sprites[fmenu].Image[0]); |
| 1188 | AddBouton(2, T_exit_game, 340, 415); |
| 1189 | Menu_Py[3].DepX = -1; |
| 1190 | } |
| 1191 | |
| 1192 | /*** Gestion du menu dans le jeu ***/ |
| 1193 | /***********************************/ |
| 1194 | eMenu Menu::SDLMain_InGame() |
| 1195 | { |
| 1196 | Print_InGame(); |
| 1197 | |
| 1198 | // Prend les evenements |
| 1199 | do { |
| 1200 | SDL_RenderClear(sdlRenderer); |
| 1201 | SDL_Event event; |
| 1202 | while (SDL_PollEvent(&event)) { |
| 1203 | m_mouse.GetEvent(event, PyE); // Handle mouse |
| 1204 | m_gamepad.GetEvent(event); // Handle gamepad |
| 1205 | |
| 1206 | switch (event.type) { |
| 1207 | case SDL_WINDOWEVENT: |
| 1208 | if (event.window.event == SDL_WINDOWEVENT_ENTER) { |
| 1209 | // SDL_RenderPresent(sdlRenderer); |
| 1210 | // Ec.Cls(fmenu); |
| 1211 | } |
| 1212 | break; |
| 1213 | case SDL_KEYDOWN: |
| 1214 | if (event.key.state == SDL_PRESSED) { |
| 1215 | m_audio.Play(sClic); |
| 1216 | switch (event.key.keysym.sym) { |
| 1217 | case SDLK_ESCAPE: |
| 1218 | case SDLK_AC_BACK: // Android back button |
| 1219 | return mGame; |
| 1220 | case SDLK_UP: |
| 1221 | PyE--; |
| 1222 | if (PyE < 0) { |
| 1223 | PyE = 2; |
| 1224 | } |
| 1225 | break; |
| 1226 | case SDLK_DOWN: |
| 1227 | PyE++; |
| 1228 | if (PyE > 2) { |
| 1229 | PyE = 0; |
| 1230 | } |
| 1231 | break; |
| 1232 | case SDLK_F12: // Save screenshot |
| 1233 | if (event.key.repeat == 0) { |
| 1234 | Utils::doScreenshot(sdlRenderer); |
| 1235 | } |
| 1236 | break; |
| 1237 | case ' ': |
| 1238 | case SDLK_RETURN: |
| 1239 | case SDLK_KP_ENTER: |
| 1240 | switch (PyE) { |
| 1241 | case 0: |
| 1242 | return mGame; |
| 1243 | case 1: |
| 1244 | SDLMain_Options(); |
| 1245 | PyE = 1; |
| 1246 | break; |
| 1247 | case 2: |
| 1248 | return mScoreEdit; |
| 1249 | } |
| 1250 | break; |
| 1251 | default: |
| 1252 | break; |
| 1253 | } |
| 1254 | } |
| 1255 | break; |
| 1256 | case SDL_QUIT: |
| 1257 | return mQuit; |
| 1258 | break; |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | // Gère les variables |
| 1263 | HorlogeAvant = Horloge; |
| 1264 | Horloge = SDL_GetTicks(); |
| 1265 | Sleeping(); |
| 1266 | |
| 1267 | // Gère l'Affichage |
| 1268 | Ec.ClearSprite(fmenu); |
| 1269 | Print_InGame(); |
| 1270 | Print_Main(340); |
| 1271 | m_mouse.Print(); |
| 1272 | |
| 1273 | // Echange les buffets video |
| 1274 | SDL_RenderPresent(sdlRenderer); |
| 1275 | |
| 1276 | } while (true); |
| 1277 | |
| 1278 | return mQuit; |
| 1279 | } |
| 1280 | |
| 1281 | /*** SDL Main Menu Choix de la difficulté ***/ |
| 1282 | /********************************************/ |
| 1283 | eMenu Menu::SDLMain_Score(bool EditScore) |
| 1284 | { |
| 1285 | int i; |
| 1286 | int NEdit = -1; |
| 1287 | char Provi[256]; |
| 1288 | int PosCur = 0; |
| 1289 | char key; |
| 1290 | |
| 1291 | // Cherche le numéro du score à remplacer si edition des scores |
| 1292 | if (EditScore) { |
| 1293 | for (i = 7; i >= 0; i--) { |
| 1294 | if (Pref.Sco[i].Score < Pref.Score) { |
| 1295 | NEdit = i; |
| 1296 | } |
| 1297 | } |
| 1298 | if (NEdit == -1) { |
| 1299 | return mMenu; |
| 1300 | } |
| 1301 | |
| 1302 | if (NEdit < 7) { // Si doit fair un décalage |
| 1303 | for (i = 7; i > NEdit; i--) { |
| 1304 | Pref.Sco[i].Score = Pref.Sco[i - 1].Score; |
| 1305 | strcpy(Pref.Sco[i].Name, Pref.Sco[i - 1].Name); |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | // Efface le nouveau nom et met le score |
| 1310 | Pref.Sco[NEdit].Score = Pref.Score; |
| 1311 | Pref.Sco[NEdit].Name[0] = 0; |
| 1312 | } |
| 1313 | |
| 1314 | // Met la sourie sur tous l'ecran |
| 1315 | m_mouse.Init(Menu_Py); // Initialise la sourie |
| 1316 | Menu_Py[0].DepX = 0; |
| 1317 | Menu_Py[0].DepY = 0; |
| 1318 | Menu_Py[0].FinX = 800; |
| 1319 | Menu_Py[0].FinY = 600; |
| 1320 | Menu_Py[0].Py = 0; |
| 1321 | Menu_Py[0].Valide = true; |
| 1322 | Menu_Py[1].DepX = -1; |
| 1323 | |
| 1324 | if (EditScore) { |
| 1325 | SDL_StartTextInput(); |
| 1326 | } |
| 1327 | |
| 1328 | // Prend les evenements |
| 1329 | do { |
| 1330 | // Efface le fond |
| 1331 | Ec.CleanSpriteAndScreen(fmenu); |
| 1332 | SDL_RenderClear(sdlRenderer); |
| 1333 | // Prend l'image du fond et fait l'affichage |
| 1334 | Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); |
| 1335 | |
| 1336 | // Affiche le titre et les commandes |
| 1337 | AfficheText(400, 50, T_better_scores, Sprites[fmenu].Image[0]); |
| 1338 | AfficheText(400, 550, T_press_any_key, Sprites[fmenu].Image[0]); |
| 1339 | |
| 1340 | // Affiche les scores |
| 1341 | for (i = 0; i < 8; i++) { |
| 1342 | sprintf(Provi, "%d", i + 1); |
| 1343 | AfficheString(70, 120 + i * (360 / 7), Provi, Sprites[fmenu].Image[0]); |
| 1344 | |
| 1345 | if (EditScore == false || NEdit != i) { |
| 1346 | if (Pref.Sco[i].Name[0]) { |
| 1347 | AfficheString(140, 120 + i * (360 / 7), Pref.Sco[i].Name, Sprites[fmenu].Image[0]); |
| 1348 | } |
| 1349 | else { |
| 1350 | AfficheString(140, 120 + i * (360 / 7), Points, Sprites[fmenu].Image[0]); |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | sprintf(Provi, "%i", Pref.Sco[i].Score); |
| 1355 | AfficheString(740 - LongueurString(Provi), 120 + i * (360 / 7), Provi, Sprites[fmenu].Image[0]); |
| 1356 | } |
| 1357 | |
| 1358 | // Efface le fond |
| 1359 | SDL_Event event; |
| 1360 | while (SDL_PollEvent(&event)) { |
| 1361 | m_mouse.GetEvent(event, PyE); // Handle mouse |
| 1362 | m_gamepad.GetEvent(event); // Handle gamepad |
| 1363 | |
| 1364 | switch (event.type) { |
| 1365 | case SDL_WINDOWEVENT: |
| 1366 | if (event.window.event == SDL_WINDOWEVENT_ENTER) { |
| 1367 | SDL_RenderPresent(sdlRenderer); |
| 1368 | } |
| 1369 | break; |
| 1370 | case SDL_KEYDOWN: // Prend un touche au clavier |
| 1371 | if (event.key.state == SDL_PRESSED) { |
| 1372 | m_audio.Play(sClic); |
| 1373 | if (EditScore == false && event.key.keysym.sym != SDLK_F12) { |
| 1374 | event.key.keysym.sym = SDLK_RETURN; |
| 1375 | } |
| 1376 | switch (event.key.keysym.sym) { |
| 1377 | case SDLK_F12: // Save screenshot |
| 1378 | if (event.key.repeat == 0) { |
| 1379 | Utils::doScreenshot(sdlRenderer); |
| 1380 | } |
| 1381 | break; |
| 1382 | case SDLK_ESCAPE: // Valide l'entrée |
| 1383 | case SDLK_RETURN: |
| 1384 | case SDLK_KP_ENTER: |
| 1385 | if (EditScore) { |
| 1386 | SDL_StopTextInput(); |
| 1387 | } |
| 1388 | return mMenu; |
| 1389 | case SDLK_BACKSPACE: // Fait un retour de chariot |
| 1390 | if (PosCur) { |
| 1391 | PosCur--; |
| 1392 | Pref.Sco[NEdit].Name[PosCur] = 0; |
| 1393 | } |
| 1394 | break; |
| 1395 | default: |
| 1396 | break; |
| 1397 | } |
| 1398 | } |
| 1399 | break; |
| 1400 | case SDL_TEXTINPUT: |
| 1401 | /* Add new text onto the end of our text */ |
| 1402 | if (LongueurString(Pref.Sco[NEdit].Name) < LSCOREMAX && PosCur < 79 && CharExiste(event.text.text[0])) { |
| 1403 | PosCur += strlen(event.text.text); |
| 1404 | strcat(Pref.Sco[NEdit].Name, event.text.text); |
| 1405 | } |
| 1406 | break; |
| 1407 | case SDL_QUIT: |
| 1408 | if (EditScore) { |
| 1409 | SDL_StopTextInput(); |
| 1410 | } |
| 1411 | return mQuit; |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | // Gère les variables |
| 1416 | HorlogeAvant = Horloge; |
| 1417 | Horloge = SDL_GetTicks(); |
| 1418 | Sleeping(); |
| 1419 | |
| 1420 | if (EditScore) { // Gère l'affiche pour l'édition des scores |
| 1421 | AfficheString(140, 120 + NEdit * (360 / 7), Pref.Sco[NEdit].Name); |
| 1422 | |
| 1423 | i = (Horloge / 50) % 20; // Affiche les curseurs |
| 1424 | Ec.PrintSprite(fleche_gauche, i, 110, 120 + NEdit * (360 / 7)); |
| 1425 | Ec.PrintSprite(fleche_droite, i, 180 + LongueurString(Pref.Sco[NEdit].Name), 120 + NEdit * (360 / 7)); |
| 1426 | } |
| 1427 | |
| 1428 | // Echange les buffets video |
| 1429 | SDL_RenderPresent(sdlRenderer); |
| 1430 | |
| 1431 | } while (true); |
| 1432 | |
| 1433 | if (EditScore) { |
| 1434 | SDL_StopTextInput(); |
| 1435 | } |
| 1436 | return mQuit; |
| 1437 | } |
| 1438 | |
| 1439 | /*** Affiche le menu Principale ***/ |
| 1440 | /**********************************/ |
| 1441 | void Menu::Print_Main(int Centre) const |
| 1442 | { |
| 1443 | int const NumSp = (Horloge / 50) % 20; |
| 1444 | int const x1 = Menu_Py[PyE].DepX - 25; |
| 1445 | int const x2 = (Centre - x1) + Centre; |
| 1446 | int const y = (Menu_Py[PyE].FinY + Menu_Py[PyE].DepY) / 2; |
| 1447 | |
| 1448 | Ec.PrintSprite(fleche_gauche, NumSp, x1, y); |
| 1449 | Ec.PrintSprite(fleche_droite, NumSp, x2, y); |
| 1450 | } |
| 1451 | |
| 1452 | /*** Centre les flèches sur le boutton ***/ |
| 1453 | /*****************************************/ |
| 1454 | void Menu::Affiche_Main_Centre() const |
| 1455 | { |
| 1456 | int const NumSp = (Horloge / 50) % 20; |
| 1457 | int const x1 = Menu_Py[PyE].DepX - 5; |
| 1458 | int const x2 = Menu_Py[PyE].FinX + 5; |
| 1459 | int const y = (Menu_Py[PyE].FinY + Menu_Py[PyE].DepY) / 2; |
| 1460 | |
| 1461 | Ec.PrintSprite(fleche_gauche, NumSp, x1, y); |
| 1462 | Ec.PrintSprite(fleche_droite, NumSp, x2, y); |
| 1463 | } |