// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º CREATEBUTTONS º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Cette proc‚dure initialise les boutons du menu. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
void CreateButtons()
{
bouton[0].x1 = 100; bouton[0].y1 = 100;
bouton[0].x2 = 250; bouton[0].y2 = 140;
bouton[0].etat = 0;
strcpy(bouton[0].text, "JoueR");
bouton[1].x1 = 100; bouton[1].y1 = 150;
bouton[1].x2 = 250; bouton[1].y2 = 190;
bouton[1].etat = 0;
strcpy(bouton[1].text, "OptionS");
/*
bouton[2].x1 = 100; bouton[2].y1 = 200;
bouton[2].x2 = 250; bouton[2].y2 = 240;
bouton[2].etat = 0;
strcpy(bouton[2].text, "High scoreS");
*/
bouton[3].x1 = 100; bouton[3].y1 = 200;
bouton[3].x2 = 250; bouton[3].y2 = 240;
bouton[3].etat = 0;
strcpy(bouton[3].text, "AidE");
bouton[4].x1 = 100; bouton[4].y1 = 250;
bouton[4].x2 = 250; bouton[4].y2 = 290;
bouton[4].etat = 0;
strcpy(bouton[4].text, "QuitteR");
bouton[5].x1 = 540; bouton[5].y1 = 260;
bouton[5].x2 = 580; bouton[5].y2 = 280;
bouton[5].etat = 0;
strcpy(bouton[5].text, "Ok");
bouton[6].x1 = 400; bouton[6].y1 = 260;
bouton[6].x2 = 480; bouton[6].y2 = 280;
bouton[6].etat = 0;
strcpy(bouton[6].text, "Annuler");
bouton[7].x1 = 380; bouton[7].y1 = 140;
bouton[7].x2 = 500; bouton[7].y2 = 160;
bouton[7].etat = 0;
strcpy(bouton[7].text, "Single Player");
bouton[8].x1 = 380; bouton[8].y1 = 200;
bouton[8].x2 = 500; bouton[8].y2 = 220;
bouton[8].etat = 0;
strcpy(bouton[8].text, "Entrez un code");
}
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º INIT_CADRE º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Cette proc‚dure affiche un cadre bleu, point par point, dans le º \\
// º menu. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
void init_cadre()
{
// efface le curseur
_AX = 0x02;
geninterrupt(0x33);
// effacement des menus secondaires (… droite)
setfillstyle(SOLID_FILL, BLACK);
bar(300, 100, 600, 300);
// affiche le curseur
_AX = 0x01;
geninterrupt(0x33);
// on initialise tous les boutons
for (int i=0; i<9; i++)
bouton[i].etat = 0;
// rectangle 300/100 - 600/300
for (i=300; i<600; i++) { putpixel(i, 100, BLUE); delay(1); }
for (i=100; i<300; i++) { putpixel(600, i, BLUE); delay(1); }
for (i=600; i>300; i--) { putpixel(i, 300, BLUE); delay(1); }
for (i=300; i>100; i--) { putpixel(300, i, BLUE); delay(1); }
}
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º CUBE º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Cette proc‚dure affiche un cube dans le menu. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
void cube(float *c, float *s)
{
int i;
float x2[8], y2[8], z2[8], x3[8], y3[8];
static int phi=1, theta=1;
int xcenter=450, ycenter=200, zcenter=300;
int x1[8] = {50,-50,-50,50,50,-50,-50,50};
int y1[8] = {50,-50,50,-50,50,-50,50,-50};
int z1[8] = {-50,-50,-50,-50,50,50,50,50};
setfillstyle(SOLID_FILL, BLACK);
bar(340,101,560,299);
for (i=0; i<8; i++)
{
x2[i] = float(-x1[i] * s[theta] + y1[i] * c[theta]);
y2[i] = float(-x1[i] * c[theta] * s[phi] - y1[i] * s[theta] * s[phi] - z1[i] * c[phi]);
z2[i] = float(-x1[i] * c[theta] * c[phi] - y1[i] * s[theta] * c[phi] + z1[i] * s[phi]);
x3[i] = float(256 * (x2[i] / (z2[i] + zcenter)) + xcenter + (phi-180)*random(5)/45);
y3[i] = float(256 * (y2[i] / (z2[i] + zcenter)) + ycenter + (phi-180)*random(5)/45);
}
setcolor(1); line ( x3[0], y3[0], x3[2], y3[2] );
setcolor(2); line ( x3[0], y3[0], x3[3], y3[3] );
setcolor(3); line ( x3[0], y3[0], x3[4], y3[4] );
setcolor(4); line ( x3[1], y3[1], x3[2], y3[2] );
setcolor(5); line ( x3[1], y3[1], x3[3], y3[3] );
setcolor(6); line ( x3[1], y3[1], x3[5], y3[5] );
setcolor(7); line ( x3[6], y3[6], x3[5], y3[5] );
setcolor(8); line ( x3[6], y3[6], x3[2], y3[2] );
setcolor(9); line ( x3[6], y3[6], x3[4], y3[4] );
setcolor(10);line ( x3[7], y3[7], x3[4], y3[4] );
setcolor(11);line ( x3[7], y3[7], x3[3], y3[3] );
setcolor(12);line ( x3[7], y3[7], x3[5], y3[5] );
phi=(phi+1)%360;
theta=(theta+1)%360;
delay(20);
}
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º MENU_PRINCIPAL º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Cette fonction affiche le menu principal. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
int menu_principal()
{
int mposx=0, mposy=0, mclic=0, i, touche=0, result=-1;
init_cadre();
float c[360], s[360];
for (i=0; i<360; i++)
{
c[i] = cos(i * M_PI / float(180));
s[i] = sin(i * M_PI / float(180));
}
do
{
// cherche le bouton enfonc‚
_AX = 0x03;
geninterrupt(0x33);
mclic = _BX & 1;
mposx = _CX;
mposy = _DX;
for (i=0; i<5; i++)
{
if (((mposx >= bouton[i].x1) && (mposx <= bouton[i].x2)) && ((mposy >= bouton[i].y1) && (mposy<=bouton[i].y2)))
{
if (mclic)
{ bouton[i].etat=1; result=i; }
else
setcolor(RED);
}
else
setcolor(YELLOW);
rectangle(bouton[i].x1,bouton[i].y1, bouton[i].x2, bouton[i].y2);
setcolor(CYAN);
outtextxy(bouton[i].x1+(bouton[i].x2-bouton[i].x1)/2, bouton[i].y1+(bouton[i].y2-bouton[i].y1)/2, bouton[i].text);
}
if (kbhit()) touche = getch();
cube(c, s);
}
while ((touche!=13) && (result==-1));
return result;
}
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º MENU_JOUER º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Cette fonction affiche le sous-menu jouer. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
int menu_jouer()
{
int mposx=0, mposy=0, mclic=0, i, touche;
long int code;
char msg[25];
int result=-1;
init_cadre();
settextjustify(CENTER_TEXT, CENTER_TEXT);
do
{
// cherche le bouton enfonc‚
_AX = 0x03;
geninterrupt(0x33);
mclic = _BX & 1;
mposx = _CX;
mposy = _DX;
for (i=0; i<9; i++)
{
if (i==5) i++;
if (((mposx >= bouton[i].x1) && (mposx <= bouton[i].x2)) && ((mposy >= bouton[i].y1) && (mposy<=bouton[i].y2)))
{
if (mclic)
{ bouton[i].etat=1; result = i; }
else
setcolor(RED);
}
else
setcolor(YELLOW);
rectangle(bouton[i].x1,bouton[i].y1, bouton[i].x2, bouton[i].y2);
setcolor(CYAN);
outtextxy(bouton[i].x1+(bouton[i].x2-bouton[i].x1)/2, bouton[i].y1+(bouton[i].y2-bouton[i].y1)/2, bouton[i].text);
}
if (kbhit()) touche = getch();
}
while ((touche!=13) && (result==-1));
if (bouton[8].etat==1)
{
outtextxy(510, 210, "->");
gotoxy(66, 14);
scanf("%li", &code);
code=SearchMap(code);
if (code==-1)
{
outtextxy(400, 240, "Mauvais Code");
bouton[8].etat=0;
delay(1000);
}
else
{
jeu.nivo=code;
sprintf(msg, "Bon code : nivo%d", jeu.nivo);
outtextxy(400, 240, msg);
delay(1000);
}
}
return result;
}
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º MENU_OPTIONS º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Cette fonction affiche le sous-menu des options. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
int menu_options(struct_pacman &pacman)
{
int mposx=0, mposy=0, mclic=0, i, touche, color1=pacman.color, color2=jeu.bkground, son=jeu.son, select;
char msg[25];
int result=-1;
LoadOptions("options.map", pacman);
init_cadre();
setcolor(LIGHTRED);
settextjustify(LEFT_TEXT, CENTER_TEXT);
outtextxy(350, 150, "Son");
outtextxy(350, 175, "Couleur Pacman");
outtextxy(350, 200, "Couleur BackGround");
select=0;
settextjustify(CENTER_TEXT, CENTER_TEXT);
do
{
// cherche le bouton enfonc‚
_AX = 0x03;
geninterrupt(0x33);
mclic = _BX & 1;
mposx = _CX;
mposy = _DX;
if ((touche == 72) && (select>0)) select--;
if ((touche == 80) && (select<2)) select++;
setcolor(WHITE);
setfillstyle(SOLID_FILL, BLACK);
sprintf(msg, "%s", (son==0)?"OFF":"ON");
if (select==0)
{
setfillstyle(SOLID_FILL, WHITE);
if (touche == 75) { son=0; setcolor(BLACK); }
if (touche == 77) { son=1; setcolor(BLACK); }
}
outtextxy(560, 150, msg);
setcolor(WHITE);
pieslice(325, 150, 0, 360, 5);
setfillstyle(SOLID_FILL, BLACK);
// couleur du pacman (diff‚rente du background)
if (select==1)
{
setfillstyle(SOLID_FILL, WHITE);
if (touche == 75)
{
color1--;
if (color1==color2) color1--;
if (color1<0) color1+=16;
}
if (touche == 77)
{
color1++;
if (color1==color2) color1++;
if (color1>15) color1-=16;
}
}
pieslice(325, 175, 0, 360, 5);
setfillstyle(SOLID_FILL, color1);
bar3d (550, 165, 580, 185, 1, 0);
setfillstyle(SOLID_FILL, BLACK);
if (color1==color2) color1++;
// couleur background (diff‚rente du monstre (red))
if (select==2)
{
setfillstyle(SOLID_FILL, WHITE);
if (touche == 75)
{
color2--;
if (color2==RED) color2--;
if (color1<0) color1+=16;
}
if (touche == 77)
{
color2++;
if (color2==RED) color2++;
if (color1>15) color1-=16;
}
}
pieslice(325, 200, 0, 360, 5);
setfillstyle(SOLID_FILL, color2);
bar3d (550, 190, 580, 210, 1, 0);
for (i=0; i<7; i++)
{
if (((mposx >= bouton[i].x1) && (mposx <= bouton[i].x2)) && ((mposy >= bouton[i].y1) && (mposy<=bouton[i].y2)))
{
if (mclic)
{ bouton[i].etat=1; result = i; }
else
setcolor(RED);
}
else
setcolor(YELLOW);
rectangle(bouton[i].x1,bouton[i].y1, bouton[i].x2, bouton[i].y2);
setcolor(CYAN);
outtextxy(bouton[i].x1+(bouton[i].x2-bouton[i].x1)/2, bouton[i].y1+(bouton[i].y2-bouton[i].y1)/2, bouton[i].text);
}
touche=0;
if (kbhit()) touche = getch();
}
while ((touche!=13) && (result==-1));
// btn OK
if (result == 5)
{
color1=color1%16;
while (color1<0) color1+=16;
color2=color2%16;
while (color2<0) color2+=16;
pacman.color=color1;
jeu.bkground=color2;
jeu.son=son;
WriteOptions("Options.map", pacman);
}
return result;
}
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º MENU_AIDE º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Cette fonction affiche le sous-menu de l'aide. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
int menu_aide()
{
int mposx=0, mposy=0, mclic=0, i, j, k, size, touche;
char msg[300], c[1];
int result=-1;
init_cadre();
setcolor(LIGHTRED);
settextjustify(LEFT_TEXT, CENTER_TEXT);
k=0, j=0, size=20;
sprintf(msg, "Pour faire bouger Pacman, vous devez utiliser les touches fl‚ch‚es. Une simple pression suffit … le faire avancer. Pour quitter, utilisez la touche Entr‚e. Pour plus d'infos, lisez le fichier Readme. Have Fun, Julien Durieux & R‚mi Duhautoy.");
settextjustify(CENTER_TEXT, CENTER_TEXT);
do
{
settextjustify(CENTER_TEXT, CENTER_TEXT);
// cherche le bouton enfonc‚
_AX = 0x03;
geninterrupt(0x33);
mclic = _BX & 1;
mposx = _CX;
mposy = _DX;
for (i=0; i<6; i++)
{
if (((mposx >= bouton[i].x1) && (mposx <= bouton[i].x2)) && ((mposy >= bouton[i].y1) && (mposy<=bouton[i].y2)))
{
if (mclic)
{ bouton[i].etat=1; result = i; }
else
setcolor(RED);
}
else
setcolor(YELLOW);
rectangle(bouton[i].x1,bouton[i].y1, bouton[i].x2, bouton[i].y2);
setcolor(CYAN);
outtextxy(bouton[i].x1+(bouton[i].x2-bouton[i].x1)/2, bouton[i].y1+(bouton[i].y2-bouton[i].y1)/2, bouton[i].text);
}
if (k<=strlen(msg))
{
settextjustify(LEFT_TEXT, CENTER_TEXT);
sprintf(c, "%c", msg[k]);
outtextxy(325+size, 125+j, c);
size+=textwidth(c);
if ((size>200) && (c[0]==' ')) { size = 0; j += 10; }
if (c[0]=='.') { size=10; j+=20; }
delay(30);
k++;
}
if (kbhit()) touche = getch();
}
while ((touche!=13) && (result==-1));
settextjustify(CENTER_TEXT, CENTER_TEXT);
return result;
}