// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º Super Hyper Mega º \\
// º P A C M A N º \\
// º Extra Version Gold Deluxe º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ º \\
// º ³ Compilateur et options de compilation ³ º \\
// º ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ º \\
// º ³ þ Borland © Turbo C++ 3.0 ³ º \\
// º ³ þ M‚moire Large (options/compiler/code generation/model->large) ³ º \\
// º ³ þ Graphics.h (options/linker/librairies->Graphics Librairy ON) ³ º \\
// º ³ þ 256 ko (options/debugger/program heap size->256 ko) ³ º \\
// º ³ þ Changer le r‚pertoire courant (file/change dir...) ³ º \\
// º ³ ³ º \\
// º ³ þ A COMPILER DE PREFERENCE SOUS WINDOWS 95/98/ME. ³ º \\
// º ³ Une compilation sous WinNT pose trop souvent des problŠmes. ³ º \\
// º ³ ³ º \\
// º ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º HEADERS DU COMPILATEUR º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Chargements des headers n‚cessaires … Turbo C. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
#include <graphics.h> // Header graphique
#include <conio.h> // Header pour la console d'entr‚e/sortie
#include <stdio.h> // Header d'entr‚e/sortie
#include <dos.h> // Header pour les fonctions de dos
#include <stdlib.h> // Header pour les librairies standard
#include <math.h> // Header pour les fonctions math‚matiques
#include <string.h> // Header pour la gestion des chaŒnes
#include <bios.h> // Header pour avoir les bonnes touches
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º CONSTANTES º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Cr‚ation et initialisation des constantes. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
#define EXIT { fclose(fichier); exit(0); } // permet de quitter plus rapidement un fichier
#define T_CASE 20 // taille d'une case (en pixel)
#define T_CASE_2 10 // taille d'une demi-case (en pixel)
#define M_SOL 0 // sol sans boule
#define M_SOLB 1 // sol avec boule
#define M_PACMAN 2 // point de d‚part du pacman
#define M_MONSTRE 3 // point de d‚part des monstres
#define M_BONUS 4 // emplacement des bonus
#define M_CLE 5 // emplacement d'une cl‚
#define M_PORTE 6 // emplacement d'une porte
#define M_MUR 7 // emplacement des murs
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º VARIABLES GLOBALES º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Cr‚ation d'une structure pour les niveaux. º \\
// º þ Cr‚ation d'une structure pour les boutons du menu. º \\
// º þ Cr‚ation d'une structure pour Pacman. º \\
// º þ Cr‚ation d'une structure pour les monstres. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
struct struct_jeu
{
int nivo; // niveau en cours
int score; // score pour le high score
int sec; // secondes de jeu
int min; // minutes de jeu
char nom[10]; // nom du joueur
int son; // son (1 : activ‚)
int nb_nivo; // nombre de niveaux
int bkground; // couleur de background
int min_score; // score minimum … battre pour se placer dans le high score
struct struct_nivo
{
char nom_map[15]; // nom d'une map
} path[50]; // nombre de maps charg‚es
struct struct_score // sous structure de chargement des maps
{
char nom[15]; // nom du joueur dans le high score
int points; // et ses points
} hscore[5]; // sous structure de chargement des high scores
} jeu; // structure de la partie
struct struct_boutons
{
int x1, x2, y1, y2, etat; // position et etat du bouton
char text[25]; // texte du bouton
} bouton[10]; // structure d'un bouton
typedef struct
{
int val[20][20]; // matrice de la carte charg‚e (largeur x et hauteur y)
int width; // largeur (en case)
int height; // hauteur (en case)
int coinx; // haut gauche (x) de la map (en pixel)
int coiny; // haut gauche (y) de la map (en pixel)
char nom[20]; // nom de la map
long int code; // code barre de la map
int boules; // compte le nombre de boules
int load; // map charg‚e (0 : non / 1 : oui)
int nb_monstres; // nombre de monstres dans le niveau
} struct_map; // nom de la structure
typedef struct
{
int touch1; // premiŠre touche appuy‚e
int touch2; // seconde touche appuy‚e
float startx; // position de d‚part de Pacman (x)
float starty; // position de d‚part de Pacman (y)
float x; // position r‚el de Pacman (x)
float y; // position r‚el de Pacman (y)
float oldx; // position pr‚c‚dente de Pacman (x)
float oldy; // position pr‚c‚dente de Pacman (y)
int bouge; // 0 : no move / 1 : bouge
long int score; // score effectu‚
int angle; // angle form‚ par la bouche
int ouvre; // ouvre (ou non) la bouche
int vie; // le nombre de vie de Pacman
int color; // couleur du pacman
int mort; // pacman mang‚
} struct_pacman; // nom de la structure
typedef struct
{
int touch1; // d‚placement principal du monstre
int touch2; // d‚placement secondaire du monstre
float startx; // position de d‚part du monstre (x)
float starty; // position de d‚part du monstre (y)
float x; // position r‚el du monstre (x)
float y; // position r‚el du monstre (y)
float oldx; // position pr‚c‚dente du monstre (x)
float oldy; // position pr‚c‚dente du monstre (y)
int bouge; // 0 : no move / 1 : bouge
} struct_monstre; // nom de la structure
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º HEADERS DU PROGRAMME º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Chargements des headers n‚cessaires au programme. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
#include "extra.h"
// int SearchMap(long int code)
// void LoadOptions(char *option_name, struct_pacman &pacman)
// void WriteOptions(char *option_name, struct_pacman &pacman)
// int LoadScore(char *score_name)
// void WriteScore(char *score_name, char j_nom[10], int points)
// int getkey()
// void random_touch(int &touch1, int &touch2)
// void joue_son(int hertz, int delay_son, int delay_no_son)
// void intro()
// void init_graph()
#include "affiche.h"
// void affiche_score (long int score, int refresh)
// void affiche_vie (int vie, int refresh)
// void affiche_bonus(int bonus, int refresh)
// void affiche_temps(struct time *t, struct time *told, struct time *deb, struct_jeu *jeu)
// void affiche_nivo(char *msg, int refresh)
// void affiche_HighScore(int pos)
#include "draw.h"
// void draw_mur (int x, int y, struct_map *map)
// void draw_boule (int x, int y, struct_map *map)
// void draw_megaboule (int x, int y, struct_map *map)
// void draw_monstre(struct_monstre *monstre, int move, struct_map *map)
// void draw_pacman(struct_pacman &pacman, int move, struct_map *map)
// void draw_map(struct_pacman &pacman, struct_monstre *monstre, struct_map *map)
// int LoadMAP(char *map_name, struct_map *map, long int code)
// int LoadMAPS(char *map_name)
#include "menu.h"
// void CreateButtons()
// void init_cadre()
// void cube(float *c, float *s)
// int menu_principal()
// int menu_jouer()
// int menu_options(struct_pacman &pacman)
// int menu_aide()
// affiche.h : 210 lignes
// draw.h : 620 lignes
// extra.h : 460 lignes
// menu.h : 500 lignes
// main.cpp : 690 lignes
// ----------------------
// total : 2480 lignes
// ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» \\
// º º \\
// º MAIN º \\
// º º \\
// ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ \\
// º º \\
// º þ Fonction principale du programme. º \\
// º º \\
// ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ \\
int main()
{
randomize();
init_graph();
cleardevice(); // effacement de l'‚cran
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ LES VARIABLES LOCALES ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
char msg[80];
float t;
int x;
int y;
int midx = getmaxx()/2;
int midy = getmaxy()/2;
int nb_m; // boucle pour les monstres
int nb_btn=-1; // bouton cliqu‚
int map_dist; // distance entre un coin et le milieu de la map
jeu.nivo = 1; // on demande le permier niveau
jeu.bkground = 2; // couleur de background
struct_map map; // variable locale pour la map
map.load = 0; // map pas encore charg‚e
struct_pacman pacman; // variable locale pour Pacman
pacman.touch1 = 0; // Touche enfonc‚e nø1
pacman.touch2 = 0; // Touche enfonc‚e nø2
pacman.score = 0; // score initialis‚ … 0
pacman.angle = 0; // angle de la bouche de Pacman est 0 degr‚
pacman.ouvre = 1; // Pacman ouvre donc la bouche (1 pour ouvrir / 0 pour fermer)
pacman.mort = 0; // on va dire que Pacman est en vie, c'est mieux !)
struct_monstre *monstre; // variable locale pour le monstre
monstre = (struct_monstre *) malloc(sizeof(struct_monstre));
CreateButtons(); // cr‚ation des boutons du menu (pas d'affichage)
LoadOptions("options.map", pacman); // chargement des options
jeu.nb_nivo=LoadMAPS("nivo.map"); // chargement des niveaux
jeu.min_score=LoadScore("score.map"); // chargement des high scores
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ L'INTRODUCTION ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
delay(1500);
intro();
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ LE MENU ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
// TITRE
setcolor(12); // rouge clair
settextjustify(CENTER_TEXT, CENTER_TEXT); // centr‚ horizontalement et verticalement
settextstyle(10, HORIZ_DIR, 4); // nø de police, ‚crire horizontalement, taille 4
outtextxy(midx, 30, "PACMAN"); // on place et on ‚crit le texte
settextstyle(2, 0, 5);
// centre la souris
_AX = 0x00;
geninterrupt(0x33);
// affiche la souris
_AX = 0x01;
geninterrupt(0x33);
settextjustify(CENTER_TEXT, CENTER_TEXT);
do
{
if (nb_btn>4) nb_btn=-1; // si on a appuy‚ sur Ok ou Annuler, on retourne au menu principal
if (nb_btn==-1) nb_btn=menu_principal();
if (nb_btn==0) nb_btn=menu_jouer(/*&map*/);
if (nb_btn==1) nb_btn=menu_options(pacman);
if (nb_btn==3) nb_btn=menu_aide();
do
{
// cherche le bouton enfonc‚
_AX = 0x03;
geninterrupt(0x33);
}
while (_BX & 1 != 0);
}
while ((nb_btn!=4) && (nb_btn<7));
// bouton 4 : Quitter / 7 ‚tant le nombre total de boutons
// efface le curseur
_AX = 0x02;
geninterrupt(0x33);
delay(1000);
free(bouton); // on libŠre la m‚moire, les boutons prennent bcp de place
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ LE JEU ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
struct time temps; // variable locale pour le temps
struct time tempsold; // variable locale pour le temps
struct time temps_deb; // variable locale pour le temps
gettime (&temps_deb);
gettime (&tempsold);
// si on a pas appuy‚ sur le bouton Quitter
if (nb_btn!=4)
{
delay(1000);
// efface l'‚cran (mieux que cleardevice ?)
setfillstyle(SOLID_FILL, BLACK);
bar(0,0,639,439);
// TITRE
setcolor(LIGHTRED);
settextjustify(CENTER_TEXT, CENTER_TEXT); // centr‚ horizontalement et verticalement
settextstyle(10, HORIZ_DIR, 4); // nø de police, ‚crire horizontalement, taille 4
outtextxy(midx, 30, "PACMAN"); // on place et on ‚crit le texte
setcolor(YELLOW);
settextjustify(LEFT_TEXT, CENTER_TEXT); // centr‚ horizontalement et verticalement
settextstyle(2, HORIZ_DIR, 6); // nø de police, ‚crire horizontalement, taille 4
outtextxy(520, 100, "POINTS :"); // on place et on ‚crit le texte
outtextxy(520, 160, "VIES :");
outtextxy(520, 220, "BONUS :");
outtextxy(520, 280, "TEMPS :");
outtextxy(520, 340, "NIVEAU :");
delay(1000);
affiche_HighScore(0); // affiche le high score … gauche
delay(1000);
// tq on appuie pas sur Entr‚e, qu'on a pas fini le jeu et qu'on est pas mort
while ((pacman.touch1!=13) && (jeu.nivo<=jeu.nb_nivo) && (pacman.vie>=0))
{
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ CHARGEMENT DE LA MAP ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
if (map.load==0)
{
affiche_nivo(map.nom, 1);
sprintf(msg, "%s", jeu.path[jeu.nivo-1].nom_map);
map.nb_monstres=LoadMAP(msg, &map, 39416587);
monstre = (struct_monstre *) realloc(monstre, map.nb_monstres * sizeof(struct_monstre));
// DESSINE LA MAP
draw_map(pacman, monstre, &map);
map.load=1;
affiche_nivo(map.nom, 0);
// initialisation des d‚placements des monstres
for (nb_m=0; nb_m<map.nb_monstres; nb_m++)
{
monstre[nb_m].bouge = 1; // on active les d‚placements du monstre
monstre[nb_m].touch1 = 0; // on initialise la premiŠre direction du monstre
random_touch(monstre[nb_m].touch1, monstre[nb_m].touch2); // on "randomize" les d‚placements
}
map_dist=(int)sqrt(pow(map.width/2,2) + pow(map.height/2,2));
}
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ BOUGE LE MONSTRE ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
// on affiche et on d‚place tous les monstres, un par un
for (int nb_m=0; nb_m<map.nb_monstres; nb_m++)
{
if ((int)sqrt(pow(pacman.x-monstre[nb_m].x,2) + pow(pacman.y-monstre[nb_m].y,2))>map_dist)
{
if (monstre[nb_m].x<pacman.x) monstre[nb_m].touch1=3; // droite
if (monstre[nb_m].x>pacman.x) monstre[nb_m].touch1=2; // gauche
if (monstre[nb_m].y<pacman.y) monstre[nb_m].touch2=4; // bas
if (monstre[nb_m].y>pacman.y) monstre[nb_m].touch2=1; // haut
}
else
{
if (monstre[nb_m].bouge == 0)
{
monstre[nb_m].touch1=0;
random_touch(monstre[nb_m].touch1, monstre[nb_m].touch2);
}
}
// fait bouger le monstre sans d‚placement (evite le scintillement)
if (monstre[nb_m].bouge == 0)
{
monstre[nb_m].bouge=1;
draw_monstre(&monstre[nb_m], 0, &map);
}
else
{
// on fait bouger le monstre avec son d‚placement principal
draw_monstre(&monstre[nb_m], 2, &map);
if (monstre[nb_m].bouge==0)
{
monstre[nb_m].bouge=1;
draw_monstre(&monstre[nb_m], 1, &map);
}
else
{
monstre[nb_m].touch1=monstre[nb_m].touch2;
random_touch(monstre[nb_m].touch1, monstre[nb_m].touch2);
}
}
}
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ BOUGE PACMAN ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
fflush(stdin); // on vide le buffer du clavier
// si on appuie sur une touche et que le d‚placement principal est nul (cad que Pacman ne bouge plus)
if ((kbhit()) && (pacman.touch1==0))
{
pacman.bouge=1; // on fait bouger Pacman
pacman.touch1=getkey(); // on lit la touche
}
// on dessine Pacman sans le d‚placer
draw_pacman(pacman, 0, &map);
if ((pacman.bouge == 1) && (pacman.touch1 != 13))
{
if (kbhit())
{
if (pacman.touch2==0) pacman.touch2=pacman.touch1;
pacman.touch1=getkey();
}
draw_pacman(pacman, 1, &map);
if ((pacman.bouge == 1) && (pacman.touch2 != 0)) pacman.touch2=0;
if ((pacman.bouge == 0) && (pacman.touch2 != 0))
{
pacman.bouge=1;
draw_pacman(pacman, 2, &map);
}
if (pacman.bouge==0) pacman.touch1=0;
}
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ AFFICHE LES SCORES ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
settextjustify(LEFT_TEXT, CENTER_TEXT); // centr‚ horizontalement et verticalement
settextstyle(2, HORIZ_DIR, 6); // nø de police, ‚crire horizontalement, taille 4
affiche_vie (pacman.vie,1);
affiche_bonus(0,1);
affiche_score(pacman.score, 1);
gettime(&temps);
affiche_temps(&temps, &tempsold, &temps_deb);
delay(20/(map.nb_monstres/2+1));
nosound();
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ SI ON RETIRE TOUTES LES BOULES DE LA MAP ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
if (map.boules == 0)
{
setcolor(YELLOW);
setfillstyle (SOLID_FILL, RED);
bar3d (midx-100, midy-20, midx+100, midy+50, 0, 1);
settextjustify(CENTER_TEXT, CENTER_TEXT); // centr‚ horizontalement et verticalement
settextstyle(2, 0, 6);
outtextxy(midx, midy-10, "Bravo");
setcolor(WHITE);
sprintf(msg, "Le code : %li", map.code);
outtextxy(midx, midy+15, msg);
joue_son(1000,50,50);
joue_son(1000,50,50);
joue_son(1000,50,50);
joue_son(2000,150,50);
joue_son(1000,50,50);
joue_son(2000,250,0);
setcolor(YELLOW);
settextstyle(2, 0, 5);
outtextxy(midx, midy+40, "Appuyez sur Entr‚e ...");
while (pacman.touch1!=13) if (kbhit()) pacman.touch1=getkey(); // = getch()
// efface la magic box
setcolor(BLACK);
setfillstyle (SOLID_FILL, BLACK); // style solide, couleur rouge
bar3d (midx-100, midy-20, midx+100, midy+50, 0, 1);
// efface la map
map.coinx = (640-T_CASE*(map.width+1))/2; // on calcule la taille par rapport
map.coiny = (450-T_CASE*(map.height)); // a la taille trouvee dans le fichier map
setfillstyle (SOLID_FILL, BLACK); // style solide, couleur rouge
bar (map.coinx,map.coiny,T_CASE*map.width+map.coinx,450);
// r‚initialisation des variables
map.load=0; // on rechargera la map
jeu.nivo++; // on passe au niveau suivant
pacman.touch1=0;
pacman.touch2=0;
}
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ SI ON SE FAIT MANGER PAR UN MONSTRE (COLLISION) ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
for (nb_m=0; nb_m<map.nb_monstres; nb_m++)
if ((pacman.x-1<monstre[nb_m].x) && (pacman.x+1>monstre[nb_m].x))
if ((pacman.y-1<monstre[nb_m].y) && (pacman.y+1>monstre[nb_m].y))
pacman.mort=1;
if (pacman.mort==1)
{
x = map.coinx+(pacman.x)*T_CASE;
y = map.coiny+(pacman.y)*T_CASE;
for (nb_m=9; nb_m>=0; nb_m--)
{
setcolor(pacman.color);
setfillstyle(SOLID_FILL, pacman.color);
pieslice (x, y, 0, 360, nb_m);
switch (nb_m)
{
case 0 : joue_son(1000,50,150); break;
case 1 : joue_son(1200,200,0); break;
case 2 : joue_son(1100,100,100); break;
case 3 : joue_son(1000,50,150); break;
case 4 : joue_son(1400,100,100); break;
case 5 : joue_son(1200,100,100); break;
case 6 : joue_son(1000,50,150); break;
case 7 : joue_son(1800,100,100); break;
case 8 : joue_son(1400,50,150); break;
case 9 : joue_son(1000,50,150); break;
}
setcolor(jeu.bkground);
setfillstyle(SOLID_FILL, jeu.bkground);
pieslice (x, y, 0, 360, nb_m);
}
joue_son(900,100,100);
joue_son(800,300,0);
affiche_vie (pacman.vie, 0);
pacman.vie--;
pacman.touch1=0; // Touche enfonc‚e nø1
pacman.touch2=0; // Touche enfonc‚e nø2
pacman.x=pacman.startx;
pacman.y=pacman.starty;
pacman.bouge=0;
pacman.mort=0;
// on remet les monstres … leur point de d‚part
for (nb_m=0; nb_m<map.nb_monstres; nb_m++)
{
monstre[nb_m].x=monstre[nb_m].startx;
monstre[nb_m].y=monstre[nb_m].starty;
monstre[nb_m].bouge=1;
draw_monstre(&monstre[nb_m], 0, &map);
}
}
}
} // fin si bouton quitter non cliqu‚
// ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ \\
// ³ FIN DE LA PARTIE ³ \\
// ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ \\
cleardevice();
setcolor(YELLOW);
setfillstyle (SOLID_FILL, RED);
bar3d (midx-150, 20, midx+150, 80, 0, 1);
settextstyle(2, HORIZ_DIR, 6); // nø de police, ‚crire horizontalement, taille 4
settextjustify(CENTER_TEXT, CENTER_TEXT); // centr‚ horizontalement et verticalement
outtextxy(midx, 40, "Jeu Fini");
settextstyle(2, HORIZ_DIR, 6); // nø de police, ‚crire horizontalement, taille 4
settextstyle(2, HORIZ_DIR, 5); // nø de police, ‚crire horizontalement, taille 4
sprintf(msg, "Votre Score : %d points", pacman.score);
outtextxy(midx, 100, msg);
sprintf(msg, "Votre Temps : %02dm %02ds", jeu.min, jeu.sec);
outtextxy(midx, 125, msg);
if (pacman.score==0)
outtextxy(midx, 150, "Salut");
if ((pacman.score>0) && (pacman.score<10))
outtextxy(midx, 150, "La Honte");
if ((pacman.score>10) && (pacman.score<100))
outtextxy(midx, 150, "Mouais ...");
if ((pacman.score>100) && (pacman.score<500))
outtextxy(midx, 150, "Bien");
if (pacman.score>500)
outtextxy(midx, 150, "Excellent");
if (pacman.score>jeu.min_score)
{
setcolor(BLUE);
outtextxy(midx, 200, "Vous Entrez Dans Le High Score !!");
outtextxy(midx, 230, "Entrez Votre Nom :");
do
{
gotoxy(51,15);
scanf("%s", &jeu.nom);
} while (jeu.nom[0]=='\n');
setcolor(YELLOW);
WriteScore("score.map", jeu.nom, pacman.score);
}
outtextxy(midx, 60, "Appuyez sur Entr‚e pour Quitter ...");
LoadScore("score.map");
affiche_HighScore(270);
free(monstre);
pacman.touch1=0;
while (pacman.touch1!=13) if (kbhit()) pacman.touch1=getkey(); // = getch()
closegraph();
return 0;
}