-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSource.asm
1852 lines (1605 loc) · 55.3 KB
/
Source.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
; M. Zubair Adnan
; 22i-0789-B
; Semester Project
INCLUDE Irvine32.inc
BUFFER_SIZE = 5000
includelib Winmm.lib
PlaySound PROTO,
pszSound:PTR BYTE,
hmod:DWORD,
fdwSound:DWORD
.data
beginSound db ".\startSound.wav",0
pacmandeath db ".\DeathSound.wav",0
foodsound db ".\FoodSound.wav",0
wakasound db ".\WakaSound.wav",0
gameOverSound db ".\GameOverSound.wav",0
errorMessage1 BYTE "Cannnot Open File", 0
errorMessage2 BYTE "Error Reading File", 0
errorMessage3 BYTE "Buffer too small for the file", 0
ground BYTE "------------------------------------------------------------------------------------------------------------------------",0
ground1 BYTE "|",0ah,0
ground2 BYTE "|",0
level1 BYTE "_", 0
level1Coordinates Word 250 dup (?)
levelCoordinatesOffset DD ?
numberOfCoordinates Word ?
levelTemp BYTE 2 dup(?)
temp byte ?
intro1 BYTE " ________ ___ ___ ___ _______ ________ ________ ___ __ ", 0ah
BYTE " |\ __ \ |\ \ |\ \|\ \ |\ ___ \ |\ __ \ |\ __ \ |\ \|\ \ ", 0ah
BYTE " \ \ \|\ /_\ \ \ \ \ \\\ \\ \ __/| \ \ \|\ \\ \ \|\ \\ \ \/ /|_ ", 0ah
BYTE " \ \ __ \\ \ \ \ \ \\\ \\ \ \_|/__ \ \ \\\ \\ \ _ _\\ \ ___ \ ", 0ah
BYTE " \ \ \|\ \\ \ \____ \ \ \\\ \\ \ \_|\ \ \ \ \\\ \\ \ \\ \|\ \ \\ \ \ ", 0ah
BYTE " \ \_______\\ \_______\\ \_______\\ \_______\ \ \_______\\ \__\\ _\ \ \__\\ \__\", 0ah
BYTE " \|_______| \|_______| \|_______| \|_______| \|_______| \|__|\|__| \|__| \|__|", 0ah
BYTE " ", 0ah
BYTE " ________ ________ _______ ________ _______ ________ _________ ________ ", 0ah
BYTE " |\ __ \ |\ __ \ |\ ___ \ |\ ____\ |\ ___ \ |\ ___ \ |\___ ___\|\ ____\ ", 0ah
BYTE " \ \ \|\ \\ \ \|\ \\ \ __/| \ \ \___|_\ \ __/| \ \ \\ \ \\|___ \ \_|\ \ \___|_ ", 0ah
BYTE " \ \ ____\\ \ _ _\\ \ \_|/__\ \_____ \\ \ \_|/__\ \ \\ \ \ \ \ \ \ \_____ \ ", 0ah
BYTE " \ \ \___| \ \ \\ \|\ \ \_|\ \\|____|\ \\ \ \_|\ \\ \ \\ \ \ \ \ \ \|____|\ \ ", 0ah
BYTE " \ \__\ \ \__\\ _\ \ \_______\ ____\_\ \\ \_______\\ \__\\ \__\ \ \__\ ____\_\ \ ", 0ah
BYTE " \|__| \|__|\|__| \|_______||\_________\\|_______| \|__| \|__| \|__| |\_________\ ", 0ah
BYTE " \|_________| \|_________|", 0
intro2 BYTE " ________ ________ ________ _____ ______ ________ ________ ", 0ah
BYTE " |\ __ \ |\ __ \ |\ ____\ |\ _ \ _ \ |\ __ \ |\ ___ \ ", 0ah
BYTE " \ \ \|\ \\ \ \|\ \\ \ \___| \ \ \\\__\ \ \\ \ \|\ \\ \ \\ \ \ ", 0ah
BYTE " \ \ ____\\ \ __ \\ \ \ \ \ \\|__| \ \\ \ __ \\ \ \\ \ \ ", 0ah
BYTE " \ \ \___| \ \ \ \ \\ \ \____ \ \ \ \ \ \\ \ \ \ \\ \ \\ \ \ ", 0ah
BYTE " \ \__\ \ \__\ \__\\ \_______\\ \__\ \ \__\\ \__\ \__\\ \__\\ \__\", 0ah
BYTE " \|__| \|__|\|__| \|_______| \|__| \|__| \|__|\|__| \|__| \|__|", 0
intro3 BYTE " Press Any Key To Continue", 0
intro4 BYTE " ", 0
mainMenu1 BYTE "Welcome, ", 0
mainMenu2 BYTE " Press 1 to Start the Game ", 0ah
BYTE " Press 2 to see the instructions", 0ah
BYTE " Press 3 to see the Hall of Fame", 0
infoMenu1 BYTE "Player: ", 0
pauseMenu1 BYTE "Game Paused. Press P to Resume", 0
pauseMenu2 BYTE " ", 0
instructionMenu1 BYTE " ___ ________ ________ _________ ________ ___ ___ ________ _________ ___ ________ ________ ", 0ah
BYTE " |\ \|\ ___ \|\ ____\|\___ ___|\ __ \|\ \|\ \|\ ____|\___ ___|\ \|\ __ \|\ ___ \ ", 0ah
BYTE " \ \ \ \ \\ \ \ \ \___|\|___ \ \_\ \ \|\ \ \ \\\ \ \ \___\|___ \ \_\ \ \ \ \|\ \ \ \\ \ \ ", 0ah
BYTE " \ \ \ \ \\ \ \ \_____ \ \ \ \ \ \ _ _\ \ \\\ \ \ \ \ \ \ \ \ \ \ \\\ \ \ \\ \ \ ", 0ah
BYTE " \ \ \ \ \\ \ \|____|\ \ \ \ \ \ \ \\ \\ \ \\\ \ \ \____ \ \ \ \ \ \ \ \\\ \ \ \\ \ \ ", 0ah
BYTE " \ \__\ \__\\ \__\____\_\ \ \ \__\ \ \__\\ _\\ \_______\ \_______\ \ \__\ \ \__\ \_______\ \__\\ \__\", 0ah
BYTE " \|__|\|__| \|__|\_________\ \|__| \|__|\|__|\|_______|\|_______| \|__| \|__|\|_______|\|__| \|__|", 0ah
BYTE " \|_________| ", 0
instructionMenu2 BYTE " Press w to go up", 0ah
BYTE " Press s to do down", 0ah
BYTE " Press d to go right", 0ah
BYTE " Press a to go left", 0ah
BYTE " Press x to quit", 0ah
BYTE " Press p to pause game", 0ah
BYTE " Press i to see instructions menu during game", 0ah
BYTE " Press b to go back to", 0
hallOfFameMenu1 BYTE " ___ ___ ________ ___ ___ ________ ________ ________ ________ _____ ______ _______ ", 0ah
BYTE "|\ \|\ \|\ __ \|\ \ |\ \ |\ __ \|\ _____\ |\ _____|\ __ \|\ _ \ _ \|\ ___ \ ", 0ah
BYTE " \ \ \\\ \ \ \|\ \ \ \ \ \ \ \ \ \|\ \ \ \__/ \ \ \__/\ \ \|\ \ \ \\\__\ \ \ \ __/| ", 0ah
BYTE " \ \ __ \ \ __ \ \ \ \ \ \ \ \ \\\ \ \ __\ \ \ __\\ \ __ \ \ \\|__| \ \ \ \_|/__ ", 0ah
BYTE " \ \ \ \ \ \ \ \ \ \ \____\ \ \____ \ \ \\\ \ \ \_| \ \ \_| \ \ \ \ \ \ \ \ \ \ \ \_|\ \ ", 0ah
BYTE " \ \__\ \__\ \__\ \__\ \_______\ \_______\ \ \_______\ \__\ \ \__\ \ \__\ \__\ \__\ \ \__\ \_______\", 0ah
BYTE " \|__|\|__|\|__|\|__|\|_______|\|_______| \|_______|\|__| \|__| \|__|\|__|\|__| \|__|\|_______|", 0
hallOfFameMenu2 BYTE " Press m to go back to main menu", 0
getSetGo BYTE " ________ _______ _________ ________ _______ _________ ________ ________ ", 0ah
BYTE " |\ ____\ |\ ___ \ |\___ ___\ |\ ____\ |\ ___ \ |\___ ___\ |\ ____\ |\ __ \ ", 0ah
BYTE " \ \ \___| \ \ __/|\|___ \ \_| \ \ \___|_\ \ __/|\|___ \ \_| \ \ \___| \ \ \|\ \ ", 0ah
BYTE " \ \ \ ___\ \ \_|/__ \ \ \ \ \_____ \\ \ \_|/__ \ \ \ \ \ \ ___\ \ \\\ \ ", 0ah
BYTE " \ \ \|\ \\ \ \_|\ \ \ \ \ \|____|\ \\ \ \_|\ \ \ \ \ \ \ \|\ \\ \ \\\ \ ", 0ah
BYTE " \ \_______\\ \_______\ \ \__\ ____\_\ \\ \_______\ \ \__\ \ \_______\\ \_______\", 0ah
BYTE " \|_______| \|_______| \|__| |\_________\\|_______| \|__| \|_______| \|_______|", 0ah
BYTE " \|_________| ", 0
level1StartMsg BYTE " ___ _______ ___ ___ _______ ___ _____ ", 0ah
BYTE " |\ \ |\ ___ \ |\ \ / /||\ ___ \ |\ \ / __ \ ", 0ah
BYTE " \ \ \ \ \ __/| \ \ \ / / /\ \ __/| \ \ \ |\/_|\ \ ", 0ah
BYTE " \ \ \ \ \ \_|/__\ \ \/ / / \ \ \_|/__\ \ \ \|/ \ \ \ ", 0ah
BYTE " \ \ \____ \ \ \_|\ \\ \ / / \ \ \_|\ \\ \ \____ \ \ \ ", 0ah
BYTE " \ \_______\\ \_______\\ \__/ / \ \_______\\ \_______\ \ \__\", 0ah
BYTE " \|_______| \|_______| \|__|/ \|_______| \|_______| \|__|", 0
level2StartMsg BYTE " ___ _______ ___ ___ _______ ___ _______ ", 0ah
BYTE " |\ \ |\ ___ \ |\ \ / /||\ ___ \ |\ \ / ___ \ ", 0ah
BYTE " \ \ \ \ \ __/| \ \ \ / / /\ \ __/| \ \ \ /__/|_/ /| ", 0ah
BYTE " \ \ \ \ \ \_|/__\ \ \/ / / \ \ \_|/__\ \ \ |__|// / / ", 0ah
BYTE " \ \ \____ \ \ \_|\ \\ \ / / \ \ \_|\ \\ \ \____ / /_/__ ", 0ah
BYTE " \ \_______\\ \_______\\ \__/ / \ \_______\\ \_______\ |\________\", 0ah
BYTE " \|_______| \|_______| \|__|/ \|_______| \|_______| \|_______|", 0
level3StartMsg BYTE " ___ _______ ___ ___ _______ ___ ________ ", 0ah
BYTE " |\ \ |\ ___ \ |\ \ / /||\ ___ \ |\ \ |\_____ \ ", 0ah
BYTE " \ \ \ \ \ __/| \ \ \ / / /\ \ __/| \ \ \ \|____|\ /_ ", 0ah
BYTE " \ \ \ \ \ \_|/__\ \ \/ / / \ \ \_|/__\ \ \ \|\ \ ", 0ah
BYTE " \ \ \____ \ \ \_|\ \\ \ / / \ \ \_|\ \\ \ \____ __\_\ \ ", 0ah
BYTE " \ \_______\\ \_______\\ \__/ / \ \_______\\ \_______\ |\_______\", 0ah
BYTE " \|_______| \|_______| \|__|/ \|_______| \|_______| \|_______|", 0
gameOver BYTE " ________ ________ _____ ______ _______ ________ ___ ___ _______ ________ ", 0ah
BYTE " |\ ____\ |\ __ \ |\ _ \ _ \ |\ ___ \ |\ __ \ |\ \ / /||\ ___ \ |\ __ \ ", 0ah
BYTE " \ \ \___| \ \ \|\ \\ \ \\\__\ \ \\ \ __/| \ \ \|\ \\ \ \ / / /\ \ __/| \ \ \|\ \ ", 0ah
BYTE " \ \ \ ___\ \ __ \\ \ \\|__| \ \\ \ \_|/__ \ \ \\\ \\ \ \/ / / \ \ \_|/__\ \ _ _\ ", 0ah
BYTE " \ \ \|\ \\ \ \ \ \\ \ \ \ \ \\ \ \_|\ \ \ \ \\\ \\ \ / / \ \ \_|\ \\ \ \\ \| ", 0ah
BYTE " \ \_______\\ \__\ \__\\ \__\ \ \__\\ \_______\ \ \_______\\ \__/ / \ \_______\\ \__\\ _\ ", 0ah
BYTE " \|_______| \|__|\|__| \|__| \|__| \|_______| \|_______| \|__|/ \|_______| \|__|\|__|", 0
gameWon BYTE " ___ ___ ________ ___ ___ ___ __ ________ ________ ___ ", 0ah
BYTE " |\ \ / /||\ __ \ |\ \|\ \ |\ \ |\ \ |\ __ \ |\ ___ \ |\ \ ", 0ah
BYTE " \ \ \/ / /\ \ \|\ \\ \ \\\ \ \ \ \ \ \ \\ \ \|\ \\ \ \\ \ \ \ \ \ ", 0ah
BYTE " \ \ / / \ \ \\\ \\ \ \\\ \ \ \ \ __\ \ \\ \ \\\ \\ \ \\ \ \ \ \ \ ", 0ah
BYTE " \/ / / \ \ \\\ \\ \ \\\ \ \ \ \|\__\_\ \\ \ \\\ \\ \ \\ \ \ \ \__\ ", 0ah
BYTE " __/ / / \ \_______\\ \_______\ \ \____________\\ \_______\\ \__\\ \__\ \|__| ", 0ah
BYTE " |\___/ / \|_______| \|_______| \|____________| \|_______| \|__| \|__| ___ ", 0ah
BYTE " \|___|/ |\__\ ", 0ah
BYTE " \|__| ", 0
Level1Row1 BYTE "########################################################################################", 0ah
BYTE "# ................ #", 0ah
BYTE "# ............... #", 0ah
BYTE "############################ ###########################", 0ah
BYTE "############################ ...................... ###########################", 0ah
BYTE "# ###################### #", 0ah
BYTE "# .............. ######################## ............. #", 0ah
BYTE "# ############## ########################## ############# #", 0ah
BYTE "# ## ........ ## ######################## ## .......... #", 0ah
BYTE "# ###################### ## #", 0ah
BYTE "#############..############# ...................... #############..############", 0ah
BYTE "#############..############# #############..############", 0ah
BYTE "# ...... ######### ...... #", 0ah
BYTE "#############..############# #############..############", 0ah
BYTE "#############..############# ...................... #############..############", 0ah
BYTE "# ###################### #", 0ah
BYTE "# .......... ######################## .......... #", 0ah
BYTE "# ########## ########################## ########## #", 0ah
BYTE "# .. ## .... ######################## .......... #", 0ah
BYTE "# ###################### #", 0ah
BYTE "#### ###################### ...................... #################### ######", 0ah
BYTE "#### ###################### #################### ######", 0ah
BYTE "# ### ................. #", 0ah
BYTE "# ............... #", 0ah
BYTE "########################################################################################", 0
Level2Row1 BYTE "########################################################################################", 0ah
BYTE "# ................................................................................... #", 0ah
BYTE "# .. ########################## ........########################################## .. #", 0ah
BYTE "# .. ## ## .. #", 0ah
BYTE "# .. ## ############################################ ############ ....... #", 0ah
BYTE "# .. ## .... ####### .. #", 0ah
BYTE "# .. ## ...... ################# ..... ## .. #", 0ah
BYTE "# .. ## .. ## ############## ....... ############## ## .. #", 0ah
BYTE "# .. ## .. ## ## .. #", 0ah
BYTE "# .. ## .. ## ###########..#########..##################..############### ## .. #", 0ah
BYTE "# .. ## .. ## ## .. #", 0ah
BYTE "# .. ## .. ## ## .. #", 0ah
BYTE "# ........ ## ########### ################# ## . ## .. .. #", 0ah
BYTE "# .. ## .. ## ## . ## ## .. #", 0ah
BYTE "# .. ## .. ## ........ .. ## . ## ## .. #", 0ah
BYTE "# .. ## .. ## ######## ## . ## ## .. ######## ## ## .. #", 0ah
BYTE "# .. ## .. ## ## .. ## ## . ## ## .. ## . ## ## .. #", 0ah
BYTE "# .. ## .. ## ## .. ## ######## . ## ## .. ## . ## ## .. #", 0ah
BYTE "# .. ## .. ## ## .. ## .... ## . ## ######## . ## ## .. #", 0ah
BYTE "# .. ## .. ## ## . ## ## ## .. #", 0ah
BYTE "# ........ ## ######################### . ############################# ## .. #", 0ah
BYTE "# .. ## .. ## ## .. #", 0ah
BYTE "# .. ############################################# ....... ####################### .. #", 0ah
BYTE "# ................................................................................... #", 0ah
BYTE "########################################################################################", 0
Level3Row1 BYTE "########################################################################################", 0ah
BYTE "# ... #", 0ah
BYTE "# ... ###### ## ###### #", 0ah
BYTE "# ############# ## ... ###### ## ## .. #", 0ah
BYTE "# ####### ..... ## ... ... ###### ... ## ## .. #", 0ah
BYTE "# ## ######## .###### ######## ## .. #", 0ah
BYTE "####### ## ## ... ## ########## #", 0ah
BYTE "# .... ## ## .... ###### ... ## #", 0ah
BYTE "# ## ## .... ... ###### ... ### .. #", 0ah
BYTE "########## . ######### ## .... ... ###### ########### . ##########", 0ah
BYTE "########## . ######### ... ########### . ##########", 0ah
BYTE "########## . ######### ########### . ##########", 0ah
BYTE " ......... ######################## ........... ", 0ah
BYTE "########## . ######### ########### . ##########", 0ah
BYTE "########## . ######### #### ########### . ##########", 0ah
BYTE "########## . ######### ############ .. # ########### . ##########", 0ah
BYTE "# .. ## ## ................. #", 0ah
BYTE "# .. ## ## .### .#############. #### ## #", 0ah
BYTE "# .. ## ..... ## .### .#############. #### ## .##### #", 0ah
BYTE "# .. ########## ## .######## ...... ##. #### ## .##### #", 0ah
BYTE "# #### ...... ##### ## .###### .. #### ... #### ## ........... #", 0ah
BYTE "# ### ...... ## .###### .################ ############## #", 0ah
BYTE "# #### ........ ## #", 0ah
BYTE "# #", 0ah
BYTE "########################################################################################", 0
levelCoins Word 260, 376, 185 ; 260, 376, 185
currentLevelNumber BYTE 0
maxLevel BYTE 2
levelOffsets DD offset Level1Row1, offset Level2Row1, offset Level3Row1
currentLevelOffset DD ?
currentLevelCoins Word 0
coinsCollected Word ?
enemy1 BYTE "#", 0
enemyCoordinates Word 3 dup(?)
enemyMVMT WORD 0, 0, 0
tempHold DD 0
strScore BYTE "Your score is: ",0
score WORD 0
strLife BYTE "Lives Left: ", 0
lives BYTE 3
initialXPos BYTE 44 ; 44
initialYPos BYTE 12 ; 12
xPos BYTE 44
yPos BYTE 12
xCoinPos BYTE ?
yCoinPos BYTE ?
inputChar BYTE ?
userNamePrompt BYTE "Enter Your Name: ", 0
userName BYTE 255 dup(?), 0
userNameSize BYTE ?
buffer BYTE BUFFER_SIZE DUP(?)
filename BYTE "output.txt"
fileHandle HANDLE ?
.code
main PROC
; call PROC to display the intro at the start of the game
call displayIntro
; make space for return value
sub esp, 4
push offset userNamePrompt
push offset userName
; call PROC to prompt the user to get their Name
call getUserName
pop eax
mov userNameSize, al
mainMenu:
push offset hallOfFameMenu1
push offset hallOfFameMenu2
push offset instructionMenu1
push offset instructionMenu2
push offset intro2
push offset userName
push offset mainMenu1
push offset mainMenu2
; call PROC to display the main menu to the player
call displayMainMenu
newLevel:
; load the offset of the current level into the currentLevelOffset variable
sub esp, 4
movzx edx, currentLevelNumber
push edx
push offset levelOffsets
call selectCurrentLevelOffset
pop currentLevelOffset
pop eax
sub esp, 4
push offset levelCoins
movzx edx, currentLevelNumber
push edx
call selectCurrentLevelCoins
pop eax
add currentLevelCoins, ax
movzx edx, currentLevelNumber
push edx
; call PROC to prompt the start of the level
call displayLevelStart
; draw the current level by the offset currently present in the currentLevelOffset
mov edx, currentLevelOffset
push edx
call displayLevel
;call DrawPlayer
call Randomize
cmp currentLevelNumber, 0
JE lowerLevel1
call CreateRandomCoin
call DrawCoin
lowerLevel1:
resetAfterCollision:
; generate the initial spawn point for the player
mov edx, 0
push edx
call setInitialPlayerSpawn
pop edx
mov xPos, dl
mov yPos, dh
; display the player
call DrawPlayer
; generate the initial spawn points for the ghosts associated with the current level
movzx edx, currentLevelNumber
push edx
push offset enemyCoordinates
call setInitialEnemySpawn ; set enemyMVMT to zero
; display the ghosts
movzx edx, currentLevelNumber
push edx
push offset enemyCoordinates
call drawEnemy
; draw score:
push offset strScore
call drawScore
mov eax, 300
call delay
gameLoop:
push offset infoMenu1
push offset userName
call drawName
movzx eax, currentLevelCoins
cmp coinsCollected, ax
JL continue
inc currentLevelNumber
movzx eax, maxLevel
cmp currentLevelNumber, al
JG gameFinished
jmp newLevel
continue:
mov edx, currentLevelOffset
push edx
call displayLevel
; PROC to display the bonus coin
cmp currentLevelNumber, 0
JE lowerLevel2
call DrawCoin
lowerLevel2:
call DrawPlayer
; clears the current position of the ghost
movzx edx, currentLevelNumber
push edx
push offset enemyCoordinates
call updateEnemy
; generate the moves for the ghost
movzx edx, currentLevelNumber
push edx
push offset enemyMVMT
call randEnemyMVMT
; moves enemy in the relevant direction
movzx ecx, currentLevelNumber
inc ecx
mov edx, offset enemyMVMT
mov esi, offset enemyCoordinates
movEnemyLoop:
push ecx
push edx
push esi
mov eax, [edx]
push eax
mov eax, [esi]
push eax
push currentLevelOffset
call movEnemy
pop eax
pop ebx
pop esi
pop edx
pop ecx
mov [esi], ax
mov [edx], bx
add edx, 2
add esi, 2
loop movEnemyLoop
; draws enemy at the relevant position
movzx edx, currentLevelNumber
push edx
push offset enemyCoordinates
call drawEnemy
mov eax, 100
call delay
; checking for ghost collision
movzx ecx, currentLevelNumber
inc ecx ; current number of ghosts
mov esi, offset enemyCoordinates
ghostCollisionLoop:
push ecx
push esi
sub esp, 4
mov edx, 0
mov dl, xPos
mov dh, yPos
push edx
mov edx, 0
mov edx, [esi]
push edx
call checkGhostCollision
pop eax
cmp eax, 0
JE noLivesLost1
;INVOKE PlaySound, OFFSET pacmandeath, NULL,11h
mov eax, 200
call delay
cmp lives, 0
JE livesFinished
dec lives
movzx edx, currentLevelNumber
push edx
push offset enemyCoordinates
call updateEnemy
call UpdatePlayer
mov eax, 200
call delay
jmp resetAfterCollision
noLivesLost1:
pop esi
add esi, 2
pop ecx
loop ghostCollisionLoop
; displaying the current number of lives
mov esi, offset strLife
movzx edx, lives ; lives left
push esi
push edx
call drawLives
; getting points:
mov bl,xPos
cmp bl,xCoinPos
jne notCollecting
mov bl,yPos
cmp bl,yCoinPos
jne notCollecting
; player is intersecting coin:
add score, 10
INVOKE PlaySound, OFFSET foodsound, NULL,11h
mov eax, 200
call delay
; draw score:
push offset strScore
call drawScore
call CreateRandomCoin
call DrawCoin
notCollecting:
mov eax,white (black * 16)
call SetTextColor
; get user key input:
call ReadKey
jz gameLoop ; if no input has been given
mov inputChar,al
; exit game if user types 'x':
cmp inputChar,"x"
je exitGame
cmp inputChar,"w"
je moveUp
cmp inputChar,"s"
je moveDown
cmp inputChar,"a"
je moveLeft
cmp inputChar,"d"
je moveRight
cmp inputChar, "p"
je showPauseMenu
cmp inputChar, "i"
je showInstructionsMenu
jmp gameLoop
showPauseMenu:
push offset pauseMenu1
push offset pauseMenu2
call displayPauseMenu
jmp gameLoop
showInstructionsMenu:
push offset instructionMenu1
push offset instructionMenu2
call displayInstructionsMenu
jmp gameLoop
moveUp:
; allow player to jump:
call UpdatePlayer
dec yPos
cmp yPos, 2 ; min possible y coordinate
JGE noUpperBoundaryCollision
inc yPos
noUpperBoundaryCollision:
sub esp, 4
mov edx, 0
mov dl, xPos
mov dh, yPos
push edx
push currentLevelOffset
call checkUpCollision ; check for collision with a wall
add esp, 8
pop eax
cmp eax, 0
JE withinBound1
inc yPos
withinBound1:
INVOKE PlaySound, OFFSET wakasound, NULL,11h
call DrawPlayer
sub esp, 4
mov edx, 0
mov dl, xPos
mov dh, yPos
push edx
push currentLevelOffset
call checkUpCoinCollision
add esp, 8
pop eax
cmp eax, 0
JE noCoinCollision1
inc score
inc coinsCollected
noCoinCollision1:
push offset strScore
call drawScore
jmp gameLoop
moveDown:
call UpdatePlayer
inc yPos
; check for boundary collision
cmp yPos, 28 ; max possible y coordinate
JBE noBottomBoundaryCollision
dec ypos
noBottomBoundaryCollision:
sub esp, 4
mov edx, 0
mov dl, xPos
mov dh, yPos
push edx
push currentLevelOffset
call checkDownCollision ; check for collision with a wall
add esp, 8
;add esp, 12
pop eax
cmp al, 0
JE withinBound2
dec yPos
withinBound2:
call DrawPlayer
INVOKE PlaySound, OFFSET wakasound, NULL,11h
sub esp, 4
mov edx, 0
mov dl, xPos
mov dh, yPos
push edx
push currentLevelOffset
call checkDownCoinCollision
add esp, 8
pop eax
cmp eax, 0
JE noCoinCollision2
inc score
inc coinsCollected
noCoinCollision2:
push offset strScore
call drawScore
jmp gameLoop
moveLeft:
call UpdatePlayer
cmp yPos, 13
JNE noTeleportation3
cmp xPos, 1
JNE noTeleportation3
mov yPos, 13
mov xPos, 87
jmp withinBound3
noTeleportation3:
dec xPos
; check for boundary collision
cmp xPos, 1 ; min possible x coordinate
JGE noLeftBoundaryCollision
inc xPos
noLeftBoundaryCollision:
sub esp, 4
mov edx, 0
mov dl, xPos
mov dh, yPos
push edx
push currentLevelOffset
call checkLeftCollision ; check for collision with a wall
add esp, 8
pop eax
cmp al, 0
JE withinBound3
inc xPos
withinBound3:
call DrawPlayer
INVOKE PlaySound, OFFSET wakasound, NULL,11h
sub esp, 4
mov edx, 0
mov dl, xPos
mov dh, yPos
push edx
push currentLevelOffset
call checkLeftCoinCollision
add esp, 8
pop eax
cmp eax, 0
JE noCoinCollision3
inc score
inc coinsCollected
noCoinCollision3:
push offset strScore
call drawScore
jmp gameLoop
moveRight:
call UpdatePlayer
cmp yPos, 13
JNE noTeleportation4
cmp xPos, 87
JNE noTeleportation4
mov yPos, 13
mov xPos, 1
jmp withinBound4
noTeleportation4:
inc xPos
; check for boundary collision
cmp xPos, 118 ; max possible x coordinate
JBE noRightBoundaryCollision
dec xPos
noRightBoundaryCollision:
sub esp, 4
mov edx, 0
mov dl, xPos
mov dh, yPos
push edx
push currentLevelOffset
call checkRightCollision ; check for collision with a wall
add esp, 8
pop eax
cmp al, 0
JE withinBound4
dec xPos
withinBound4:
call DrawPlayer
INVOKE PlaySound, OFFSET wakasound, NULL,11h
sub esp, 4
mov edx, 0
mov dl, xPos
mov dh, yPos
push edx
push currentLevelOffset
call checkRightCoinCollision
add esp, 8
pop eax
cmp eax, 0
JE noCoinCollision4
inc score
inc coinsCollected
noCoinCollision4:
push offset strScore
call drawScore
jmp gameLoop
jmp gameLoop
gameFinished:
push offset gameWon
push offset infoMenu1
push offset userName
push offset strScore
movzx eax, score
push eax
push offset strLife
movzx eax, lives
push eax
call displayGameWon
jmp exitGame
livesFinished:
push offset gameOver
push offset infoMenu1
push offset userName
push offset strScore
movzx eax, score
push eax
push offset strLife
movzx eax, lives
push eax
call displayGameOver
exitGame:
exit
main ENDP
drawScore PROC
push ebp
mov ebp, esp
mov eax, white
call setTextColor
mov dl,0
mov dh,0
call Gotoxy
mov edx, [ebp + 8]
call WriteString
mov eax, 0
mov ax,score
call WriteDec
pop ebp
ret 4
drawScore ENDP
DrawPlayer PROC
; draw player at (xPos,yPos):
mov eax,yellow ;(blue*16)
call SetTextColor
mov dl,xPos
mov dh,yPos
call Gotoxy
mov al,"X"
call WriteChar
ret
DrawPlayer ENDP
UpdatePlayer PROC
mov dl,xPos
mov dh,yPos
call Gotoxy
mov al," "
call WriteChar
ret
UpdatePlayer ENDP
DrawCoin PROC
mov eax,yellow ;(red * 16)
call SetTextColor
mov dl,xCoinPos
mov dh,yCoinPos
call Gotoxy
mov al,"$"
call WriteChar
ret
DrawCoin ENDP
CreateRandomCoin PROC
; setting the x coord of the coin
;mov eax, 118 ; max x coord
mov eax, 88
call RandomRange
cmp al, 0
JG skipXCordInc1
add al, 1
skipXCordInc1:
mov xCoinPos, al
; setting the y coord of the coin
;mov eax, 28 ; max y coord
mov eax, 24
call RandomRange
cmp al, 1
JG skipYCordInc1
add al, 2
skipYCordInc1:
mov yCoinPos, al
; ensuring that the coin does not spawn on the wall of a given level
checkAgain:
sub esp, 4
mov edx, 0
mov dl, xCoinPos
mov dh, yCoinPos
push edx
push currentLevelOffset
call checkUpCollision
add esp, 8
pop eax
cmp al, 0
JE noChange
dec yCoinPos
jmp checkAgain
noChange:
ret
CreateRandomCoin ENDP
selectCurrentLevelOffset PROC
push ebp
mov ebp, esp
mov eax, [ebp + 12]
mov esi, [ebp + 8]
CDQ
mov bx, 4
imul bx
mov edx, [esi + eax]
mov [ebp + 16], edx
pop ebp
ret 8
selectCurrentLevelOffset ENDP
displayLevel PROC
push ebp
mov ebp, esp
mov dl, 0
mov dh, 1
call gotoxy
mov eax, blue
call setTextColor
mov edx, [ebp + 8]
;mov edx, offset Level1Row2
call writeString
pop ebp
ret 4
displayLevel ENDP
checkUpCollision PROC
push ebp
mov ebp, esp
mov eax, 0 ; 0 for no collision and 1 for collision detected
mov [ebp + 16], eax ; space to hold true or false
mov ecx, [ebp + 12] ; current coordinates
mov esi, [ebp + 8]
mov edx, 0
mov dl, ch ; ch has the y coord
imul edx, 89
mov ebx, 0
mov bl, cl ; cl has the x cord
add edx, ebx
sub edx, 89 ; since each line has at max 89 characters, adjusting the coordinates accordingly
mov al, [esi + edx] ; comparing the current coordinate with the equivalent coordinate in the map
cmp al, '#'
jne noCollision1
mov eax, 1 ; collision detected
mov [ebp + 16], eax
noCollision1:
pop ebp
ret
checkUpCollision ENDP
checkUpCoinCollision PROC
push ebp
mov ebp, esp
mov eax, 0
mov [ebp + 16], eax ; space to hold true or false
mov ecx, [ebp + 12] ; current coordinates
mov esi, [ebp + 8]
mov edx, 0
mov dl, ch ; ch has the y coord
imul edx, 89
mov ebx, 0
mov bl, cl ; cl has the x cord
add edx, ebx
sub edx, 89
;sub edx, 120
mov al, [esi + edx]
cmp al, '.'
jne noCoinCollision1
mov al, ' '
mov [esi + edx], al
mov eax, 1
mov [ebp + 16], eax
noCoinCollision1:
pop ebp
ret
checkUpCoinCollision ENDP
checkDownCollision PROC
push ebp
mov ebp, esp
mov eax, 0
mov [ebp + 16], eax
mov ecx, [ebp + 12]
mov esi, [ebp + 8]
mov edx, 0
mov dl, ch
imul edx, 89
mov ebx, 0
mov bl, cl
add edx, ebx
sub edx, 89
mov al, [esi + edx]
cmp al, '#'
jne noCollision2
mov eax, 1
mov [ebp + 16], eax
noCollision2:
pop ebp
ret
checkDownCollision ENDP
checkDownCoinCollision PROC
push ebp
mov ebp, esp
mov eax, 0
mov [ebp + 16], eax
mov ecx, [ebp + 12]
mov esi, [ebp + 8]
mov edx, 0
mov dl, ch
imul edx, 89
mov ebx, 0
mov bl, cl
add edx, ebx
sub edx, 89
mov al, [esi + edx]
cmp al, '.'
jne noCoinCollision2
mov al, ' '
mov [esi + edx], al
mov eax, 1
mov [ebp + 16], eax
noCoinCollision2: