Pascal/Turbo Pascal - Ayuda con el código del juego pacman

 
Vista:
sin imagen de perfil

Ayuda con el código del juego pacman

Publicado por oswaldo (11 intervenciones) el 23/04/2013 08:37:08
Buenas amigo, sera que me puede ayudar con algun codigo fuente de el juego de pacman en pascal, dev pascal o free pascal. encontre un condigo pero no compila, tiene muchos errores. en esta pagina http://n.bernier.free.fr/pascal/pacman/ ...

Por favor, Saludos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Ayuda con el código del juego pacman

Publicado por ramon (2158 intervenciones) el 23/04/2013 23:30:10
Pero el juego completo o una simulación en modo mini
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con el código del juego pacman

Publicado por ramon (2158 intervenciones) el 24/04/2013 23:16:08
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
{A ver funciona pero tiene asociados archivos pcx por ello teda el error va en partes}
 
program pacman;
 
{$G+} { Activation des instructions 286 / 287 }
 
uses Crt, Dos;
 
 
{ ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ
  Û D‚claration des constantes, types et variables Û
  ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ }
 
const
   { Tableau des directions }
   tdir : array[0..4, 1..2] of integer = ((0, -1), (-1, 0), (0, 1), (1, 0), (0, 0));
                                          { Haut    Gauche    Bas   Droite }
   MAX_NB_FANT = 10;                      { Nombre maximum de fant“mes }
 
type
   spr10    = array[0..100]       of byte;   { Sprite 10 * 10 }
   pal      = array[0..767]       of byte;   { Palette 256 * 3 }
   ecran    = array[0..64000]     of byte;   { Ecran 320 * 200 }
   niveau   = array[0..33, 0..18] of byte;   { Niveau 31 * 17 + bords }
   fantomes = array[1..MAX_NB_FANT, 1..11] of integer; { Tableau des fant“mes }
   police   = array[0..4000] of byte;        { Police de caractŠres 10x10 }
 
