-
Notifications
You must be signed in to change notification settings - Fork 0
/
shooter.asm
1350 lines (1067 loc) · 43 KB
/
shooter.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
; http://win32assembly.programminghorizon.com/tut25.html
; http://win32assembly.programminghorizon.com/tut3.html
.386
.model flat,stdcall
option casemap:none
include shooter.inc
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
.DATA
ClassName db "ShooterWindowClass",0 ; nome da classe de janela
AppName db "ATARI SHOOTER",0
.DATA?
hInstance HINSTANCE ? ; Instance handle do programa
CommandLine LPSTR ?
.CODE ; Here begins our code
start:
; invoke LoadLibrary,addr Libname ; splash screen reasons
; .if eax!=NULL
; invoke FreeLibrary,eax
; .endif
invoke GetModuleHandle, NULL ; get the instance handle of our program.
; Under Win32, hmodule==hinstance mov hInstance,eax
mov hInstance,eax
invoke GetCommandLine ; get the command line. You don't have to call this function IF
; your program doesn't process the command line.
mov CommandLine,eax
invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT ; call the main function
invoke ExitProcess, eax ; quit our program. The exit code is returned in eax from WinMain.
; _ PROCEDURES ___________________________________________________________________________
loadImages proc
;Loading background bitmap
invoke LoadBitmap, hInstance, 169
mov h_background, eax
invoke LoadBitmap, hInstance, 170
mov h_enterprise, eax
invoke LoadBitmap, hInstance, 171
mov h_menu, eax
;Loading Arrow 1's Bitmaps:
invoke LoadBitmap, hInstance, 100
mov A1_top_left, eax
invoke LoadBitmap, hInstance, 101
mov A1_top, eax
invoke LoadBitmap, hInstance, 102
mov A1_top_right, eax
invoke LoadBitmap, hInstance, 103
mov A1_right, eax
invoke LoadBitmap, hInstance, 104
mov A1_down_right, eax
invoke LoadBitmap, hInstance, 105
mov A1_down, eax
invoke LoadBitmap, hInstance, 106
mov A1_down_left, eax
invoke LoadBitmap, hInstance, 107
mov A1_left, eax
invoke LoadBitmap, hInstance, 108
mov A1_ground, eax
;Loading Arrow 2's Bitmaps:
invoke LoadBitmap, hInstance, 109
mov A2_top_left, eax
invoke LoadBitmap, hInstance, 110
mov A2_top, eax
invoke LoadBitmap, hInstance, 111
mov A2_top_right, eax
invoke LoadBitmap, hInstance, 112
mov A2_right, eax
invoke LoadBitmap, hInstance, 113
mov A2_down_right, eax
invoke LoadBitmap, hInstance, 114
mov A2_down, eax
invoke LoadBitmap, hInstance, 115
mov A2_down_left, eax
invoke LoadBitmap, hInstance, 116
mov A2_left, eax
invoke LoadBitmap, hInstance, 124
mov A2_ground, eax
;Loading Player's Bitmaps:
invoke LoadBitmap, hInstance, 130
mov p2_spritesheet, eax
invoke LoadBitmap, hInstance, 134
mov p1_spritesheet, eax
;Loading winner's Bitmaps:
invoke LoadBitmap, hInstance, 300
mov p1_won, eax
invoke LoadBitmap, hInstance, 301
mov p2_won, eax
;Loading Heart Bitmaps:
invoke LoadBitmap, hInstance, 200
mov HT_heart1, eax
invoke LoadBitmap, hInstance, 201
mov HT_heart2, eax
ret
loadImages endp
;______________________________________________________________________________
isColliding proc obj1Pos:point, obj2Pos:point, obj1Size:point, obj2Size:point
;.if obj1Pos.x < obj2Pos.x + obj2Size.x && \
; obj1Pos.x + obj1Size.x > obj2Pos.x && \
; obj1Pos.y < obj2Pos.y + obj2Size.y && \
; obj1Pos.y + obj1Size.y > obj2Pos.y
; mov eax, TRUE
;.else
; mov eax, FALSE
;.endif
push eax
push ebx
mov eax, obj1Pos.x
add eax, obj1Size.x ; eax = obj1Pos.x + obj1Size.x
mov ebx, obj2Pos.x
add ebx, obj2Size.x ; ebx = obj2Pos.x + obj2Size.x
.if obj1Pos.x < ebx && eax > obj2Pos.x
mov eax, obj1Pos.y
add eax, obj1Size.y ; eax = obj1Pos.y + obj1Size.y
mov ebx, obj2Pos.y
add ebx, obj2Size.y ; ebx = obj2Pos.y + obj2Size.y
.if obj1Pos.y < ebx && eax > obj2Pos.y
; the objects are colliding
mov edx, TRUE
.else
mov edx, FALSE
.endif
.else
mov edx, FALSE
.endif
pop ebx
pop eax
ret
isColliding endp
;______________________________________________________________________________
isStopped proc addrPlayer:dword
assume edx:ptr player
mov edx, addrPlayer
.if [edx].playerObj.speed.x == 0 && [edx].playerObj.speed.y == 0
mov [edx].stopped, 1
.endif
ret
isStopped endp
;______________________________________________________________________________
;______________________________________________________________________________
paintBackground proc _hdc:HDC, _hMemDC:HDC, _hMemDC2:HDC
.if GAMESTATE == 0
invoke SelectObject, _hMemDC2, h_enterprise
invoke BitBlt, _hMemDC, 0, 0, 1200, 800, _hMemDC2, 0, 0, SRCCOPY
.endif
.if GAMESTATE == 1
invoke SelectObject, _hMemDC2, h_menu
invoke BitBlt, _hMemDC, 0, 0, 1200, 800, _hMemDC2, 0, 0, SRCCOPY
.endif
.if GAMESTATE == 2
invoke SelectObject, _hMemDC2, h_background
invoke BitBlt, _hMemDC, 0, 0, 1200, 800, _hMemDC2, 0, 0, SRCCOPY
.endif
.if GAMESTATE == 3 ; player 1 won
invoke SelectObject, _hMemDC2, p1_won
invoke BitBlt, _hMemDC, 0, 0, 1200, 800, _hMemDC2, 0, 0, SRCCOPY
.endif
.if GAMESTATE == 4 ; player 2 won
invoke SelectObject, _hMemDC2, p2_won
invoke BitBlt, _hMemDC, 0, 0, 1200, 800, _hMemDC2, 0, 0, SRCCOPY
.endif
ret
paintBackground endp
;______________________________________________________________________________
paintHearts proc _hdc:HDC, _hMemDC:HDC, _hMemDC2:HDC
; PLAYER 1
invoke SelectObject, _hMemDC2, HT_heart1
mov ebx, 0
movzx ecx, player1.life
.while ebx != ecx
mov eax, HEART_SIZE
mul ebx
push ecx
invoke TransparentBlt, _hMemDC, eax, 0,\
HEART_SIZE, HEART_SIZE, _hMemDC2,\
0, 0, HEART_SIZE, HEART_SIZE, 16777215
;invoke BitBlt, _hdc, eax, 0, HEART_SIZE, HEART_SIZE, _hMemDC, 0, 0, SRCCOPY
pop ecx
inc ebx
.endw
; PLAYER 2
invoke SelectObject, _hMemDC2, HT_heart2
mov ebx, 1
movzx ecx, player2.life
inc ecx
.while ebx != ecx
mov eax, HEART_SIZE
mul ebx
push ecx
mov edx, WINDOW_SIZE_X
sub edx, eax
invoke TransparentBlt, _hMemDC, edx, 0,\
HEART_SIZE, HEART_SIZE, _hMemDC2,\
0, 0, HEART_SIZE, HEART_SIZE, 16777215
pop ecx
inc ebx
.endw
ret
paintHearts endp
;______________________________________________________________________________
paintPlayers proc _hdc:HDC, _hMemDC:HDC, _hMemDC2:HDC
;PLAYER 1___________________________________________
invoke SelectObject, _hMemDC2, p1_spritesheet
movsx eax, player1.direction
mov ebx, PLAYER_SIZE
mul ebx
mov ecx, eax
invoke isStopped, addr player1
.if player1.stopped == 1
mov edx, 0
.elseif player1.dashsequence == 0
movsx eax, player1.walksequence
mov ebx, PLAYER_SIZE ; se for mudar hitbox, essa e a largura
mul ebx
mov edx, eax
.else
movsx eax, player1.dashsequence
mov ebx, PLAYER_SIZE ; se for mudar hitbox, essa e a largura
mul ebx
mov edx, eax
.endif
;________PLAYER 1 PAINTING________________________________________________________________________
mov eax, player1.playerObj.pos.x
mov ebx, player1.playerObj.pos.y
sub eax, PLAYER_HALF_SIZE
sub ebx, PLAYER_HALF_SIZE
;invoke BitBlt, _hdc, eax, ebx, PLAYER_SIZE, PLAYER_SIZE, _hMemDC, edx, ecx, SRCCOPY
invoke TransparentBlt, _hMemDC, eax, ebx,\
PLAYER_SIZE, PLAYER_SIZE, _hMemDC2,\
edx, ecx, PLAYER_SIZE, PLAYER_SIZE, 16777215
;________________________________________________________________________________
;PLAYER 2___________________________________________
invoke SelectObject, _hMemDC2, p2_spritesheet
movsx eax, player2.direction
mov ebx, PLAYER_SIZE
mul ebx
mov ecx, eax
invoke isStopped, addr player2
.if player2.stopped == 1
mov edx, 0
.elseif player2.dashsequence == 0
movsx eax, player2.walksequence
mov ebx, PLAYER_SIZE ; se for mudar hitbox, essa e a largura
mul ebx
mov edx, eax
.else
movsx eax, player2.dashsequence
mov ebx, PLAYER_SIZE ; se for mudar hitbox, essa e a largura
mul ebx
mov edx, eax
.endif
;________PLAYER 2 PAINTING________________________________________________________________________
mov eax, player2.playerObj.pos.x
mov ebx, player2.playerObj.pos.y
sub eax, PLAYER_HALF_SIZE
sub ebx, PLAYER_HALF_SIZE
;invoke BitBlt, _hdc, eax, ebx, PLAYER_SIZE, PLAYER_SIZE, _hMemDC, edx, ecx, SRCCOPY
invoke TransparentBlt, _hMemDC, eax, ebx,\
PLAYER_SIZE, PLAYER_SIZE, _hMemDC2,\
edx, ecx, PLAYER_SIZE, PLAYER_SIZE, 16777215
;________________________________________________________________________________
ret
paintPlayers endp
;________________________________________________________________________________
paintArrows proc _hdc:HDC, _hMemDC:HDC, _hMemDC2
;________PLAYER 1 PAINTING_____________________________________________________________
.if arrow1.onGround == 1
;invoke wsprintf, ADDR buffer, ADDR test_header_format, 0
;invoke MessageBox, NULL, ADDR buffer, ADDR msgBoxTitle, MB_OKCANCEL
invoke SelectObject, _hMemDC2, A1_ground
;invoke SelectObject, _hMemDC, A1_left
.else
.if arrow1.direction == D_TOP_LEFT
invoke SelectObject, _hMemDC2, A1_top_left
.elseif arrow1.direction == D_TOP
invoke SelectObject, _hMemDC2, A1_top
.elseif arrow1.direction == D_TOP_RIGHT
invoke SelectObject, _hMemDC2, A1_top_right
.elseif arrow1.direction == D_RIGHT
invoke SelectObject, _hMemDC2, A1_right
.elseif arrow1.direction == D_DOWN_RIGHT
invoke SelectObject, _hMemDC2, A1_down_right
.elseif arrow1.direction == D_DOWN
invoke SelectObject, _hMemDC2, A1_down
.elseif arrow1.direction == D_DOWN_LEFT
invoke SelectObject, _hMemDC2, A1_down_left
.elseif arrow1.direction == D_LEFT ;left is the last possible direction
invoke SelectObject, _hMemDC2, A1_left
.endif
.endif
mov eax, arrow1.arrowObj.pos.x
mov ebx, arrow1.arrowObj.pos.y
sub eax, ARROW_HALF_SIZE_P.x
sub ebx, ARROW_HALF_SIZE_P.y
invoke TransparentBlt, _hMemDC, eax, ebx,\
ARROW_SIZE_POINT.x, ARROW_SIZE_POINT.y, _hMemDC2,\
0, 0, ARROW_SIZE_POINT.x, ARROW_SIZE_POINT.y, 16777215
;invoke BitBlt, _hdc, eax, ebx, ARROW_SIZE_POINT.x, ARROW_SIZE_POINT.y, _hMemDC, 0, 0, SRCCOPY
;________PLAYER 2 PAINTING_____________________________________________________________
.if arrow2.onGround == 1
invoke SelectObject, _hMemDC2, A2_ground
.else
.if arrow2.direction == D_TOP_LEFT
invoke SelectObject, _hMemDC2, A2_top_left
.elseif arrow2.direction == D_TOP
invoke SelectObject, _hMemDC2, A2_top
.elseif arrow2.direction == D_TOP_RIGHT
invoke SelectObject, _hMemDC2, A2_top_right
.elseif arrow2.direction == D_RIGHT
invoke SelectObject, _hMemDC2, A2_right
.elseif arrow2.direction == D_DOWN_RIGHT
invoke SelectObject, _hMemDC2, A2_down_right
.elseif arrow2.direction == D_DOWN
invoke SelectObject, _hMemDC2, A2_down
.elseif arrow2.direction == D_DOWN_LEFT
invoke SelectObject, _hMemDC2, A2_down_left
.elseif arrow2.direction == D_LEFT ;left is the last possible direction
invoke SelectObject, _hMemDC2, A2_left
.endif
.endif
mov eax, arrow2.arrowObj.pos.x
mov ebx, arrow2.arrowObj.pos.y
sub eax, ARROW_HALF_SIZE_P.x
sub ebx, ARROW_HALF_SIZE_P.y
invoke TransparentBlt, _hMemDC, eax, ebx,\
ARROW_SIZE_POINT.x, ARROW_SIZE_POINT.y, _hMemDC2,\
0, 0, ARROW_SIZE_POINT.x, ARROW_SIZE_POINT.y, 16777215
;invoke BitBlt, _hdc, eax, ebx, ARROW_SIZE_POINT.x, ARROW_SIZE_POINT.y, _hMemDC, 0, 0, SRCCOPY
ret
paintArrows endp
;________________________________________________________________________________
updateScreen proc
LOCAL hMemDC:HDC
LOCAL hMemDC2:HDC
LOCAL hBitmap:HDC
LOCAL hDC:HDC
invoke BeginPaint, hWnd, ADDR paintstruct
mov hDC, eax
invoke CreateCompatibleDC, hDC
mov hMemDC, eax
invoke CreateCompatibleDC, hDC ; for double buffering
mov hMemDC2, eax
invoke CreateCompatibleBitmap, hDC, WINDOW_SIZE_X, WINDOW_SIZE_Y
mov hBitmap, eax
invoke SelectObject, hMemDC, hBitmap
;invoke wsprintf, ADDR buffer, ADDR test_header_format, h_V1_top_left
;invoke MessageBox, NULL, ADDR buffer, ADDR msgBoxTitle, MB_OKCANCEL
;invoke SelectObject, hMemDC, h_V1_top_left
;invoke TransparentBlt, hDC, 0, 0,\
; 50, 50, hMemDC,\
; 0, 0, 50, 50, 16777215
;if gamestate == 0
; invoke paintSplashScreen
;elseif gamestate == 1
invoke paintBackground, hDC, hMemDC, hMemDC2
.if GAMESTATE == 2
invoke paintPlayers, hDC, hMemDC, hMemDC2
invoke paintArrows, hDC, hMemDC, hMemDC2
invoke paintHearts, hDC, hMemDC, hMemDC2
.endif
invoke BitBlt, hDC, 0, 0, WINDOW_SIZE_X, WINDOW_SIZE_Y, hMemDC, 0, 0, SRCCOPY
invoke DeleteDC, hMemDC
invoke DeleteDC, hMemDC2
invoke DeleteObject, hBitmap
invoke EndPaint, hWnd, ADDR paintstruct
;endif
ret
updateScreen endp
;______________________________________________________________________________
paintThread proc p:DWORD
.while !over
invoke Sleep, 17 ; 60 FPS
;invoke updateScreen
invoke InvalidateRect, hWnd, NULL, FALSE
.endw
ret
paintThread endp
;______________________________________________________________________________
movePlayer proc uses eax addrPlayer:dword ; updates a gameObject position based on its speed
assume ecx:ptr gameObject
mov ecx, addrPlayer
; X AXIS ______________
mov eax, [ecx].pos.x
mov ebx, [ecx].speed.x
.if bx > 7fh
or bx, 65280 ; if negative
.endif
add eax, ebx
mov [ecx].pos.x, eax
; Y AXIS ______________
mov eax, [ecx].pos.y
mov ebx, [ecx].speed.y
.if bx > 7fh
or bx, 65280 ; if negative
.endif
add ax, bx
mov [ecx].pos.y, eax
assume ecx:nothing
ret
movePlayer endp
;______________________________________________________________________________
dashPlayer proc addrPlayer:dword
assume eax:ptr player
mov eax, addrPlayer
mov edx, DASH_DISTANCE
mov [eax].stopped, 0
mov [eax].dashsequence, 6
.if [eax].direction == D_TOP_LEFT
mov [eax].playerObj.speed.x, -DASH_SPEED
mov [eax].playerObj.speed.y, -DASH_SPEED
.elseif [eax].direction == D_TOP
mov [eax].playerObj.speed.y, -DASH_SPEED
.elseif [eax].direction == D_TOP_RIGHT
mov [eax].playerObj.speed.x, DASH_SPEED
mov [eax].playerObj.speed.y, -DASH_SPEED
.elseif [eax].direction == D_RIGHT
mov [eax].playerObj.speed.x, DASH_SPEED
.elseif [eax].direction == D_DOWN_RIGHT
mov [eax].playerObj.speed.x, DASH_SPEED
mov [eax].playerObj.speed.y, DASH_SPEED
.elseif [eax].direction == D_DOWN
mov [eax].playerObj.speed.y, DASH_SPEED
.elseif [eax].direction == D_DOWN_LEFT
mov [eax].playerObj.speed.x, -DASH_SPEED
mov [eax].playerObj.speed.y, DASH_SPEED
.elseif [eax].direction == D_LEFT
mov [eax].playerObj.speed.x, -DASH_SPEED
.endif
mov [eax].cooldownDash, 0
ret
dashPlayer endp
;______________________________________________________________________________
updateDirection proc addrPlayer:dword ; updates direction based on players axis's speed
assume eax:ptr player
mov eax, addrPlayer
mov ebx, [eax].playerObj.speed.x ; player's x axis
mov edx, [eax].playerObj.speed.y ; player's y axis
.if ebx != 0 || edx != 0
.if ebx == 0 ; if x axis = 0 then:
.if edx > 7fh ; if y axis < 0
mov [eax].direction, D_TOP
.else ; y axis > 0
mov [eax].direction, D_DOWN
.endif
.elseif ebx > 7fh ; if x axis > 0
.if edx == 0 ; if y axis = 0
mov [eax].direction, D_LEFT
.elseif edx > 7fh ; if y axis > 0
mov [eax].direction, D_TOP_LEFT
.else
mov [eax].direction, D_DOWN_LEFT ; if y axis < 0
.endif
.else ; if x axis < 0
.if edx == 0 ; if y axis = 0
mov [eax].direction, D_RIGHT
.elseif edx > 7fh ; if y axis > 0
mov [eax].direction, D_TOP_RIGHT
.else ; y axis < 0
mov [eax].direction, D_DOWN_RIGHT
.endif
.endif
.endif
ret
updateDirection endp
;______________________________________________________________________________
moveArrow proc uses eax addrArrow:dword ; updates a gameObject position based on its speed
assume eax:ptr arrow
mov eax, addrArrow
mov ebx, [eax].arrowObj.speed.x
mov ecx, [eax].arrowObj.speed.y
mov [eax].onGround, 0
.if [eax].remainingDistance > 0
.if [eax].direction == D_TOP_LEFT
add [eax].arrowObj.pos.x, -ARROW_SPEED
add [eax].arrowObj.pos.y, -ARROW_SPEED
sub [eax].remainingDistance, ARROW_SPEED
.elseif [eax].direction == D_TOP
add [eax].arrowObj.pos.y, -ARROW_SPEED
sub [eax].remainingDistance, ARROW_SPEED
.elseif [eax].direction == D_TOP_RIGHT
add [eax].arrowObj.pos.x, ARROW_SPEED
add [eax].arrowObj.pos.y, -ARROW_SPEED
sub [eax].remainingDistance, ARROW_SPEED
.elseif [eax].direction == D_RIGHT
add [eax].arrowObj.pos.x, ARROW_SPEED
sub [eax].remainingDistance, ARROW_SPEED
.elseif [eax].direction == D_DOWN_RIGHT
add [eax].arrowObj.pos.x, ARROW_SPEED
add [eax].arrowObj.pos.y, ARROW_SPEED
sub [eax].remainingDistance, ARROW_SPEED
.elseif [eax].direction == D_DOWN
add [eax].arrowObj.pos.y, ARROW_SPEED
sub [eax].remainingDistance, ARROW_SPEED
.elseif [eax].direction == D_DOWN_LEFT
add [eax].arrowObj.pos.x, -ARROW_SPEED
add [eax].arrowObj.pos.y, ARROW_SPEED
sub [eax].remainingDistance, ARROW_SPEED
.elseif [eax].direction == D_LEFT
add [eax].arrowObj.pos.x, -ARROW_SPEED
sub [eax].remainingDistance, ARROW_SPEED
.endif
.else
mov [eax].onGround, 1
.endif
assume eax:nothing
ret
moveArrow endp
;______________________________________________________________________________
fixCoordinates proc addrPlayer:dword
assume eax:ptr player
mov eax, addrPlayer
.if [eax].playerObj.pos.x > WINDOW_SIZE_X && [eax].playerObj.pos.x < 80000000h
mov [eax].playerObj.pos.x, 20 ;sorry
.endif
.if [eax].playerObj.pos.x <= 10 || [eax].playerObj.pos.x > 80000000h
mov [eax].playerObj.pos.x, WINDOW_SIZE_X - 20
.endif
.if [eax].playerObj.pos.y > WINDOW_SIZE_Y - 70 && [eax].playerObj.pos.y < 80000000h
mov [eax].playerObj.pos.y, 20
.endif
.if [eax].playerObj.pos.y <= 10 || [eax].playerObj.pos.y > 80000000h
mov [eax].playerObj.pos.y, WINDOW_SIZE_Y - 80
.endif
ret
fixCoordinates endp
;______________________________________________________________________________
fixArrowCoordinates proc addrArrow:dword
assume eax:ptr arrow
mov eax, addrArrow
.if [eax].onGround == 0
.if [eax].arrowObj.pos.x > WINDOW_SIZE_X && [eax].arrowObj.pos.x < 80000000h
mov [eax].arrowObj.pos.x, 20
.endif
.if [eax].arrowObj.pos.x <= 10 || [eax].arrowObj.pos.x > 80000000h
mov [eax].arrowObj.pos.x, 1180
.endif
.if [eax].arrowObj.pos.y > WINDOW_SIZE_Y - 80 && [eax].arrowObj.pos.y < 80000000h
mov [eax].arrowObj.pos.y, 20
.endif
.if [eax].arrowObj.pos.y <= 10 || [eax].arrowObj.pos.y > 80000000h
mov [eax].arrowObj.pos.y, WINDOW_SIZE_Y - 90
.endif
.endif
ret
fixArrowCoordinates endp
;______________________________________________________________________________
gameOver proc
mov player1.playerObj.pos.x, 100
mov player1.playerObj.pos.y, 350
mov player2.playerObj.pos.x, 1120
mov player2.playerObj.pos.y, 350
mov player1.playerObj.speed.x, 0
mov player1.playerObj.speed.y, 0
mov player2.playerObj.speed.x, 0
mov player2.playerObj.speed.y, 0
mov player1.stopped, 1
mov player2.stopped, 1
mov player1.life, 4
mov player2.life, 4
mov player1.direction, D_RIGHT
mov player2.direction, D_LEFT
mov player1.walkanimationCD, 0
mov player2.walkanimationCD, 0
mov player1.walksequence, 0
mov player2.walksequence, 0
mov player1.dashanimationCD, 0
mov player2.dashanimationCD, 0
mov player1.dashsequence, 0
mov player2.dashsequence, 0
mov arrow1.onGround, 1
mov arrow1.remainingDistance, 0
mov arrow1.arrowObj.speed.x, 0
mov arrow1.arrowObj.speed.y, 0
mov arrow1.arrowObj.pos.x, -100
mov arrow1.arrowObj.pos.y, -100
mov arrow1.playerOwns, 1
mov arrow2.onGround, 1
mov arrow2.remainingDistance, 0
mov arrow2.arrowObj.speed.x, 0
mov arrow2.arrowObj.speed.y, 0
mov arrow2.arrowObj.pos.x, -100
mov arrow2.arrowObj.pos.y, -100
mov arrow2.playerOwns, 1
ret
gameOver endp
;______________________________________________________________________________
gameManager proc p:dword
LOCAL area:RECT
.if GAMESTATE == 0
invoke Sleep, 3000
inc GAMESTATE
.endif
.while GAMESTATE == 1
invoke Sleep, 30
.endw
game:
.while GAMESTATE == 2
invoke Sleep, 30
;invoke isColliding, player1.playerObj.pos, player2.playerObj.pos, PLAYER_SIZE_POS_S, PLAYER_SIZE_POS_S
;.if edx == TRUE
; invoke wsprintf, ADDR buffer, ADDR test_header_format, edx
; invoke MessageBox, NULL, ADDR buffer, ADDR msgBoxTitle, MB_OKCANCEL
;.endif
invoke isColliding, player2.playerObj.pos, arrow1.arrowObj.pos, PLAYER_SIZE_POINT, ARROW_SIZE_POINT
.if edx == TRUE
mov player2.playerObj.pos.x, 1120
mov player2.playerObj.pos.y, 350
dec player2.life
.if player2.life == 0
invoke gameOver
mov GAMESTATE, 3 ; player 1 won
.continue
.endif
.endif
invoke isColliding, player1.playerObj.pos, arrow1.arrowObj.pos, PLAYER_SIZE_POINT, ARROW_SIZE_POINT
.if edx == TRUE
.if arrow1.onGround == 1
;mov arrow1.onGround, 0 ; pick up arrow from the ground
mov arrow1.arrowObj.pos.x, -100
mov arrow1.arrowObj.pos.y, -100
mov arrow1.playerOwns, 1
.endif
.endif
invoke isColliding, player1.playerObj.pos, arrow2.arrowObj.pos, PLAYER_SIZE_POINT, ARROW_SIZE_POINT
.if edx == TRUE
mov player1.playerObj.pos.x, 100
mov player1.playerObj.pos.y, 350
dec player1.life
.if player1.life == 0
invoke gameOver
mov GAMESTATE, 4 ; player 2 won
.continue
.endif
.endif
invoke isColliding, player2.playerObj.pos, arrow2.arrowObj.pos, PLAYER_SIZE_POINT, ARROW_SIZE_POINT
.if edx == TRUE
.if arrow2.onGround == 1
;mov arrow1.onGround, 0 ; pick up arrow from the ground
mov arrow2.arrowObj.pos.x, -100
mov arrow2.arrowObj.pos.y, -100
mov arrow2.playerOwns, 1
.endif
.endif
.if player2.cooldownDash != 30
inc player2.cooldownDash
.else
mov player2CanDash, 1
.endif
.if player1.cooldownDash != 30
inc player1.cooldownDash
.else
mov player1CanDash, 1
.endif
.if player2DashClick == 1
invoke dashPlayer, addr player2
mov player2DashClick, 0
mov player2CanDash, 0
.endif
.if player1DashClick == 1
invoke dashPlayer, addr player1
mov player1DashClick, 0
mov player1CanDash, 0
.endif
.if arrow1.remainingDistance > 0
invoke moveArrow, addr arrow1
.else
mov arrow1.onGround, 1
.endif
.if arrow2.remainingDistance > 0
invoke moveArrow, addr arrow2
.else
mov arrow2.onGround, 1
.endif
; ----- PLAYER 1 WALKING SEQUENCE ------
.if player1.dashsequence == 0
; the player is walking
.if player1.walkanimationCD != 2
inc player1.walkanimationCD
.else
inc player1.walksequence
.if player1.walksequence == 6
; walking animation over
mov player1.walksequence, 0
.endif
mov player1.walkanimationCD, 0
.endif
.else
; the player is dashing
.if player1.dashanimationCD != 2
inc player1.dashanimationCD
.else
inc player1.dashsequence
.if player1.dashsequence == 12
; dash over
mov player1.dashsequence, 0
.if player1.playerObj.speed.x == DASH_SPEED
mov player1.playerObj.speed.x, PLAYER_SPEED
.elseif player1.playerObj.speed.x == -DASH_SPEED
mov player1.playerObj.speed.x, -PLAYER_SPEED
.endif
.if player1.playerObj.speed.y == DASH_SPEED
mov player1.playerObj.speed.y, PLAYER_SPEED
.elseif player1.playerObj.speed.y == -DASH_SPEED
mov player1.playerObj.speed.y, -PLAYER_SPEED
.endif
;mov player1.playerObj.speed.x, 0
;mov player1.playerObj.speed.y, 0
.endif
mov player1.dashanimationCD, 0
.endif
.endif
; ----- PLAYER 2 WALKING SEQUENCE ------
.if player2.dashsequence == 0
; the player is walking
.if player2.walkanimationCD != 2
inc player2.walkanimationCD
.else
inc player2.walksequence
.if player2.walksequence == 6
; walking animation over
mov player2.walksequence, 0
.endif
mov player2.walkanimationCD, 0
.endif
.else
; the player is dashing
.if player2.dashanimationCD != 2
inc player2.dashanimationCD
.else
inc player2.dashsequence
.if player2.dashsequence == 12
; dash over
mov player2.dashsequence, 0
.if player2.playerObj.speed.x == DASH_SPEED
mov player2.playerObj.speed.x, PLAYER_SPEED
.elseif player2.playerObj.speed.x == -DASH_SPEED
mov player2.playerObj.speed.x, -PLAYER_SPEED
.endif
.if player2.playerObj.speed.y == DASH_SPEED
mov player2.playerObj.speed.y, PLAYER_SPEED
.elseif player2.playerObj.speed.y == -DASH_SPEED
mov player2.playerObj.speed.y, -PLAYER_SPEED
.endif
;mov player2.playerObj.speed.x, 0
;mov player2.playerObj.speed.y, 0
.endif
mov player2.dashanimationCD, 0
.endif
.endif
invoke movePlayer, addr player1
invoke movePlayer, addr player2
invoke updateDirection, addr player1.playerObj
invoke updateDirection, addr player2.playerObj
invoke fixArrowCoordinates, addr arrow1
invoke fixArrowCoordinates, addr arrow2
invoke fixCoordinates, addr player1
invoke fixCoordinates, addr player2
;invoke InvalidateRect, hWnd, NULL, TRUE
.endw
.while GAMESTATE == 3 || GAMESTATE == 4
invoke Sleep, 30
.endw
jmp game
ret
gameManager endp
;_____________________________________________________________________________________________________________________________
changePlayerSpeed proc uses eax addrPlayer : DWORD, direction : BYTE, keydown : BYTE
assume eax: ptr player
mov eax, addrPlayer
.if keydown == FALSE
.if direction == 0 ;w
.if [eax].playerObj.speed.y > 7fh
mov [eax].playerObj.speed.y, 0
.endif
.elseif direction == 1 ;a
.if [eax].playerObj.speed.x > 7fh
mov [eax].playerObj.speed.x, 0
.endif
.elseif direction == 2 ;s
.if [eax].playerObj.speed.y < 80h
mov [eax].playerObj.speed.y, 0
.endif
.elseif direction == 3 ;d
.if [eax].playerObj.speed.x < 80h
mov [eax].playerObj.speed.x, 0