-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRoad_Fighter.asm
1056 lines (818 loc) · 30.5 KB
/
Road_Fighter.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
; #########################################################################
;
; GENERIC.ASM is a roadmap around a standard 32 bit
; windows application skeleton written in MASM32.
;
; #########################################################################
; Assembler specific instructions for 32 bit ASM code
.386 ; minimum processor needed for 32 bit
.model flat, stdcall ; FLAT memory model & STDCALL calling
option casemap :none ; set code to case sensitive
; #########################################################################
; ---------------------------------------------
; main include file with equates and structures
; ---------------------------------------------
include \masm32\include\windows.inc
; -------------------------------------------------------------
; In MASM32, each include file created by the L2INC.EXE utility
; has a matching library file. If you need functions from a
; specific library, you use BOTH the include file and library
; file for that library.
; -------------------------------------------------------------
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\msimg32.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\msimg32.lib
; #########################################################################
; ------------------------------------------------------------------------
; MACROS are a method of expanding text at assembly time. This allows the
; programmer a tidy and convenient way of using COMMON blocks of code with
; the capacity to use DIFFERENT parameters in each block.
; ------------------------------------------------------------------------
; 1. szText
; A macro to insert TEXT into the code section for convenient and
; more intuitive coding of functions that use byte data as text.
szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM
; 2. m2m
; There is no mnemonic to copy from one memory location to another,
; this macro saves repeated coding of this process and is easier to
; read in complex code.
m2m MACRO M1, M2
push M2
pop M1
ENDM
; 3. return
; Every procedure MUST have a "ret" to return the instruction
; pointer EIP back to the next instruction after the call that
; branched to it. This macro puts a return value in eax and
; makes the "ret" instruction on one line. It is mainly used
; for clear coding in complex conditionals in large branching
; code such as the WndProc procedure.
return MACRO arg
mov eax, arg
ret
ENDM
; #########################################################################
; ----------------------------------------------------------------------
; Prototypes are used in conjunction with the MASM "invoke" syntax for
; checking the number and size of parameters passed to a procedure. This
; improves the reliability of code that is written where errors in
; parameters are caught and displayed at assembly time.
; ----------------------------------------------------------------------
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
TopXY PROTO :DWORD,:DWORD
Paint_Proc PROTO :DWORD, :DWORD
; #########################################################################
; definindo as constantes
.Const
sprites equ 100
cenario equ 101
percurso equ 102
score equ 103
telavitoria equ 104
window_height equ 480
window_width equ 520
CREF_TRANSPARENT EQU 0800040h
CREF_TRANSPARENT2 EQU 000FF00h
ID_TIMER equ 1
TIMER_MAX equ 60
; ------------------------------------------------------------------------
; This is the INITIALISED data section meaning that data declared here has
; an initial value. You can also use an UNINIALISED section if you need
; data of that type [ .data? ]. Note that they are different and occur in
; different sections.
; ------------------------------------------------------------------------
.data
szDisplayName db "Road Fighter",0
CommandLine dd 0
hWnd dd 0
hInstance dd 0
hBmpSprites dd 0
hBmpCenario dd 0
hBmpPercurso dd 0
hBmpScore dd 0
hBmpTelaVitoria dd 0
header_format_score_show db "%d", 0
seed dd 123212
venceu db 0
pontos dd 100000
combustivel dd 100
.data?
carstruct struct
posX dd ?
posY dd ? ; nao tem
velY dd ?
carstruct ends
keystruct struct
direita db ?
esquerda db ?
z db ?
x db ?
keystruct ends
iTimer dd ?
posYbg dd ?
posYperc dd ?
delayMorreu dd ?
delayPontinho dd ?
delaySpawn dd ?
delaySpawnCarro dd ?
delaySpawnCarro2 dd ?
delaySpawnCarroBonus dd ?
buffer db 300 dup(?)
hFont dd ?
jogador carstruct <>
truck carstruct <>
carro_inimigo carstruct <>
carro_inimigo2 carstruct <>
carro_bonus carstruct <>
teclas keystruct <>
; #########################################################################
; ------------------------------------------------------------------------
; This is the start of the code section where executable code begins. This
; section ending with the ExitProcess() API function call is the only
; GLOBAL section of code and it provides access to the WinMain function
; with the necessary parameters, the instance handle and the command line
; address.
; ------------------------------------------------------------------------
.code
; -----------------------------------------------------------------------
; The label "start:" is the address of the start of the code section and
; it has a matching "end start" at the end of the file. All procedures in
; this module must be written between these two.
; -----------------------------------------------------------------------
start:
mov teclas.direita, 0
mov teclas.esquerda, 0
mov teclas.x, 0
mov teclas.z, 0
invoke GetModuleHandle, NULL ; provides the instance handle
mov hInstance, eax
invoke LoadBitmap, hInstance, sprites
mov hBmpSprites, eax
invoke LoadBitmap, hInstance, cenario
mov hBmpCenario, eax
invoke LoadBitmap, hInstance, percurso
mov hBmpPercurso, eax
invoke LoadBitmap, hInstance, score
mov hBmpScore, eax
invoke LoadBitmap, hInstance, telavitoria
mov hBmpTelaVitoria, eax
;invoke GetStockObject,DEVICE_DEFAULT_FONT
invoke CreateFontA, 25, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, NULL
mov hFont,eax
invoke GetCommandLine ; provides the command line address
mov CommandLine, eax
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax ; cleanup & return to operating system
Collision proc sx:DWORD, sy:DWORD, sb:DWORD, sh:DWORD, qx:DWORD, qy:DWORD, qb:DWORD, qh:DWORD
mov eax, qx
add eax, qb
mov ebx, sx
add ebx, sb
mov ecx, qy
add ecx, qh
mov edx, sy
add edx, sh
.if (sx < eax) && (ebx > qx) && (sy < ecx) && (edx > qy)
return 1;
.endif
return 0
Collision endp
getrandom proc
gerar:
invoke GetTickCount
invoke nseed, seed
invoke nrandom, 120 ;gera um numero random de 0 a 8
;geramos de 0 a 8 para que os numeros que nós queremos (1-7) se tornam equiprováveis
mov seed, eax
return eax
getrandom endp
; #########################################################################
WinMain proc hInst :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD
;====================
; Put LOCALs on stack
;====================
LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL Wwd :DWORD
LOCAL Wht :DWORD
LOCAL Wtx :DWORD
LOCAL Wty :DWORD
szText szClassName,"Primeiro_Class"
;==================================================
; Fill WNDCLASSEX structure with required variables
;==================================================
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW \
or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset WndProc ; address of WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
m2m wc.hInstance, hInst ; instance handle
mov wc.hbrBackground, NULL ; system color
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset szClassName ; window class name
invoke LoadIcon,hInst,500 ; icon ID ; resource icon
mov wc.hIcon, eax
invoke LoadCursor,NULL,IDC_ARROW ; system cursor
mov wc.hCursor, eax
mov wc.hIconSm, 0
invoke RegisterClassEx, ADDR wc ; register the window class
;================================
; Centre window at following size
;================================
mov Wwd, 530
mov Wht, 490
invoke GetSystemMetrics,SM_CXSCREEN ; get screen width in pixels
invoke TopXY,Wwd,eax
mov Wtx, eax
invoke GetSystemMetrics,SM_CYSCREEN ; get screen height in pixels
invoke TopXY,Wht,eax
mov Wty, eax
; ==================================
; Create the main application window
; ==================================
invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,
ADDR szClassName,
ADDR szDisplayName,
WS_OVERLAPPEDWINDOW,
Wtx,Wty,Wwd,Wht,
NULL,NULL,
hInst,NULL
mov hWnd,eax ; copy return value into handle DWORD
invoke LoadMenu,hInst,600 ; load resource menu
invoke SetMenu,hWnd,eax ; set it to main window
invoke ShowWindow,hWnd,SW_SHOWNORMAL ; display the window
invoke UpdateWindow,hWnd ; update the display
;===================================
; Loop until PostQuitMessage is sent
;===================================
StartLoop:
invoke GetMessage,ADDR msg,NULL,0,0 ; get each message
cmp eax, 0 ; exit if GetMessage()
je ExitLoop ; returns zero
invoke TranslateMessage, ADDR msg ; translate it
invoke DispatchMessage, ADDR msg ; send it to message proc
jmp StartLoop
ExitLoop:
return msg.wParam
WinMain endp
; #########################################################################
WndProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD
LOCAL Ps :PAINTSTRUCT
LOCAL hDC :DWORD ; handle do dispositivo (tela)
; -------------------------------------------------------------------------
; Message are sent by the operating system to an application through the
; WndProc proc. Each message can have additional values associated with it
; in the two parameters, wParam & lParam. The range of additional data that
; can be passed to an application is determined by the message.
; -------------------------------------------------------------------------
.if uMsg == WM_COMMAND
;----------------------------------------------------------------------
; The WM_COMMAND message is sent by menus, buttons and toolbar buttons.
; Processing the wParam parameter of it is the method of obtaining the
; control's ID number so that the code for each operation can be
; processed. NOTE that the ID number is in the LOWORD of the wParam
; passed with the WM_COMMAND message. There may be some instances where
; an application needs to seperate the high and low words of wParam.
; ---------------------------------------------------------------------
;======== menu commands ========
.if wParam == 1000
invoke SendMessage,hWin,WM_SYSCOMMAND,SC_CLOSE,NULL
.elseif wParam == 1900
szText TheMsg,"Teste"
invoke MessageBox,hWin,ADDR TheMsg,ADDR szDisplayName,MB_OK
.endif
;====== end menu commands ======
.elseif uMsg == WM_PAINT
invoke BeginPaint, hWin, ADDR Ps
mov hDC, eax
invoke Paint_Proc, hWin, hDC
invoke EndPaint, hWin, ADDR Ps
.elseif uMsg == WM_CREATE
; --------------------------------------------------------------------
; This message is sent to WndProc during the CreateWindowEx function
; call and is processed before it returns. This is used as a position
; to start other items such as controls. IMPORTANT, the handle for the
; CreateWindowEx call in the WinMain does not yet exist so the HANDLE
; passed to the WndProc [ hWin ] must be used here for any controls
; or child windows.
; --------------------------------------------------------------------
mov jogador.posX, 220
mov jogador.posY, 330
mov jogador.velY, 0
mov truck.posX, 180
mov truck.posY, 1000
mov truck.velY, 10
mov carro_inimigo.posX, 180
mov carro_inimigo.posY, 330
mov carro_inimigo.velY, 15
mov carro_inimigo2.posX, 230
mov carro_inimigo2.posY, 300
mov carro_inimigo2.velY, 15
mov carro_bonus.posX, 600
mov carro_bonus.posY, 600
mov carro_bonus.velY, 15
mov posYbg, 0
mov posYperc, 418
mov delayMorreu, 0
mov delayPontinho, 0
mov delaySpawn, 4
mov delaySpawnCarro, 2
mov delaySpawnCarro2, 3
mov delaySpawnCarroBonus, 15
invoke SetTimer, hWin, ID_TIMER, TIMER_MAX, NULL
mov iTimer, eax
.elseif uMsg == WM_TIMER
invoke KillTimer, hWin, iTimer
mov eax, pontos
sbb eax, 10
mov pontos, eax
.if delayMorreu == 0
.if teclas.direita == 1
.if jogador.posX < 282
mov eax, jogador.posX
add eax, 5
mov jogador.posX, eax
.endif
.if jogador.posX > 282 && jogador.velY > 1
mov delayMorreu, 20
mov jogador.velY, 0
mov eax, pontos
sbb eax, 1000
mov pontos, eax
.endif
.endif
.if teclas.esquerda == 1
.if jogador.posX > 153
mov eax, jogador.posX
sbb eax, 5
mov jogador.posX, eax
.endif
.if jogador.posX < 158 && jogador.velY > 1
mov delayMorreu, 20
mov jogador.velY, 0
mov eax, pontos
sbb eax, 1000
mov pontos, eax
.endif
.endif
.else
.if delayMorreu == 1
mov jogador.posX, 220
mov jogador.posY, 330
.endif
mov eax, delayMorreu
dec eax
mov delayMorreu, eax
.endif
.if teclas.z == 1 && delayMorreu == 0
.if jogador.velY < 25
mov eax, jogador.velY
add eax, 2
mov jogador.velY, eax
.endif
.else
.if jogador.velY > 0
mov eax, jogador.velY
sbb eax, 1
mov jogador.velY, eax
.endif
.endif
.if teclas.x == 1 && delayMorreu == 0
.if jogador.velY < 40
mov eax, jogador.velY
add eax, 3
mov jogador.velY, eax
.endif
.else
.if jogador.velY > 8
mov eax, jogador.velY
sbb eax, 1
mov jogador.velY, eax
.endif
.endif
;desce o fundo
mov eax, posYbg
add eax, jogador.velY
mov posYbg, eax
;--
.if delayPontinho != 0
mov eax, delayPontinho
dec eax
mov delayPontinho, eax
.endif
;move o caminhao
mov eax, jogador.velY
.if truck.velY > eax
mov eax, truck.posY
mov ebx, truck.velY
sbb ebx, jogador.velY
sbb eax, ebx
mov truck.posY, eax
.else
mov eax, truck.posY
mov ebx, jogador.velY
sbb ebx, truck.velY
add eax, ebx
mov truck.posY, eax
.endif
;move carro inimigo
mov eax, jogador.velY
.if carro_inimigo.velY > eax
mov eax, carro_inimigo.posY
mov ebx, carro_inimigo.velY
sbb ebx, jogador.velY
sbb eax, ebx
mov carro_inimigo.posY, eax
.else
mov eax, carro_inimigo.posY
mov ebx, jogador.velY
sbb ebx, carro_inimigo.velY
add eax, ebx
mov carro_inimigo.posY, eax
.endif
mov eax, jogador.velY
.if carro_inimigo2.velY > eax
mov eax, carro_inimigo2.posY
mov ebx, carro_inimigo2.velY
sbb ebx, jogador.velY
sbb eax, ebx
mov carro_inimigo2.posY, eax
.else
mov eax, carro_inimigo2.posY
mov ebx, jogador.velY
sbb ebx, carro_inimigo2.velY
add eax, ebx
mov carro_inimigo2.posY, eax
.endif
;move carro bonus
mov eax, jogador.velY
.if carro_bonus.velY > eax
mov eax, carro_bonus.posY
mov ebx, carro_bonus.velY
sbb ebx, jogador.velY
sbb eax, ebx
mov carro_bonus.posY, eax
.else
mov eax, carro_bonus.posY
mov ebx, jogador.velY
sbb ebx, carro_bonus.velY
add eax, ebx
mov carro_bonus.posY, eax
.endif
invoke Collision, truck.posX, truck.posY, 20, 64, jogador.posX, jogador.posY, 16, 32
.if eax == 1 && delayMorreu == 0 ;qd ele colidir e estiver vivo entra aqui
mov delayMorreu, 20
mov jogador.velY, 0
mov eax, pontos
sbb eax, 1000
mov pontos, eax
.endif
;--
invoke Collision, carro_inimigo.posX, carro_inimigo.posY, 14, 32, jogador.posX, jogador.posY, 16, 32
.if eax == 1 && delayMorreu == 0 ;qd ele colidir e estiver vivo entra aqui
mov delayMorreu, 20
mov jogador.velY, 0
mov eax, pontos
sbb eax, 1000
mov pontos, eax
.endif
invoke Collision, carro_inimigo2.posX, carro_inimigo2.posY, 14, 32, jogador.posX, jogador.posY, 16, 32
.if eax == 1 && delayMorreu == 0 ;qd ele colidir e estiver vivo entra aqui
mov delayMorreu, 20
mov jogador.velY, 0
mov eax, pontos
sbb eax, 1000
mov pontos, eax
.endif
invoke Collision, carro_bonus.posX, carro_bonus.posY, 22, 32, jogador.posX, jogador.posY, 16, 32
.if eax == 1 ;qd ele colidir e estiver vivo entra aqui
mov eax, pontos ;adiciona 1000 pontos
add eax, 1000
mov pontos, eax
mov delayPontinho, 8
mov carro_bonus.posY, 600 ;manda ele pra fora da tela
mov carro_bonus.posX, 1200 ;manda ele pra fora da tela
.endif
.if posYbg > 448
;anda o carrinho do percurso
mov eax, posYperc
sbb eax, 8
mov posYperc, eax
;---------------------------
;coloca o cenario referencia de volta a 0
mov eax, 0
mov posYbg, eax
;----------------------------------------
.if delaySpawn == 0
.if truck.posY > 448
mov delaySpawn, 4
mov ecx, 0
sbb ecx, 32
mov truck.posY, ecx
invoke getrandom
add eax, 153
mov truck.posX, eax
.endif
.else
mov eax, delaySpawn
dec eax
mov delaySpawn, eax
.endif
.if delaySpawnCarro == 0
.if carro_inimigo.posY > 448
mov delaySpawnCarro, 2
mov ecx, 0
sbb ecx, 32
mov carro_inimigo.posY, ecx
invoke getrandom
add eax, 153
mov carro_inimigo.posX, eax
.endif
.else
mov eax, delaySpawnCarro
dec eax
mov delaySpawnCarro, eax
.endif
.if delaySpawnCarro2 == 0
.if carro_inimigo2.posY > 448
mov delaySpawnCarro2, 3
mov ecx, 0
sbb ecx, 32
mov carro_inimigo2.posY, ecx
invoke getrandom
add eax, 153
mov carro_inimigo2.posX, eax
.endif
.else
mov eax, delaySpawnCarro2
dec eax
mov delaySpawnCarro2, eax
.endif
.if delaySpawnCarroBonus == 0
.if carro_bonus.posY > 448
mov delaySpawnCarroBonus, 20
mov ecx, 0
sbb ecx, 32
mov carro_bonus.posY, ecx
invoke getrandom
add eax, 153
mov carro_bonus.posX, eax
.endif
.else
mov eax, delaySpawnCarroBonus
dec eax
mov delaySpawnCarroBonus, eax
.endif
.endif
invoke InvalidateRect, hWin, NULL, TRUE
invoke SetTimer, hWin, ID_TIMER, TIMER_MAX, NULL
mov iTimer, eax
.elseif uMsg == WM_CLOSE
; -------------------------------------------------------------------
; This is the place where various requirements are performed before
; the application exits to the operating system such as deleting
; resources and testing if files have been saved. You have the option
; of returning ZERO if you don't wish the application to close which
; exits the WndProc procedure without passing this message to the
; default window processing done by the operating system.
; -------------------------------------------------------------------
.elseif uMsg == WM_KEYDOWN
.if wParam == VK_LEFT
mov teclas.esquerda, 1
.endif
.if wParam == VK_RIGHT
mov teclas.direita, 1
.endif
.if wParam == 58h
mov teclas.x, 1
.endif
.if wParam == 5Ah
mov teclas.z, 1
.endif
.elseif uMsg == WM_KEYUP
.if wParam == VK_LEFT
mov teclas.esquerda, 0
.endif
.if wParam == VK_RIGHT
mov teclas.direita, 0
.endif
.if wParam == 58h
mov teclas.x, 0
.endif
.if wParam == 5Ah
mov teclas.z, 0
.endif
.if wParam == 52h
mov posYperc, 418
mov jogador.posX, 220
mov jogador.posY, 330
mov jogador.velY, 0
mov truck.posX, 180
mov truck.posY, 1000
mov truck.velY, 10
mov carro_inimigo.posX, 180
mov carro_inimigo.posY, 330
mov carro_inimigo.velY, 15
mov carro_inimigo2.posX, 220
mov carro_inimigo2.posY, 300
mov carro_inimigo2.velY, 15
mov carro_bonus.posX, 600
mov carro_bonus.posY, 600
mov carro_bonus.velY, 15
mov posYbg, 0
mov posYperc, 418
mov delayMorreu, 0
mov delayPontinho, 0
mov delaySpawn, 4
mov delaySpawnCarro, 2
mov delaySpawnCarroBonus, 15
mov pontos, 100000
mov venceu, 0
invoke SetTimer, hWin, ID_TIMER, TIMER_MAX, NULL
mov iTimer, eax
.endif
.elseif uMsg == WM_DESTROY
; ----------------------------------------------------------------
; This message MUST be processed to cleanly exit the application.
; Calling the PostQuitMessage() function makes the GetMessage()
; function in the WinMain() main loop return ZERO which exits the
; application correctly. If this message is not processed properly
; the window disappears but the code is left in memory.
; ----------------------------------------------------------------
invoke KillTimer, hWin, iTimer
invoke PostQuitMessage,NULL
return 0
.endif
invoke DefWindowProc,hWin,uMsg,wParam,lParam
; --------------------------------------------------------------------
; Default window processing is done by the operating system for any
; message that is not processed by the application in the WndProc
; procedure. If the application requires other than default processing
; it executes the code when the message is trapped and returns ZERO
; to exit the WndProc procedure before the default window processing
; occurs with the call to DefWindowProc().
; --------------------------------------------------------------------
ret
WndProc endp
; ########################################################################
TopXY proc wDim:DWORD, sDim:DWORD
; ----------------------------------------------------
; This procedure calculates the top X & Y co-ordinates
; for the CreateWindowEx call in the WinMain procedure
; ----------------------------------------------------
shr sDim, 1 ; divide screen dimension by 2
shr wDim, 1 ; divide window dimension by 2
mov eax, wDim ; copy window dimension into eax
sub sDim, eax ; sub half win dimension from half screen dimension
return sDim
TopXY endp
; ########################################################################
Paint_Proc proc hWin:DWORD, hDC:DWORD
LOCAL hOld:DWORD
LOCAL memDC:DWORD
LOCAL memDC2:DWORD
LOCAL hBitmap:DWORD
invoke CreateCompatibleDC, hDC
mov memDC, eax
invoke CreateCompatibleDC, hDC
mov memDC2, eax
invoke CreateCompatibleBitmap, hDC, window_width, window_height
mov hBitmap, eax
invoke SelectObject, memDC2, hBitmap
.if posYperc <= 2 || venceu == 1
mov venceu, 1
invoke SelectObject, memDC, hBmpTelaVitoria
mov hOld, eax
invoke TransparentBlt,memDC2,0,0,512,448,memDC,0,0,500,375, CREF_TRANSPARENT2
;-------
;Pontuacao
invoke SelectObject, memDC2, hFont
invoke SetTextColor, memDC2, 0FFFFFFh
invoke SetBkColor, memDC2, 0h
invoke wsprintfA, ADDR buffer, ADDR header_format_score_show, pontos
invoke ExtTextOutA, memDC2, 190, 165, ETO_CLIPPED, NULL, ADDR buffer, eax, NULL
invoke KillTimer, hWin, iTimer
.else
;;Percurso
invoke SelectObject, memDC, hBmpPercurso
mov hOld, eax
invoke TransparentBlt, memDC2, 0, 0, 64, 448, memDC, 0, 0, 32, 224, CREF_TRANSPARENT
;carrinhoperc
invoke SelectObject, memDC, hBmpSprites
mov hOld, eax
invoke TransparentBlt,memDC2,24,posYperc,16,30,memDC,5,36,8,15, CREF_TRANSPARENT
;-------
;cenario
invoke SelectObject, memDC, hBmpCenario
mov hOld, eax
mov ecx, posYbg
sbb ecx, 448
invoke TransparentBlt, memDC2, 64, ecx, 320, 448, memDC, 0, 0, 160, 224, CREF_TRANSPARENT
invoke SelectObject, memDC, hBmpCenario
mov hOld, eax
invoke TransparentBlt, memDC2, 64, posYbg, 320, 448, memDC, 0, 0, 160, 224, CREF_TRANSPARENT
.if posYperc <= 10
invoke SelectObject, memDC, hBmpSprites
mov hOld, eax
invoke TransparentBlt,memDC2,153,posYbg,146,18,memDC,69,62,64,8, CREF_TRANSPARENT
.endif
;-------
;Placar de pontuacao
invoke SelectObject, memDC, hBmpScore
mov hOld, eax
invoke TransparentBlt, memDC2, 384, 0, 126, 448, memDC, 0, 0, 63, 224, CREF_TRANSPARENT
;-------
;Pontuacao
invoke SelectObject, memDC2, hFont
invoke SetTextColor, memDC2, 0FFFFFFh
invoke SetBkColor, memDC2, 0h
invoke wsprintfA, ADDR buffer, ADDR header_format_score_show, pontos
invoke ExtTextOutA, memDC2, 400, 85, ETO_CLIPPED, NULL, ADDR buffer, eax, NULL
;-------
;Jogador
.if delayMorreu == 0
invoke SelectObject, memDC, hBmpSprites
mov hOld, eax
invoke TransparentBlt,memDC2,jogador.posX,jogador.posY,22,32,memDC,3,3,11,16, CREF_TRANSPARENT
.elseif delayMorreu < 10
invoke SelectObject, memDC, hBmpSprites
mov hOld, eax
mov ecx, jogador.posX
sbb ecx, 2
invoke TransparentBlt,memDC2,ecx,jogador.posY,30,32,memDC,59,35,15,16, CREF_TRANSPARENT
.else
invoke SelectObject, memDC, hBmpSprites
mov hOld, eax
invoke TransparentBlt,memDC2,jogador.posX,jogador.posY,22,26,memDC,45,36,11,13, CREF_TRANSPARENT
.endif
;----------
;pontinhos bonus
.if delayPontinho != 0
invoke SelectObject, memDC, hBmpSprites
mov hOld, eax
mov ecx, jogador.posX
add ecx, 10
mov ebx, jogador.posY
sbb ebx, 10