-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.asm
executable file
·948 lines (713 loc) · 20 KB
/
game.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
; #########################################################################
;
; game.asm - Assembly file for EECS205 Assignment 5
; Mateusz Ryczek - mrr958
;
; #########################################################################
.586
.MODEL FLAT,STDCALL
.STACK 4096
option casemap :none
include stars.inc
include lines.inc
include trig.inc
include blit.inc
include game.inc
;; Keycodes
include keys.inc
;; Library Includes
include\masm32\include\windows.inc
include\masm32\include\winmm.inc
includelib\masm32\lib\winmm.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
.DATA
;; Debugging strings
collision_str BYTE "Collision Detected", 0
no_collision_str BYTE "No Collision Detected", 0
mouse_str BYTE "Mouse Pressed", 0
p1_fire_str BYTE "P1 fired!", 0
p2_fire_str BYTE "P2 fired!", 0
tank_pos_str BYTE "x: %d", 0
tank_pos_out BYTE 16 DUP (0)
;; Sounds
fire_snd BYTE "fire_01.wav", 0
;; Game info strings
paused_msg BYTE "Game Paused", 0
unpause_msg BYTE "Press tab to resume!", 0
p1_win_str BYTE "Game Over: P1 Won!!", 0
p2_win_str BYTE "Game Over: P2 Won!!", 0
restart_str BYTE "Press esc to restart.", 0
score_str BYTE "$%d", 0
score_out BYTE 32 DUP (0)
health_str BYTE "HP: %d", 0
health_out BYTE 16 DUP (0)
salvo_str BYTE "Salvos: %d", 0
salvo_out BYTE 8 DUP (0)
;; Game state vars
paused_state DWORD 0
tabloop_active DWORD 0
tabinit_active DWORD 0
MaxVelo DWORD 5
MaxVeloNeg DWORD -5
P1Wrench_active DWORD 0
P2Wrench_active DWORD 0
;; Sprite struct declarations
Player1 PLAYER< >
Player2 PLAYER< >
P1Shot BULLET< >
P2Shot BULLET< >
WALL1 OBJECT< >
WALL2 OBJECT< >
WALL3 OBJECT< >
HEALTHBOX BULLET< >
P1AIM ROTSPRT< >
P2AIM ROTSPRT< >
P1SALVO BULLET 5 DUP (< >)
P2SALVO BULLET 5 DUP (< >)
;; Collision helper vars
xCollide DWORD 0
yCollide DWORD 0
.CODE
;; Clear the screen (fill entire thing with dark blue)
ClearScreen PROC USES eax ebx
;; Find end of screen
LOCAL ScreenBitsEnd:DWORD
;; Set up loop for clearing
mov eax, ScreenBitsPtr
mov ebx, ScreenBitsPtr
add ebx, 307199
mov ScreenBitsEnd, ebx
clearLoop:
;; Write the color byte to the whole screen
mov (BYTE PTR [eax]), 001h
inc eax
;; 640 * 480 = 307,200 - 1 for zero index
;; Loop through entire screen array
cmp eax, ScreenBitsEnd
jl clearLoop
ret
ClearScreen ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Imaginary Motor 4® (Collision Detection)
CheckIntersect PROC USES ebx oneX:DWORD, oneY:DWORD, oneBitmap:PTR EECS205BITMAP, twoX:DWORD, twoY:DWORD, twoBitmap:PTR EECS205BITMAP
;; More comparisons than a 5th grader telling yo momma jokes
;;
;; return (((x.width / 2) + (y.width / 2)) < (abs (x1 - x2)) &&
;; ((x.height / 2) + (y.height / 2)) < (abs (y1 -y2)))
;;
;; Calculate half-width and half-height for faster computes
LOCAL oneHalfHeight:DWORD, oneHalfWidth:DWORD, twoHalfHeight:DWORD, twoHalfWidth:DWORD
;; Clear out collision vars from before
mov xCollide, 0
mov yCollide, 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Chop some widths and heights
mov ebx, oneBitmap
mov eax, (EECS205BITMAP PTR [ebx]).dwWidth
sar eax, 1
mov oneHalfWidth, eax
mov eax,(EECS205BITMAP PTR [ebx]).dwHeight
sar eax, 1
mov oneHalfHeight, eax
;; Next bitmap
mov ebx, twoBitmap
mov eax, (EECS205BITMAP PTR [ebx]).dwWidth
sar eax, 1
mov twoHalfWidth, eax
mov eax,(EECS205BITMAP PTR [ebx]).dwHeight
sar eax, 1
mov twoHalfHeight, eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Compute x-axis intersection
mov eax, oneHalfWidth
add eax, twoHalfWidth
mov ebx, twoX
sub ebx, oneX
cmp ebx, 0
jg eval_x_axis
;; fell through; compute abs(ebx)
neg ebx
eval_x_axis:
cmp eax, ebx
jl compute_y_axis
;; Fell through so there's potentially a collision on the x-axis.
;; Set the flag and check y-axis
mov xCollide, 1
compute_y_axis:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Compute y-axis intersection
mov eax, oneHalfHeight
add eax, twoHalfHeight
mov ebx, twoY
sub ebx, oneY
cmp ebx, 0
jg eval_y_axis
;; fell through; compute abs(ebx)
neg ebx
eval_y_axis:
cmp eax, ebx
jl compute_intersect
;; Fell through so there's potentially a collision on the y-axis.
;; Set the flag and cross check with x-axis
mov yCollide, 1
compute_intersect:
mov eax, xCollide
mov ebx, yCollide
and eax, ebx
;; From the AND, eax will have either a 1 if collision or 0 if none.
;; In either case, return it.
ret
CheckIntersect ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Like Unity Start() func, runs once at startup
GameInit PROC
;; Initialize P1 at (50,380)
mov Player1.bitmap, OFFSET P1TANK
mov eax, 100
shl eax, 16
mov Player1.posX, eax
mov eax, 380
shl eax, 16
mov Player1.posY, eax
;; P1 goes first
mov Player1.is_turn, 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Initialize P2 at (550, 380)
mov Player2.bitmap, OFFSET P2TANK
mov eax, 550
shl eax, 16
mov Player2.posX, eax
mov eax, 380
shl eax, 16
mov Player2.posY, eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Initialize P1 projectile at P1 start pos
mov P1Shot.bitmap, OFFSET SHOT_01
mov eax, 50
shl eax, 16
mov P1Shot.posX, eax
mov eax, 380
shl eax, 16
mov P1Shot.posY, eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Initialize P2 projectile at P2 start pos
mov P2Shot.bitmap, OFFSET SHOT_01
mov eax, 550
shl eax, 16
mov P2Shot.posX, eax
mov eax, 380
shl eax, 16
mov P2Shot.posY, eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Initialize 3 wall objects on top of each other, in the middle
mov WALL1.bitmap, OFFSET WALL
mov WALL2.bitmap, OFFSET WALL
mov WALL3.bitmap, OFFSET WALL
mov WALL1.is_active, 1
mov WALL2.is_active, 1
mov WALL3.is_active, 1
mov eax, 320
shl eax, 16
mov WALL1.posX, eax
mov WALL2.posX, eax
mov WALL3.posX, eax
mov eax, 384
shl eax, 16
mov WALL1.posY, eax
mov eax, 352
shl eax, 16
mov WALL2.posY, eax
mov eax, 320
shl eax, 16
mov WALL3.posY, eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Initialize aim arrows
mov P1AIM.bitmap, OFFSET ARROW
mov eax, 50
shl eax, 16
mov P1AIM.posX, eax
mov eax, 100
shl eax, 16
mov P1AIM.posY, eax
mov eax, 0
shl eax, 16
mov P1AIM.angle, eax
mov P1AIM.is_active, 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Initialize Health Powerup
mov HEALTHBOX.bitmap, OFFSET WRENCH
mov HEALTHBOX.dmg, -20
mov eax, 320
shl eax, 16
mov HEALTHBOX.posX, eax
mov eax, 100
shl eax, 16
mov HEALTHBOX.posY, eax
mov HEALTHBOX.is_active, 0
ret
GameInit ENDP
P1ShotPhysX PROC USES eax ebx ecx edx
mov eax, P1Shot.accY
sub P1Shot.velY, eax
;; Move the bullet
mov eax, P1Shot.velX
add P1Shot.posX, eax
mov eax, P1Shot.velY
sub P1Shot.posY, eax
;; Shift position and render bullet
mov ebx, P1Shot.posX
sar ebx, 16
mov ecx, P1Shot.posY
sar ecx, 16
cmp ebx, 0
jle p1_shot_dead
cmp ebx, 640
jge p1_shot_dead
cmp ecx, 400
jge p1_shot_dead
push ebx
push ecx
INVOKE BasicBlit, P1Shot.bitmap, ebx, ecx
pop ecx
pop ebx
;; Collision Detection
mov eax, Player2.posX
sar eax, 16
mov edx, Player2.posY
sar edx, 16
INVOKE CheckIntersect, ebx, ecx, P1Shot.bitmap, eax, edx, Player2.bitmap
cmp eax, 1
jne end_proj_1
add Player1.score, 100
sub Player2.health, 10
;; Shot dead
p1_shot_dead:
mov P1Shot.is_active, 0
mov Player1.reloaded, 1
end_proj_1:
ret
P1ShotPhysX ENDP
P2ShotPhysX PROC USES eax ebx ecx edx
mov eax, P2Shot.accY
sub P2Shot.velY, eax
;; Move the bullet
mov eax, P2Shot.velX
add P2Shot.posX, eax
mov eax, P2Shot.velY
sub P2Shot.posY, eax
;; Shift position and render bullet
mov ebx, P2Shot.posX
sar ebx, 16
mov ecx, P2Shot.posY
sar ecx, 16
cmp ebx, 0
jle p2_shot_dead
cmp ebx, 640
jge p2_shot_dead
cmp ecx, 400
jge p2_shot_dead
push ebx
push ecx
INVOKE BasicBlit, P2Shot.bitmap, ebx, ecx
pop ecx
pop ebx
;; Collision Detection
mov eax, Player1.posX
sar eax, 16
mov edx, Player1.posY
sar edx, 16
INVOKE CheckIntersect, ebx, ecx, P2Shot.bitmap, eax, edx, Player1.bitmap
cmp eax, 1
jne end_proj_2
add Player2.score, 100
sub Player1.health, 10
;; Shot dead
p2_shot_dead:
mov Player2.reloaded, 1
mov P2Shot.is_active, 0
end_proj_2:
ret
P2ShotPhysX ENDP
P1WrenchPhysX PROC USES eax ebx ecx edx
mov HEALTHBOX.is_active, 1
mov eax, HEALTHBOX.accY
sub HEALTHBOX.velY, eax
;; Move the box
mov eax, HEALTHBOX.velX
add HEALTHBOX.posX, eax
mov eax, HEALTHBOX.velY
sub HEALTHBOX.posY, eax
;; Shift position and render box
mov ebx, HEALTHBOX.posX
sar ebx, 16
mov ecx, HEALTHBOX.posY
sar ecx, 16
push ebx
push ecx
INVOKE BasicBlit, HEALTHBOX.bitmap, ebx, ecx
pop ecx
pop ebx
;; Collision Detection
mov eax, Player1.posX
sar eax, 16
mov edx, Player1.posY
sar edx, 16
INVOKE CheckIntersect, ebx, ecx, HEALTHBOX.bitmap, eax, edx, Player1.bitmap
cmp eax, 1
jne end_box_1
mov eax, HEALTHBOX.dmg
sub Player1.health, eax
mov HEALTHBOX.is_active, 0
mov P1Wrench_active, 0
mov HEALTHBOX.velY, 0
end_box_1:
ret
P1WrenchPhysX ENDP
P2WrenchPhysX PROC USES eax ebx ecx edx
mov HEALTHBOX.is_active, 1
mov eax, HEALTHBOX.accY
sub HEALTHBOX.velY, eax
;; Move the box
mov eax, HEALTHBOX.velX
add HEALTHBOX.posX, eax
mov eax, HEALTHBOX.velY
sub HEALTHBOX.posY, eax
;; Shift position and render box
mov ebx, HEALTHBOX.posX
sar ebx, 16
mov ecx, HEALTHBOX.posY
sar ecx, 16
push ebx
push ecx
INVOKE BasicBlit, HEALTHBOX.bitmap, ebx, ecx
pop ecx
pop ebx
;; Collision Detection
mov eax, Player2.posX
sar eax, 16
mov edx, Player2.posY
sar edx, 16
INVOKE CheckIntersect, ebx, ecx, HEALTHBOX.bitmap, eax, edx, Player2.bitmap
cmp eax, 1
jne end_box_2
mov eax, HEALTHBOX.dmg
sub Player2.health, eax
mov HEALTHBOX.is_active, 0
mov P2Wrench_active, 0
mov HEALTHBOX.velY, 0
end_box_2:
ret
P2WrenchPhysX ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The Game Loop
GamePlay PROC
;; Check player healths to see if anyone died
mov eax, Player1.health
cmp eax, 0
jg p2_check
INVOKE ClearScreen
INVOKE DrawPauseField
INVOKE DrawStr, OFFSET p2_win_str, 245, 220, 0ffh
INVOKE DrawStr, OFFSET restart_str, 240, 240, 0ffh
jmp FrameComplete
p2_check:
mov eax, Player2.health
cmp eax, 0
jg tab_checks
INVOKE ClearScreen
INVOKE DrawPauseField
INVOKE DrawStr, OFFSET p1_win_str, 245, 220, 0ffh
INVOKE DrawStr, OFFSET restart_str, 240, 240, 0ffh
jmp FrameComplete
tab_checks:
;; Game not paused, waiting for TAB to be released to pause
cmp tabinit_active, 1
je TABINIT
;; Game paused, waiting for TAB to be released to unpause
cmp tabloop_active, 1
je TABLOOP
;; Clear the screen on each runthrough to prevent artifacts
INVOKE ClearScreen
;; Check right away if game is paused. Only render pause screen if it is
cmp paused_state, 1
jne draw_game
;; The game is paused. Draw it and check TAB keypress
draw_paused:
INVOKE DrawPauseField
INVOKE DrawStr, OFFSET paused_msg, 280, 220, 0ffh
INVOKE DrawStr, OFFSET unpause_msg, 240, 240, 0ffh
;; Now check if TAB is currently being pressed
mov eax, KeyPress
cmp eax, VK_TAB
jne FrameComplete
mov tabinit_active, 1
;; TAB is being pressed, wait for it to be released
TABINIT:
cmp KeyPress, 0
jne FrameComplete
;; Fallthrough: TAB was released, reset pause state and ret
mov tabinit_active, 0
mov paused_state, 0
jmp FrameComplete
draw_game:
;; Draw the background
INVOKE DrawStarField
INVOKE DrawRect, 0, 400, 639, 479, 0ffh
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Draw walls if active
;; cmp WALL1.is_active, 1
;; jne wall2_render
;;
;; mov eax, WALL1.posX
;; sar eax, 16
;; mov ebx, WALL1.posY
;; sar ebx, 16
;; INVOKE BasicBlit, WALL1.bitmap, eax, ebx
;;
;; wall2_render:
;; cmp WALL2.is_active, 1
;; jne wall3_render
;;
;; mov eax, WALL2.posX
;; sar eax, 16
;; mov ebx, WALL2.posY
;; sar ebx, 16
;; INVOKE BasicBlit, WALL2.bitmap, eax, ebx
;;
;; wall3_render:
;; cmp WALL3.is_active, 1
;; jne no_wall
;;
;; mov eax, WALL3.posX
;; sar eax, 16
;; mov ebx, WALL3.posY
;; sar ebx, 16
;; INVOKE BasicBlit, WALL3.bitmap, eax, ebx
no_wall:
;; Draw the player health
INVOKE VarToStr, Player1.health, OFFSET health_str, OFFSET health_out, 5, 100
INVOKE VarToStr, Player2.health, OFFSET health_str, OFFSET health_out, 570, 100
;; Draw player scores
INVOKE VarToStr, Player1.score, OFFSET score_str, OFFSET score_out, 5, 110
INVOKE VarToStr, Player2.score, OFFSET score_str, OFFSET score_out, 570, 110
;; Draw player salvo counts
;; INVOKE VarToStr, P1Wrench_active, OFFSET salvo_str, OFFSET salvo_out, 5, 120
;; INVOKE VarToStr, P2Wrench_active, OFFSET salvo_str, OFFSET salvo_out, 550, 120
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Do a physics on Player1 and then draw it
mov eax, Player1.accX
add Player1.velX, eax
mov eax, Player1.accY
add Player1.velY, eax
;; Move the player
mov eax, Player1.velX
add Player1.posX, eax
mov eax, Player1.velY
add Player1.posY, eax
;; Shift positions from FXPT so that we can draw sprite
mov ebx, Player1.posX
sar ebx, 16
mov ecx, Player1.posY
sar ecx, 16
;; Draw Player1
INVOKE BasicBlit, Player1.bitmap, ebx, ecx
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Do a physics on Player2 and then draw it
mov eax, Player2.accX
add Player2.velX, eax
mov eax, Player2.accY
add Player2.velY, eax
;; Move the player
mov eax, Player2.velX
add Player2.posX, eax
mov eax, Player2.velY
add Player2.posY, eax
;; Shift positions from FXPT so that we can draw them
mov ebx, Player2.posX
sar ebx, 16
mov ecx, Player2.posY
sar ecx, 16
INVOKE BasicBlit, Player2.bitmap, ebx, ecx
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Render and do physX if projectiles active
cmp P1Shot.is_active, 1
jne render_proj2
INVOKE P1ShotPhysX
render_proj2:
cmp P2Shot.is_active, 1
jne skip_proj
INVOKE P2ShotPhysX
skip_proj:
;; Powerup render logic
cmp P1Wrench_active, 1
jne wrench_checks2
INVOKE P1WrenchPhysX
jmp FrameComplete
wrench_checks2:
cmp P2Wrench_active, 1
jne check_keys
INVOKE P2WrenchPhysX
jmp FrameComplete
check_keys:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check if D key was pressed. If yes move P1 right, else brake
mov eax, KeyPress
cmp eax, VK_D
jne DNotPressed
;; Set velocity
mov eax, MaxVelo
sal eax, 16
mov Player1.velX, eax
jmp FrameComplete
;; Stop moving if the key was not pressed
DNotPressed:
mov eax, 0
sal eax, 16
mov Player1.velX, eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check if A key was pressed. If yes move P1 left, else brake
mov eax, KeyPress
cmp eax, VK_A
jne ANotPressed
;; Set velocity
mov eax, MaxVeloNeg
shl eax, 16
mov Player1.velX, eax
jmp FrameComplete
;; Stop moving if the key was not pressed
ANotPressed:
mov eax, 0
sal eax, 16
mov Player1.velX, eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check if left arrow was pressed. If yes move P2 left, else brake
mov eax, KeyPress
cmp eax, VK_LEFT
jne LeftNotPressed
;; Set velocity
mov eax, MaxVeloNeg
shl eax, 16
mov Player2.velX, eax
jmp FrameComplete
;; Stop moving if the key was not pressed
LeftNotPressed:
mov eax, 0
sal eax, 16
mov Player2.velX, eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check if right arrow was pressed. If yes move P2 right, else brake
mov eax, KeyPress
cmp eax, VK_RIGHT
jne RightNotPressed
;; Set velocity
mov eax, MaxVelo
shl eax, 16
mov Player2.velX, eax
jmp FrameComplete
;; Stop moving if the key was not pressed
RightNotPressed:
mov eax, 0
sal eax, 16
mov Player2.velX, eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check if S was pressed. If yes give P1 powerup
mov eax, KeyPress
cmp eax, VK_S
jne SNotPressed
;; Do powerup stuff
cmp Player1.score, 500
jl DownNotPressed
sub Player1.score, 500
mov P1Wrench_active, 1
mov eax, Player1.posX
mov HEALTHBOX.posX, eax
mov eax, 100
shl eax, 16
mov HEALTHBOX.posY, eax
jmp FrameComplete
SNotPressed:
;; Continue
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check if down arrow was pressed. If yes give P2 powerup
mov eax, KeyPress
cmp eax, VK_DOWN
jne DownNotPressed
;; Do powerup stuff
cmp Player2.score, 500
jl DownNotPressed
sub Player2.score, 500
mov P2Wrench_active, 1
mov eax, Player2.posX
mov HEALTHBOX.posX, eax
mov eax, 100
shl eax, 16
mov HEALTHBOX.posY, eax
jmp FrameComplete
DownNotPressed:
;; Continue
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check if W was pressed. If yes fire P1 projectile.
mov eax, KeyPress
cmp eax, VK_W
jne next_fire
;; Do firing stuff
cmp Player1.reloaded, 1
jne next_fire
mov P1Shot.is_active, 1
mov Player1.reloaded, 0
mov eax, Player1.posY
sub eax, 0001B0000h ;; 20
mov P1Shot.posY, eax
mov eax, Player1.posX
mov P1Shot.posX, eax
mov eax, 10
shl eax, 16
mov P1Shot.velX, eax
mov eax, 10
shl eax, 16
mov P1Shot.velY, eax
INVOKE PlaySound, OFFSET fire_snd , 0, SND_FILENAME OR SND_ASYNC
next_fire:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check if UP was pressed. If yes fire P2 projectile.
mov eax, KeyPress
cmp eax, VK_UP
jne UpNotPressed
cmp Player2.reloaded, 1
jne UpNotPressed
mov P2Shot.is_active, 1
mov Player2.reloaded, 0
mov eax, Player2.posY
sub eax, 0001B0000h ;; 20
mov P2Shot.posY, eax
mov eax, Player2.posX
mov P2Shot.posX, eax
mov eax, -10
shl eax, 16
mov P2Shot.velX, eax
mov eax, 10
shl eax, 16
mov P2Shot.velY, eax
INVOKE PlaySound, OFFSET fire_snd , 0, SND_FILENAME OR SND_ASYNC
UpNotPressed:
;; Continue
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check if TAB was pressed. If yes , wait for it to be released, then
;; set the paused_state bool.
mov eax, KeyPress
cmp eax, VK_TAB
jne FrameComplete
mov tabloop_active, 1
;; TAB is currently down, wait until it is released.
TABLOOP:
cmp KeyPress, 0
jne FrameComplete
;; TAB was released, set state and RET
mov tabloop_active, 0
mov paused_state, 1
;; We've finished doing something somewhere else, ret
FrameComplete:
ret
GamePlay ENDP
END