var
   buf        : ^ecran;              { Tampon vid‚o }
   buf_adr    : word;                { Adresse du tampon vid‚o }
   ancien_int : procedure;           { Ancien gestionnaire d'interruptions }
   a_touches  : word;                { Adresse (Offset) du nouveau gestionnaire d'interruptions }
   s_touches  : word;                { Segment du nouveau gestionnaire d'interruptions }
   touches    : array[0..3] of byte; { Tableau des touches de direction }
   valeur     : byte;                { Code de la touche press‚e }

   hr, min    : word;                { Heure et minute systŠme }
   sec100     : word;                { CentiŠmes de seconde systŠme }
   sec, dsec  : word;                { Seconde en cours et derniŠre seconde }
   pfps, fps  : integer;             { Prochain nombre d'image par secondes et
                                       nombre actuel }
   nouvsec    : boolean;             { Vrai si une nouvelle seconde vient de commencer }
   showfps    : boolean;             { Vrai si le compteur d'images par secondes est activ‚ }

   chiffres           : array[0..1000]  of byte; { Chiffres du score }
   score_img          : array[0..500]   of byte; { Texte "Score" }
   temp_img           : array[0..40000] of byte; { Image temporaire }
   police_1           : police;                  { Police de caractŠres par d‚faut }
   coeur              : spr10;    { Petit coeur rouge }
   pac_oh , pac_fh    : spr10;    { Pacman haut  , bouche ouverte / ferm‚e }
   pac_og , pac_fg    : spr10;    { Pacman gauche, bouche ouverte / ferm‚e }
   pac_ob , pac_fb    : spr10;    { Pacman bas   , bouche ouverte / ferm‚e }
   pac_od , pac_fd    : spr10;    { Pacman droit , bouche ouverte / ferm‚e }
   pac_ohd, pac_fhd   : spr10;    { Pacman Diablo haut  , bouche ouverte / ferm‚e }
   pac_ogd, pac_fgd   : spr10;    { Pacman Diablo gauche, bouche ouverte / ferm‚e }
   pac_obd, pac_fbd   : spr10;    { Pacman Diablo bas   , bouche ouverte / ferm‚e }
   pac_odd, pac_fdd   : spr10;    { Pacman Diablo droit , bouche ouverte / ferm‚e }
   energie            : spr10;    { Capsule d'‚nergie }
   pastille           : spr10;    { Pastille }
 
   fant_1o, fant_1f   : spr10;    { Fant“me orange, agressif, neutre, effray‚ }
   fant_1p            : spr10;
   fant_2o, fant_2f   : spr10;    { Fant“me rouge , agressif, neutre, effray‚ }
   fant_2p            : spr10;
   fant_3o, fant_3f   : spr10;    { Fant“me vert  , agressif, neutre, effray‚ }
   fant_3p            : spr10;
   fant_4o, fant_4f   : spr10;    { Fant“me bleu  , agressif, neutre, effray‚ }
   fant_4p            : spr10;
   zyeux_1            : spr10;    { Yeux }
   zyeux_2            : spr10;
 
            { Murs }
   mur_               : spr10;    { Mur isol‚ }
   mur_h  , mur_b     : spr10;    { Murs … 1 raccord }
   mur_g  , mur_d     : spr10;
 
   mur_hg , mur_gb    : spr10;    { Murs coud‚s (2 raccords) }
   mur_bd , mur_hd    : spr10;
 
   mur_gd , mur_hb    : spr10;    { Murs droits (2 raccords) }
 
   mur_hgb, mur_gbd   : spr10;    { Murs en T }
   mur_hbd, mur_hgd   : spr10;    { (3 raccords) }
   mur_hgbd           : spr10;    { Mur en croix (4 raccords) }
 
   porte_gd           : spr10;    { Porte de la prison : horizontale et verticale }
   porte_hb           : spr10;
   portet_gd          : spr10;    { Porte transparente : horizontale et verticale }
   portet_hb          : spr10;
 
   vide               : spr10;    { Bloc noir (vide) }
 
   bouche             : integer;  { Pacman ouvre la bouche si positif }
   blink              : integer;  { Couleur des pastilles d'‚nergie et des portes }
   tfantomes          : fantomes; { Tableau des fant“mes }
   max_fant           : integer;  { Nombre maxinum de fant“mes dans le niveau }
   depart_x, depart_y : integer;  { Coordonn‚es de d‚part de Pacman }
   mort               : boolean;  { Vrai si Pacman est mort }
   vies               : integer;  { Nombres de vies }
   quitte             : boolean;  { Vrai si le joueur veut quitter }
   score, score2      : longint;  { Score actuel, ancien score }


   p1, p2, nega, noir : pal;      { Palettes }
   niv                : niveau;   { Le niveau }
   boules             : integer;  { Le nombre de pastilles restant … manger dans le niveau }
   titre_niv          : string;   { Le titre du niveau }
   num_niv, max_niv   : integer;  { Num‚ro du niveau en cours, et nombre maxi de niveaux }
   diablo             : integer;  { Mode Diablo >:-D (si > 0) }
   nom_fic_niv        : string;   { Nom du fichier des niveaux }
   bruit              : boolean;  { Vrai si le son est activ‚ }


{ ÛßßßßßßßßßßßßßßßßßßßßßßßßßßÛ
  Û Proc‚dures et fonctions  Û
  ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ }


{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE nouveau_int                                ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Installe un nouveau gestionnaire d'interruption, ³
  ³       en mettant les valeurs 0 ou 1 dans le tableau    ³
  ³       d'adresse "a_touches" et de segment "s_touches"  ³
  ³       o— 0 : haut  1 : gauche  2 : bas  3 : droite     ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure nouveau_int; interrupt; assembler;

asm
   in      al, $60       { al prend la v‚leur de la touche press‚e }
   mov valeur, al        { "valeur" est la valeur de la touche press‚e }
   mov     si, a_touches { si prend la valeur du segment du tableau de touches }
   mov     bx, s_touches { bx prend la valeur de l'offset du tableau de touches }
 
   mov     es, bx        { dest prend la vleur de l'offset }

   cmp      al, 72       { si touche press‚e = 72 (haut) }
   je   @@th_on          { Va activer la touche haut (th_on) }
   mov      ah, 0        { Sinon, met 0 … la valeur de la touche (touches[0] <- 0) }
   mov es:[si], ah

@@tg:
   cmp      al, 75       { si touche press‚e = 75 (gauche) }
   je   @@tg_on          { Va activer la touche gauche (tg_on) }
   mov      ah, 0        { Sinon, met 0 … la valeur de la touche (touches[1] <- 0) }
   mov es:[si+1], ah

@@tb:
   cmp       al, 80      { si touche press‚e = 80 (bas) }
   je   @@tb_on          { Va activer la touche bas (tb_on) }
   mov      ah, 0        { Sinon, met 0 … la valeur de la touche (touches[2] <- 0) }
   mov es:[si+2], ah

@@td:
   cmp       al, 77      { si touche press‚e = 77 (droite) }
   je   @@td_on          { Va activer la touche droite (td_on) }
   mov        ah, 0      { Sinon, met 0 … la valeur de la touche (touches[3] <- 0) }
   mov es:[si+3], ah

   jmp  @@fini           { On a termin‚, va … la fin de la proc‚dure }

@@th_on:                 { Touche haut press‚e }
   mov      ah, 1        { On place la valeur 1 dans le tableau }
   mov es:[si], ah       { (touches[0] <- 1) }
   jmp @@tg              { Passe … la touche suivante (gauche) }

@@tg_on:                 { Touche gauche press‚e }
   mov      ah, 1        { On place la valeur 1 dans le tableau }
   mov es:[si+1], ah     { (touches[1] <- 1) }
   jmp @@tb              { Passe … la touche suivante (bas) }

@@tb_on:                 { Touche bas press‚e }
   mov       ah, 1       { On place la valeur 1 dans le tableau }
   mov es:[si+2], ah     { (touches[2] <- 1) }
   jmp @@td              { Passe … la touche suivante (droite) }

@@td_on:                 { Touche droite press‚e }
   mov       ah, 1       { On place la valeur 1 dans le tableau }
   mov es:[si+3], ah     { (touches[3] <- 1) }

@@fini:                  { Fin de la proc‚dure }
   pushf

   call ancien_int       { Appelle l'ancien gestionnaire pour que les autres touches
                           puissent fonctionner }
end;
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE mode_320_200_256                           ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Passe en mode video 320 * 200 * 8 bits           ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure mode_320_200_256; assembler;
asm
   mov AX, $13           { Installe le mode $13 … l'interruption $10 }
   int $10
end;



{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE refresh                                    ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Copie le tampon vid‚o dans la m‚moire vid‚o      ³
  ³       (affiche le tampon vid‚o quoi !)                 ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure refresh; assembler;

asm
  push    ds             { Sauvegarde de ds }
  mov     ax, $A000      { adresse de destination es : segment vid‚o }
  mov     es, ax         { VGA ($A000) }
  mov     ax, buf_adr    { Adresse de source ds : celle du tampon vid‚o }
  mov     ds, ax
  xor     si, si         { SI <- 0 (Xor est plus rapide que mov car pas besoin
                           d'aller chercher dans la m‚moire) }
  xor     di, di         { DI <- 0 (idem) }
  mov     cx, 32000      { Compteur CX mis … 32000 (64000 / 2) }
  rep     movsw          { rep r‚pŠte CX fois (32000) l'op‚ration qui suit :
                           movsw copie le mot … [DS:SI] vers [ES:DI], puis
                           incr‚mente SI et DI }
  pop     ds             { Restaure ds }
end;

{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE retrace                                    ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Attend le top de synchronisation du signal vid‚o ³
  ³       pour que les modifications … l'‚cran qui suivent ³
  ³       soient invisibles. Mesure ‚galement le nombre    ³
  ³       d'images par seconde, cad le nombre d'appel de   ³
  ³       la proc‚dure par seconde.                        ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure retrace;
 
begin
   gettime(hr, min, sec, sec100); { heure systŠme }
   if sec <> dsec then      { Si nouvelle seconde }
   begin
      fps  := pfps;         { fps : nombre d'images affich‚es … la
                              seconde pr‚c‚dente }
      pfps := 1;            { Remise … 1 du compteur (cette image) }
      dsec := sec;          { Seconde p‚c‚dente : maintenant celle-ci }
      nouvsec := true;      { Nouvelle seconde }
   end
   else                     { Sinon }
   begin
      inc(pfps);            { Une image de plus … cette seconde }
      nouvsec := false;     { Ce n'est pas une nouvelle seconde }
   end;
 
   { Attente du top de synchro }
   asm
       mov dx, $3DA         { Adresse de l'interruption : $3DA }

   @@et1:                   { Si le signal vid‚o est d‚j… sur le top de synchro }
       in  al, dx
       and al, $08          { On attend qu'il se termine (al and 1000b = 0) }
       jnz @@et1

   @@et2:                   { Attend que le signal vid‚o arrive au prochain top }
       in  al, dx
       and al, $08          { On attend qu'il se termine (al and 1000b <> 0) }
       jz  @@et2
   end;
end;
 
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE eff_ecr                                    ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Efface le tampon vid‚o d'adresse "addr"          ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure efface(addr : word); assembler;

asm
   push    es            { Sauvegarde es }
   mov     cx, 32000
   mov     ax, addr      { ax : adresse cible }
   mov     es, ax        { place ES sur l'adresse cible }
   xor     di, di        { Met DI … 0 (c'est plus rapide avec XOR) }
   xor     ax, ax        { Met tous les bits de AX … 0 (XOR + rapide)
                           cad AH = 0 et AL = 0 }
   rep     stosw         { rep r‚pŠte CX fois (32000) l'op‚ration qui suit :
                           stosw copie le contenu du registre AX dans [ES:DI]
                           et incr‚mente DI. AX = 16 bits = 2 octets = 1 mot
                           On fait d'une pierre deux coups (32000 * 2 = 64000) }
   pop     es            { Restaure es }
end;



{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE changer_palette                            ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Change les attributs de couleur de la palette par³
  ³       ceux du tableau "coulRVB".                       ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure changer_palette(var coulRVB); assembler;
asm
   push ds

   lds si, coulRVB     { Adresse source : le tableau de la palette }
   xor bx, bx          { bx : position dans le tableau … 0 }
   xor cl, cl          { cl : num‚ro de l'indice de couleur (mis … 0) }
 
@@debut:
   cmp bx, 768         { Si pas au bout du tableau (768) }
   jae @@fin
 
   mov dx, $3C8        { Place dx … l'adresse cible de la palette $3C8 }
   mov al, cl
   out dx, al
   inc dx

   mov ax, ds:[si+bx]  { Rouge }
   shr ax, 2           { Division par 4 pour convertir en couleur VGA }
   out dx, al
   inc bx

   mov ax, ds:[si+bx]  { Vert }
   shr ax, 2           { Division par 4 pour convertir en couleur VGA }
   out dx, al
   inc bx

   mov ax, ds:[si+bx]  { Bleu }
   shr ax, 2           { Division par 4 pour convertir en couleur VGA }
   out dx, al
   inc bx

   inc cl

   jmp @@debut

@@fin:

   pop ds              { Restaure ds }

end;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con el código del juego pacman

Publicado por ramon (2158 intervenciones) el 24/04/2013 23:17:28
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
{2}
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE colle                                      ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Copie une zone m‚moire dans une autre            ³
  ³       source : DS:[BX]   dest : ES:[BX]   taille : CX  ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure colle; assembler;
 
asm
 
   push AX  { Sauvegarde des registres }
   push BX
 
   mov BX, 0          { BX : d‚but de la ligne source }
 
@@debut:
   cmp BX, CX         { Si BX = CX, fin }
   jae @@fin
 
   mov AH, DS:[SI+BX] { charge la valeur dans AH }
   mov ES:[DI+BX], AH { ‚crit la valeur dans dest }
 
   inc BX             { bx augment‚ de 1 pour passer au pixel suivant }
   jmp @@debut
 
@@fin:
   pop BX  { restauration registres }
   pop AX
end;
 
 
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE coller                                     ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Colle l'image du tableau lin‚aire "spr" de taille³
  ³       i, j … la position x, y du tampon d'adresse      ³
  ³       addr                                             ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure coller(x, y : integer;
                 i, j : integer;
                 var spr; addr : word); assembler;
asm
   mov CX, i    { CX : Taille X }
 
   mov BX, 0
   mov AX, j    { AX : Taille Y }
 
   lds SI, spr  { pointe DS:SI sur spr }
 
   { Dessine une ligne }
 
@@ligne:
   push BX      { Sauvegarde registres }
   push AX
 
   push DS
 
   mov AX, y    { offset video }
   shl AX, 2    { de la ligne (320) }
   mov BX, AX
   shl AX, 2
   add AX, BX
   mov BX, addr { Segment de la zone m‚moire }
   add AX, BX
   mov ES, AX
 
   mov DI, x    { position horizontale cible }
 
   call colle   { Copie la ligne … l'endroit indiqu‚ }

   pop DS       { restaure DS }

   { Passe … la ligne suivante }

   pop AX       { Taille y du dessin (AX lignes) }
   pop BX       { jŠme ligne }

   inc BX       { Prochaine ligne }
   inc y

   add SI, CX   { place la source sur la ligne suivante (taille CX) }

   cmp AX, BX   { Recommence si pas la derniŠre ligne (AX) }
   jne @@ligne
end;




{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE colle_transp                               ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Copie une zone m‚moire dans une autre pour toute ³
  ³       valeur diff‚rente de 253 (couleur "transparente")³
  ³       source : DS:[BX]   dest : ES:[BX]   taille : CX  ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure colle_transp; assembler;

asm
   push AX  { Sauvegarde des registres }
   push BX

   mov BX, 0          { BX : d‚but de la ligne source }

@@debut:
   cmp BX, CX
   jae @@fin

   mov AH, DS:[SI+BX] { charge la valeur dans AH }
   cmp AH, 253        { passe au pixel suivant si couleur transparente }
   je @@pixelsuiv     { (indice 253) }

   mov ES:[DI+BX], AH { sinon, ‚crit la valeur dans dest }

@@pixelsuiv:

   inc BX             { bx augment‚ de 1 pour passer au pixel suivant }
   jmp @@debut

@@fin:
   pop BX  { restauration registres }
   pop AX
end;



{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE coller_transp                              ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Colle l'image du tableau lin‚aire "spr" de taille³
  ³       i, j … la position x, y du tampon "addr" avec un ³
  ³       fond transparent (code 253)                      ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure coller_transp(x, y : integer;
                        i, j : integer;
                 var spr; addr : word); assembler;
asm
   mov CX, i    { CX : Taille X }
 
   mov BX, 0
   mov AX, j    { AX : Taille Y }
 
   lds SI, spr  { pointe DS:SI sur spr }
 
   { Dessine une ligne }
 
@@ligne:
   push BX      { Sauvegarde registres }
   push AX
 
   push DS
 
   mov AX, y    { offset video }
   shl AX, 2    { de la ligne (320) }
   mov BX, AX
   shl AX, 2
   add AX, BX
   mov BX, addr { Segment de la zone m‚moire }
   add AX, BX
   mov ES, AX
 
   mov DI, x    { position horizontale cible }
 
   call colle_transp { Copie la ligne … l'endroit indiqu‚, avec transparence }

   pop DS       { restaure DS }

   { Passe … la ligne suivante }

   pop AX       { Taille y du dessin (AX lignes) }
   pop BX       { jŠme ligne }

   inc BX       { Prochaine ligne }
   inc y

   add SI, CX   { place la source sur la ligne suivante (taille CX) }

   cmp AX, BX   { Recommence si pas la derniŠre ligne (AX) }
   jne @@ligne

end;


{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE point                                      ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Fait prendre la couleur c au pixel de position   ³
  ³       x, y dans le tampon vid‚o d'adresse "addr"       ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure point(x, y: word ; c : byte; addr : word); assembler;
asm
   mov ax, y    { Calcul de l'offset du point (y * 320 + x) }
   shl ax, 2
   mov bx, ax
   shl ax, 2
   add ax, bx
   mov BX, addr { On y ajoute l'adresse }
   add ax, bx
 
   mov es, ax   { Et on y place l'octet c }
   mov bx, x
   mov al, c
   mov es:[bx], al
end;



{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³FONCTION existe                                   PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Donne vrai si le fichier de nom "nom" existe     ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

function existe(nom : string) : boolean;

var
   F : file;

begin
   assign(F, nom);         { Ouverture du fichier F de nom "nom" }
       {$I-}
   reset(F);
       {$I+}
   if (IOResult = 0) then  { Si ouverture sans encombres }
   begin
      close(F);            { On ferme le fichier }
      existe := true;      { Le fichier existe donc bien }
   end
   else
      existe := false;     { Autrement, il n'existe pas }
end;
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE son_erreur                              PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Emet un bip suite … une erreur (chargement de    ³
  ³       fichier par exemple.                             ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure son_erreur;
 
begin
   sound(1000); { Son 1 KHz }
   delay(200);  { pendant 200 ms }
   nosound;     { repos ! }
end;
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE charger_palette                         PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Charge la palette de l'image PCX de nom "S" dans ³
  ³       le tableau palette "p"                           ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure charger_palette(S : string; var p : pal);

var
    F : file;

begin
   assign(F,S);              { Ouverture du fichier image PCX F de nom S }
       {$I-}
   reset(F,1);
       {$I+}
   if IOResult = 0 then      { Si ouverture sans problŠmes }
   begin
      seek(F, filesize(F) - 768); { Va au 768 Šme dernier octet }
      blockread(F, p, 768);  { Et balance toute la fin du fichier dans le tableau "p" }
      close(F);              { Et on ferme le fichier image }
   end;
end;


{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE charger_PCX                 MIX   PASCAL / ASM³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Charge l'image au format PCX dans le tableau img ³
  ³       et donne ses dimensions dans "tx" et "ty".       ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure charger_PCX(          S : string; var img;
                      var tx, ty  : word);
 
var
    b1, b2                 : byte;    { Octets lus }
    fp, j                  : integer; { Pointeur fichier, indice }
    i                      : word;    { Position dans le tableau image }
    F                      : file;    { Fichier PCX }
    xmin, ymin, xmax, ymax : integer; { Dimensions de l'image }

begin
   assign(F,S);                { Ouverture du fichier image PCX F de nom S }
       {$I-}
   reset(F,1);
       {$I+}
   if IOResult = 0 then        { Si ouverture sans problŠmes }
   begin
      seek(F, 4);              { Va au 4Šme octet }
      blockread(F, xmin, 2);   { Origine X }
      blockread(F, ymin, 2);   { Origine Y }
      blockread(F, xmax, 2);   { Fin X }
      blockread(F, ymax, 2);   { Fin Y }
      tx := xmax - xmin + 1;   { Taille X : diff‚rence des 2 + 1 }
      ty := ymax - ymin + 1;   { Taille Y : diff‚rence des 2 + 1 }

      fp := 129;               { Position du pointeur : 129 Šme octet }
                               { 1er octet de l'image en elle-mˆme) }
      i := 0;                  { iŠme pixel = 0 }
      seek(F,128);             { On y va }
 
      { TQ pas arriv‚ au bout et que toute l'image n'est pas charg‚e }
      while (fp <= (FileSize(F) - 768)) and (i <= tx * ty) do
      begin
         blockread(F, b1, 1);  { Lit l'octet b1 }
         inc(fp);              { position du pointeur : prochain octet }
         if ((b1 and 192) = 192) then { si les 2 bits de poids fort sont … 1 }
         begin
            blockread(F,b2,1); { On lit l'octet suivant }
            inc(fp);           { position du pointeur : prochain octet }
            for j := 1 to (b1 and 63) do { Et copie l'octet b2 le nombre de fois }
            begin              { d‚fini par les 6 octets de poids faible de b1 }
               asm
                  les DI, [img]{ Dans le tableau image "img" … la position du pixel "i" }
                  mov BX, i    { Et en assembleur parce qu'en Pascal, on doit }
                  mov AL, b2   { avoir une taille d'image fixe, ce qui n'est }
                  mov ES:[DI + BX], AL { pas pratique du tout... }
                  inc i        { Pixel suivant (en assembleur, ‡a fait plus savant) }
               end;
            end;
         end
         else                  { Sinon }
         begin
            asm
               les DI, [img]   { Copie juste "b1" dans "img" en "i" }
               mov BX, i
               mov AL, b1
               mov ES:[DI + BX], AL
               inc i           { "i" Incr‚ment‚ de 1 (pixel suivant) }
            end;
         end;
      end;
      close(F);                { Ferme "F" }
   end
   else son_erreur;            { Si erreur d'ouverture, bip d'erreur }
end;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con el código del juego pacman

Publicado por ramon (2158 intervenciones) el 24/04/2013 23:19:29
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
{3}
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³FONCTION inttostr                                ³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Convertit l'entier "i" en chaŒne          ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

function inttostr(i : longint) : string;

var
   s : string[11]; { ChaŒne obtenue }

begin
   str(i, s);      { Convertit l'entier "i" en chaŒne "s" }
   inttostr := s;  { Et donne "s" }
end;
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE fondu_ouverture                         PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Fait un fondu en ouverture avec la palette "p".  ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure fondu_ouverture(p : pal);
 
var
   tp   : pal;     { Palette temporaire }
   i, j : integer; { Indices }
 
begin
   for i := 0 to 64 do { i de 0 … 64 }
   begin
      for j := 0 to 767 do { j : parcours du tableau des couleurs }
         tp[j] := (p[j] * i) div 64; { variation de la couleur en fonction de i }
      retrace;             { Attente du top de synchro }
      changer_palette(tp); { Application de la nouvelle palette }
      if keypressed then readkey; { Evite les bipbipbipbip quand on s'‚nerve sur le clavier }
   end;
end;

{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE fondu_fermeture                         PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Fait un fondu en fermeture avec la palette "p".  ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure fondu_fermeture(p : pal);

var
   tp   : pal;     { Palette temporaire }
   i, j : integer; { Indices }

begin
   for i := 64 downto 0 do { i de 64 … 0 }
   begin
      for j := 0 to 767 do { j : parcours du tableau des couleurs }
         tp[j] := (p[j] * i) div 64; { variation de la couleur en fonction de i }
      retrace;             { Attente du top de synchro }
      changer_palette(tp); { Application de la nouvelle palette }
      if keypressed then readkey; { Evite les bipbipbipbip quand on s'‚nerve sur le clavier }
   end;
end;
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE charger_niveau                          PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Charge le niveau nø "n" de titre "titre" dans le ³
  ³       fichier texte "S".                               ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure charger_niveau(    S : string; n : integer;
                         var niv : niveau; var max_niv : integer; var titre : string);
 
var
    i, j  : word;       { Indices }
    ligne : string[34]; { Ligne lue dans le fichier }
    F     : text;       { Fichier texte des niveaux }
    elt   : integer;    { Valeur du tile }
 
begin
   assign(F,S); { Ouverture de F de nom S en lecture }
       {$I-}
   reset(F);
       {$I+}
 
   if IOResult = 0 then   { Si le fichier existe bien }
   begin
      readln(F, max_niv); { nombre total de niveaux }
      for i := 1 to n - 1 do { On cherche le niveau "n" qui nous int‚resse }
         for j := 1 to 20 do readln(F, titre); { Un niveau = 20 lignes }
 
      readln(F, titre);   { 1Šre ligne : titre }
      for j := 0 to 18 do { Les 19 autres : le niveau en lui-mˆme }
      begin
         readln(F, ligne); { On charge ligne par ligne }
         for i := 1 to 34 do { CaractŠre par caractŠre }
         begin
            case ligne[i] of { Et on attribue chaque caractŠre sa valeur }
               '.' : elt := 0; { Vide }
               'ø' : elt := 1; { Pastille (boule) }
               '*' : elt := 2; { Capsule d'‚nergie }
               'T' : elt := 3; { T‚l‚porteur }
               'P' : elt := 4; { D‚part de Pacman }
               'F' : elt := 5; { D‚part d'un fant“me }
               '=' : elt := 6; { Porte de prison }
               'O' : elt := 7; { Mur }
            else
               elt := 8        { Mur invisible si caractŠre non reconnu }
            end;
            niv[i - 1, j] := elt; { On place la valeur trouv‚e dans le tableau de niveau }
         end;
      end;
 
      close(F); { Ferme le fichier }
   end
   else son_erreur;            { Sinon, bip d'erreur }
end;


{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE affiche_porte                           PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Affiche la porte de la prison aux coordonn‚es    ³
  ³       "porte_x", "porte_y" (s'il y'en a une bien s–r ! ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure affiche_porte(porte_x, porte_y : integer; t : word);

var
   h, g, b, d : boolean; { Vrai si mur en haut, gauche, bas, droite du mur
                           en cours }

begin
   if niv[porte_x, porte_y] = 6 then { S'il y a une porte aux coordonn‚es }
   begin
      h := niv[porte_x     , porte_y - 1]  > 5; { Mur en haut ? }
      g := niv[porte_x - 1 , porte_y    ]  > 5; { Mur … gauche ? }
      b := niv[porte_x     , porte_y + 1]  > 5; { Mur en bas ? }
      d := niv[porte_x + 1 , porte_y    ]  > 5; { Mur … droit ? }
      { Affiche une porte transparente verticale ou horizontale selon h, g, b, d }
      if g and d and not(h or b) then coller_transp(-10 + 10 * porte_x, 10 + 10 * porte_y, 10, 10, portet_gd, t);
      if h and b and not(g or d) then coller_transp(-10 + 10 * porte_x, 10 + 10 * porte_y, 10, 10, portet_hb, t);
   end;
end;
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE affiche_portes                          PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Affiche les portes de la prison                  ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure affiche_portes(pex, pey : integer);
 
var
   dir : integer; { Direction }
 
begin
   affiche_porte(pex div 10, pey div 10, $A000); { Affiche la porte ‚ventuelle
   aux coordonn‚es correspondant … celle du fant“me ("pex, pey") }
   for dir := 0 to 3 do  { Et autour (4 directions) }
      affiche_porte(pex div 10 + tdir[dir, 1], pey div 10 + tdir[dir, 2], $A000);
 
end;
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³FONCTION affiche_score                            PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : affiche le score "score"                         ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure affiche_score;
 
 
var
   i : integer;     { Indice }
   sc : longint;    { Score temporaire }
 
begin
   i := 120;        { Position du premier chiffre }
   sc := score;     { Score temporaire <- score actuel }
   coller(0, 0, 50, 10, score_img, $A000); { Affiche "SCORE" }
   coller(i, 0, 10, 10, chiffres[0], $A000); { Affiche le 0 du score nul }
   while sc > 0 do  { TQ le score temporaire n'est pas nul }
   begin
      { On colle le chiffre des unit‚s en i }
      coller(i, 0, 10, 10, chiffres[(sc mod 10) * 100], $A000);
      sc := sc div 10; { On divise le score temporaire "sc" par 10 pour
                         supprimer le chiffre d‚j… affich‚ }
      i  := i - 10; { On recule la position du chiffre des unit‚s de 10 }
   end;
   { Affiche les vies }
   for i := 1 to vies do coller(150 + 12 * i, 0, 10, 10, coeur, $A000);
   { Avec un blanc … la fin (au cas o— une vie a ‚t‚ perdue) }
   if vies < 13 then coller(150 + 12 * (vies + 1), 0, 10, 10, vide, $A000);
end;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con el código del juego pacman

Publicado por ramon (2158 intervenciones) el 24/04/2013 23:22:27
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
{4}
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³FONCTION texte_xy                                 PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Affiche le texte "texte" aux coordonn‚es "x, y"  ³
  ³       avec la police "police" dans le tampon "t", avec ³
  ³       transparence "transp" ou non.                    ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure texte_xy(texte : string; x, y : integer; t : word; transp : boolean);
 
 
var
   c : char;    { CaractŠre … afficher }
   i : integer; { Indice }
 
begin
   i := 0; { Position du caractŠre en cours, relative … x }
   while i <= length(texte) - 1 do { TQ i n'est pas au dernier caractŠre }
   begin
      c := texte[i + 1];           { "c" : caractŠre en cours }
      if    ((c >= 'A') and (c <= 'Z')) { Si "c" caractŠre affichable }
         or ((c >= '0') and (c <= '9'))
         or  (c  = '!') or  (c  = '?')
         or  (c  = '_') or  (c  = ' ') then
      begin
            { Si pas transparence, on affiche un bloc vide }
         if not(transp) then coller(x + i * 10, y, 10, 10, vide, t);
            { Puis, on affiche le caractŠre correspondant
              en fonction de sa position dans l'image "police_1" }
         if ((c >= 'A') and (c <= 'Z')) then
         begin
            coller_transp(x + i * 10, y, 10, 10, police_1[100 * (ord(c) - ord('A'))], t)
         end
         else
         begin
            if ((c >= '0') and (c <= '9')) then
               coller_transp(x + i * 10, y, 10, 10, police_1[100 * (ord(c) - ord('0') + 27)], t)
               else
               begin
                  case c of
                     '_' : coller_transp(x + i * 10, y, 10, 10, police_1[3700], t);
                     '!' : coller_transp(x + i * 10, y, 10, 10, police_1[3800], t);
                     '?' : coller_transp(x + i * 10, y, 10, 10, police_1[3900], t);
                  end;
               end;
         end;
      end
      else coller_transp(x + i * 10, y, 10, 10, police_1[2600], t);
      inc(i); { CaractŠre suivant }
      if x + i * 10 > 310 then { Si sortie de la zone ‚cran }
      begin
         x := x - i * 10;      { "retour … la ligne" }
         y := y + 10;
      end;
   end;
end;
 
 
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE affiche_tile                            PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Affiche le tile du niveau "niv" de position "i,j"³
  ³       aux coordonn‚es ‚cran "px, py" dans le tampon "t"³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure affiche_tile(i, j : integer; t : word);
 
var
   h, g, b, d : boolean; { Vrai si mur en haut, gauche, bas, droite du mur
                           en cours }
 
begin
   { Mur en haut ? }
   h := (niv[i     , j - 1]  = 6) or (niv[i     , j - 1]  = 7);
   { Mur … gauche ? }
   g := (niv[i - 1 , j    ]  = 6) or (niv[i - 1 , j    ]  = 7);
   { Mur en bas ? }
   b := (niv[i     , j + 1]  = 6) or (niv[i     , j + 1]  = 7);
   { Mur … droite ? }
   d := (niv[i + 1 , j    ]  = 6) or (niv[i + 1 , j    ]  = 7);
      case niv[i, j] of
          { Pastille }
      1 : coller(-10 + 10 * i, 10 + 10 * j, 10, 10, pastille, t);
          { Energie }
      2 : coller(-10 + 10 * i, 10 + 10 * j, 10, 10, energie, t);
          { Porte de prison }
      6 : begin
             if g and d and not(h or b) then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, porte_gd, t);
             if h and b and not(g or d) then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, porte_hb, t);
          end;
          { Mur }
      7 : begin
             if not(h or b or g or d)     then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_    , t);
             if h and not(b or g or d)    then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_h   , t);
             if g and not(b or h or d)    then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_g   , t);
             if b and not(h or g or d)    then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_b   , t);
             if d and not(b or g or h)    then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_d   , t);
             if h and b and not(g or d)   then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_hb  , t);
             if g and d and not(h or b)   then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_gd  , t);
             if h and g and not(b or d)   then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_hg  , t);
             if g and b and not(d or h)   then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_gb  , t);
             if b and d and not(h or g)   then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_bd  , t);
             if h and d and not(g or b)   then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_hd  , t);
             if h and g and b and not(d)  then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_hgb , t);
             if g and b and d and not(h)  then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_gbd , t);
             if h and b and d and not(g)  then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_hbd , t);
             if h and g and d and not(b)  then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_hgd , t);
             if h and g and d and b       then coller(-10 + 10 * i, 10 + 10 * j, 10, 10, mur_hgbd, t);
          end;
      else { autre ‚l‚ment = vide }
          coller(-10 + 10 * i, 10 + 10 * j, 10, 10, vide, t);
   end;
end;
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE init_niveau                             PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Affiche le niveau "niv" dans le tampon vid‚o,    ³
  ³       et initialise les paramŠres (position de Pacman, ³
  ³       les fant“mes et le nombre de pastilles … manger).³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure init_niveau(niv : niveau);
 
var
   i, j       : integer; { Indices de position du tableau du niveau }
   px, py     : integer; { Position ‚cran du niveau }
 
begin
   affiche_score;        { Affiche le score }
   max_fant := 0;        { aucun fant“me pour le moment }
   boules   := 0;        { Et aucune boule (pastille) }
   px       :=  -10;     { Position du niveau … l'‚cran }
   py       :=  10;      { (Les bords ne sont pas affich‚s) }
   for j := 1 to 17 do   { Parcours du tableau avec "i", et "j" }
   begin
      for i := 1 to 32 do
      begin
         case niv[i, j] of
            1 : inc(boules); { Une boule de plus, une ! }
                   { "depart_x", "depart_y" : position de d‚part de Pacman }
            4 : begin depart_x := i; depart_y := j; end;
            5 : begin
                   if max_fant < MAX_NB_FANT then { Si on peut encore rajouter }
                   begin                          { des fant“mes }
                      inc(max_fant);  { on en rajoute un ! }
                      tfantomes[max_fant, 1]  := i; { Position X }
                      tfantomes[max_fant, 2]  := j; { Position Y }
                      tfantomes[max_fant, 3]  := 3; { Direction par d‚faut (droite) }
                      tfantomes[max_fant, 4]  := i * 10; { Position ‚cran X }
                      tfantomes[max_fant, 5]  := j * 10; { Position ‚cran Y }
                      tfantomes[max_fant, 6]  := (max_fant - 1) mod 4 + 1; { Couleur (1-4) }
                      tfantomes[max_fant, 7]  := - 10 + 5 * (max_fant mod 4); { Animation [-10 ; 10] }
                      tfantomes[max_fant, 8]  := 300; { images restantes avant sortie de prison }
                      tfantomes[max_fant, 9]  := - max_fant * 300; { vie du fant“me (nombre d'images
                                                                     avant sa naissance) }
                      tfantomes[max_fant, 10] := i; { Position X de d‚part }
                      tfantomes[max_fant, 11] := j; { Position Y de d‚part }
                   end;
                end;
         end;
         affiche_tile(i, j, buf_adr); { Affiche le tile correspondant dans le tampon vid‚o }
      end
 
   end;
end;
 
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE efface_perso                            PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Efface le personnage … la position "px", "py" de ³
  ³       direction "dir" dans le niveau "niv".            ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure efface_perso(pex, pey : integer);
 
var
   dir      : integer; { Direction temporaire }
   tex, tey : integer; { Position ‚cran du tile }
 
begin
   affiche_tile(pex div 10, pey div 10, $A000); { Affiche le tile … la position
                                                  du personnage }
   for dir := 0 to 3 do { Et aux 4 directions possibles }
   begin
      tex := pex div 10 + tdir[dir, 1];
      tey := pey div 10 + tdir[dir, 2];
      if (tex >= 1) and (tex <= 32) and (tey >= 1) and (tey <= 17) then
      affiche_tile(tex, tey, $A000);
   end;
 
end;
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE affiche_pacman                          PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Dessine pacman … la position "pex", pey" de dire-³
  ³       ction "dir" dans le niveau "niv" dans le tampon  ³
  ³       "t".                                             ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure affiche_pacman(pex, pey, dir : integer ; t : word);

begin
   if (diablo = 0) or ((diablo > 0) and (diablo <= 80) and ((diablo mod 2) = 0)) then   { Si pas en mode diablo (gentil quoi) }
   begin
      if bouche < 0 then { bouche < 0 : bouche ouverte }
      begin
         case dir of { Affiche Pacman en fonction de sa direction }
            0 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_oh, t); end;
            1 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_og, t); end;
            2 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_ob, t); end;
            3 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_od, t); end;
            4 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_od, t); end;
         end;
      end
      else               { Sinon bouche ferm‚e }
      begin
         case dir of { Affiche Pacman en fonction de sa direction }
            0 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_fh, t); end;
            1 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_fg, t); end;
            2 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_fb, t); end;
            3 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_fd, t); end;
            4 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_fd, t); end;
         end;
      end;
   end
   else    { Sinon, mode diablo }
   begin
      if bouche < 0 then { bouche < 0 : bouche ouverte }
      begin
         case dir of { Affiche Pacman en fonction de sa direction }
            0 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_ohd, t); end;
            1 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_ogd, t); end;
            2 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_obd, t); end;
            3 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_odd, t); end;
            4 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_odd, t); end;
         end;
      end
      else               { Sinon bouche ferm‚e }
      begin
         case dir of { Affiche Pacman en fonction de sa direction }
            0 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_fhd, t); end;
            1 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_fgd, t); end;
            2 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_fbd, t); end;
            3 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_fdd, t); end;
            4 : begin coller_transp(pex - 10, pey + 10, 10, 10, pac_fdd, t); end;
         end;
      end;
   end;
end;

{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE affiche_fant“mes                        PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Dessine les fant“mes "fant" dans le tampon "t"   ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure affiche_fantomes(tfant : fantomes; t : word);

var
   i : integer; { Indice }
   fex, fey : integer; { Position physique du fant“me }
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con el código del juego pacman

Publicado por ramon (2158 intervenciones) el 24/04/2013 23:23:39
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
{5}
 
begin
   for i := 1 to max_fant do  { Parcours du tableau de fant“mes }
   begin
      fex := tfant[i, 4];     { Position physique du fant“me }
      fey := tfant[i, 5];
      if tfant[i, 9] = 0 then { si le fant“me est vivant ( = 0) }
      begin
         if tfant[i, 7] < 0 then { Si animation < 0 (bouche ferm‚e) }
         begin
            case tfant[i, 6] of { Affiche le fant“me, en fonction de sa couleur }
               1 : coller_transp(fex - 10, fey + 10, 10, 10, fant_1f, t);
               2 : coller_transp(fex - 10, fey + 10, 10, 10, fant_2f, t);
               3 : coller_transp(fex - 10, fey + 10, 10, 10, fant_3f, t);
               4 : coller_transp(fex - 10, fey + 10, 10, 10, fant_4f, t);
            end;
         end
         else            { Sinon, bouche ouverte en fonction de son humeur }
         begin
            if diablo = 0 then { Si pas mode diablo, le fant“me est agressif }
            begin
               case tfant[i, 6] of { Affiche le fant“me, en fonction de sa couleur }
                  1 : coller_transp(fex - 10, fey + 10, 10, 10, fant_1o, t);
                  2 : coller_transp(fex - 10, fey + 10, 10, 10, fant_2o, t);
                  3 : coller_transp(fex - 10, fey + 10, 10, 10, fant_3o, t);
                  4 : coller_transp(fex - 10, fey + 10, 10, 10, fant_4o, t);
               end;
            end
            else               { Sinon, il est carr‚ment flipp‚ }
            begin
               case tfant[i, 6] of { Affiche le fant“me, en fonction de sa couleur }
                  1 : coller_transp(fex - 10, fey + 10, 10, 10, fant_1p, t);
                  2 : coller_transp(fex - 10, fey + 10, 10, 10, fant_2p, t);
                  3 : coller_transp(fex - 10, fey + 10, 10, 10, fant_3p, t);
                  4 : coller_transp(fex - 10, fey + 10, 10, 10, fant_4p, t);
               end;
            end;
         end;
         affiche_portes(fex, fey); { Affiche les portes de prison ‚ventuelles
                                     transparentes par dessus le fant“me }
      end;
      if tfant[i, 9] > 0 then      { Si le fant“me a ‚t‚ mang‚ ( > 0 )}
      begin
         if tfant[i, 7] < 0        { Affiche les yeux }
            then coller_transp(fex - 10, fey + 10, 10, 10, zyeux_1, t)
            else coller_transp(fex - 10, fey + 10, 10, 10, zyeux_2, t);
         affiche_portes(fex, fey);
      end;
   end; { Et boum la m‚m‚ }
end; { et paf le chien si tu veux bien }
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³FONCTION droite                                   PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Donne la droite de la direction "dir"            ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
function droite(dir : integer) : integer;
 
begin
   dec(dir); { Diminue "dir" d'un cran }
   if dir < 0 then droite := 3 { modulo 4 }
              else droite := dir;
end;

{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³FONCTION gauche                                   PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Donne la gauche de la direction "dir"            ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

function gauche(dir : integer): integer;

begin
   inc(dir); { Augmente "dir" d'un cran }
   if dir > 3 then gauche := 0 { modulo 4 }
              else gauche := dir;
end;
 
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³FONCTION demi_tour                                PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Donne la direction oppos‚e … la direction "dir"  ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
function demi_tour(dir : integer) : integer;
 
begin
     { Faire un demi tour, c'est tourner 2 fois … droite
       (ou 2 fois … gauche, c'est pareil en somme) }
   demi_tour := droite(droite(dir));
end;
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE efface_fant“mes                         PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Efface les fant“mes "fant" dans le tampon "t"    ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure efface_fantomes(tfant : fantomes);
 
var
   i : integer;
 
begin
   for i := 1 to max_fant do { Parcourt le tableau des fant“mes et
         efface chaque fant“me tour … tour }
      efface_perso(tfant[i, 4], tfant[i, 5]);
end;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con el código del juego pacman

Publicado por ramon (2158 intervenciones) el 24/04/2013 23:24:58
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
{6}
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE bouge_fant“mes                          PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Contr“le le d‚placement des fant“mes "tfant"     ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure bouge_fantomes(var tfant : fantomes; px, py : integer);
 
var
   directions   : array[1..4] of integer; { Directions possibles }
   i, j         : integer; { Indices }
   max_dir      : integer; { indice de direction maximal }
   d, dir       : integer; { Indice de direction, direction }
   dst, min_dst : real;    { Carr‚ de la distance fant“me <-> cible, et
                             carr‚ de la plus courte distance }
   num_fant     : integer; { Num‚ro du fant“me vivant }
   fx, fy       : integer; { Position du fant“me dans le niveau }
 
 
begin
   num_fant := 0;          { Num‚ro fant“me vivant }
   for i := 1 to max_fant do { Parcours du tableau de fant“mes }
   begin
      inc(tfant[i, 7]);    { Incr‚mentation du compteur d'animation }
      if tfant[i, 7] > 10 then tfant[i, 7] := -10; { s'il d‚passe 10,
                                                     on le remet … -10 }
      { Si fant“me est n‚ }
      if (tfant[i, 9] >= 0) then
      begin
         { Si le fant“me n'est pas libre (8) et que Pacman n'est pas en mode diablo,
           on d‚cr‚mente le compteur de lib‚ration (8) }
         if (tfant[i, 8] > 0) and (diablo = 0) then dec(tfant[i, 8]);
 
         { Si le fant“me est pile poil sur une case, il peut changer de direction }
         if (tfant[i, 4] mod 10 = 0) and (tfant[i, 5] mod 10 = 0) then
         begin
            max_dir := 0; { nombre de directions maximum (direction maximale) = 0 }
            tfant[i, 1] := tfant[i, 4] div 10; { Position du fant“me dans le niveau }
            tfant[i, 2] := tfant[i, 5] div 10; { … partir de la position physique }
 
            fx := tfant[i, 1]; { Position du fant“me dans le niveau }
            fy := tfant[i, 2];
 
            { Si le fant“me peut aller en face }
            dir := tfant[i, 3];
            { Si la case en face }
            if (       { n'est pas un mur }
                (      (niv[fx + tdir[dir, 1], fy + tdir[dir, 2]]  < 6)
                       { ou est une porte de prison et que le fant“me est libre }
                  or  ((niv[fx + tdir[dir, 1], fy + tdir[dir, 2]]  = 6) and (tfant[i, 8] = 0))
                       { et n'est pas un t‚l‚porteur }
                ) and  (niv[fx + tdir[dir, 1], fy + tdir[dir, 2]] <> 3)
                { Ou si le fant“me a ‚t‚ mang‚ (peut passer … travers les murs) }
               ) or (tfant[i, 9] = 1)
            then
            begin
               { On ajoute cette direction au tableau de directions }
               inc(max_dir);
               directions[max_dir] := dir;
            end;
 
            { Si le fant“me peut aller … droite }
            dir := droite(tfant[i, 3]);
            { Si la case … droite }
            if (       { n'est pas un mur }
                (      (niv[fx + tdir[dir, 1], fy + tdir[dir, 2]]  < 6)
                       { ou est une porte de prison et que le fant“me est libre }
                  or  ((niv[fx + tdir[dir, 1], fy + tdir[dir, 2]]  = 6) and (tfant[i, 8] = 0))
                       { et n'est pas un t‚l‚porteur }
                ) and  (niv[fx + tdir[dir, 1], fy + tdir[dir, 2]] <> 3)
                { Ou si le fant“me a ‚t‚ mang‚ (peut passer … travers les murs) }
               ) or (tfant[i, 9] = 1)
            then
            begin
               { On ajoute cette direction au tableau de directions }
               inc(max_dir);
               directions[max_dir] := dir;
            end;
 
 
            { Si le fant“me peut aller … gauche }
            dir := gauche(tfant[i, 3]);
            { Si la case … gauche }
            if (       { n'est pas un mur }
                (      (niv[fx + tdir[dir, 1], fy + tdir[dir, 2]]  < 6)
                       { ou est une porte de prison et que le fant“me est libre }
                  or  ((niv[fx + tdir[dir, 1], fy + tdir[dir, 2]]  = 6) and (tfant[i, 8] = 0))
                       { et n'est pas un t‚l‚porteur }
                ) and  (niv[fx + tdir[dir, 1], fy + tdir[dir, 2]] <> 3)
                { Ou si le fant“me a ‚t‚ mang‚ (peut passer … travers les murs) }
               ) or (tfant[i, 9] = 1)
            then
            begin
               { On ajoute cette direction au tableau de directions }
               inc(max_dir);
               directions[max_dir] := dir;
            end;
 
            { Si impasse (aucune direction possible),
              ou que Pacman vient de prendre une capsule d'‚nergie, demi-tour ! }
            if (max_dir = 0) or (diablo >= 480) or (tfant[i, 9] = 1 )then
            begin
               dir := demi_tour(tfant[i, 3]);
               { Si la case derriŠre }
               if (       { n'est pas un mur }
                   (      (niv[fx + tdir[dir, 1], fy + tdir[dir, 2]]  < 6)
                          { ou est une porte de prison et que le fant“me est libre }
                     or  ((niv[fx + tdir[dir, 1], fy + tdir[dir, 2]]  = 6) and (tfant[i, 8] = 0))
                          { et n'est pas un t‚l‚porteur }
                   ) and  (niv[fx + tdir[dir, 1], fy + tdir[dir, 2]] <> 3)
                   { Ou si le fant“me a ‚t‚ mang‚ (peut passer … travers les murs) }
                  ) or (tfant[i, 9] = 1)
               then
               begin
                  { On ajoute cette direction au tableau de directions }
                  inc(max_dir);
                  directions[max_dir] := dir;
               end;
            end;

            { Si aucune direction possible (fant“me bloqu‚ entre 4 murs) }
            if (max_dir = 0) then
            begin
               { On ajoute la direction nulle (4) }
               inc(max_dir);
               directions[max_dir] := 4;
            end;

            { Carr‚ de la distance minimum par d‚faut :
              celui de la diagonale du niveau (Phytagore, 33ý + 19ý) }
            min_dst := 1089 + 361;
            d := 1; { indice de la distance choisie par d‚faut : la premiŠre qui vient }
            for j := 1 to max_dir do { Parcours du tableau de directions possibles }
            begin
               if tfant[i, 9] = 0 { Si pas mang‚ }
                     { calcul du carr‚ de la distance fant“me <-> Pacman }
                  then dst :=   sqr(fx + tdir[directions[j], 1] - px)
                              + sqr(fy + tdir[directions[j], 2] - py)
                     { calcul du carr‚ de la distance fant“me <-> point de d‚part fant“me }
                  else dst :=   sqr(fx + tdir[directions[j], 1] - tfant[i, 10])
                              + sqr(fy + tdir[directions[j], 2] - tfant[i, 11]);
               { Si le r‚sultat trouv‚ est plus petit que le minimum d‚j… trouv‚ }
               if (diablo > 0) and (tfant[i, 9] = 0) then dst := -dst;
               if dst < min_dst then
               begin
                  { "min_dst", l'ancien minimum devient le nouveau }
                  min_dst := dst;
                  d := j; { Indice de la direction la plus courte : j }
               end;
            end;
 
            dir := directions[d]; { "dir" : valeur de la direction trouv‚e }
            tfant[i, 3] := dir; { que le fant“me prend }
         end;
 
         dir := tfant[i, 3]; { "dir" : direction du fant“me }
         { Le fant“me avance d'un pixel … l'‚cran vers la direction choisie }
         tfant[i, 4] := tfant[i, 4] + tdir[dir, 1];
         tfant[i, 5] := tfant[i, 5] + tdir[dir, 2];
 
 
         { Si fant“me mang‚ }
         if tfant[i, 9] = 1 then
            { Si le fant“me est sur sa case de d‚part }
            if (tfant[i, 4] div 10 = tfant[i, 10]) and (tfant[i, 5] div 10 = tfant[i, 11]) then
            begin
               { il r‚apparait ! }
               tfant[i, 9] := 0;
               { mais est emprisonn‚ pour 30 + 305 * num_fant images }
               tfant[i, 8] := 30 + 305 * num_fant;
         end;
         inc(num_fant); { Fant“me suivant }
      end
      else { Sinon, le fant“me n'est pas encore n‚ (tfant[i, 9] < 0) }
         inc(tfant[i, 9]); { Incr‚mentation du compteur de vie }
   end;
end;

{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE jouer_niveau                            PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Proc‚dure principale du jeu : joue une vie dans  ³
  ³       un niveau.                                       ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con el código del juego pacman

Publicado por ramon (2158 intervenciones) el 24/04/2013 23:26:39
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
{7}
 
procedure jouer_niveau;
 
var
   blinkdir       : integer; { "Direction" de la variation de la oculeur
                               des pastilles et des portes }
   i, j           : integer; { indices }
   px, py         : integer; { Position de Pacman dans le niveau }
   pex, pey       : integer; { Position de Pacman sur l'‚cran }
   dir            : byte;    { Direction de Pacman }
   th, tg, tb, td : boolean; { Touches haut, gauche, bas, droite press‚es }

begin
   { Position de d‚part de Pacman }
   px  := depart_x;
   py  := depart_y;
   { Position physique de d‚part de Pacman }
   pex := px * 10;
   pey := py * 10;

   fps := 0; { Initialisation du nombre d'images / seconde }
 
   { Aucune touche de direction }
   th := false; tg := false; tb := false; td := false;
 
   dir    := 4;       { Direction par d‚faut : 4 (fixe) }
   diablo := 0;       { Mode diablo d‚sactiv‚ }
   mort   := false;   { Pas mort (pas d‚j… !) }
   quitte := false;   { Ne quitte pas }
 
   p1[77]  := 0;      { Colorisation des valeurs de gris }
   p1[137] := 0;      { utilis‚es par les portes et les capsules }
   p1[149] := 0;      { d'‚nergie en jaune, en mettant les quantit‚s }
   p1[200] := 0;      { de bleu … 0 dans la palette de base "p1" }
   p1[206] := 0;

   p2 := p1;          { Palette "p2" (actuelle) prend les valeurs de "p1"
                        (palette de base) }

   { Affiche Pacman … son point de d‚part }
   affiche_pacman(pex, pey, dir, $A000);
   { Affiche le score }
   affiche_score;
   fondu_ouverture(p2); { Fondu ouverture }

   bouche   := -20;   { Initialisation animation bouche }
   blink    := 64;    { valeur de la variation de couleur des pastilles et des portes }
   blinkdir := 8;     { "Direction" (augmentation / diminution) de la quantit‚ de vert
                        de la couleur des pastilles et des portes }

   texte_xy('PRET ?', 125, 100, $A000, false); { Affiche le message "PRET ?" }
   while keypressed do readkey; { Vide le tampon clavier }

   readkey;           { Attente d'une touche press‚e }
   gettime(hr, min, dsec, sec100); { Initialisation des secondes }
   retrace;           { Attente du top de synchro }
   refresh;           { Affichage du tampon vid‚o (pour effacer le message) }
 
   getintvec($9, @ancien_int); { Sauvegarde de l'ancien gestionnaire clavier }
   repeat
      p2[76]  := (p1[76]  * blink) div 64; { Variation de la valeur de vert }
      p2[136] := (p1[136] * blink) div 64; { des couleurs de la palette utilis‚es }
      p2[148] := (p1[148] * blink) div 64; { par les portes et les capsules d'‚nergie }
      p2[199] := (p1[199] * blink) div 64;
      p2[205] := (p1[205] * blink) div 64;
 
      nosound;        { Arrˆte un ‚ventuel son }
      retrace;        { Attente du top de synchro }
      changer_palette(p2); { Application des nouvelles valeurs de couleurs "p2" }
      { Si la quantit‚ de vert devient limite, on inverse la direction de variation }
      if (blink < 8) or (blink > 56) then
         blinkdir := - blinkdir;
 
      blink := blink + blinkdir; { Variation du vert... }
 
      if not(th or tg or tb or td) then
      begin
         setintvec($9, @ancien_int); { R‚installation de l'ancien gestionnaire clavier
                                    pour ‚viter que le tableau "touches" ne soit modifi‚ }
         th := touches[0] = 1;
         tg := touches[1] = 1;
         tb := touches[2] = 1;
         td := touches[3] = 1;

         getintvec($9, @ancien_int);  { Sauvegarde de l'ancien gestionnaire clavier }
         setintvec($9, @nouveau_int); { Installation du nouveau gestionnaire clavier }
      end;
 
      { Calcul de la position de Pacman dans le niveau … partir de sa position physique }
      px := pex div 10;
      py := pey div 10;
 
      efface_perso(pex, pey);      { Efface Pacman }
      efface_fantomes(tfantomes);  { et les fant“mes }
      bouge_fantomes(tfantomes, px, py); { D‚place les fant“mes }
 
      { Si Pacman est sur une case et une seule }
      if ((pex mod 10) = 0) and ((pey mod 10) = 0) then
      begin
         { Si la case est une pastille }
         if niv[px, py] = 1 then
         begin
            niv[px, py] := 0;         { On l'enlŠve, il l'a mang‚e }
            dec(boules);              { Il reste une boule en moins }
            if bruit then sound(440); { Petit bruit }
            score := score + 10;      { Ca fait 10 points de plus }
         end;
 
         { Si la case est une capsule d'‚nergie }
         if niv[px, py] = 2 then
         begin
            niv[px, py] := 0;    { On l'enlŠve, il l'a mang‚e }
            diablo := 500;       { Mode diablo pendant 500 images }

            { "nega" : palette n‚gatif de la palette en cours "p2" }
            for i := 0 to 767 do nega[i] := 255 - p2[i];

            affiche_pacman(pex, pey, dir, $A000); { Affiche pacman }
            affiche_fantomes(tfantomes, $A000); { Affiche les fant“mes }

            { Eclair stroboscopique + gros son de la mort qui tue }
            for i := 1 to 10 do
            begin
               retrace;            { Top de synchro }
               changer_palette(nega); { Met l'‚cran en n‚gatif }
               for j := 1 to 10 do { Fait un premier son }
               begin
                  if bruit then sound(i * j * 100 + 500);
                  delay(2);
                  nosound;
                  delay(1);
                  if keypressed then readkey; { Evite les bipbipbipbip quand on s'‚nerve sur le clavier }
               end;
               retrace;          { Top de synchro }
               changer_palette(p2); { Remet l'‚cran en positif }
               for j := 10 downto 1 do { Fait un deuxiŠme son }
               begin
                  if bruit then sound(i * j * 100 + 500);
                  delay(2);
                  nosound;
                  delay(1);
                  if keypressed then readkey; { Evite les bipbipbipbip quand on s'‚nerve sur le clavier }
               end;

            end;
         end;

         { Si la case est un t‚l‚porteur }
         if niv[px, py] = 3 then
         begin
            repeat { R‚p‚ter }
               px := px + tdir[dir, 1]; { Avance Pacman de case en case }
               py := py + tdir[dir, 2]; { Dans sa direction }
               if px > 34 then px := 1; { s'il sort du niveau, on le ramŠne }
               if px < 0  then px := 34;{ au bord oppos‚ }
               if py > 18 then py := 0; { zoup l… ! }
               if py < 0  then py := 18;
            until niv[px, py] = 3; { Jusqu'au prochain t‚l‚porteur ou le mˆme }
            pex := 10 * px; { Calcul des nouvelles coordonn‚es physiques }
            pey := 10 * py;
         end
         else { Si ce n'est pas un t‚l‚porteur }
         begin
            { changement de direction en fonction des touches de direction et
              des murs }
            if th and (niv[px    , py - 1] < 6) then dir := 0;
            if tg and (niv[px - 1, py    ] < 6) then dir := 1;
            if tb and (niv[px    , py + 1] < 6) then dir := 2;
            if td and (niv[px + 1, py    ] < 6) then dir := 3;
         end;
 
         { Si Pacman ne fonce pas dans un mur }
         if niv[px + tdir[dir, 1], py + tdir[dir, 2]] < 6 then
         begin
            pex := pex + tdir[dir, 1]; { On le fait avancer d'un pixel dans }
            pey := pey + tdir[dir, 2]; { la direction voulue }
         end;
         th := false; tg := false; tb := false; td := false;
      end
      else { Sinon, Pacman est entre 2 cases }
      begin
         pex := pex + tdir[dir, 1]; { il peut avancer librement d'un pixel }
         pey := pey + tdir[dir, 2]; { dans la direction voulue }
      end;
 
 
      if diablo > 0 then dec(diablo); { Si en mode diablo, on d‚cr‚mente
                                        le compteur diablo }
      inc(bouche); { Incr‚mentation du compteur d'animation de la bouche }

      if bouche > 20 then bouche := -20; { Si limite sup atteinte, remise …
                                           la limite inf }
      affiche_fantomes(tfantomes, $A000); { Affiche les fant“mes }
      affiche_pacman(pex, pey, dir, $A000); { Et notre ami Pacman }

      { EmpŠche que le score d‚passe 999990 points (sinon, d‚bordement de
        l'affichage) }
      if score > 999990 then score := 999990;
 
      { Si la diff‚rence du nouveau et de l'ancien score est sup‚rieure …
        50000 points }
      if score >= score2 + 50000 then
      begin
         score2 := score2 + 50000; { On ajoute 50000 … l'ancien score }
         inc(vies);                { Et une vie ! }
         if vies > 13 then vies := 13; { Sauf s'il y en a 13 (le maxi) }
         affiche_score;            { Affiche le score et les vies }
         { Et ‚met un petit son rigolo }
         for i := 100 to 500 do begin if bruit then sound(i * 5); delay(1); end; nosound;
      end
      else { Sinon }
         affiche_score; { Affiche le score et les vies }

      { Contr“le des contacts fant“mes <-> Pacman }
      for i := 1 to max_fant do { Parcours du tableau des fant“mes }
      begin  { Si le fant“me est vivant et "touche" Pacman }
         if     (pex < tfantomes[i, 4] + 6) and (pex > tfantomes[i, 4] - 6)
            and (pey < tfantomes[i, 5] + 6) and (pey > tfantomes[i, 5] - 6)
            and (tfantomes[i, 9] = 0) then
            begin
               if diablo > 0 then { Si Pacman est en mode diablo }
               begin
                  tfantomes[i, 9] := 1; { Le fant“me est mort ( > 0) }
                  { Petit bruitage }
                  for j := 50 downto 10 do
                  begin
                     if bruit then sound(j * 20);
                     delay(1);
                  end;
                  { et 5000 points de plus ! }
                  score := score + 5000;
                  nosound { ta gueule ! }
               end
               else { Sinon }
                  mort := true; { Pacman est mort }
            end;
      end;

      if mort then { Et si Pacman est mort }
      begin
         dec(vies);     { Une vie en moins }
         affiche_score; { Affiche le score avec la vie en moins }
         for j := 500 downto 100 do { Ca fait un bruit }
         begin
            if bruit then sound(j * 5);
            delay(1);
         end;
      end;

      if showfps and nouvsec then texte_xy(inttostr(fps) + ' FPS ', 0, 190, $A000, false);

      { Si touche press‚e }
      if keypressed then
      case readkey of
         { Echap : quitter }
         #27      : quitte := true;
         { F : afficher ou cacher le compteur d'images / seconde }
         'F', 'f' : begin
                       showfps := not(showfps);
                       if not(showfps) then
                       begin
                          for i := 0 to 6 do coller(i * 10, 190, 10, 10, vide, $A000);
                       end;
                    end;
      end;
 
 
   { Reboucle jusqu'… ce que l'on quitte, que Pacman est mort ou qu'il
     ne reste plus de pastilles … manger }
   until quitte or (boules = 0) or mort;
   nosound;                    { La ferme, y'a des gens qui bossent ici ! }
   fondu_fermeture(p2);        { Fondu fermeture }
   setintvec($9, @ancien_int); { R‚installlation de l'ancien gestionnaire clavier }
end;


{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³FUNCTION saisie_chaine_xy                         PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Saisit une chaŒne de caractŠres aux coordonn‚es  ³
  ³       "x, y" de longueur maxi "longmax"                ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

function saisie_chaine_xy(x, y : integer; longmax : integer) : string;

var
   ch    : string;  { ChaŒne saisie }
   k     : char;    { CaractŠre de la touche }
   s     : boolean; { Vrai si touche sp‚ciale }
   t     : boolean; { Vrai si la saisie est termin‚e }
   ck    : byte;    { Code ASCII de la touche }
   lc    : integer; { Position du curseur d'‚dition }
   i     : integer; { Indice }
 
begin
   ch := '';        { ChaŒne finale initialement vide }
   t := false;      { Termin‚ : faux }
   lc := 0;         { Longueur de la chaŒne = 0 }
 
   while not(t) do  { Tant qu'on n'a pas termin‚ }
   begin
      { Affiche le curseur }
      coller_transp(lc * 10 + x, y , 10, 10, police_1[3700], $A000);
      k  := readkey;           { "k" valeur de la touche press‚e }
      s  := keypressed;        { "s" vrai si un deuxiŠme signal de touche re‡u = touche sp‚ciale }
      if s then k := readkey;  { Il s'agit alors d'une touche sp‚ciale, lecture de "k" }
      ck := ord(k);            { ck : code ASCII de la touche }
      coller(lc * 10 + x, y , 10, 10, vide, $A000);
      if not(s) then           { Si ce n'est pas une touche sp‚ciale }
      begin
         { Si lettre majuscule et qu'il reste de la place }
         if (k <= 'Z') and (k >= 'A') and (lc < longmax) then
         begin
            inc(lc);       { Incr‚mentation de la longueur de la chaŒne }
            ch := ch + k;  { On ajoute la lettre tap‚e }
            { Affiche la lettre tap‚e }
            coller_transp((lc - 1) * 10 + x, y , 10, 10, police_1[(ck - ord('A')) * 100], $A000);
         end;
         { Si lettre minuscule et qu'il reste de la place }
         if (k <= 'z') and (k >= 'a') and (lc < longmax) then
         begin
            inc(lc);       { Incr‚mentation de la longueur de la chaŒne }
            { On ajoute la lettre tap‚e mise en majuscule }
            ch := ch + chr(ord(k) - ord('a') + ord('A'));
            { Affiche la lettre tap‚e }
            coller_transp((lc - 1) * 10 + x, y , 10, 10, police_1[(ck - ord('a')) * 100], $A000);
         end;
         { Si espace }
         if (k = ' ') and (lc < longmax) then
         begin
            inc(lc);       { Incr‚mentation de la longueur de la chaŒne }
            ch := ch + k;  { On y ajoute l'espace }
            { Affichage d'un blanc }
            coller_transp((lc - 1) * 10 + x, y , 10, 10, police_1[2600], $A000);
         end;
         { Si retour arriŠre et qu'il y a des caractŠres … effacer }
         if (ck = 8) and (lc > 0) then
         begin
            { Efface le dernier caractŠre de la chaŒne }
            delete(ch, length(ch), 1);
            { Efface le caractŠre … l'‚cran }
            coller((lc - 1) * 10 + x, y , 10, 10, vide, $A000);
            dec(lc);       { D‚cr‚mentation de la longueur de la chaŒne }
         end;
         if ck = 13 then t := true; { Si "Entr‚e", fin de la saisie }
      end;
   end;
   saisie_chaine_xy := ch; { On retourne la chaŒne saisie }
end;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con el código del juego pacman

Publicado por ramon (2158 intervenciones) el 24/04/2013 23:28:24
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
{8}
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE ajoute_meilleurs_scores                 PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Affiche les meilleurs scores … partie du fichier ³
  ³       d'extension ".sco" .                             ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }

procedure ajoute_meilleurs_scores;

type
   t_score = record
                nom   : string;   { Nom du joueur }
                score : longint;  { Son score }
             end;

var
   F      : text;                 { Fichier texte de scores }
   i, j   : integer;              { Indices }
   nom    : string;               { Nom du joueur }
   sc     : longint;              { Score lu dans le fichier }
   sc_min : longint;              { Score minimum }
   sc_max : longint;              { Score maximum }
   i_max  : integer;              { position du score maxi dans le tableau }
   car    : char;                 { CaractŠre lu dans le fichier }
   scores : array[1..11] of t_score; { Tableau des scores }

begin
   assign(F, nom_fic_niv + '.sco');{ Ouverture du fichier texte F }
       {$I-}                      { des scores }
   reset(F);
       {$I+}
   if (IOResult = 0) then         { Si ouverture sans problŠmes }
   begin
      sc_min := 999990;           { Score le plus faible : le maxi ! }
      for i := 1 to 10 do         { Lecture du fichier }
      begin
         { Lecture du nom }
         nom := '';
         read(F, car);
         { Lit le caractŠre TQ ce n'est pas un : }
         while (car <> ':') do
         begin
            nom := nom + car; { Et l'ajoute au nom }
            read(F, car);
         end;
         { Lit ensuite le score du joueur }
         readln(F, sc);
         { Si c'est le score le plus faible du fichier }
         { le score mini prend la valeur du score du joueur }
         if sc < sc_min then sc_min := sc;
         { Balance le score et le nom dans le tableau des scores }
         scores[i].nom   := nom;
         scores[i].score := sc;
      end;
      close(F); { Ferme le fichier }
      { Si le score actuel "score" est sup‚rieur au plus petit
        score du fichier, on a un nouveau meilleur score }
   end
   else { Si le fichier des scores n'existe pas }
   begin
      { Cr‚ation d'une liste de scores vierge }
      for i := 1 to 10 do
      begin
         scores[i].nom   := '';
         scores[i].score := 0;
      end;
      sc_min := 0; { Le score minimum est alors 0 }
   end;
 
   if score > sc_min then
   begin
      efface($A000); { Efface l'‚cran }
      { Charge la palette par d‚faut }
      charger_palette('palette.pcx', p1);
      { Applique la pelette "noir" }
      changer_palette(noir);
      { Dessine l'encadr‚ }
      for i := 9 to 23 do
      begin
         coller(i * 10, 105, 10, 10, mur_gd, $A000);
         coller(i * 10, 125, 10, 10, mur_gd, $A000);
      end;
      coller( 80, 105, 10, 10, mur_bd, $A000);
      coller(240, 105, 10, 10, mur_gb, $A000);
      coller( 80, 125, 10, 10, mur_hd, $A000);
      coller(240, 125, 10, 10, mur_hg, $A000);
      coller( 80, 115, 10, 10, mur_hb, $A000);
      coller(240, 115, 10, 10, mur_hb, $A000);
      texte_xy('NOUVEAU MEILLEUR SCORE !', 35, 85, $A000, true);
 
      fondu_ouverture(p1); { Fondu ouverture }
      { Saisie du nom du joueur et ajout … la liste }
      scores[11].nom := saisie_chaine_xy(90, 115, 14);
      scores[11].score := score; { Ainsi que le score }
      fondu_fermeture(p1); { Fondu fermeture }
 
      rewrite(F);          { R‚ecriture (‚crasement) de F }
 
      for j := 1 to 10 do  { Ecriture des 10 meilleurs scores (parmi les 11) }
      begin
         sc_max := 0;      { Score maxi }
         i_max  := 1;      { Position du score maxi }
         { Recherche du score maximal, et de sa position }
         for i := 1 to 11 do
         begin
            if scores[i].score > sc_max then
            begin
               i_max := i;
               sc_max := scores[i].score;
            end;
         end;
         { Ecrit le plus haut score dans le fichier }
         writeln(F, scores[i_max].nom, ':', inttostr(scores[i_max].score));
         { Et on l'efface dans la liste maintenant qu'on n'en n'a plus besoin }
         scores[i_max].score := 0;
         scores[i_max].nom   := '';
      end; { On recommence }
 
      close(F); { Et on ferme F pour sauvegarder }
   end;
end;
 
{ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³PROCEDURE affiche_meilleurs_scores                PASCAL³
  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  ³R“le : Affiche les meilleurs scores … partie du fichier ³
  ³       "scores.dat".                                    ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ }
 
procedure affiche_meilleurs_scores;
 
var
   F      : text;                 { Fichier texte de scores }
   i, j   : integer;              { Indices }
   sc     : string;               { Score lu dans le fichier }
   nom    : string;               { Nom du joueur }
   car    : char;                 { CaractŠre lu dans le fichier }
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda con el código del juego pacman

Publicado por ramon (2158 intervenciones) el 24/04/2013 23:29:22
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
{9}
 
begin
   assign(F, nom_fic_niv + '.sco'); { Ouverture du fichier texte F des scores }
       {$I-}
   reset(F);
       {$I+}
   if (IOResult = 0) then         { Si ouverture sans encombres }
   begin
      efface($A000);              { Efface l'‚cran }
      { Chargement palette par d‚faut }
      charger_palette('palette.pcx', p1);
      { On applique la pelette "noir" }
      changer_palette(noir);
      { Dessine le tableau des scores }
      for i := 6 to 26 do
      begin
         coller(i * 10,  10, 10, 10, mur_gd, $A000);
         coller(i * 10, 180, 10, 10, mur_gd, $A000);
      end;
      for i := 2 to 17 do
      begin
         coller( 50, i * 10, 10, 10, mur_hb, $A000);
         coller(270, i * 10, 10, 10, mur_hb, $A000);
      end;
      coller( 50,  10, 10, 10, mur_bd, $A000);
      coller( 50, 180, 10, 10, mur_hd, $A000);
      coller(270,  10, 10, 10, mur_gb, $A000);
      coller(270, 180, 10, 10, mur_hg, $A000);
      texte_xy('MEILLEURS SCORES', 80, 30, $A000, true);
      { Affiche le nom de chaque joueur et son score }
      for i := 1 to 10 do
      begin
         { Lecture du nom du joueur }
         nom := '';
         read(F, car);
         while (car <> ':') do
         begin
            nom := nom + car;
            read(F, car);
         end;
         { Lecture de son score }
         readln(F, sc);
         { Affichage des 2 }
         texte_xy(nom, 60, i * 10 + 50, $A000, true);
         texte_xy(sc, 270 - (10 * length(sc)), i * 10 + 50, $A000, true);
      end;
      close(F); { Fermeture du fichier }
      fondu_ouverture(p1); { Fondu ouverture }
      readkey;             { Attente d'une touche press‚e }
      fondu_fermeture(p1); { Fondu fermeture }
   end;
end;
 
 
{ ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ
  Û             Programme Principal          Û
  ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ }
 
 
var
   i            : integer; { Indice }
   anim         : integer; { Num‚ro de l'image de l'animation }
   tx, ty       : word;    { Tailles d'images }
   para1, para2 : string;  { ParamŠtres de lancement du jeu }

begin
   nom_fic_niv := 'pacman';{ Nom fichier niveau par d‚faut }
   bruit := true;          { Son activ‚ par d‚faut }
   { On n'affiche pas le nombre d'images / seconde }
   showfps := false;

   { Un paramŠtre }
   if Paramcount = 1 then
   begin
      { S'il s'agit de la d‚sactivation du son, on le d‚sactive }
      if paramstr(1) = '/nosound' then bruit := false
      { Sinon, c'est un nom de fichier de niveaux }
                                  else nom_fic_niv := paramstr(1);
   end;
   { 2 paramŠtres au moins }
   if Paramcount >= 2 then
   begin
      { Le nom du fichier niveaux est le premier paramŠtre }
      nom_fic_niv := paramstr(1);
      { la d‚sactivation du son est le second }
      if (paramstr(2) = '/nosound') then bruit := false;
   end;
 
 
   { Si le fichier niveaux existe }
   if existe(nom_fic_niv + '.niv') then
   begin
      { Attribution de l'espace m‚moire pour le tampon vid‚o ( 64 Ko) }
      getmem(buf, 64000);
      buf_adr := seg(buf^);

      { Passe en mode 320 * 200 * 8 bits }
      mode_320_200_256;

      { Initiailisation des touches de direction, et recherche du segment
        et de l'offset du tableau "touches }
      valeur     := 0;
      touches[0] := 0 ; touches[1] := 0 ; touches[2] := 0 ; touches[3] := 0;
      a_touches  := ofs(touches);
      s_touches  := seg(touches);

      { Chargement des graphismes }
      efface($A000);             { Efface l'‚cran }
      { Chargement de la palette de la police de caractŠres }
      charger_palette('police_1.pcx', p1);
      changer_palette(p1);
      { Chargement de la police de caractŠres }
      charger_PCX('police_1.pcx' , police_1 , tx, ty);
      { Affiche le message 'CHARGEMENT' }
      texte_xy('CHARGEMENT', 105, 95, $A000, true);

      { Pacman }
      charger_PCX('pac_oh.pcx'   , pac_oh   , tx, ty);
      charger_PCX('pac_fh.pcx'   , pac_fh   , tx, ty);
      charger_PCX('pac_og.pcx'   , pac_og   , tx, ty);
      charger_PCX('pac_fg.pcx'   , pac_fg   , tx, ty);
      charger_PCX('pac_ob.pcx'   , pac_ob   , tx, ty);
      charger_PCX('pac_fb.pcx'   , pac_fb   , tx, ty);
      charger_PCX('pac_od.pcx'   , pac_od   , tx, ty);
      charger_PCX('pac_fd.pcx'   , pac_fd   , tx, ty);
      { Pacman diablo }
      charger_PCX('pac_ohd.pcx'  , pac_ohd  , tx, ty);
      charger_PCX('pac_fhd.pcx'  , pac_fhd  , tx, ty);
      charger_PCX('pac_ogd.pcx'  , pac_ogd  , tx, ty);
      charger_PCX('pac_fgd.pcx'  , pac_fgd  , tx, ty);
      charger_PCX('pac_obd.pcx'  , pac_obd  , tx, ty);
      charger_PCX('pac_fbd.pcx'  , pac_fbd  , tx, ty);
      charger_PCX('pac_odd.pcx'  , pac_odd  , tx, ty);
      charger_PCX('pac_fdd.pcx'  , pac_fdd  , tx, ty);
      { Fant“me orange }
      charger_PCX('fant_1o.pcx'  , fant_1o  , tx, ty);
      charger_PCX('fant_1f.pcx'  , fant_1f  , tx, ty);
      charger_PCX('fant_1p.pcx'  , fant_1p  , tx, ty);
      { Fant“me rouge }
      charger_PCX('fant_2o.pcx'  , fant_2o  , tx, ty);
      charger_PCX('fant_2f.pcx'  , fant_2f  , tx, ty);
      charger_PCX('fant_2p.pcx'  , fant_2p  , tx, ty);
      { Fant“me vert }
      charger_PCX('fant_3o.pcx'  , fant_3o  , tx, ty);
      charger_PCX('fant_3f.pcx'  , fant_3f  , tx, ty);
      charger_PCX('fant_3p.pcx'  , fant_3p  , tx, ty);
      { Fant“me bleu }
      charger_PCX('fant_4o.pcx'  , fant_4o  , tx, ty);
      charger_PCX('fant_4f.pcx'  , fant_4f  , tx, ty);
      charger_PCX('fant_4p.pcx'  , fant_4p  , tx, ty);
      { Yeux }
      charger_PCX('zyeux_1.pcx'  , zyeux_1  , tx, ty);
      charger_PCX('zyeux_2.pcx'  , zyeux_2  , tx, ty);
      { Capsule d'‚nergie }
      charger_PCX('energie.pcx'  , energie  , tx, ty);
      { Pastille }
      charger_PCX('pastille.pcx' , pastille , tx, ty);
      { Murs }
      charger_PCX('mur_.pcx'     , mur_     , tx, ty);
      charger_PCX('mur_h.pcx'    , mur_h    , tx, ty);
      charger_PCX('mur_b.pcx'    , mur_b    , tx, ty);
      charger_PCX('mur_g.pcx'    , mur_g    , tx, ty);
      charger_PCX('mur_d.pcx'    , mur_d    , tx, ty);
      charger_PCX('mur_gd.pcx'   , mur_gd   , tx, ty);
      charger_PCX('mur_hb.pcx'   , mur_hb   , tx, ty);
      charger_PCX('mur_hd.pcx'   , mur_hd   , tx, ty);
      charger_PCX('mur_gb.pcx'   , mur_gb   , tx, ty);
      charger_PCX('mur_bd.pcx'   , mur_bd   , tx, ty);
      charger_PCX('mur_hg.pcx'   , mur_hg   , tx, ty);
      charger_PCX('mur_gbd.pcx'  , mur_gbd  , tx, ty);
      charger_PCX('mur_hgd.pcx'  , mur_hgd  , tx, ty);
      charger_PCX('mur_hgb.pcx'  , mur_hgb  , tx, ty);
      charger_PCX('mur_hbd.pcx'  , mur_hbd  , tx, ty);
      charger_PCX('mur_hgbd.pcx' , mur_hgbd , tx, ty);
      { Porte prison opaque }
      charger_PCX('porte_gd.pcx' , porte_gd  , tx, ty);
      charger_PCX('porte_hb.pcx' , porte_hb  , tx, ty);
      { Porte prison transparente }
      charger_PCX('portetgd.pcx' , portet_gd  , tx, ty);
      charger_PCX('portethb.pcx' , portet_hb  , tx, ty);
      { Vide }
      charger_PCX('rien.pcx'     , vide     , tx, ty);
      { Chiffres du score }
      charger_PCX('chiffres.pcx' , chiffres , tx, ty);
      { le mot "SCORE" }
      charger_PCX('score.pcx'    , score_img, tx, ty);
      { Coeur }
      charger_PCX('coeur.pcx'    , coeur    , tx, ty);
      { Image de titre }
      charger_PCX('pactitre.pcx' , buf^     , tx, ty);
      charger_palette('pactitre.pcx', p1);

      { Affiche l'image de titre avec fondus }
      for i := 0 to 767 do noir[i] := 0; { Cr‚ation d'une palette noire }

      changer_palette(noir);
      refresh;
      fondu_ouverture(p1);
      readkey;
      fondu_fermeture(p1);
      efface($A000);
      charger_palette('palette.pcx', p1);
      efface(buf_adr);

      max_fant := 0; { 0 fant“mes }
      num_niv  := 0; { Niveau en cours : 0 (y'en n'a pas) }
      score    := 0; { Score actuel }
      score2   := 0; { Score initial }
      vies     := 3; { 3 vies pour commencer }

      repeat
         inc(num_niv); { Niveau en cours : le pr‚c‚dent + 1 }
         { Charge le niveau "niv" de titre "titre_niv" dans le fichier
           de niveaux "nom_fic_niv" }
         charger_niveau(nom_fic_niv + '.niv', num_niv, niv, max_niv, titre_niv);
         if (max_niv > 0) then { Si il y a des niveaux dans le fichier }
         begin
            repeat
               { Efface l'‚cran et affiche le num‚ro et le titre du niveau }
               efface($A000);
               texte_xy('NIVEAU ' + inttostr(num_niv), 120, 80, $A000, true);
               texte_xy(titre_niv, (320 - (length(titre_niv) * 10)) div 2 , 110, $A000, true);
               fondu_ouverture(p1);
               readkey;               { Attend une touche }
               fondu_fermeture(p1);   { Fondu fermeture }
               efface($A000);         { Efface l'‚cran }
               efface(buf_adr);       { et le tampon vid‚o }
               changer_palette(noir); { Applique la palette "noir" }
               init_niveau(niv);      { Dessine le niveau et initialise les personnages }

               refresh;               { Affiche le tampon vid‚o contenant le niveau }

               jouer_niveau;          { Lancement de la proc‚dure de jeu ! }
            { Jusqu'… ce que toutes les pastilles soient mang‚es, ou que toutes
              les vies ont ‚t‚ perdues ou que le joueur quitte le jeu }
            until (vies = 0) or quitte or (boules = 0);

            { Si toutes les pastille ont ‚t‚ mang‚es, le niveau est gagn‚ }
            if boules = 0 then
            begin
               { Animation "Niveau Termin‚" : Pacman se la pŠte grave }
               efface($A000);
               charger_palette('lunettes.pcx', p1);
               charger_PCX('termine.pcx' , temp_img, tx, ty);
               coller(92 , 70, 136, 10,    temp_img, $A000);
               charger_PCX('lunettes.pcx' , temp_img, tx, ty);
               coller(135, 100,  50, 50, temp_img[0], $A000);
               fondu_ouverture(p1);
               anim := 0;
               repeat
                   retrace;
                   coller(135, 100,  50, 50, temp_img[2500 * anim], $A000);
                   delay(300);
                   inc(anim);
                   if anim = 5 then anim := 3;
               until keypressed;
               fondu_fermeture(p1);
               efface($A000);
               charger_palette('palette.pcx', p1);
            end;
         end
         else { Sinon, il n'y a aucun niveau }
            quitte := true; { On quitte le jeu, puisqu'il n'y a rien … jouer ! }
      until (num_niv = max_niv) or quitte or (vies = 0);

      if not(quitte) then { Si on ne quitte pas }
      begin
         efface($A000); { On efface l'‚cran }
         if vies = 0 then { Si toutes les vies ont ‚t‚ perdues : Game Over }
         begin
            { Animation "Game Over" + Pacman qui a bobo … la cabeza }
            efface($A000);
            charger_palette('bobo.pcx', p1);
            charger_PCX('gameover.pcx' , temp_img, tx, ty);
            coller(112, 70, 96, 10,   temp_img, $A000);
            charger_PCX('bobo.pcx' , temp_img, tx, ty);
            coller(135, 100, 50, 50, temp_img[0], $A000);
            fondu_ouverture(p1);
            anim := 0;
            repeat
                retrace;
                coller(135, 100,  50, 50, temp_img[2500 * anim], $A000);
                delay(300);
                inc(anim);
                if anim = 2 then anim := 0;
            until keypressed;
         end;
         { Si le dernier niveau … ‚t‚ termin‚ }
         if (num_niv = max_niv) and (boules = 0) then
         begin
            { Affiche le message "YOU WIN" et le score }
            texte_xy('YOU WIN !', 115, 80, $A000, true);
            texte_xy('SCORE', 100 , 110, $A000, true);
            texte_xy(inttostr(score), 170 , 110, $A000, true);
            fondu_ouverture(p1);
            { Pendant ce temps l…, on charge l'animation de fin }
            charger_PCX('banc.pcx' , buf^       ,tx, ty);
            charger_PCX('kiss.pcx' , temp_img    , tx, ty);
            readkey;
            fondu_fermeture(p1);
            { Affiche l'image de fin }
            efface($A000);
            refresh; { Attente touche press‚e }
            charger_palette('banc.pcx', p1);
            fondu_ouverture(p1);
            delay(2000);
            { Animation du bisou 'smak !' }
            for anim := 0 to 3 do
            begin
               retrace;
               coller(106,  55, 110, 78, temp_img[anim * 8580], $A000);
               delay(600);
            end;
            { Animation texte 'Fin' }
            charger_PCX('fin.pcx' , temp_img    , tx, ty);
            delay(1400);
            for anim := 0 to 2 do
            begin
               retrace;
               coller(138, 164,  54, 21, temp_img[anim * 1134], $A000);
               delay(300);
            end;
            readkey; { Attente touche press‚e }
         end;
         fondu_fermeture(p1);  { Fondu fermeture }
         efface($A000);        { Efface l'‚cran }
         charger_palette('palette.pcx', p1); { Palette par d‚faut }
         ajoute_meilleurs_scores;   { Ajoute le score aux meilleur scores
                                      (s'il est aussi bon que ‡a) }
         affiche_meilleurs_scores;  { Affiche les meilleurs scores }
      end;
      textmode(C80);           { Restaure le mode texte 80 colonnes }
   end
   else { Sinon, fichier niveaux non trouv‚ }
   begin
      { Message d'erreur }
      textcolor(12);
      write('ERREUR');
      textcolor(7);
      write(' : Le fichier niveau ');
      textcolor(15);
      write(nom_fic_niv);
      textcolor(7);
      writeln(' n''a pu ˆtre ouvert ! ');
      son_erreur; { Et petit son ! }
   end;
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Ayuda

Publicado por Oswaldo Suarez (11 intervenciones) el 25/04/2013 00:17:47
Amigo puedes ayudarme, como hago para compilarlo todo? si esta en partes los 9 archivos . gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda

Publicado por ramon (2158 intervenciones) el 25/04/2013 21:32:48
Copia cada parte y pega las en el bloc de notas y luego guarda lo donde tengas el pascal guarda
como pacman.pas y vale pero como comento necesitas los archivos pcx que tendrás que bajar
de la dirección que me pasaste
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Ayuda

Publicado por omsg63 (11 intervenciones) el 27/04/2013 02:53:15
Hola, una pregunta cada una de los 9 archivos que me dices que nombre le debo poner??????con que nombre debo llamar a cada uno de los 9 archivos ejemplo pas1, pas2, pas3, pas4, pas5 pas6, pas7, pas8 y pas9 asi los puedo llamar, los archvivos pcx donde los debo guardar.

O tengo que unir los 9 archivos y llamar a ese archivo pacman.pas

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Ayuda

Publicado por omsg63 (11 intervenciones) el 28/04/2013 00:11:34
Hola, ya logre hacer funcionar el condigo pero solo trabaja con las librerias graficas en windows xp de 32 bits, cuando lo pruebo en windows 7 o windows 8 no me funciona.
Al modificar los comentarios del codigo ( Borro alguna frase ) deja de funcionar el codigo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda

Publicado por ramon (2158 intervenciones) el 29/04/2013 12:45:03
Yo lo probé con windows 7 32 bit y funciona correcto.
Ten encenta que estos programas como mucho funcionan en 32 bit no en mayores.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda

Publicado por ramon (2158 intervenciones) el 29/04/2013 13:07:07
Con los mensajes el código funciona correcto si quitas alguno tendrás que buscar donde es llamado
para anular la llamada también sino tendrás problemas de ejecución.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Punto Pendiente

Publicado por oswaldo (11 intervenciones) el 08/05/2013 05:41:52
Buenas y saludos a la comunidad tengo un nuevo programa a realizar:

Necesito crear un programa que grafique en un plano cartesiano (X) (Y) a partir de la ecuacion punto pendiente :

y-y1=m(x-x1)

Observación
De la definicion se observa que los elementos importantes de la recta y para hallar su ecuacion son:

a)Un punto por donde pasa la recta
b)El valor de la pendiente
Ejemplo:
Halla la ecuacion de la recta que pasa por los puntos A(3,-1) y tiene pendiente -2/3

Es decir el usuario me dara EL PUNTO y LA PENDIENTE el programa debe graficar , necesito hacerlo en PASCAL MODO GRAFICO SI ES POSIBLE, gracias

saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Punto Pendiente

Publicado por [email protected] (11 intervenciones) el 09/05/2013 05:46:56
Buenas y saludos a la comunidad tengo un nuevo programa a realizar:

Necesito crear un programa que grafique en un plano cartesiano (XY) a partir de la ecuacion punto pendiente :

y-y1=m(x-x1)

Observación
De la definicion se observa que los elementos importantes de la recta son los puntos X1, Y1 y m y para hallar su ecuacion es necesario y encontrar los puentos para graficar es necesario:

a)Un punto por donde pasa la recta (X1,Y1)
b)El valor de la pendiente (m)
c) luego con esta ecuación hallo los valores de los punto a graficar y = m(X-X1) + y1

Si le doy valores a X en un rango que me pida el programa( ejemplo -100 a 100) obtendre otros valores de Y, o sea un punto (x, m(x-x1)+y), (ojo; y = m(X-X1) + y1) estos puntos se pueden ir graficando y luego unir mediante segmentos rectos y hacer la gráfica, ahora mi problema es como programo esto en Dev Pascal


El usuario me daria EL PUNTO y LA PENDIENTE, posteriormente se establece el rango para graficarel y el programa debe graficar los puntos y unirlos, necesito hacerlo en PASCAL MODO GRAFICO, gracias

saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar