This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.pas
1402 lines (1241 loc) · 33.8 KB
/
game.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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit Game;
interface
uses Globals, Elements;
procedure CheckIfGameLost;
procedure GetPlayerCommands( fastPhase : Boolean );
procedure MovePlayer( cmd : Integer; c, c2 : PCharacter; fastPhase : Boolean );
procedure MoveBadGuys( fastPhase : Boolean );
procedure MoveBullets( fastPhase : Boolean );
procedure MoveAllCharacters;
procedure UpdateCharacters( fastPhase, slowPhase : Boolean );
procedure UpdateExplosions( fastPhase : Boolean );
function MakeBadGuy( baddieType : Byte; makeTarget : Boolean ) : Boolean;
function MakeAnyBadGuy : Boolean;
procedure RelocateBadGuys;
procedure ClearAllPosFlags;
procedure SetPosFlag( c : PCharacter );
implementation
uses Keyboard, Joystick, Stick, Pics, GameArea, Buffer, Screen, Sounds;
procedure ClearAllPosFlags;
begin
FillChar( gCharacterMap^, SizeOf( gCharacterMap^), 0);
end;
function PotentialCollision( x, y : Integer ) : Boolean;
var f : Word;
x1, x2, y1, y2 : Integer;
begin
PotentialCollision := False;
x1 := x div cwCharMap;
x2 := (x + cCharacterWidth) div cwCharMap;
y1 := y div chCharMap;
y2 := (y + cCharacterHeight) div chCharMap;
if (x1 < cxFlagMin) or (x2 > cxFlagMax) or
(y1 < cyMin) or (y2 > cyMax) then
Exit;
f := gCharacterMap^[ x1, y1];
f := f + gCharacterMap^[ x1, y2];
f := f + gCharacterMap^[ x2, y1];
f := f + gCharacterMap^[ x2, y2];
PotentialCollision := f > 4;
end;
function PotentialHit( x, y, radius : Integer ) : Boolean;
var f : Word;
x1, x2, y1, y2 : Integer;
begin
x1 := (x - radius) div cwCharMap;
x2 := (x + radius) div cwCharMap;
y1 := (y - radius) div chCharMap;
y2 := (y + radius) div chCharMap;
f := gCharacterMap^[ x1, y1];
f := f + gCharacterMap^[ x1, y2];
f := f + gCharacterMap^[ x2, y1];
f := f + gCharacterMap^[ x2, y2];
PotentialHit := f > 0;
end;
procedure ClearPosFlag( c : PCharacter );
var x1, x2, y1, y2 : Integer;
begin
x1 := c^.x div cwCharMap;
x2 := (c^.x + cCharacterWidth) div cwCharMap;
y1 := c^.y div chCharMap;
y2 := (c^.y + cCharacterHeight) div chCharMap;
Dec( gCharacterMap^[ x1, y1]);
Dec( gCharacterMap^[ x1, y2]);
Dec( gCharacterMap^[ x2, y1]);
Dec( gCharacterMap^[ x2, y2]);
end;
procedure SetPosFlag( c : PCharacter );
var x1, x2, y1, y2 : Integer;
begin
x1 := c^.x div cwCharMap;
x2 := (c^.x + cCharacterWidth) div cwCharMap;
y1 := c^.y div chCharMap;
y2 := (c^.y + cCharacterHeight) div chCharMap;
Inc( gCharacterMap^[ x1, y1]);
Inc( gCharacterMap^[ x1, y2]);
Inc( gCharacterMap^[ x2, y1]);
Inc( gCharacterMap^[ x2, y2]);
end;
procedure KillCharacter( c : PCharacter; byChainSaw : Boolean );
var x, y : Integer;
begin
if byChainSaw then
DoSound( cChainSawSound)
else
DoSound( cScreamSound);
if c^.isTarget then
Dec( gTargetsLeft);
x := (c^.x + cCharacterWidth div 2) div 32;
y := (c^.y + 12) div 24;
if gWorld[ x, y] = cBkgFloor then
begin
if c^.id < cIdEvil then
gWorld[ x, y] := cBkgFloorSkull
else
gWorld[ x, y] := cBkgFloorBlood;
end;
ClearPosFlag( c);
c^.armor := 0;
c^.dead := True;
c^.deathCount := 0;
end;
function HurtCharacter( c : PCharacter; attackerId : Byte; damage : Integer; closeCombat : Boolean ) : Boolean;
begin
if (damage > 0) and (c^.invincibility = 0) then
begin
if attackerId < cIdEvil then
begin
if damage < c^.armor then
Inc( gPlayerData[ attackerId].mission.score, damage)
else
Inc( gPlayerData[ attackerId].mission.score, c^.armor);
end;
Dec( c^.armor, damage);
if c^.armor <= 0 then
begin
KillCharacter( c, closeCombat and (attackerId <> cIdEvil) and (damage > 1));
if attackerId < cIdEvil then
begin
Inc( gPlayerData[ attackerId].mission.kills);
if closeCombat then
Inc( gPlayerData[ attackerId].mission.closeCombat);
end;
end;
end;
end;
function CloseContact( c : PCharacter; x, y : LongInt ) : Boolean;
var c2 : PCharacter;
begin
CloseContact := False;
if PotentialCollision( x, y) then
begin
c2 := gCharacters;
while c2 <> nil do
begin
if not c2^.dead and (c <> c2) and
(Abs( x - c2^.x) <= cCharacterWidth) and
(Abs( y - c2^.y) <= cCharacterHeight) then
begin
{if (c2^.id <> cIdEvil) and (c^.id = cIdEvil) and
(c2^.invincibility > 0) then
KillCharacter( c, False)
else}
if (c2^.invincibility <= 0) and
((c2^.id = cIdEvil) xor (c^.id = cIdEvil)) then
HurtCharacter( c2, c^.id, c^.closeCombat, True);
if (Abs( x - c2^.x) < Abs( c^.x - c2^.x)) or
(Abs( y - c2^.y) < Abs( c^.y - c2^.y)) then
CloseContact := True;
Exit;
end;
c2 := c2^.next;
end;
end;
end;
function PositionOK( x, y : LongInt ) : Boolean;
{
function WorldBlocked( x, y, xMod : Integer ) : Boolean;
var w : Byte;
begin
w := gWorld[ x, y];
if w and cNoWalk <> 0 then
WorldBlocked := True
else if (w and cNoWalkLeft <> 0) and (xMod < 16) then
WorldBlocked := True
else
WorldBlocked := False;
end;
}
var x1, y1,
x2, y2 : Integer;
begin
PositionOk := False;
Inc( y, 10);
x1 := x div cwWalkMap;
y1 := y div chWalkMap;
x2 := (x + cCharacterWidth) div cwWalkMap;
y2 := (y + 12) div chWalkMap;
if (x1 < cxFlagMin) or (x2 > cxFlagMax) or
(y1 < cyMin) or (y2 > cyMax) then
Exit;
if gNoWalk^[ x1, y1] or
gNoWalk^[ x1, y2] or
gNoWalk^[ x2, y1] or
gNoWalk^[ x2, y2] then
Exit;
PositionOk := True;
end;
function CheckPosition( c : PCharacter; dx, dy : Integer ) : Boolean;
var nx, ny : LongInt;
begin
CheckPosition := True;
nx := c^.x*8 + c^.xFrac + dx * c^.speed;
ny := c^.y*8 + c^.yFrac + dy * c^.speed;
if CloseContact( c, nx div 8, ny div 8) then
Exit;
if (dx <> 0) and (dy <> 0) and PositionOK( nx div 8, ny div 8) then
begin
ClearPosFlag( c);
c^.x := nx div 8;
c^.xFrac := nx and 7;
c^.y := ny div 8;
c^.yFrac := ny and 7;
SetPosFlag( c);
end
else if (dx <> 0) and PositionOK( nx div 8, c^.y) then
begin
ClearPosFlag( c);
c^.x := nx div 8;
c^.xFrac := nx and 7;
SetPosFlag( c);
end
else if (dy <> 0) and PositionOK( c^.x, ny div 8) then
begin
ClearPosFlag( c);
c^.y := ny div 8;
c^.yFrac := ny and 7;
SetPosFlag( c);
end
else
CheckPosition := False;
end;
function MoveCharacter( c : PCharacter; cmd : Byte; slowPhase : Boolean ) : Boolean;
var dx, dy : Integer;
begin
MoveCharacter := False;
dx := 0;
dy := 0;
if cmd and cCommandMoving <> 0 then
begin
if gFreeMovement or
(cmd and cCommandFiring = 0) or
(cmd and cCommandNoTurn <> 0) then
begin
if cmd and cCommandLeft <> 0 then
dx := -1
else if cmd and cCommandRight <> 0 then
dx := 1;
if cmd and cCommandUp <> 0 then
dy := -1
else if cmd and cCommandDown <> 0 then
dy := 1;
MoveCharacter := CheckPosition( c, dx, dy);
if slowPhase then
c^.phase := 1 + (c^.phase and 3);
end;
if cmd and cCommandNoTurn = 0 then
c^.direction := cDirectionFromCmd[ cmd and cCommandMoving];
c^.faceDir := c^.direction;
end
else if slowPhase then
c^.phase := 0;
end;
procedure CheckIfGameLost;
begin
if ((gHero1 = nil) or (gHero1^.dead)) and
((gHero2 = nil) or (gHero2^.dead)) then
gGameOver := True;
end;
procedure PickPos( var x, y : Integer );
begin
if (gHero1 <> nil) and (gHero2 <> nil) then
begin
if Random( 2) = 0 then
begin
x := gHero1^.x;
y := gHero1^.y;
end
else begin
x := gHero2^.x;
y := gHero2^.y;
end
end
else if gHero1 <> nil then
begin
x := gHero1^.x;
y := gHero1^.y;
end
else if gHero2 <> nil then
begin
x := gHero2^.x;
y := gHero2^.y;
end;
Inc( x, Random( 2*cRelocationDistance));
Inc( y, Random( 2*cRelocationDistance));
Dec( x, cRelocationDistance);
Dec( y, cRelocationDistance);
end;
function MakeBadGuy( baddieType : Byte; makeTarget : Boolean ) : Boolean;
var c : PCharacter;
function PlacementOk( c : PCharacter ) : Boolean;
begin
PlacementOk := False;
if not PositionOK( c^.x, c^.y) then
Exit;
SetPosFlag( c);
if CloseContact( c, c^.x, c^.y) or
CharacterVisible( c) then
begin
ClearPosFlag( c);
Exit;
end;
PlacementOk := True;
end;
begin
c := AddCharacter( cIdEvil);
c^.direction := 4;
c^.faceDir := c^.direction;
c^.gunPos := cGunReady;
PickPos( c^.x, c^.y);
c^.gun.kind := cGoonGun;
c^.gun.ammo := 10000;
c^.gunPic := cGunDogs;
c^.isTarget := makeTarget;
if not c^.isTarget and (Random( 10) = 0) then
c^.sleeping := False
else
c^.sleeping := True;
if PlacementOk( c) then
begin
c^.gun.lock := 120;
case baddieType of
cBaddieKiller:
begin
c^.body := cRedBody;
c^.face := cFaceGrunt2;
c^.tracking := 15;
c^.moving := 15;
c^.shooting := 2;
c^.actionDelay := 20;
c^.speed := 12;
c^.armor := 10;
c^.closeCombat := 1;
c^.gun.kind := cGoonGun2;
end;
cBaddieRobot:
begin
c^.body := cGreyBody;
c^.face := cFaceMechGrunt;
c^.tracking := 15;
c^.moving := 15;
c^.shooting := 5;
c^.actionDelay := 25;
c^.speed := 4;
c^.armor := 20;
c^.closeCombat := 1;
c^.gun.kind := cGoonGun3;
end;
cBaddieLittleBad:
begin
c^.body := cBlackBody;
c^.face := cFaceGrunt2;
c^.tracking := 15;
c^.moving := 15;
c^.shooting := 1;
c^.actionDelay := 10;
c^.speed := 16;
c^.armor := 10;
c^.closeCombat := 2;
c^.gun.kind := cGoonGun2;
end;
cBaddieMeanGoon:
begin
c^.body := cBrownBody;
c^.face := cFaceBlondGrunt;
c^.tracking := 15;
c^.moving := 15;
c^.shooting := 5;
c^.actionDelay := 15;
c^.speed := 8;
c^.armor := 15;
c^.closeCombat := 1;
c^.gun.kind := cGoonGun2;
end;
cBaddieBigBad:
begin
c^.body := cBlackBody;
c^.face := cFaceBigBadGuy;
c^.tracking := 10;
c^.moving := 10;
c^.shooting := 5;
c^.actionDelay := 10;
c^.speed := 8;
c^.armor := 20;
c^.closeCombat := 3;
c^.gun.kind := cGoonGun4;
end;
else
begin
c^.body := cBrownBody;
c^.face := cFaceGrunt;
c^.tracking := 10;
c^.moving := 10;
c^.shooting := 2;
c^.actionDelay := 25;
c^.speed := 6;
c^.armor := 15;
end;
end;
c^.invincibility := 30;
MakeBadGuy := True;
end
else begin
RemoveCharacter( c);
MakeBadGuy := False;
end;
end;
function MakeAnyBadGuy : Boolean;
var x : Integer;
kind : Integer;
begin
x := Random( 100);
for kind := cBaddieGoon to cBaddieBigBad do
begin
if x < gBaddieProbs[ kind] then
begin
MakeAnyBadGuy := MakeBadGuy( kind, False);
Exit;
end;
Dec( x, gBaddieProbs[ kind]);
end;
MakeAnyBadGuy := MakeBadGuy( cBaddieGoon, False);
end;
procedure Explode( cx, cy : LongInt; bigBang : Boolean );
var f : PFireBall;
count,
delay : Integer;
begin
if bigBang then
DoSound( cBangSound)
else
DoSound( cSmallBangSound);
for count := 1 to cFireBallsPerExplosion do
begin
f := AddFireBall;
with f^ do
begin
stage := 1 - count;
x := cx - 16 + Random(32);
y := cy - 16 + Random(32);
end;
end;
cx := cx div cwWorldMap;
cy := cy div chWorldMap;
if gWorld[ cx, cy] = cBkgFloor then
gWorld[ cx, cy] := cBkgFloorCrater;
end;
procedure UpdateCharacters( fastPhase, slowPhase : Boolean );
function UpdateCharacter( c : PCharacter ) : Boolean;
begin
UpdateCharacter := True;
with c^ do
begin
if gun.lock > 0 then
begin
if gun.lock > 1{gCyclesPerFrame} then
Dec( gun.lock)
else
gun.lock := 0;
if (gunPos = cGunRecoil) and (gun.lock + 5 < cGunStyles[ gun.kind].rate) then
gunPos := cGunReady;
end
else begin
facial := cFaceNormal;
if id <> cIdEvil then
gunPos := cGunIdle;
end;
if invincibility <> 0 then
Dec( invincibility);
if slowPhase and (c^.phase = 0) and (c^.gunPos = cGunIdle) and (Random( 6) = 0) then
faceDir := (direction + Random( 3) + 7) and 7;
if not dead then
Exit;
if not fastPhase then
Exit;
Inc( deathCount);
if deathCount > cMaxDeath then
begin
if id = cIdEvil then
UpdateCharacter := False
else begin
if lives > 1 then
begin
Dec( lives);
armor := gPlayerData[ id].armor;
dead := False;
SetPosFlag( c);
invincibility := 240;
end
else if (g2PlayerPool and cPoolLives <> 0) and
(gHero1 <> nil) and (gHero2 <> nil) and
((gHero1^.lives > 1) or (gHero2^.lives > 1)) then
begin
if c = gHero1 then
Dec( gHero2^.lives)
else
Dec( gHero1^.lives);
armor := gPlayerData[ id].armor;
dead := False;
SetPosFlag( c);
invincibility := 240;
end
else begin
UpdateCharacter := False;
CheckIfGameLost;
end;
end;
end;
end;
end;
var c : PCharacter;
begin
c := gCharacters;
while c <> nil do
begin
if UpdateCharacter( c) then
c := c^.next
else
c := RemoveCharacter( c);
end;
end;
function HitWall( b : PBullet ) : Boolean;
var x, y1, y2 : Integer;
flag : Byte;
begin
x := b^.x div cwWalkMap;
y1 := b^.y div chWalkMap;
y2 := (b^.y + 10) div chWalkMap;
HitWall := gNoWalk^[ x, y1] and gNoWalk^[ x, y2];
end;
procedure BlastCharacters( b : PBullet );
var c : PCharacter;
radius : Integer;
begin
b^.range := 0;
Explode( b^.x, b^.y, True);
c := gCharacters;
while c <> nil do
begin
with c^ do
if (invincibility <= 0) and not dead and
((id = cIdEvil) xor (b^.id = cIdEvil)) and
(armor > 0) and
(x + 8 > b^.x - 100) and (x + 8 < b^.x + 100) and
(y + 10 > b^.y - 100) and (y + 10 < b^.y + 100) then
HurtCharacter( c, b^.id, cGunStyles[ b^.kind].power, False);
c := c^.next;
end;
end;
function HitCharacter( b : PBullet ) : Boolean;
var c : PCharacter;
r : Integer;
begin
r := cGunStyles[ b^.kind].radius;
if PotentialHit( b^.x, b^.y, r) then
begin
c := gCharacters;
while c <> nil do
begin
with c^ do
if ((b^.id = cIdEvil) xor (id = cIdEvil)) and
(not dead) and
(b^.y + r > y) and (b^.y - r < y + cCharacterHeight) and
(b^.x + r > x) and (b^.x - r < x + cCharacterWidth) then
begin
if b^.kind <> cGrenade then
begin
{DoSound( cBulletHitSound);}
if invincibility <= 0 then
HurtCharacter( c, b^.id, cGunStyles[ b^.kind].power, False);
if b^.id <> cIdEvil then
Inc( gPlayerData[ b^.id].mission.hits)
else if c^.id <> cIdEvil then
Inc( gPlayerData[ c^.id].mission.hitsTaken);
end
else
BlastCharacters( b);
HitCharacter := True;
Exit;
end;
c := c^.next;
end;
end;
HitCharacter := False;
end;
procedure CheckForStructureDamage( b : PBullet );
procedure TargetHit( x, y : Integer );
begin
Dec( gTargetsLeft);
{gWorld[ x, y] := cBkgFloorCrater;
gNoWalk^[ 2*x, y] := False;
gNoWalk^[ 2*x + 1, y] := False;}
if b^.id < cIdEvil then
begin
Inc( gPlayerData[ b^.id].mission.targets);
Inc( gPlayerData[ b^.id].mission.score, 50);
end;
end;
function CheckStructure( x, y : Integer ) : Boolean;
begin
CheckStructure := False;
with gStructureMap^[ x, y] do
begin
if structure = 0 then
Exit;
CheckStructure := True;
if cGunStyles[ b^.kind].power >= structure then
begin
if b^.id < cIdEvil then
Inc( gPlayerData[ b^.id].mission.demolition, structure);
structure := 0;
Explode( x*cwWorldMap + cwWorldMap div 2, y*chWorldMap + chWorldMap div 2, gWorld[ x, y] in gMissionTargets);
if gWorld[ x, y] in gMissionTargets then
TargetHit( x, y);
gWorld[ x, y] := wreckagePic;
gNoWalk^[ 2*x, y] := (wreckagePic and (cNoWalk or cNoWalkLeft) <> 0);
gNoWalk^[ 2*x + 1, y] := (wreckagePic and cNoWalk <> 0);
end
else begin
Dec( structure, cGunStyles[ b^.kind].power);
if b^.id < cIdEvil then
Inc( gPlayerData[ b^.id].mission.demolition, cGunStyles[ b^.kind].power);
end;
end;
end;
var x, y1, y2 : Integer;
begin
{if b^.id = cIdEvil then
Exit;}
x := b^.x div cwWorldMap;
y1 := b^.y div chWorldMap;
y2 := (b^.y + 10) div chWorldMap;
if not CheckStructure( x, y1) then
CheckStructure( x, y2);
end;
procedure MoveBullets( fastPhase : Boolean );
var b : PBullet;
procedure ShotConnected;
begin
with b^ do
begin
Inc( x, Random( 4));
Dec( x, 2);
Inc( y, Random( 4));
Dec( y, 2);
pic := cShotConnectPic;
range := -3;
end;
end;
begin
b := gBullets;
while b <> nil do
begin
with b^ do
begin
if range > 0 then
begin
x := x*8 + xFrac;
y := y*8 + yFrac;
Inc( x, dx);
Inc( y, dy);
xFrac := x and 7;
yFrac := y and 7;
x := x div 8;
y := y div 8;
Dec( range);
if range > 0 then
begin
if HitWall( b) then
begin
CheckForStructureDamage( b);
if kind = cGrenade then
BlastCharacters( b)
else
ShotConnected;
end
else if HitCharacter( b) then
ShotConnected
else if fastPhase and (cGunStyles[ kind].animated <> cAnimationNone) then
pic := (pic + 1) and 7;
end
else if kind = cGrenade then
BlastCharacters( b);
b := b^.next;
end
else begin
Inc( range);
if range >= 0 then
b := RemoveBullet( b)
else
b := b^.next;
end;
end;
end;
end;
procedure UpdateExplosions( fastPhase : Boolean );
var f : PFireBall;
begin
if not fastPhase then
Exit;
f := gFireBalls;
while f <> nil do
with f^ do
begin
Inc( stage);
if stage > cMaxFireBalls + cFireBallsPerExplosion then
f := RemoveFireBall( f)
else
f := f^.next;
end;
end;
procedure Shoot( c : PCharacter );
var b : PBullet;
begin
if (c^.gun.ammo = 0) or (c^.gun.lock <> 0) then
Exit;
b := AddBullet;
with b^ do
begin
kind := c^.gun.kind;
id := c^.id;
if (c^.id <> cIdEvil) and (kind <> cGrenade) then
Inc( gPlayerData[ c^.id].mission.shotsFired);
DoSound( cGunStyles[ kind].sound);
c^.gun.lock := cGunStyles[ kind].rate;
c^.gunPos := cGunRecoil;
c^.facial := cFaceHard;
c^.faceDir := c^.direction;
Dec( c^.gun.ammo);
pic := c^.direction;
range := cGunStyles[ kind].range;
x := c^.x + cMuzzleOfs[ c^.direction].x;
y := c^.y + cMuzzleOfs[ c^.direction].y;
dx := cMuzzleDXY[ c^.direction].x * cGunStyles[ kind].speed;
dy := cMuzzleDXY[ c^.direction].y * cGunStyles[ kind].speed;
xFrac := 0;
yFrac := 0;
end;
end;
function LeavingOtherPlayer( cmd : Integer; c1, c2 : PCharacter ) : Boolean;
var x, y : LongInt;
begin
if (gSplitScreenMode <> cSplitScreenNever) or
(c1 = nil) or (c2 = nil) or
c1^.dead or c2^.dead then
begin
LeavingOtherPlayer := False;
Exit;
end;
LeavingOtherPlayer := True;
x := c1^.x;
y := c1^.y;
if cmd and cCommandLeft <> 0 then
begin
Dec( x);
if c2^.x - x > cMaxHorizontalDistance then
Exit;
end
else if cmd and cCommandRight <> 0 then
begin
Inc( x);
if x - c2^.x > cMaxHorizontalDistance then
Exit;
end;
if cmd and cCommandUp <> 0 then
begin
Dec( y);
if c2^.y - y > cMaxVerticalDistance then
Exit;
end
else if cmd and cCommandDown <> 0 then
begin
Inc( y);
if y - c2^.y > cMaxVerticalDistance then
Exit;
end;
LeavingOtherPlayer := False;
end;
procedure CheckIfPickup( c : PCharacter );
function AddWeapon( kind : Byte; ammo : Integer ) : Boolean;
var i : Integer;
begin
AddWeapon := True;
for i := 0 to cMaxWeaponry do
if (gPlayerData[ c^.id].weapons[i].kind = kind) or
(gPlayerData[ c^.id].weapons[i].kind <= 0) then
begin
gPlayerData[ c^.id].weapons[i].kind := kind;
Inc( gPlayerData[ c^.id].weapons[i].ammo, ammo);
if kind = c^.gun.kind then
c^.gun.ammo := gPlayerData[ c^.id].weapons[i].ammo;
Exit;
end;
AddWeapon := False;
end;
var x, y : Integer;
begin
x := c^.x div cwWorldMap;
y := (c^.y + 10) div chWorldMap;
case gWorld[ x, y] of
cBkgFloorItem1: if not AddWeapon( cPowerGun, 5) then Exit;
cBkgFloorItem2: if not AddWeapon( cBlaster, 50) then Exit;
cBkgFloorItem3: if not AddWeapon( cSprayer, 100) then Exit;
cBkgFloorItem4: if not AddWeapon( cFlamer, 50) then Exit;
cBkgFloorItem5: if not AddWeapon( cGrenade, 5) then Exit;
cBkgFloorItem6: if c^.armor < gPlayerData[ c^.id].armor then
c^.armor := gPlayerData[ c^.id].armor
else
Exit;
cBkgFloorItem7: Inc( c^.lives);
cBkgFloorArmorAddOn:
if c^.armor < 70 then
c^.armor := 70
else
Exit;
cBkgFloorAxe: Inc( c^.closeCombat, 10);
cBkgFloorDocs,
cBkgFloorFolder,
cBkgFloorDisk,
cBkgFloorCircuit,
cBkgFloorTeddy:
Inc( gPlayerData[ c^.id].mission.objects);
else
Exit;
end;
DoSound( cPickupSound);
gWorld[ x, y] := cBkgFloor;
end;
procedure CheckIfExit( c : PCharacter );
var x, y, i : Integer;
begin
x := c^.x div cwWorldMap;
y := (c^.y + 10) div chWorldMap;
if {(gTargetsLeft <= 0) and} (gWorld[ x, y] = cBkgExit) then
begin
if c^.gun.kind > 0 then
begin
i := 0;
while gPlayerData[ c^.id].weapons[ i].kind <> c^.gun.kind do
Inc( i);
gPlayerData[ c^.id].weapons[ i].ammo := c^.gun.ammo;
end;
gPlayerData[ c^.id].completed := True;
{if c^.lives < gPlayerData[ c^.id].lives then}
gPlayerData[ c^.id].lives := c^.lives;
gPlayerData[ c^.id].mission.time := gMissionTime div 60;
RemoveCharacter( c);
if (gHero1 = nil) and (gHero2 = nil) then
gGameOver := True;
end;
end;
procedure MovePlayer( cmd : Integer; c, c2 : PCharacter; fastPhase : Boolean );
begin
if (c = nil) or c^.dead or LeavingOtherPlayer( cmd, c, c2) then
Exit;
c^.command := cmd;
MoveCharacter( c, cmd, fastPhase);
CheckIfPickup( c);
CheckIfExit( c);
if cmd and cCommandShoot <> 0 then
Shoot( c);
end;
function GetStickCommand( const keys : KeyControls; c : PCharacter ) : Byte;
var cmd : Byte;
begin
cmd := 0;
if c = nil then
Exit;
if StickUp( keys.stick) then
cmd := cmd or cCommandUp
else if StickDown( keys.stick) then
cmd := cmd or cCommandDown;
if StickLeft( keys.stick) then
cmd := cmd or cCommandLeft
else if StickRight( keys.stick) then
cmd := cmd or cCommandRight;
if StickButton1( keys.stick) then
cmd := cmd or cCommandShoot;
if StickButton2( keys.stick) then
cmd := cmd or cCommandSwitch;
GetStickCommand := cmd;
end;