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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
| #include "Menu.h"
#include <iostream>
#include <string>
#include <SDL/SDL.h>
#include <SDL_image.h>
#include "Images.h"
#include <fmodex/fmod.h>
#include <SDL_ttf.h>
#include "Jeu.h"
using namespace std;
Menu::Menu()
{
}
int Menu::menuDeJeu()
{
SDL_Surface *menu = NULL, *ecran = NULL, *texteMenu = NULL, *texteMenu1 = NULL, *texteMenu2 = NULL, *texteMenu3 = NULL;
int continuer = 1, changement = 0, tempsPrecedent = 0, tempsActuel = 0, i = 2;
Images img;
Jeu suite;
FMOD_SYSTEM *system1, *system2;
FMOD_SOUND *musiqueMenu = NULL, *selection = NULL;
FMOD_RESULT resultatMenu, resultatSelection;
SDL_Rect positionTexte, positionTexte1, positionTexte2, positionTexte3;
TTF_Font *policeMenu = NULL;
SDL_Color couleurTexte = {0, 255, 0}, couleurTexte1 = {255, 0, 0}, couleurTexte2 = {255, 0, 0}, couleurTexte3 = {255, 0, 0};
TTF_Init();
SDL_putenv ("SDL_VIDEO_CENTERED=center"); //mais la fenetre au centre de l'écran
ecran = SDL_SetVideoMode(800, 500, 32,SDL_HWSURFACE| SDL_DOUBLEBUF);
SDL_WM_SetCaption("Menu", NULL);
menu = IMG_Load("Images/menu.jpg");
FMOD_System_Create(&system1);
FMOD_System_Init(system1, 3, FMOD_INIT_NORMAL, NULL);
FMOD_System_Create(&system2);
FMOD_System_Init(system2, 2, FMOD_INIT_NORMAL, NULL);
resultatMenu = FMOD_System_CreateStream(system1, "Musiques/MusiqueMenu.wma", FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &musiqueMenu);
resultatSelection = FMOD_System_CreateStream(system2, "Musiques/2181.mp3", FMOD_HARDWARE | FMOD_2D, 0, &selection);
// On vérifie si elle a bien été ouverte (IMPORTANT)
if (resultatMenu != FMOD_OK)
{
fprintf(stderr, "Impossible de lire le fichier mp3\n");
exit(EXIT_FAILURE);
}
if (resultatSelection != FMOD_OK)
{
fprintf(stderr, "Impossible de lire le fichier mp3\n");
exit(EXIT_FAILURE);
}
FMOD_System_PlaySound(system1, FMOD_CHANNEL_FREE, musiqueMenu, 0, NULL);
policeMenu = TTF_OpenFont("Polices/Stencil Style New.ttf", 30);
SDL_EnableKeyRepeat(100, 100);
tempsActuel = SDL_GetTicks();
while(continuer)
{
continuer = img.quitter();
texteMenu = TTF_RenderText_Blended(policeMenu, "Nouvelle partie", couleurTexte); // assigne la police, ce qui est écrit, la couleur
texteMenu1 = TTF_RenderText_Blended(policeMenu, "ContrÔles", couleurTexte1);
texteMenu2 = TTF_RenderText_Blended(policeMenu, "Credits", couleurTexte2);
texteMenu3 = TTF_RenderText_Blended(policeMenu, "Quitter", couleurTexte3);
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
if(SDL_GetTicks() - tempsActuel> 1)
{
Uint8 *keystate = SDL_GetKeyState(NULL); // gère le déplacement du héros
img.blittage(-150, 0, menu, ecran);//blittage du fond
img.texte(350, 300, texteMenu, ecran); //tout comme les images mais pour le blittage du texte
img.texte(350, 350, texteMenu1, ecran);// (x, y, source, destination)
img.texte(350, 400, texteMenu2, ecran);
img.texte(350, 450, texteMenu3, ecran);
SDL_Flip(ecran);
if (keystate[SDLK_DOWN])
{
switch(i) // à chaque appuie touche du bas la ligne du menu change et devient verte
{
case 1:
couleurTexte3 = {255, 0, 0};
couleurTexte = {0, 255, 0};
i = 2;
FMOD_System_PlaySound(system2, FMOD_CHANNEL_FREE, selection, 0, NULL);
break;
case 2:
couleurTexte = {255, 0, 0};
couleurTexte1 = {0, 255, 0};
i = 3;
FMOD_System_PlaySound(system2, FMOD_CHANNEL_FREE, selection, 0, NULL);
if (keystate[SDLK_UP])
{
couleurTexte = {255, 0, 0};
couleurTexte3 = {0, 255, 0};
i = 4;
FMOD_System_PlaySound(system2, FMOD_CHANNEL_FREE, selection, 0, NULL);
}
break;
case 3:
couleurTexte1 = {255, 0, 0};
couleurTexte2 = {0, 255, 0};
i = 4;
FMOD_System_PlaySound(system2, FMOD_CHANNEL_FREE, selection, 0, NULL);
break;
case 4:
couleurTexte2 = {255, 0, 0};
couleurTexte3 = {0, 255, 0};
i = 1;
FMOD_System_PlaySound(system2, FMOD_CHANNEL_FREE, selection, 0, NULL);
break;
}
}
else if (keystate[SDLK_RETURN])
{
switch(i)
{
case 1:
FMOD_System_PlaySound(system2, FMOD_CHANNEL_FREE, selection, 0, NULL);
continuer = false;
break;
case 2: //3
FMOD_System_PlaySound(system2, FMOD_CHANNEL_FREE, selection, 0, NULL);
FMOD_Sound_Release(musiqueMenu);
FMOD_Sound_Release(selection);
FMOD_System_Close(system1);
FMOD_System_Release(system1);
FMOD_System_Close(system2);
FMOD_System_Release(system2);
TTF_CloseFont(policeMenu);
TTF_Quit();
SDL_FreeSurface(texteMenu);
SDL_FreeSurface(menu);
SDL_Quit();
suite.ecranDeJeu();
break;
case 3:
FMOD_System_PlaySound(system2, FMOD_CHANNEL_FREE, selection, 0, NULL);
break;
case 4:
FMOD_System_PlaySound(system2, FMOD_CHANNEL_FREE, selection, 0, NULL);
break;
}
}
else if (keystate[SDL_BUTTON_LEFT])
{
FMOD_System_PlaySound(system2, FMOD_CHANNEL_FREE, selection, 0, NULL);
}
tempsActuel = SDL_GetTicks();
}
}
FMOD_Sound_Release(musiqueMenu);
FMOD_Sound_Release(selection);
FMOD_System_Close(system1);
FMOD_System_Release(system1);
FMOD_System_Close(system2);
FMOD_System_Release(system2);
TTF_CloseFont(policeMenu);
TTF_Quit();
SDL_FreeSurface(texteMenu);
SDL_FreeSurface(menu);
SDL_Quit();
return EXIT_SUCCESS;
} |
Partager