-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal.asm
More file actions
1953 lines (1691 loc) · 74.5 KB
/
final.asm
File metadata and controls
1953 lines (1691 loc) · 74.5 KB
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
%include "/usr/local/share/csc314/asm_io.inc"
; the files that stores the boards/screens
%define BOARD_FILE 'board.txt'
%define BOARDII_FILE 'level2.txt'
%define BOARDIII_FILE 'level3.txt'
%define BOARDIV_FILE 'level4.txt'
%define MARRIAGE_FILE 'Marriage.txt'
%define LOADING_FILE 'loading.txt'
%define LOSE_FILE 'lose.txt'
; how to represent everything
%define WALL_CHAR '#'
%define GATE_CHAR '_'
%define PLAYER_CHAR 'O'
%define THE_MISSUS 'M' ;get caught and get Married
%define TELEPORT_CHAR '='
%define NULL_CHAR ' '
%define ORB_CHAR '.'
%define SPECIALORB_CHAR '@' ;make it to end of game and get a Divorce
%define BOMB_CHAR '*'
%define WATER_CHAR '~'
%define WET_ORB_CHAR ','
; the size of the game screen in characters
%define HEIGHT 23 ;also used for marriage file
%define WIDTH 45 ; mfile
%define HEIGHTII 21
%define WIDTHII 57
%define HEIGHTIII 23
%define WIDTHIII 55
%define HEIGHTIV 23
%define WIDTHIV 49
; the player and missus starting positions for every level.
; top left is considered (0,0)
%define STARTX 22 ;level 1
%define STARTY 15 ;level 1
%define M_STARTX 22 ;level 1
%define M_STARTY 11 ;level 1
%define MII_STARTX 24 ;level 1
%define MII_STARTY 11 ;level 1
%define STARTIIX 28 ;level 2
%define STARTIIY 14 ;level 2
%define M_STARTIIX 28 ;level 2
%define M_STARTIIY 9 ;level 2
%define MII_STARTIIX 30 ;level 2
%define MII_STARTIIY 9 ;level 2
%define STARTIIIX 28 ;level 3
%define STARTIIIY 13 ;level 3
%define M_STARTIIIX 28 ;level 3
%define M_STARTIIIY 11 ;level 3
%define MII_STARTIIIX 30 ;level 3
%define MII_STARTIIIY 11 ;level 3
%define STARTIVX 26 ;level 4
%define STARTIVY 15 ;level 4
%define M_STARTIVX 28 ;level 4
%define M_STARTIVY 11 ;level 4
%define MII_STARTIVX 30 ;level 4
%define MII_STARTIVY 11 ;level 4
; teleport to positions for each board
%define TEL_ONEX 2 ;level 1,2,3
%define TEL_ONEY 11 ;level 1,2,3
%define TEL_ONEIVY 5 ;level 4
%define TEL_TWOX 42 ;for level 1
%define TEL_TWOIIX 54 ;for level 2
%define TEL_TWOIIIX 52 ;level 3
%define TEL_TWOIVX 46 ;level 4
%define TEL_TWOY 11 ;for level 1,2,3,4
; ending player positions
%define WIN_X 24
%define WIN_Y 6
%define LOSE_X 22
%define LOSE_Y 14
; these keys do things/actions the player can take
%define EXITCHAR 'x'
%define UPCHAR 'w'
%define LEFTCHAR 'a'
%define DOWNCHAR 's'
%define RIGHTCHAR 'd'
%define BOMBCHAR 'b'
%define ONECHAR '1' ;yellow player character
%define TWOCHAR '2' ;green player character
%define THREECHAR '3' ;lavender player character
; how many orbs to replace with bombs
%define NUM_BOMBS 3
; dot counts per board, used to track when level over
%define DOTS 248
%define DOTSII 256
%define DOTSIII 300
%define DOTSIV 262
segment .data
; used to fopen() the board files defined above
board_file db BOARD_FILE,0
level2_file db BOARDII_FILE,0
level3_file db BOARDIII_FILE,0
level4_file db BOARDIV_FILE,0
win_file db MARRIAGE_FILE,0
loading_file db LOADING_FILE,0
lose_file db LOSE_FILE,0
;helper vars
score dq 0
level db 1 ;current board level
caught db 0 ;keeps track of if player has been caught by missus (0=no,1=yes)
;special orbs
safeguard dq 0 ;allows you to send the missus back to her start
safetxt db 27, "[38;2;255;165;0m", " Safeguard: ", 27, "[0m",0
;bomb vars
bombs dd 0 ;keeps track of how many bombs player has currently
bombtxt db 27, "[38;5;74m", " Bombs: ", 27, "[0m",0
explode db 0
spacetxt db " - ",0
;water label to check if water was added
water_increased db 0
;lives
lives dd 3 ;keeps track of player lives
livestxt db 27,"[31m"," Lives: ",27,"[0m",0
; used to change the terminal mode
mode_r db "r",0
raw_mode_on_cmd db "stty raw -echo",0
raw_mode_off_cmd db "stty -raw echo",0
; ANSI escape sequence to clear/refresh the screen
clear_screen_code db 27,"[2J",27,"[H",0
; things the program will print
help_str db 13,10,"Controls: ", \
UPCHAR,"=UP / ", \
LEFTCHAR,"=LEFT / ", \
DOWNCHAR,"=DOWN / ", \
RIGHTCHAR,"=RIGHT / ", \
BOMBCHAR,"=BOMB / ", \
EXITCHAR,"=EXIT", \
13,10,0
;player color options
color_opt db 13,10,"Characters: ", \
ONECHAR, "=YELLOW / ", \
TWOCHAR, "=GREEN / ", \
THREECHAR, "=PURPLE", \
13,10,10,0
;player color
pcolor db 1 ;keeps track of which color player chooses to play as
; helper text
scoretxt db "Score: ",0
; won the game
congrats_txt db 13,10,"YOU WIN: ",\
"Congrats on your marriage to The Missus!",\
13,10,10,0
winvar db 0 ;keeps track of if the player has won or not
losevar db 0 ;keeps track of if the player has lost or not
loading db 0 ;keeps track of if the player is between levels
missus_first_move dd 1 ;keeps track of if the missus needs to execute her first move to escape home
missusII_first_move dd 1 ;same for missusII
;colors used in printing
yellow_code db 27,"[38;2;255;255;0m",0 ; 1.player character
orange_code db 27,"[38;2;255;165;0m",0 ; 1.safe player
green_code db 27,"[32m",0 ; 2.player character
lightgreen_code db 27,"[38;2;142;194;21m",0 ; 2.safe player
lavender_code db 27,"[38;2;115;79;150m",0 ; 3.player character
violet_code db 27,"[35m",0 ; 3.safe player
blue_code db 27,"[38;2;33;33;222m",0 ; the walls
cyan_code db 27,"[38;2;0;255;255m",0 ; the teleport tunnels
gray_code db 27,"[38;2;211;211;211m",0 ; the gate for missus's home
pink_code db 27,"[38;2;247;83;148m",0 ; Missus character
peach_code db 27,"[38;2;255;211;172m",0 ; orbs
red_code db 27,"[31m",0 ; plus sign in wedding image
light_blue_code db 27,"[38;5;74m",0 ; bombs
blue_background_code db 27,"[44m",0 ; water
reset_code db 27,"[0m",0 ; used to stop printing in color
board_pointers: ;used to keep track of which board array to use for calculations
dd board
dd board2
dd board3
dd board4
segment .bss
; this array stores the current rendered gameboard (HxW)
board resb (HEIGHT * WIDTH)
board2 resb (HEIGHTII * WIDTHII)
board3 resb (HEIGHTIII * WIDTHIII)
board4 resb (HEIGHTIV * WIDTHIV)
; these variables store the current player position
xpos resd 1
ypos resd 1
; random number seed variable
seed resd 1
;bomb location variable (for replacing orbs)
bomb_x resd 1
; missus position vars
m_xpos resd 1 ; missus x-coordinate
m_ypos resd 1 ; missus y-coordinate
; second missus
mII_xpos resd 1 ;second missus x-coordinate
mII_ypos resd 1 ;second missus y-coordinate
missusII_right_streak resd 1 ;stroes if missusII is moving
missusII_last_move resd 1 ;stores missusII laster direction: 1=left, 2=down, 3=right 4=up
curheight resd 1 ;used to keep track of board height for current level
curwidth resd 1 ;board width for current level
dots_req resd 1 ;dots needed to end the current level
dots_eaten resd 1 ;how many have been collected by player for current level
segment .text
global asm_main
global raw_mode_on
global raw_mode_off
global init_board
global render
global explode_space ;used for bomb logic
extern system
extern putchar
extern getchar
extern printf
extern fopen
extern fread
extern fgetc
extern fclose
asm_main:
push ebp
mov ebp, esp
; put the terminal in raw mode so the game works nicely
call raw_mode_on
initial_levelchk:
; read the game board file into the global variable
; check level to load proper level variables (board dimensions, dots required, player/missus starting positions)
cmp BYTE [level], 1
je start_pos
cmp BYTE [level],2
je start2_pos
cmp BYTE [level],3
je start3_pos
;else level 4
mov DWORD [curheight], HEIGHTIV
mov DWORD [curwidth], WIDTHIV
mov DWORD [dots_req], DOTSIV
call init_board ;init a dif board
reset_positions4:
mov DWORD [xpos], STARTIVX
mov DWORD [ypos], STARTIVY
;missus code
just_mpos4: ;the two missus's starting x & y positions 4
mov DWORD [m_xpos], M_STARTIVX
mov DWORD [m_ypos], M_STARTIVY
mov DWORD [mII_xpos], MII_STARTIVX
mov DWORD [mII_ypos], MII_STARTIVY
jmp end_lvlchk
start_pos:
;board1 has extra checks because it's dimensions are used for other screens (Marriage, Lose, Loading Screens)
mov DWORD [curheight], HEIGHT
mov DWORD [curwidth], WIDTH
call init_board
;check if win
cmp BYTE [winvar], 1
je win_step2 ;used to return to win code if coming from there
;check if loading screen
cmp BYTE [loading], 1
je loading_step2 ;used to return to load code
;check if lose
cmp BYTE [losevar], 1
je lose_step2 ;used to ret to los code
mov DWORD [dots_req], DOTS
reset_positions:
mov DWORD [xpos], STARTX
mov DWORD [ypos], STARTY
;missus code
just_mpos: ;the two missus's starting x & y positions 1
mov DWORD [m_xpos], M_STARTX
mov DWORD [m_ypos], M_STARTY
mov DWORD [mII_xpos], MII_STARTX
mov DWORD [mII_ypos], MII_STARTY
jmp end_lvlchk
start2_pos:
mov DWORD [curheight], HEIGHTII
mov DWORD [curwidth], WIDTHII
mov DWORD [dots_req], DOTSII
call init_board ;init a dif board
reset_positions2:
mov DWORD [xpos], STARTIIX
mov DWORD [ypos], STARTIIY
;missus code
just_mpos2: ;the two missus's starting x & y positions 2
mov DWORD [m_xpos], M_STARTIIX
mov DWORD [m_ypos], M_STARTIIY
mov DWORD [mII_xpos], MII_STARTIIX
mov DWORD [mII_ypos], MII_STARTIIY
jmp end_lvlchk
start3_pos:
mov DWORD [curheight], HEIGHTIII
mov DWORD [curwidth], WIDTHIII
mov DWORD [dots_req], DOTSIII
call init_board ;init a dif board
reset_positions3:
mov DWORD [xpos], STARTIIIX
mov DWORD [ypos], STARTIIIY
;missus code
just_mpos3: ;the two missus's starting x & y positions 3
mov DWORD [m_xpos], M_STARTIIIX
mov DWORD [m_ypos], M_STARTIIIY
mov DWORD [mII_xpos], MII_STARTIIIX
mov DWORD [mII_ypos], MII_STARTIIIY
jmp end_lvlchk
end_lvlchk:
cmp BYTE [caught], 1
jmp post_losechk ;used to return to lose_chk code
; set the player at the proper start position
; the game happens in this loop
; the steps are...
; 1. render (draw) the current board
; 2. get a character from the user
; 3. store current xpos,ypos in esi,edi
; 4. update xpos,ypos based on character from user
; 5. check what's in the buffer (board) at new xpos,ypos
; 6. if it's a wall, reset xpos,ypos to saved esi,edi
; 7. otherwise, just continue! (xpos,ypos are ok)
game_loop:
; draw the game board
call render
;checks if water increased and the screen
cmp [water_increased], BYTE 2
jne do_not_refresh_water
call render
do_not_refresh_water:
;temporary print of score
mov eax, scoretxt
call print_string
mov eax, [score]
call print_int
;temporary print of bombs
mov eax, bombtxt
call print_string
mov eax, [bombs]
call print_int
;print of lives
mov eax, livestxt
call print_string
mov eax, [lives]
call print_int
;print safeguard
mov eax, safetxt
call print_string
mov eax, [safeguard]
call print_int
call print_nl
; get an action from the user
call getchar
; store the current position
; we will test if the new position is legal
; if not, we will restore these
mov esi, DWORD [xpos]
mov edi, DWORD [ypos]
; choose what to do
cmp eax, EXITCHAR
je game_loop_end
cmp eax, ONECHAR
je pcolor_one
cmp eax, TWOCHAR
je pcolor_two
cmp eax, THREECHAR
je pcolor_three
cmp eax, UPCHAR
je move_up
cmp eax, LEFTCHAR
je move_left
cmp eax, DOWNCHAR
je move_down
cmp eax, RIGHTCHAR
je move_right
cmp eax, BOMBCHAR
je move_bomb
jmp input_end ; or just do nothing
; move the player according to the input character/or change player color
pcolor_one:
mov BYTE [pcolor], 1
jmp game_loop
pcolor_two:
mov BYTE [pcolor], 2
jmp game_loop
pcolor_three:
mov BYTE [pcolor], 3
jmp game_loop
move_up:
dec DWORD [ypos]
jmp input_end
move_left:
sub DWORD [xpos],2
jmp input_end
move_down:
inc DWORD [ypos]
jmp input_end
move_right:
add DWORD [xpos],2
jmp input_end
move_bomb:
cmp [bombs], DWORD 1
jl input_end
mov [explode], DWORD 1 ;1 used to signal on
input_end:
; (W * y) + x = pos
; compare the current position to the wall character
mov eax, [curwidth]
mul DWORD [ypos]
add eax, DWORD [xpos]
;check board level to use lea on a board array
movzx ecx, BYTE [level]
dec ecx
mov edx, [board_pointers + ecx*4]
lea eax, [edx + eax]
cmp BYTE [eax], WALL_CHAR
je invalid_move
cmp BYTE [eax], GATE_CHAR
jne valid_move
invalid_move:
; opps, that was an invalid move, reset
mov DWORD [xpos], esi
mov DWORD [ypos], edi
valid_move:
cmp BYTE[eax], TELEPORT_CHAR ;check if player is teleporting
jne normal_mov
; teleportation, spooky
;teleport level check
cmp BYTE [level], 1
je telb1
cmp BYTE [level], 2
je telb2
cmp BYTE [level], 3
je telb3
cmp BYTE [level], 4
je telb4
telb1:
cmp DWORD [xpos], 0
jz telb1right
;else left
left1:
mov DWORD [xpos], TEL_ONEX
mov DWORD [ypos], TEL_ONEY
jmp new_pos
telb1right:
mov DWORD [xpos], TEL_TWOX
mov DWORD [ypos], TEL_TWOY
jmp new_pos
telb2:
cmp DWORD [xpos], 0
jz telb2right
;else left
jmp left1
telb2right:
mov DWORD [xpos], TEL_TWOIIX
mov DWORD [ypos], TEL_TWOY
jmp new_pos
telb3:
cmp DWORD [xpos], 0
jz telb3right
;else left
jmp left1
telb3right:
mov DWORD [xpos], TEL_TWOIIIX
mov DWORD [ypos], TEL_TWOY
jmp new_pos
telb4:
cmp DWORD [xpos], 0
jz telb4right
;else left
mov DWORD [xpos], TEL_ONEX
mov DWORD [ypos], TEL_ONEIVY
jmp new_pos
telb4right:
mov DWORD [xpos], TEL_TWOIVX
mov DWORD [ypos], TEL_TWOY
jmp new_pos
new_pos:
;recalculate position
mov eax, [curwidth]
mul DWORD [ypos]
add eax, DWORD [xpos]
;check board level to use lea on a board array
movzx ecx, BYTE [level]
dec ecx
mov edx, [board_pointers + ecx*4]
lea eax, [edx + eax]
jmp normal_mov
normal_mov:
;check if safeguard needs to dec
cmp DWORD [safeguard], 0
jle skip_safechk
dec DWORD [safeguard]
skip_safechk:
;check if need to inc the score
cmp BYTE [eax], ORB_CHAR
je check_orb
cmp BYTE [eax], WET_ORB_CHAR
jne after_orb
check_orb:
mov ebx, [score]
add ebx, 10
mov [score], ebx
inc DWORD [dots_eaten]
;replaces the orb character with empty space
mov BYTE [eax], NULL_CHAR
after_orb:
cmp BYTE [eax], SPECIALORB_CHAR ;are used for sending the missus home, activates safeguard if eaten
jne after_specialorb
mov ebx, [score]
add ebx, 50
inc DWORD [dots_eaten]
mov [score], ebx
mov BYTE [safeguard], 15
;replace with empty space
mov BYTE [eax], NULL_CHAR
after_specialorb:
;check if player ate all dots on the board
mov edx, [dots_eaten]
cmp edx, DWORD [dots_req]
jz screen_change ;level over
;check if need to increase the bombs
cmp BYTE [eax], BOMB_CHAR
jne after_bomb_collect
mov ebx, [bombs]
inc ebx
mov [bombs], ebx
;replaces the bomb character with empty space
mov BYTE [eax], NULL_CHAR
after_bomb_collect:
;checks if it should explode (this can be moved to after missus movement if wanted)
cmp [explode], DWORD 1
jne no_explode
pusha ;save registers
;does explosion via for loop
mov ecx, 0 ;ecx is the x loop counter
mov edx, 0 ;edx is the y loop counter
mov eax, DWORD [xpos]
mov ebx, DWORD [ypos]
sub eax, 2
sub ebx, 1
explode_loop_x:
explode_loop_y:
pusha ;save current registers
push eax ;pass xpos
push ebx ;pass ypos
call explode_space
add esp, 8
popa ;restore registers
inc ebx ;go to next ypos
inc edx ;up y loop counter
cmp edx, 2
jle explode_loop_y
inc eax ;go to next xpos
mov ebx, DWORD [ypos] ;set ypos to original
sub ebx, 1
;makes ypos 1 less
mov edx, 0 ;resets inner loop counter
inc ecx ;up x loop counter
cmp ecx, 4
jle explode_loop_x
;turns off the explosion and use a bomb
mov eax, 0
mov [explode], eax
sub [bombs], DWORD 1
popa ;retrieve registers
no_explode:
;check if moving into water
cmp BYTE [eax], WATER_CHAR
je water_penalty
cmp BYTE [eax], WET_ORB_CHAR
jne no_water_penalty
water_penalty:
mov ebx, [score]
sub ebx, 5
mov [score], ebx
no_water_penalty:
;********** missus movement code ***************
; check if missus first move
cmp dword[missus_first_move], 1
jne normal_missus_move ;if not first move use normal logic
mov eax, [m_xpos] ; missus current x position
mov ebx, [m_ypos] ; missus current y position
sub ebx, 2 ; up 2
mov [m_xpos], eax
mov [m_ypos], ebx
mov dword [missus_first_move],0 ;first move has happened
;jmp missus_done
;**************** normal missus logic ******************
normal_missus_move:
; compare Missus x to players x
mov eax, [m_xpos] ;missus x coordinate in eax
mov ebx, [m_ypos] ;missus y coordinate in ebx
; Try to move horizontally first, to align x-coordinate with the player
mov ecx, [xpos] ; load player x
cmp eax, ecx ; missus x cordinate and player x corrdiante
je missus_try_y
jl missus_right
jg missus_left
missus_right:
add eax, 2 ; try to move right by 2
jmp missus_check_wall ; see if moving right allowed
missus_left:
sub eax, 2 ; try to move left by 2
jmp missus_check_wall ; see if moving left is allowed
;****** if x-cordinate of player and missus is equal try to move to same y cordinate *****
missus_try_y:
mov ecx, [ypos] ; load player y
cmp ebx, ecx ; missus y cordinate and player y cordinate
je missus_done
jl missus_down
jg missus_up
missus_down:
inc ebx ; move down 1
jmp missus_check_wall
missus_up:
dec ebx ; moves up 1
missus_check_wall:
mov edx, [curwidth] ; current board width
imul edx, ebx ; linear index because 2d board
add edx, eax
;lea esi, [board + edx] ;was an issue, fixed
;check board level to use lea with board array
movzx ecx, BYTE [level]
dec ecx
mov ecx, [board_pointers + ecx*4]
lea esi, [ecx + edx]
cmp BYTE[esi], WALL_CHAR ;is there a wall there
je missus_blocked
cmp BYTE[esi], GATE_CHAR ;is there a gate there
je missus_blocked
jmp missus_set_pos ;valid move
missus_blocked: ;restore original missus position
mov eax, [m_xpos]
mov ebx, [m_ypos]
; check player y ; defaults left or right based on midline
mov ecx, [ypos]
cmp ecx, 15 ; compare to horisonal mid line
jg try_down
jl try_up
je mx_check ; if on midline check x position
; horizontal midline to establish defaults
mx_check:
mov ecx, [xpos]
cmp ecx, 22 ; check if player left or right of mid line
jg confused_move_right ; if right of midline move right
;;left
sub eax, 2
mov esi, [curwidth]
imul esi, ebx
add esi, eax
;lea esi, [board + esi] ;was an issue, fixed
;check board level
movzx edx, BYTE [level]
dec edx
mov edx, [board_pointers + edx*4]
lea esi, [edx + esi]
cmp BYTE [esi], WALL_CHAR
je missus_done ; if blocked dont go there
mov [m_xpos], eax ; else save new x position
jmp missus_done
confused_move_right:
add eax, 2
mov esi, [curwidth]
imul esi, ebx
add esi, eax
;lea esi, [board + esi] ;was an issue, fixed
;check board level to use lea with board array
movzx ecx, BYTE [level]
dec ecx
mov ecx, [board_pointers + ecx*4]
lea esi, [ecx + esi]
cmp BYTE [esi], WALL_CHAR
je missus_done
mov [m_xpos], eax ; saves new x-cordinate
jmp missus_done
; alternativly try moving up
try_up:
mov edx, ebx
dec edx ; move up by 1
mov esi, [curwidth]
imul esi, edx
add esi, eax
;lea esi, [board + esi] ;was an issue, fixed
;check board level to use lea with board array
movzx ecx, BYTE [level]
dec ecx
mov ecx, [board_pointers + ecx*4]
lea esi, [ecx + esi]
cmp BYTE[esi], WALL_CHAR
je missus_done
mov [m_ypos], edx ; save new y position
jmp missus_done
try_down:
mov edx, ebx
inc edx ; move down by 1
mov esi, [curwidth]
imul esi, edx
add esi, eax
;lea esi, [board + esi] ;ISSUE HERE
;check board level to use lea with board array
movzx ecx, BYTE [level]
dec ecx
mov ecx, [board_pointers + ecx*4]
lea esi, [ecx + esi]
cmp BYTE [esi], WALL_CHAR
je missus_done
cmp BYTE [esi], GATE_CHAR ;new (needed to keep off of gate)
je missus_done
mov [m_ypos], edx ; save new y-coordiante
jmp missus_done
;saves the valid move
missus_set_pos:
mov [m_xpos], eax ; updates missus x-cordinate
mov [m_ypos], ebx ; updates missus y-cordiante
jmp missus_done
missus_done:
; second missus priorizes following the left wall
missusII_movement:
mov eax, [score]
cmp eax, 50 ; missusII leaves spawn after player has 50 points
jl missusII_done
cmp dword [missusII_first_move], 1
jne normal_missusII_move ; if not first move, normal pathing
;else exit spawn by moving left and up
mov eax, [mII_xpos]
mov ebx, [mII_ypos]
sub eax, 2 ; moves left
sub ebx, 2 ; moves up
mov [mII_xpos], eax ; save new x-cordinate
mov [mII_ypos], ebx ; save new y-cordinate
mov dword [missusII_first_move], 0 ; first move complete
mov dword [missusII_right_streak], 0 ; not on right streak
mov dword [missusII_last_move], 0 ; reset last move
jmp missusII_done
normal_missusII_move:
;check if on player char
mov ebx, [xpos]
cmp ebx, [mII_xpos]
jne post_mIIcaughtchk
mov ebx, [ypos]
cmp ebx, [mII_ypos]
jne post_mIIcaughtchk
jmp missusII_done
post_mIIcaughtchk:
; check if last move was right
cmp dword [missusII_right_streak], 1
je missusII_continue_right ; if last move was right, next move is right
; check every direction to see if valid
; store which directions are valid on the stack
push 0 ; left valid (ebp-4)
push 0 ; down valid (ebp-8)
push 0 ; right valid (ebp-12)
push 0 ; up valid (ebp-16)
; check left
mov eax, [mII_xpos] ;current missusII position
mov ebx, [mII_ypos]
sub eax, 2 ; try moving left
mov edx, [curwidth]
imul edx, ebx
add edx, eax
movzx ecx, BYTE [level] ; check which board
dec ecx
mov ecx, [board_pointers + ecx*4]
lea esi, [ecx + edx]
cmp BYTE [esi], WALL_CHAR ; wall check
je check_down_valid
cmp BYTE [esi], GATE_CHAR ; gate check
je check_down_valid
cmp BYTE [esi], TELEPORT_CHAR ; teleport check
je check_down_valid
mov dword [esp + 12], 1 ;left is valid
check_down_valid:
mov eax, [mII_xpos]
mov ebx, [mII_ypos]
inc ebx ; try moving down
mov edx, [curwidth]
imul edx, ebx
add edx, eax
movzx ecx, BYTE [level]
dec ecx
mov ecx, [board_pointers + ecx*4]
lea esi, [ecx + edx]
cmp BYTE [esi], GATE_CHAR ; gate check
je check_right_valid
mov dword [esp + 8], 1 ;down is valid
check_right_valid:
mov eax, [mII_xpos]
mov ebx, [mII_ypos]
add eax, 2 ; try moving right
mov edx, [curwidth]
imul edx, ebx
add edx, eax
movzx ecx, BYTE [level]
dec ecx
mov ecx, [board_pointers + ecx*4]
lea esi, [ecx + edx]
cmp BYTE [esi], WALL_CHAR
je check_up_valid
cmp BYTE [esi], GATE_CHAR
je check_up_valid
cmp BYTE [esi], TELEPORT_CHAR
je check_up_valid
mov dword [esp + 4], 1 ;right is valid
check_up_valid:
mov eax, [mII_xpos]
mov ebx, [mII_ypos]
dec ebx ; try moving up
mov edx, [curwidth]
imul edx, ebx
add edx, eax
movzx ecx, BYTE [level]
dec ecx
mov ecx, [board_pointers + ecx*4]
lea esi, [ecx + edx]
cmp BYTE [esi], WALL_CHAR
je check_if_intersection
cmp BYTE [esi], GATE_CHAR
je check_if_intersection
mov dword [esp], 1 ; up is valid
; if 4 valid directions, then is intersection
check_if_intersection:
mov ecx, 0
add ecx, [esp + 12] ; add left
add ecx, [esp + 8] ; add down
add ecx, [esp + 4] ; add right
add ecx, [esp] ; add up
cmp ecx, 4 ; are 4 directions valid?
je at_intersection
;not at intersection
add esp, 16
jmp missusII_normal_priority
at_intersection:
add esp, 16 ; clean up stack
mov eax, [mII_xpos] ; check x-cordinate
cmp BYTE [level], 1 ; check x-cordinate
je use_startx
cmp BYTE [level], 2
je use_startiix
cmp BYTE [level], 3
je use_startiiix
; level 4 midline
cmp eax, STARTIVX
jl go_right_intersection ; if left of mid, go right
jmp go_left_intersection ; if right of mid, go left
; level 1 midline
use_startx:
cmp eax, STARTX
jl go_right_intersection
jmp go_left_intersection
; level 2 midling
use_startiix:
cmp eax, STARTIIX
jl go_right_intersection
jmp go_left_intersection
; level 3 midline
use_startiiix:
cmp eax, STARTIIIX
jl go_right_intersection
jmp go_left_intersection
go_left_intersection:
mov eax, [mII_xpos]
sub eax, 2 ; move left
mov [mII_xpos], eax
mov dword [missusII_last_move], 1 ; record last move
mov dword [missusII_right_streak],0 ; not on streak
jmp missusII_done
go_right_intersection:
mov eax, [mII_xpos]
add eax, 2 ; move right
mov [mII_xpos], eax
mov dword [missusII_last_move], 3 ; record last move
mov dword [missusII_right_streak], 1 ; not on streak
jmp missusII_done
; normal priority is try left, down, right, then up
; missusII doesnt try the opposite of her last move
missusII_normal_priority:
missusII_try_left:
cmp dword [missusII_last_move], 3 ; was last move right
je missusII_try_down ; prevent left if so
mov eax, [mII_xpos]
mov ebx, [mII_ypos]
sub eax, 2 ; try left
;validity check