-
Notifications
You must be signed in to change notification settings - Fork 0
/
PacMan.asm
1194 lines (1033 loc) · 20.6 KB
/
PacMan.asm
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
TITLE PacMan, Authors: Andrew Hart, Diego Prates, Mike Spallino, Josh Sullivan
INCLUDE irvine32.inc
INCLUDE macros.inc
MapObject Struct
MapFile byte 100 Dup(0)
MapIntro byte 15 Dup(0)
MapObject Ends
BUFFER_SIZE = 1000
MAX_COORD = 23
MAP_WIDTH = 25
.data
Main_MenuStr BYTE "main menu.txt"
buffer BYTE BUFFER_SIZE DUP(?)
saveBuffer BYTE BUFFER_SIZE DUP(?)
filenamePtr DWORD offset Main_MenuStr
fileHandle HANDLE ?
PacManX BYTE 11
PacManY BYTE 16
PrevX BYTE 11
PrevY BYTE 16
deltaX SBYTE 0
deltaY SBYTE 0
tempLoc BYTE ?
score DWORD 0
pointsToAdd DWORD 0
Strscre BYTE "Score: "
cherryItem BYTE 224
stwbryItem BYTE 225
orangeItem BYTE 226
appleItem BYTE 227
melonItem BYTE 228
galBssItem BYTE 229
bellItem BYTE 230
keyItem BYTE 231
ticks DWORD 0
Map1 MapObject<"Map1.txt","Level1.txt">
Map2 MapObject<"Map2.txt","Level2.txt">
Map3 MapObject<"Map3.txt","Level3.txt">
HelpMenu MapObject<"HelpMenu.txt"," ">
AboutMenu MapObject<"AboutMenu.txt"," ">
Win MapObject<"win.txt"," ">
Loss MapObject<"loss.txt"," ">
Level BYTE ?
PacDotsConsumed DWORD 0
PacDotCount DWORD 0
TotalTickCount DWORD 0
MaxTickCount DWORD 1500
laserCoord BYTE ?
fruitDrawn BYTE ? ; Value 1-8
fruitConsumed BYTE ? ; Value 0 or 1
lives BYTE 3
.code
main proc
call Randomize
call ReadMapFile
call splash
mov level, 3
MapLoop:
call GetLevel ; Sets the right map to be loaded
call DrawPacMan
call UpdateLives
MainLoop: ; Main loop
call Render
call DelayPacMan ; Delays pacman
call Update
call CheckTickCount
jmp MainLoop
NextMap::
call ResetGame ; Resets game from the begining
sub level, 1
cmp level, 0
je EndGame
jmp MapLoop
; Game Win
EndGame:
mov fileNamePtr, offset win.MapFile
call ReadMapFile
exit
; Game Lose
EndGame2::
mov fileNamePtr, offset loss.MapFile
call ReadMapFile
call GetKey
exit
Call ReadChar
main endp
; Quit the game
ExitProc proc
mov dl, 0
mov dh, 25
call GotoXY
mwrite <"Thank you for playing! ">
call crlf
exit
ret
ExitProc endp
; Redraw the map from the buffer
DrawMap proc USES edx
call ClrScr
mov edx, OFFSET buffer ; display the buffer
call WriteString
call Crlf
ret
DrawMap endp
; Handle the splash screen
; Switch between playing, help screen, and about screen
Splash proc
ReadCharLoop:
call ReadChar
cmp al, "q"
je EndOfTheGame
cmp al, "p"
je LoadGame
cmp al, "h"
je DrawHelp
cmp al, "a"
je About
jmp ReadCharLoop
EndOfTheGame:
call ExitProc
ret
LoadGame:
call LoadBufferIn
call DrawMap
ret
DrawHelp:
call DrawHelpProc
jmp ReadCharLoop
About:
call AboutGame
jmp ReadCharLoop
Splash endp
; Draw the about screen
AboutGame proc
mov fileNamePtr, offset AboutMenu.MapFile
call ReadMapFile
ret
AboutGame endp
; Draw help procedure print the help screen
DrawHelpProc proc
mov fileNamePtr, offset HelpMenu.MapFile
call ReadMapFile
call DrawHelpFruit
ret
DrawHelpProc endp
; All procedures related to updating game state will
; be called from here.
Update proc
call GetKey
call MovePacMan
call CheckMapLoc
call LaserProc
ret
Update endp
; All procedures related to rendering the game will
; be called from here.
Render proc
call DrawPacMan
call HandleFruit
ret
Render endp
; Delays the player for 150 ms so the game won't speed up
; Adds to the tick count
DelayPacMan proc USES eax
mov eax,150
add ticks, 5
call Delay
ret
DelayPacMan endp
; Map key presses to w,a,s,d,h,q
; Updates the direction the player is moving accordingly
; Can show the help screen as well
GetKey proc
mov deltaX, 0
mov deltaY, 0
call ReadChar
cmp al, "h"
je DrawHelp
cmp al, "q"
je ExitProg
cmp al, "w"
je Up
jne NotUp
ExitProg:
call ExitProc
DrawHelp:
call SaveBufferOut
call DrawHelpProc
call Splash
jmp EndOfGetKeyProc
Up:
mov deltaX, 0
mov deltaY, -1
jmp EndOfGetKeyProc
NotUp:
cmp al,"s"
je Down
jmp NotDown
Down:
mov deltaX, 0
mov deltaY, 1
jmp EndOfGetKeyProc
NotDown:
cmp al, "a"
je Left
jne NotLeft
Left:
mov deltaX, -1
mov deltaY, 0
jmp EndOfGetKeyProc
NotLeft:
cmp al, "d"
je Right
jne Invalid
Right:
mov deltaX, 1
mov deltaY, 0
jmp EndOfGetKeyProc
Invalid:
mov deltaX, 0
mov deltaY, 0
jmp EndOfGetKeyProc
EndOfGetKeyProc:
ret
GetKey endp
; Check to make sure this is a valid location to move the player to
CheckMapLoc proc USES eax ebx
mov edx, OFFSET buffer
cmp PacManX, MAX_COORD
jg DecX
je WrapPosBack
cmp PacManY, MAX_COORD
jg DecY
jmp CheckZero
; We've moved too far forward in the X
DecX:
sub PacManX, 1
jmp EndOfCheckMapLoc
WrapPosBack:
mov PacManX, 0
jmp GetCoordChar
; We've moved too far forward in the Y
DecY:
sub PacManY, 1
jmp EndOfCheckMapLoc
CheckZero:
cmp PacManX, -1
je WrapPosForward
cmp PacManX, 0
jl IncX
cmp PacManY, 0
jl IncY
jmp GetCoordChar
WrapPosForward:
mov PacManX, 22
jmp GetCoordChar
; We've moved to far back in the Y
IncX:
add PacManX, 1
jmp EndOfCheckMapLoc
; We've moved too far back in the Y
IncY:
add PacManY, 1
jmp EndOfCheckMapLoc
GetCoordChar:
mov ecx, MAP_WIDTH
movzx ax, PacManY
mul ecx
mov edx, OFFSET buffer
movsx ecx, PacManX
add eax, ecx
add edx, eax
mov bl, [edx]
mov tempLoc, bl
cmp bl, '²' ; Was this a wall?
je ResetPos ; Move back
jmp CheckTile ; It's probably consumable.
ResetPos:
call MoveBack
jmp EndOfCheckMapLoc
CheckTile:
cmp bl, '.'
je PacDot
cmp bl, cherryItem
je Cherry
cmp bl, stwbryItem
je Strawberry
cmp bl, orangeItem
je Orange
cmp bl, appleItem
je Apple
cmp bl, melonItem
je Melon
cmp bl, galBssItem
je Boss
cmp bl, bellItem
je Bell
cmp bl, keyItem
je Key
jmp InvalidChar
PacDot:
add PacDotsConsumed, 1
mov pointsToAdd, 10
jmp RemoveChar
; Move the correct points to add in based on which
; fruit was consumed. Set the fruit consumed state
; to 1.
Cherry:
mov pointsToAdd, 100
mov fruitConsumed, 1
jmp RemoveChar
Strawberry:
mov pointsToAdd, 300
mov fruitConsumed, 1
jmp RemoveChar
Orange:
mov pointsToAdd, 500
mov fruitConsumed, 1
jmp RemoveChar
Apple:
mov pointsToAdd, 700
mov fruitConsumed, 1
jmp RemoveChar
Melon:
mov pointsToAdd, 1000
mov fruitConsumed, 1
jmp RemoveChar
Boss:
mov pointsToAdd, 2000
mov fruitConsumed, 1
jmp RemoveChar
Bell:
mov pointsToAdd, 3000
mov fruitConsumed, 1
jmp RemoveChar
Key:
mov pointsToAdd, 5000
mov fruitConsumed, 1
jmp RemoveChar
InvalidChar:
mov pointsToAdd, 0 ; We probably don't wont this on the map anyway.
jmp RemoveChar
RemoveChar:
mov al, ' '
mov [edx], al
mov dl, PrevX
mov dh, PrevY
call GotoXY
call WriteChar
mov eax, pointsToAdd
add score, eax ; increments the score by one
mov pointsToAdd, 0
call UpdateScore ; updates score
jmp EndOfCheckMapLoc
EndOfCheckMapLoc:
ret
CheckMapLoc endp
; Move Pac Man to another location
; Keep track of the previous location
MovePacMan proc USES eax ebx
; Get previous coordinate
mov bl, PacManX
mov PrevX, bl
mov bl, PacManY
mov PrevY, bl
; Move to new coordinate
mov al, deltaX
add PacManX, al
mov al, deltaY
add PacManY, al
ret
MovePacMan endp
; Move the player back to their previous location
; because an invalid location was tried.
MoveBack proc USES eax
mov eax, 0
mov al, PrevX
mov PacManX, al
mov al, PrevY
mov PacManY, al
ret
MoveBack endp
; Draw Pac Man
DrawPacMan proc USES eax edx ecx
mov dl, PacManX ; Get Coordinates
mov dh, PacManY ; Get Coordinates
call GotoXY
mov eax, yellow + (black * 16)
call SetTextColor
mov eax, 1
call WriteChar ; Draw Yellow Smiley at X,Y
mov eax, white + (black * 16)
call SetTextColor ; Set the text color back to white on black
mov ecx, 23
sub cl, PacManY
ClearCRLF: ; Clear a bunch of lines to print at the bottom
call CRLF
Loop ClearCRLF
ret
DrawPacMan endp
; Read File from the book
ReadMapFile proc USES edx eax ecx
mov eax, white+(black*16)
call SetTextColor
; Open the file for input.
mov edx, filenamePtr
call OpenInputFile
mov fileHandle,eax
; Check for errors.
cmp eax,INVALID_HANDLE_VALUE ; error opening file?
jne file_ok ; no: skip
mWrite <"Cannot open file",0dh,0ah>
jmp quit ; and quit
file_ok:
; Read the file into a buffer.
mov edx,OFFSET buffer
mov ecx,BUFFER_SIZE
call ReadFromFile
jnc check_buffer_size ; error reading?
mWrite "Error reading file. " ; yes: show error message
call WriteWindowsMsg
jmp close_file
check_buffer_size:
cmp eax,BUFFER_SIZE ; buffer large enough?
jb buf_size_ok ; yes
mWrite <"Error: Buffer too small for the file",0dh,0ah>
jmp quit ; and quit
buf_size_ok:
mov edx, OFFSET buffer
call ClrScr
call WriteString
close_file:
mov eax,fileHandle
call CloseFile
quit:
call UpdateScore
ret
ReadMapFile endp
; Update the players score on the screen
UpdateScore proc USES eax edx
mov dh, 24
mov dl, 0
call GotoXY
mWrite "Score: "
mov eax, score
call WriteInt
ret
UpdateScore endp
; Draws fruit based on tick count
; Every 180 ticks a new fruit is drawn
HandleFruit proc USES eax
mov eax, ticks
cmp eax, 180
je DwChr
cmp eax, 360
je DwStr
cmp eax, 540
je DwOrg
cmp eax, 720
je DwApp
cmp eax, 900
je DwMel
cmp eax, 1080
je DwGB
cmp eax, 1260
je DwBl
cmp eax, 1440
je DwKey
jmp EndOfHandleFruit
DwChr:
call DrawCherry
jmp EndOfHandleFruit
DwStr:
call DrawStrawberry
jmp EndOfHandleFruit
DwOrg:
call DrawOrange
jmp EndOfHandleFruit
DwApp:
call DrawApple
jmp EndOfHandleFruit
DwMel:
call DrawMelon
jmp EndOfHandleFruit
DwGB:
call DrawGalaxianBoss
jmp EndOfHandleFruit
DwBl:
call DrawBell
jmp EndOfHandleFruit
DwKey:
call DrawKey
jmp EndOfHandleFruit
EndOfHandleFruit:
ret
HandleFruit endp
; Draws the cherry on the map and redraws a space over the previous fruit
; Updates fruitDrawn to show hold that the cherry has been drawn
DrawCherry proc USES eax ecx edx
mov fruitDrawn, 1
mov fruitConsumed, 0
mov eax, magenta + (black * 16)
call SetTextColor
mov eax, 0
mov ebx, 0
mov ecx, MAP_WIDTH
mov ax, 12
mul ecx
mov edx, OFFSET buffer
mov ecx, 11
add eax, ecx
add edx, eax
mov bl, cherryItem
mov [edx], bl
mov dl, 11
mov dh, 12
call GotoXY
movzx eax, cherryItem
call WriteChar
ret
DrawCherry endp
; Draws the strawberry on the map and redraws a space over the previous fruit
; Updates fruitDrawn to show hold that the strawberry has been drawn
DrawStrawberry proc USES eax ecx edx
mov fruitConsumed, 0
movzx eax, cherryItem
mov cherryItem, ' '
call DrawCherry
mov cherryItem, al
mov fruitDrawn, 2
mov eax, red + (black * 16)
call SetTextColor
mov eax, 0
mov ebx, 0
mov ecx, MAP_WIDTH
mov ax, 10
mul ecx
mov edx, OFFSET buffer
mov ecx, 5
add eax, ecx
add edx, eax
mov bl, stwbryItem
mov [edx], bl
mov dl, 5
mov dh, 10
call GotoXY
movzx eax, stwbryItem
call WriteChar
ret
DrawStrawberry endp
; Draws the orange on the map and redraws a space over the previous fruit
; Updates fruitDrawn to show hold that the orange has been drawn
DrawOrange proc USES eax ecx edx
mov fruitConsumed, 0
movzx eax, stwbryItem
mov stwbryItem, ' '
call DrawStrawberry
mov stwbryItem, al
mov fruitDrawn, 3
mov eax, brown + (black * 16)
call SetTextColor
mov eax, 0
mov ebx, 0
mov ecx, MAP_WIDTH
mov ax, 6
mul ecx
mov edx, OFFSET buffer
mov ecx, 14
add eax, ecx
add edx, eax
mov bl, orangeItem
mov [edx], bl
mov dl, 14
mov dh, 6
call GotoXY
movzx eax, orangeItem
call WriteChar
ret
DrawOrange endp
; Draws the apple on the map and redraws a space over the previous fruit
; Updates fruitDrawn to show hold that the apple has been drawn
DrawApple proc USES eax ecx edx
mov fruitConsumed, 0
movzx eax, orangeItem
mov orangeItem, ' '
call DrawOrange
mov orangeItem, al
mov fruitDrawn, 4
mov eax, green + (black * 16)
call SetTextColor
mov eax, 0
mov ebx, 0
mov ecx, MAP_WIDTH
mov ax, 3
mul ecx
mov edx, OFFSET buffer
mov ecx, 5
add eax, ecx
add edx, eax
mov bl, appleItem
mov [edx], bl
mov dl, 5
mov dh, 3
call GotoXY
movzx eax, appleItem
call WriteChar
ret
DrawApple endp
; Draws the melon on the map and redraws a space over the previous fruit
; Updates fruitDrawn to show hold that the melon has been drawn
DrawMelon proc USES eax ecx edx
mov fruitConsumed, 0
movzx eax, appleItem
mov appleItem, ' '
call DrawApple
mov appleItem, al
mov fruitDrawn, 5
mov eax, yellow + (black * 16)
call SetTextColor
mov eax, 0
mov ebx, 0
mov ecx, MAP_WIDTH
mov ax, 18
mul ecx
mov edx, OFFSET buffer
mov ecx, 20
add eax, ecx
add edx, eax
mov bl, melonItem
mov [edx], bl
mov dl, 20
mov dh, 18
call GotoXY
movzx eax, melonItem
call WriteChar
ret
DrawMelon endp
; Draws the galaxian boss on the map and redraws a space over the previous fruit
; Updates fruitDrawn to show hold that the galaxian boss has been drawn
DrawGalaxianBoss proc USES eax ecx edx
mov fruitConsumed, 0
movzx eax, melonItem
mov melonItem, ' '
call DrawMelon
mov melonItem, al
mov fruitDrawn, 6
mov eax, lightBlue + (black * 16)
call SetTextColor
mov eax, 0
mov ebx, 0
mov ecx, MAP_WIDTH
mov ax, 14
mul ecx
mov edx, OFFSET buffer
mov ecx, 3
add eax, ecx
add edx, eax
mov bl, galBssItem
mov [edx], bl
mov dl, 3
mov dh, 14
call GotoXY
movzx eax, galBssItem
call WriteChar
ret
DrawGalaxianBoss endp
; Draws the bell on the map and redraws a space over the previous fruit
; Updates fruitDrawn to show hold that the bell has been drawn
DrawBell proc USES eax ecx edx
mov fruitConsumed, 0
movzx eax, galBssItem
mov galBssItem, ' '
call DrawGalaxianBoss
mov galBssItem, al
mov fruitDrawn, 7
mov eax, yellow + (black * 16)
call SetTextColor
mov eax, 0
mov ebx, 0
mov ecx, MAP_WIDTH
mov ax, 1
mul ecx
mov edx, OFFSET buffer
mov ecx, 6
add eax, ecx
add edx, eax
mov bl, bellItem
mov [edx], bl
mov dl, 6
mov dh, 1
call GotoXY
movzx eax, bellItem
call WriteChar
ret
DrawBell endp
; Draws the key on the map and redraws a space over the previous fruit
; Updates fruitDrawn to show hold that the key has been drawn
DrawKey proc USES eax ecx edx
mov fruitConsumed, 0
movzx eax, bellItem
mov bellItem, ' '
call DrawBell
mov bellItem, al
mov fruitDrawn, 8
mov eax, yellow + (black * 16)
call SetTextColor
mov eax, 0
mov ebx, 0
mov ecx, MAP_WIDTH
mov ax, 4
mul ecx
mov edx, OFFSET buffer
mov ecx, 12
add eax, ecx
add edx, eax
mov bl, keyItem
mov [edx], bl
mov dl, 12
mov dh, 4
call GotoXY
movzx eax, keyItem
call WriteChar
ret
DrawKey endp
; Since ecx goes from 3 to 1, this function uses 3 to load the first map
; and 1 to load the last map
GetLevel proc uses eax
cmp Level,3
je Down1
cmp Level,2
je Down2
cmp Level,1
mov fileNamePtr, offset map3.MapIntro
call ReadMapFile
mov eax, 1000
Call Delay
mov fileNamePtr, offset map3.MapFile
Call ReadMapFile
jmp endprog
Down2:
mov fileNamePtr, offset map2.MapIntro
call ReadMapFile
mov eax, 1000
Call Delay
mov fileNamePtr, offset map2.MapFile
Call ReadMapFile
jmp endprog
Down1:
mov fileNamePtr, offset map1.MapIntro
call ReadMapFile
mov eax, 1000
Call Delay
mov fileNamePtr, offset map1.MapFile
Call ReadMapFile
endprog:
ret
GetLevel endp
; Resets major game pieces
; Pac Man location, Pac Dots Consumed
; Tick dount
ResetGame proc
call clrscr
mov PacManX, 11
mov PacManY, 16
mov PacDotsConsumed, 0
mov ticks, 0
ret
ResetGame endp
; Verifies the tick count is lower than the max tick count.
CheckTickCount Proc uses eax
mov eax, ticks
cmp eax, MaxTickCount
jle NotEnoughTicks
call CheckMapForDots
NotEnoughTicks:
ret
CheckTickCount endp
; Verifies there are still pac dots on the map
CheckMapForDots proc uses edx ecx eax
mov edx, offset buffer
mov ecx, sizeof buffer
L1:
mov al, [edx]
cmp al, '.'
je ThereIsDot
add edx, 1
Loop L1
call DelayPacMan
jmp NextMap
ThereIsDot:
ret
CheckMapForDots endp
; This procedure handles the logic for firing the laser
; 80 ticks = Laser Flash
; 100 ticks = Laser Fire
LaserProc proc USES eax ebx edx
mov edx, 0
mov eax, ticks
add eax, 100
mov ebx, 100
div ebx
cmp edx, 0 ; Look at the remainder
jne SkipLaser
Call FireLaser
SkipLaser:
cmp edx, 80
jne NoLaser
call FlashLaser
NoLaser:
ret
LaserProc endp
; Fires the laser down the column
; If the player is caught in it, they lose
FireLaser proc
;mov dl, laserCoord
mov dl, 5
mov dh, 0
mov ecx, 22
mov eax, red + (black * 16)
call SetTextColor
L1:
Call GotoXy
mov eax, 219
Call WriteChar
add dh,1
cmp dl, PacManX
je CheckLives
mov eax, 10
call delay
Loop L1
BackUp:
mov dh, 0
mov dl, 0
call gotoxy
mov eax, white + (black * 16)
call SetTextColor
mov edx, offset buffer
Call WriteString
call UpdateLives
; Check the drawn fruit state to see if it's been consumed
movzx eax, fruitConsumed
cmp fruitConsumed, 0
je RedrawFruit
jne EndFireLaser
; Redraw the correct fruit in color
RedrawFruit:
movzx eax, fruitDrawn
cmp eax, 1
je RedrawCherry
cmp eax, 2
je RedrawStrawberry
cmp eax, 3
je RedrawOrange
cmp eax, 4
je RedrawApple
cmp eax, 5
je RedrawMelon
cmp eax, 6
je RedrawGalaxianBoss
cmp eax, 7
je RedrawBell
cmp eax, 8
je RedrawKey
jmp EndFireLaser
RedrawCherry:
call DrawCherry
jmp EndFireLaser
RedrawStrawberry:
call DrawStrawberry