-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.asm
More file actions
1443 lines (1254 loc) · 51.4 KB
/
temp.asm
File metadata and controls
1443 lines (1254 loc) · 51.4 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 file that stores the initial state
%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 '~' ;visually replaced in render, but used to distinguish in the stack
%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 starting position.
; 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 STARTIIX 28 ;level 2
%define STARTIIY 14 ;level 2
%define M_STARTIIX 28 ;level 2
%define M_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 STARTIVX 26 ;level 4
%define STARTIVY 15 ;level 4
%define M_STARTIVX 28 ;level 4
%define M_STARTIVY 11 ;level 4
; teleport to positions
%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 positions
%define WIN_X 24
%define WIN_Y 6
%define LOSE_X 22
%define LOSE_Y 14
; these keys do things
%define EXITCHAR 'x'
%define UPCHAR 'w'
%define LEFTCHAR 'a'
%define DOWNCHAR 's'
%define RIGHTCHAR 'd'
%define BOMBCHAR 'b'
; how many orbs to replace with bombs
%define NUM_BOMBS 3
; dot counts
%define DOTS 248
%define DOTSII 256
%define DOTSIII 300
%define DOTSIV 262
segment .data
; used to fopen() the board file 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
caught db 0
;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
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
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 / ", \
EXITCHAR,"=EXIT / ", \
BOMBCHAR,"=BOMB", \
13,10,10,0
; 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
losevar db 0
loading db 0
missus_first_move dd 1
;colors
blue_code db 27,"[38;2;33;33;222m",0
cyan_code db 27,"[38;2;0;255;255m",0
gray_code db 27,"[38;2;211;211;211m",0
yellow_code db 27,"[38;2;255;255;0m",0 ;player character
orange_code db 27,"[38;2;255;165;0m",0 ;safe player
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
light_blue_code db 27,"[38;5;74m",0 ;bombs
blue_background_code db 27,"[44m",0 ;water
reset_code db 27,"[0m",0
board_pointers:
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
m_ypos resd 1
curheight resd 1
curwidth resd 1
dots_req resd 1
dots_eaten resd 1
segment .text
global asm_main
global raw_mode_on
global raw_mode_off
global init_board
global render
global explode_space
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
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:
mov DWORD [m_xpos], M_STARTIVX
mov DWORD [m_ypos], M_STARTIVY
jmp end_lvlchk
start_pos:
mov DWORD [curheight], HEIGHT
mov DWORD [curwidth], WIDTH
call init_board
;check if win
cmp BYTE [winvar], 1
je win_step2
;check if loading screen
cmp BYTE [loading], 1
je loading_step2
;check if lose
cmp BYTE [losevar], 1
je lose_step2
mov DWORD [dots_req], DOTS
reset_positions:
mov DWORD [xpos], STARTX
mov DWORD [ypos], STARTY
;missus code
just_mpos:
mov DWORD [m_xpos], M_STARTX
mov DWORD [m_ypos], M_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:
mov DWORD [m_xpos], M_STARTIIX
mov DWORD [m_ypos], M_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:
mov DWORD [m_xpos], M_STARTIIIX
mov DWORD [m_ypos], M_STARTIIIY
jmp end_lvlchk
end_lvlchk:
cmp BYTE [caught], 1
jmp post_losechk
; 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 needs a refresh
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, 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
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
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
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
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
; extra points will need to modify to give ability to eat ghosts once we get there
after_orb:
cmp BYTE [eax], SPECIALORB_CHAR
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:
mov edx, [dots_eaten]
cmp edx, DWORD [dots_req]
jz screen_change
;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
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_move:
; compare Missus x to players x
mov eax, [m_xpos]
mov ebx, [m_ypos]
mov ecx, [xpos]
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
jmp missus_check_wall
missus_left:
sub eax, 2
jmp missus_check_wall
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
jmp missus_check_wall
missus_up:
dec ebx
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
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:
mov eax, [m_xpos]
mov ebx, [m_ypos]
; check player y ; defaults left or right based on midline
mov ecx, [ypos]
cmp ecx, 15
jg try_down
jl try_up
je mx_check
; horizontal midline to establish defaults
mx_check:
mov ecx, [xpos]
cmp ecx, 22
jg confused_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
mov [m_xpos], eax
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
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
jmp missus_done
try_up:
mov edx, ebx
dec edx
mov esi, [curwidth]
imul esi, edx
add esi, eax
;lea esi, [board + esi] ;was an issue, fixed
;check board level
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
jmp missus_done
try_down:
mov edx, ebx
inc edx
mov esi, [curwidth]
imul esi, edx
add esi, eax
;lea esi, [board + esi] ;ISSUE HERE
;check board level
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
jmp missus_done
;saves the valid move
missus_set_pos:
mov [m_xpos], eax
mov [m_ypos], ebx
jmp missus_done
missus_done:
; check if player loses
;cmp BYTE [eax], THE_MISSUS ;doesn't work, compare positions instead?
mov ebx, [xpos]
cmp ebx, [m_xpos]
jne post_losechk
mov ebx, [ypos]
cmp ebx, [m_ypos]
jne post_losechk
;check if points for catching missus
cmp DWORD [safeguard],0
jle past_ghost_points
mov ebx, [score]
add ebx, 200
mov [score], ebx
inc DWORD [lives]
past_ghost_points:
mov DWORD [missus_first_move], 1
dec DWORD [lives]
cmp DWORD [lives], 0
je lose
mov BYTE [caught], 1
;check level to reset positions
cmp BYTE [level], 1
je lose1
cmp BYTE [level], 2
je lose2
cmp BYTE [level], 3
je lose3
cmp BYTE [level], 4
je lose4
lose1:
cmp DWORD [safeguard],0
jle all_pos
jmp just_mpos
all_pos:
jmp reset_positions
lose2:
cmp DWORD [safeguard],0
jle all_pos2
jmp just_mpos2
all_pos2:
jmp reset_positions2
lose3:
cmp DWORD [safeguard],0
jle all_pos
jmp just_mpos3
all_pos3:
jmp reset_positions3
lose4:
cmp DWORD [safeguard],0
jle all_pos4
jmp just_mpos4
all_pos4:
jmp reset_positions4
post_losechk:
mov BYTE [caught], 0
jmp game_loop
screen_change:
cmp BYTE [level], 4
je win
mov BYTE [loading], 1 ;loading screen in between levels
jmp start_pos
loading_step2:
mov BYTE [loading], 0
mov DWORD [dots_eaten], 0
mov DWORD [missus_first_move], 1
mov DWORD [lives], 3
mov [bombs], DWORD 0
call render
;get c input to move on
waiting_loop: ;wait for signal to continue
call getchar
cmp eax, 120 ;in case player wants to quit
je game_loop_end
cmp eax, 99 ;ascii for c or C
je end_wait
cmp eax, 67
je end_wait
jmp waiting_loop
end_wait:
inc BYTE [level]
jmp initial_levelchk ;start new level
win:
mov BYTE [winvar], 1
jmp start_pos ;need board to be size 1
;mov player char position here
win_step2:
mov DWORD [xpos], WIN_X
mov DWORD [ypos], WIN_Y
call render ;print out the new file
jmp game_loop_end
lose:
mov BYTE [losevar], 1
jmp start_pos
lose_step2:
mov DWORD [xpos], LOSE_X
mov DWORD [ypos], LOSE_Y
call render
game_loop_end:
; restore old terminal functionality
call raw_mode_off
mov eax, 0
mov esp, ebp
pop ebp
ret
raw_mode_on:
push ebp
mov ebp, esp
push raw_mode_on_cmd
call system
add esp, 4
mov esp, ebp
pop ebp
ret
raw_mode_off:
push ebp
mov ebp, esp
push raw_mode_off_cmd
call system
add esp, 4
mov esp, ebp
pop ebp
ret
init_board:
push ebp
mov ebp, esp
; FILE* and loop counter
; ebp-4, ebp-8
sub esp, 8
; open the file
push mode_r
;check the board/screen
cmp BYTE [winvar], 1
je initwin
cmp BYTE [losevar], 1
je initlose
cmp BYTE [loading], 1
je initloading
cmp BYTE [level], 1
je initb1
cmp BYTE [level], 2
je initb2
cmp BYTE [level], 3
je initb3
cmp BYTE [level], 4
je initb4
initwin:
push win_file
jmp end_filechk
initlose:
push lose_file
jmp end_filechk
initloading:
push loading_file
jmp end_filechk
initb1:
push board_file
jmp end_filechk
initb2:
push level2_file
jmp end_filechk
initb3:
push level3_file
jmp end_filechk
initb4:
push level4_file
end_filechk:
call fopen
add esp, 8
mov DWORD [ebp - 4], eax
; read the file data into the global buffer
; line-by-line so we can ignore the newline characters
mov DWORD [ebp - 8], 0
read_loop:
xor edx, edx
mov edx, [curheight]
cmp DWORD [ebp - 8], edx
je read_loop_end
; find the offset (WIDTH * counter)
mov eax, [curwidth]
mul DWORD [ebp - 8]
;check board level
movzx ecx, BYTE [level]
dec ecx
mov ecx, [board_pointers + ecx*4]
lea ebx, [ecx + eax]
; read the bytes into the buffer
push DWORD [ebp - 4]
;use a register instead of a level check
xor edx, edx
mov edx, [curwidth]
push edx
push 1
push ebx
call fread
add esp, 16
; slurp up the newline
push DWORD [ebp - 4]
call fgetc
add esp, 4
inc DWORD [ebp - 8]
jmp read_loop
read_loop_end:
; close the open file handle
push DWORD [ebp - 4]
call fclose
add esp, 4
cmp BYTE [winvar], 1
je skip_otb
cmp BYTE [loading], 1
je skip_otb
cmp BYTE [losevar], 1
je skip_otb
; replace orbs with bombs
mov ecx, 0 ;ecx is the loop counter
orb_to_bomb:
push ecx ;store ecx
;get random x
call random_num
cdq
mov ebx, [curwidth]
idiv ebx ;remainder stored in edx
mov [bomb_x], edx ;temporarily storing the remainder in bomb_x
;get random y
call random_num
cdq
mov ebx, [curheight]
idiv ebx ;remainder stored in edx
mov eax, [curwidth]
mul edx
add eax, [bomb_x]
;lea eax, [board + eax] ;will cause an error
;check board level