-
Notifications
You must be signed in to change notification settings - Fork 4
/
MISSILE.PAS
603 lines (556 loc) · 13.5 KB
/
MISSILE.PAS
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2022
@website(https://www.gladir.com/7iles)
@abstract(Target: Turbo Pascal)
}
Program MissileCommand;
Uses Crt,DOS;
Type
{Palette RVB (RGB) }
RGB=Record
R:Byte; { (R)ouge ((R)ed) }
G:Byte; { (V)ert ((G)reen) }
B:Byte; { (B)leu ((B)lue) }
End;
Const
LevelMissile:Array[0..5]of Byte=(10,10,20,50,100,200);
LevelMaxMissile:Array[0..5]of Byte=(2,4,5,6,10,16);
DefaultRGB:Array[0..15]of RGB=({ Palette RVB par d,faut }
(R:$00;G:$00;B:$00), { 00h (0): Palette RVB Noir par d,faut }
(R:$00;G:$00;B:$70), { 01h (1): Palette RVB Bleu par d,faut }
(R:$00;G:$70;B:$00), { 02h (2): Palette RVB Vert par d,faut }
(R:$00;G:$70;B:$70), { 03h (3): Palette RVB Cyan par d,faut }
(R:$70;G:$00;B:$00), { 04h (4): Palette RVB Rouge par d,faut }
(R:$70;G:$00;B:$70), { 05h (5): Palette RVB Magenta par d,faut }
(R:$70;G:$48;B:$00), { 06h (6): Palette RVB Brun par d,faut }
(R:$C4;G:$C4;B:$C4), { 07h (7): Palette RVB Gris clair par d,faut }
(R:$34;G:$34;B:$34), { 08h (8): Palette RVB Gris fonc, par d,faut }
(R:$00;G:$00;B:$FF), { 09h (9): Palette RVB Bleu claire par d,faut }
(R:$24;G:$FC;B:$24), { 0Ah (10): Palette RVB Vert claire par d,faut }
(R:$00;G:$FC;B:$FC), { 0Bh (11): Palette RVB Cyan claire par d,faut }
(R:$FC;G:$14;B:$14), { 0Ch (12): Palette RVB Rouge claire par d,faut }
(R:$B0;G:$00;B:$FC), { 0Dh (13): Palette RVB Magenta claire par d,faut }
(R:$FC;G:$FC;B:$24), { 0Eh (14): Palette RVB Jaune par d,faut }
(R:$FF;G:$FF;B:$FF));{ 0Fh (15): Palette RVB blanc par d,faut }
Var
MI,ML:Array[0..19]of Byte;
MX1,MX2:Array[0..19]of Word;
MaxMissile,Missile2Send:Integer;
Level:Word;
MouseFound:Boolean;
Score:LongInt;
NmCity:Byte;
CurrColor:Byte;
OldMouseX,OldMouseY,OldMouseButton:Word;
BufMouse:Array[0..32*16-1]of Byte;
Function MouseDriverFound:Boolean;
Var
Regs:Registers;
Begin
Regs.AX:=0;
Intr($33,Regs);
MouseDriverFound:=Regs.AX=$FFFF;
End;
Procedure SetMouseMoveArea(X1,Y1,X2,Y2:Word);Assembler;ASM
MOV AX,8
MOV CX,Y1
MOV DX,Y2
INT 033h
MOV AX,7
MOV CX,X1
MOV DX,X2
INT 033h
END;
Procedure GetMouseSwitch(Var X,Y,Button:Word);
Var
Regs:Registers;
Begin
Regs.AX:=$0003;
Intr($33,Regs);
Button:=Regs.BX;
X:=Regs.CX;
Y:=Regs.DX;
End;
Function GetMouseButton:Word;
Var
X,Y,Button:Word;
Begin
GetMouseSwitch(X,Y,Button);
GetMouseButton:=Button;
End;
Procedure WaitMsBut0;Begin
While GetMouseButton=0 do Begin
End;
End;
Function CStr(X:LongInt):String;
Var
S:String;
Begin
Str(X,S);
CStr:=S;
End;
Function WordToStr(X:Word):String;
Var
S:String;
Begin
Str(X,S);
WordToStr:=S;
End;
Procedure GetMouseImage(X1,Y1,X2,Y2:Integer);
Var
P,J:Integer;
Begin
P:=0;
For J:=Y1 to Y2 do Begin
Move(Mem[SegA000:X1+J*320],BufMouse[P],X2-X1+1);
Inc(P,X2-X1+1);
End;
End;
Procedure PutMouseImage(X1,Y1,X2,Y2:Integer);
Var
P,J:Integer;
Begin
P:=0;
For J:=Y1 to Y2 do Begin
Move(BufMouse[P],Mem[SegA000:X1+J*320],X2-X1+1);
Inc(P,X2-X1+1);
End;
End;
Procedure SetColor(Color:Byte);Begin
CurrColor:=Color;
End;
Procedure SetPixel(X,Y:Integer;Color:Byte);Begin
Mem[SegA000:X+(Y*320)]:=Color;
End;
Function GetPixel(X,Y:Integer):Byte;Begin
GetPixel:=Mem[SegA000:X+(Y*320)];
End;
Procedure SetPalRGB(Var P;Start,Num:Word);Assembler;ASM
MOV AL,Byte Ptr Start
MOV DX,3C8h
OUT DX,AL
CLD
INC DX
PUSH DS
LDS SI,P
MOV AX,Num
MOV CX,AX
ADD CX,AX
ADD CX,AX
@2:
LODSB
{$IFOPT G+}
SHR AL,2
{$ELSE}
SHR AL,1
SHR AL,1
{$ENDIF}
OUT DX,AL
LOOP @2
POP DS
END;
Procedure PutLnHor(X1,Y,X2,Kr:Integer);
Var
I:Integer;
Begin
If(X1>X2)Then Begin
I:=X1;
X1:=X2;
X2:=I;
End;
For I:=X1 to X2 do SetPixel(I,Y,Kr);
End;
Procedure PutFillBox(X1,Y1,X2,Y2,Kr:Integer);
Var
J:Integer;
Begin
For J:=Y1 to Y2 do PutLnHor(X1,J,X2,Kr);
End;
Procedure _PutFillBox(X1,Y1,X2,Y2:Integer);Begin
PutFillBox(X1,Y1,X2,Y2,CurrColor);
End;
Procedure PutLn(X1,Y1,X2,Y2,Kr:Integer);
Var
D,DX,DY,I,J,Ainc,Binc,Ic:Integer;
Begin
If(Y2=Y1)Then Begin
PutLnHor(X1,Y1,X2,Kr);
Exit;
End;
If Abs(X2-X1)<Abs(Y2-Y1)Then Begin
If(Y1>Y2)Then ASM MOV AX,X1;XCHG AX,X2;MOV X1,AX;MOV AX,Y1;XCHG AX,Y2;MOV Y1,AX;END;
If(X2>X1)Then Ic:=1 Else Ic:=-1;
DY:=Y2-Y1;DX:=Abs(X2-X1);D:=(DX shl 1)-DY;Ainc:=(DX-DY)shl 1;Binc:=DX shl 1;J:=X1;
SetPixel(X1,Y1,Kr);
I:=Y1+1;
While(I<=Y2)do Begin
If D>=0Then Begin Inc(J,Ic);Inc(D,Ainc)End else Inc(D,Binc);
SetPixel(J,I,Kr);
Inc(I);
End;
End
else
Begin
If(X1>X2)Then ASM MOV AX,X1;XCHG AX,X2;MOV X1,AX;MOV AX,Y1;XCHG AX,Y2;MOV Y1,AX;END;
If(Y2>Y1)Then Ic:=1 else Ic:=-1;
DX:=X2-X1;DY:=Abs(Y2-Y1);D:=(DY shl 1)-DX;AInc:=(DY-DX)shl 1;BInc:=DY shl 1;J:=Y1;
SetPixel(X1,Y1,Kr);
I:=X1+1;
While(I<=X2)do Begin
If D>=0Then Begin Inc(J,Ic);Inc(D,Ainc)End else Inc(D,Binc);
SetPixel(I,J,Kr);
Inc(I);
End;
End;
End;
Function MaxXTxts:Byte;Begin
MaxXTxts:=39;
End;
Procedure CopT8Bin(X,Y,Matrix,ForegroundColor:Integer);
Var
I:Byte;
Begin
For I:=0 to 7 do Begin
If(Matrix shl I)and 128=128 Then Begin
SetPixel(X+I,Y,ForegroundColor);
End;
End;
End;
Procedure Copy8Bin(X,Y,Matrix,ForegroundColor,BackgroundColor:Integer);
Var
I:Byte;
Begin
For I:=0 to 7 do Begin
If(Matrix shl I)and 128=128 Then Begin
SetPixel(X+I,Y,ForegroundColor);
End
Else
Begin
SetPixel(X+I,Y,BackgroundColor);
End;
End;
End;
Procedure PutTxtXY(X,Y:Byte;Msg:String;Attr:Byte);
Type
Font=Array[0..2047]of Byte;
PFont=^Font;
Var
Intr:Array[0..255]of PFont Absolute $0000:$0000;
I,J:Byte;
Begin
For J:=1 to Length(Msg)do For I:=0 to 7 do Begin
Copy8Bin((X+J-1)*8,Y*8+I,Intr[$43]^[Byte(Msg[J])*8+I],Attr and $F,Attr shr 4);
End;
End;
Procedure BarSpcHor(X1,Y,X2,Attr:Byte);Begin
PutFillBox(X1*8,Y*8,X2*8+7,Y*8+7,Attr shr 4);
End;
Procedure WaitRetrace;Begin
Delay(1000 div 60);
End;
Function Canon(I:Byte):Byte;
Var
S:String;
Begin
S:=Chr(20*8-3)+Chr(20*8-5)+Chr(20*8-6)+Chr(20*8-7)+Chr(20*8-7)+Chr(20*8-8)+
Chr(20*8-8)+Chr(20*8-8)+Chr(20*8-8)+Chr(20*8-8)+Chr(20*8-8)+Chr(20*8-7)+
Chr(20*8-7)+Chr(20*8-6)+Chr(20*8-5)+Chr(20*8-3);
Canon:=Byte(S[I+1]);
End;
Function XCity(I:Byte):Word;
Var
S:String;
Begin
S:=#5#10#15#23#28#33;
XCity:=Byte(S[I+1])shl 3;
End;
Procedure PtrMs;Assembler;ASM
DB 11111111b,00000000b,00000000b,11111111b
DB 11111111b,11111111b,11111111b,11111111b
DB 11111111b,11111111b,11111111b,11111111b
DB 11111111b,11111111b,11111111b,11111111b
DB 11111111b,11111111b,11111111b,11111111b
DB 11111111b,11111111b,11111111b,11111111b
DB 01111111b,11111111b,11111111b,11111110b
DB 01111111b,11111111b,11111111b,11111110b
DB 01111111b,11111111b,11111111b,11111110b
DB 01111111b,11111111b,11111111b,11111110b
DB 11111111b,11111111b,11111111b,11111111b
DB 11111111b,11111111b,11111111b,11111111b
DB 11111111b,11111111b,11111111b,11111111b
DB 11111111b,11111111b,11111111b,11111111b
DB 11111111b,11111111b,11111111b,11111111b
DB 11111111b,00000000b,00000000b,11111111b
DB 00000000b,01111100b,00111110b,00000000b
DB 00000011b,10000000b,00000001b,11000000b
DB 00001100b,00000000b,00000000b,00110000b
DB 00110000b,00000000b,00000000b,00001100b
DB 01000000b,00000000b,00000000b,00000010b
DB 10000000b,00000001b,10000000b,00000001b
DB 10000000b,00000001b,10000000b,00000001b
DB 00000000b,00000111b,11100000b,00000000b
DB 00000000b,00000111b,11100000b,00000000b
DB 10000000b,00000001b,10000000b,00000001b
DB 10000000b,00000001b,10000000b,00000001b
DB 01000000b,00000000b,00000000b,00000010b
DB 00110000b,00000000b,00000000b,00001100b
DB 00001100b,00000000b,00000000b,00110000b
DB 00000011b,10000000b,00000001b,11000000b
DB 00000000b,01111100b,00111110b,00000000b
END;
Procedure HideMousePtr;Begin
PutMouseImage(OldMouseX,OldMouseY,OldMouseX+31,OldMouseY+15);
End;
Procedure ShowMousePtr;
Type
TPtrMs=Array[0..1,0..15,0..3]of Byte;
Var
I,J:Integer;
MousePtr:^TPtrMs;
Begin
GetMouseImage(OldMouseX,OldMouseY,OldMouseX+31,OldMouseY+15);
MousePtr:=@PtrMs;
For J:=0 to 15 do For I:=0 to 3 do Begin
CopT8Bin(OldMouseX+I*8,OldMouseY+J,MousePtr^[1,J,I],$F);
End;
End;
Procedure _BackKbd;
Var
X,Y,Button:Word;
Begin
GetMouseSwitch(X,Y,Button);
If(X<>OldMouseX)or(Y<>OldMouseY)Then Begin
HideMousePtr;
OldMouseX:=X;
OldMouseY:=Y;
ShowMousePtr;
End;
End;
Function PutMissile(X1,Y1,X2,Y2,Limit,Kr:Integer;Var XOut,YOut:Integer):Byte;
Var
D,DX,DY,I,J,Ainc,Binc,Ic,OK:Integer;
Begin
PutMissile:=0;
If Abs(X2-X1)<Abs(Y2-Y1)Then Begin
If(Y1>Y2)Then ASM
MOV AX,X1;
XCHG AX,X2;
MOV X1,AX;
MOV AX,Y1;
XCHG AX,Y2;
MOV Y1,AX;
END;
If(X2>X1)Then Ic:=1 Else Ic:=-1;
DY:=Y2-Y1;DX:=Abs(X2-X1);D:=(DX shl 1)-DY;Ainc:=(DX-DY)shl 1;Binc:=DX shl 1;J:=X1;
SetPixel(X1,Y1,Kr);
I:=Y1+1;
While(I<=Y2)do Begin
If D>=0Then Begin Inc(J,Ic);Inc(D,Ainc)End else Inc(D,Binc);
OK:=GetPixel(J,I);
If OK in[1,2,3]Then Begin XOut:=J;PutMissile:=OK;Exit;End;
SetPixel(J,I,Kr);
If(I>Limit)Then Begin XOut:=J;YOut:=I;Exit;End;
Inc(I);
End;
End
else
Begin
{ If(X1>X2)Then ASM MOV AX,X1;XCHG AX,X2;MOV X1,AX;MOV AX,Y1;XCHG AX,Y2;MOV Y1,AX;END;}
If(Y2>Y1)Then Ic:=1 else Ic:=-1;
DX:=Abs(X2-X1);DY:=Abs(Y2-Y1);D:=(DY shl 1)-DX;AInc:=(DY-DX)shl 1;BInc:=DY shl 1;J:=Y1;
SetPixel(X1,Y1,Kr);
If(X1>X2)Then Begin
I:=X1;
While(I>=X2)do Begin
If D>=0Then Begin Inc(J);Inc(D,Ainc)End else Inc(D,Binc);
OK:=GetPixel(I,J);
If OK in[1,2,3]Then Begin XOut:=I;PutMissile:=OK;Exit;End;
SetPixel(I,J,Kr);
If(J>Limit)Then Begin XOut:=I;YOut:=J;Exit;End;
Dec(I);
End;
End
Else
Begin
I:=X1+1;
While(I<=X2)do Begin
If D>=0Then Begin J:=J+Ic;Inc(D,Ainc)End else Inc(D,Binc);
OK:=GetPixel(I,J);
If OK in[1,2,3]Then Begin XOut:=I;PutMissile:=OK;Exit;End;
SetPixel(I,J,Kr);
If(J>Limit)Then Begin XOut:=I;YOut:=J;Exit;End;
Inc(I);
End;
End;
End;
End;
Function EY(I:Byte):Byte;Near;
Var
S:String;
Begin
S:=#0#0#0#0#6#6#2#2#4#4#4#1#5#0#0#0#4#4#2#2#4#0#1;
EY:=Byte(S[I+1]);
End;
Procedure _PutCity(X:Word);
Var
I:Byte;
Begin
For I:=0to 22do PutLn(X+I,20*8+EY(I),X+I,22*8-1,CurrColor)
End;
Procedure PutCity(X:Word);Begin
SetColor(3);
_PutCity(X)
End;
Procedure EraseCity(X:Word);
Var
I:Byte;
Begin
For I:=0to 5do If(X>=XCity(I))and(X<=XCity(I)+22)Then Break;
SetColor(0);
_PutCity(XCity(I));
For I:=0to 2do Begin
SetPalRGB(DefaultRGB[15],0,1);WaitRetrace;
SetPalRGB(DefaultRGB[0],0,1);WaitRetrace
End;
End;
Procedure InitScr;
Var
J:Byte;
Begin
SetColor(1);
PutFillBox(0,22*8,319,191,1);
_PutFillBox(0,19*8,15,22*8-1);
_PutFillBox(38*8,19*8,319,22*8-1);
For J:=0to 15do PutLn(20*8-4+J,Canon(J),20*8-4+J,20*8-1,2);
_PutFillBox(19*8,20*8,22*8-1,22*8-1);
For J:=0to 5do PutCity(XCity(J));
BarSpcHor(0,24,MaxXTxts,$B0);
PutTxtXY(1,24,'Pointage:',$B0);
FillChar(BufMouse,SizeOf(BufMouse),0);
SetPalRGB(DefaultRGB,0,16);
SetMouseMoveArea(0,0,319-32,19*8-1);
GetMouseSwitch(OldMouseX,OldMouseY,OldMouseButton);
End;
Procedure MakeNewMissile(I:Byte);Begin
MI[I]:=0;ML[I]:=1+Random(Level);
MX1[I]:=Random(318);MX2[I]:=Random(38*8-34)+16;
End;
Procedure UpDateScore;Begin
PutTxtXY(11,24,CStr(Score),$B0)
End;
Procedure Play;
Label
C,Chk,BreakAll;
Var
Out:Byte;
XOut,T,YOut:Integer;
X,Y,B:Word;
I,J,KM:Integer;
Begin
FillChar(MI,SizeOf(MI),0);
FillChar(MX1,SizeOf(MX1),0);
FillChar(MX2,SizeOf(MX2),0);
Level:=0;Score:=0;NmCity:=6;
Repeat
If Level>5Then I:=5 Else I:=Level;
MaxMissile:=LevelMaxMissile[I];Missile2Send:=LevelMissile[I];KM:=0;
PutTxtXY(25,24,'Niveau: '+WordToStr(Level+1),$B0);
UpDateScore;
For I:=0to(MaxMissile)do MakeNewMissile(I);
ShowMousePtr;
Repeat
_BackKbd;
I:=0;
If(KeyPressed)Then Begin
ReadKey;
Exit;
End;
C:While(I<=MaxMissile)do Begin
Out:=PutMissile(MX1[I],0,MX2[I],22*8-1,MI[I],15,XOut,YOut);
If(Out>0)or(MI[I]>=22*8-1)Then Begin
{__HideMousePtr;}
PutMissile(MX1[I],0,MX2[I],22*8-1,MI[I],0,T,T);
If Out=3Then Begin
Dec(NmCity);
EraseCity(XOut);
If NmCity=0Then Begin
PutTxtXY(20,11,'TOUTES LES CIT?S SONT D?TRUITES,',$C);
PutTxtXY(20,13,'PARTIE TERMINER!',$C);
ReadKey;
Exit;
End;
End;
ShowMousePtr;
Goto Chk;
End
Else
Begin
WaitRetrace;
If Level<4Then WaitRetrace;
GetMouseSwitch(X,Y,B);
If B>0Then Begin
If(X<=XOut)and(X+31>=XOut)and(Y<=YOut)and(Y+15>=YOut)Then Begin
Inc(KM);
HideMousePtr;
PutMissile(MX1[I],0,MX2[I],22*8-1,MI[I],0,T,T);
ShowMousePtr;
Inc(Score,100);
UpDateScore;
Chk:If Missile2Send>0Then Begin
MakeNewMissile(I);
Dec(Missile2Send);
End
Else
If MaxMissile>0Then Begin
Repeat
If(I=MaxMissile)or(MaxMissile=0)Then Break;
For J:=I to MaxMissile-1do Begin
MI[J]:=MI[J+1];ML[J]:=ML[J+1];MX1[J]:=MX1[J+1];MX2[J]:=MX2[J+1]
End;
Until True;
Dec(MaxMissile);I:=0;
Goto C;
End
Else
Goto BreakAll;
End;
End;
Inc(MI[I],ML[I]);
End;
Inc(I);
End;
Until False;
BreakAll:
HideMousePtr;
If KM>0Then For I:=0to(15*NmCity)do Begin
WaitRetrace;
WaitRetrace;
Inc(Score,5);
UpDateScore;
End;
Inc(Level);
PutTxtXY(20,12,'PRES POUR LE NIVEAU '+WordToStr(Level+1)+'!',$B);
Repeat
If GetMouseButton>0Then Break;
Until KeyPressed;
If GetMouseButton=0Then ReadKey Else WaitMsBut0;
PutFillBox(0,0,319,19*8-1,0);
Until False;
End;
BEGIN
Randomize;
ASM
MOV AX,0013h
INT 10h
END;
MouseFound:=MouseDriverFound;
If Not MouseFound Then Begin
WriteLn('Une souris est requise pour jouer a ce jeu');
End
Else
Begin
InitScr;
Play;
End;
TextMode(CO80);
END.