|
| 1 | + .486 ; create 32 bit code |
| 2 | + .model flat, stdcall ; 32 bit memory model |
| 3 | + option casemap :none ; case sensitive |
| 4 | + |
| 5 | +include \masm32\include\windows.inc |
| 6 | +include \masm32\include\kernel32.inc |
| 7 | +include \masm32\include\user32.inc |
| 8 | +include \masm32\include\gdi32.inc |
| 9 | +include \masm32\include\Advapi32.inc |
| 10 | +;include \masm32\include\masm32rt.inc |
| 11 | +include \masm32\include\winmm.inc |
| 12 | +includelib \masm32\lib\winmm.lib |
| 13 | + include \masm32\include\dialogs.inc ; macro file for dialogs |
| 14 | + include \masm32\macros\macros.asm ; masm32 macro file |
| 15 | + includelib \masm32\lib\gdi32.lib |
| 16 | + includelib \masm32\lib\user32.lib |
| 17 | + includelib \masm32\lib\kernel32.lib |
| 18 | + includelib \masm32\lib\Comctl32.lib |
| 19 | + includelib \masm32\lib\comdlg32.lib |
| 20 | + includelib \masm32\lib\shell32.lib |
| 21 | + includelib \masm32\lib\oleaut32.lib |
| 22 | + includelib \masm32\lib\ole32.lib |
| 23 | + includelib \masm32\lib\msvcrt.lib |
| 24 | + |
| 25 | +.const |
| 26 | +VEL_X equ 3 |
| 27 | +VEL_Y equ 3 |
| 28 | +RECT_WIDTH_BACKUP equ 30 |
| 29 | +RECT_HEIGHT_BACKUP equ 20 |
| 30 | +WINDOW_WIDTH equ 800 |
| 31 | +WINDOW_HEIGHT equ 600 |
| 32 | +RIGHT equ 1 |
| 33 | +DOWN equ 2 |
| 34 | +LEFT equ 3 |
| 35 | +UP equ 4 |
| 36 | +MAIN_TIMER_ID equ 0 |
| 37 | +.data |
| 38 | +RECT_WIDTH DB 30 |
| 39 | +RECT_HEIGHT DB 20 |
| 40 | +PlayerX DWORD 400 |
| 41 | +PlayerY DWORD 400 |
| 42 | +;Facing DWORD LEFT ;1 - Right, 2 -Down, 3 - Left, 4 - Up |
| 43 | +ClassName DB "TheClass",0 |
| 44 | +windowTitle DB "A Game!",0 |
| 45 | +JumpState DWORD 0 |
| 46 | +StartY DWORD 400 |
| 47 | + |
| 48 | +.code |
| 49 | +BUILDRECT PROC, x:DWORD, y:DWORD, h:DWORD, w:DWORD, hdc:HDC, brush:HBRUSH |
| 50 | +LOCAL rectangle:RECT |
| 51 | +mov eax, x |
| 52 | +mov rectangle.left, eax |
| 53 | +add eax, w |
| 54 | +mov rectangle.right, eax |
| 55 | + |
| 56 | +mov eax, y |
| 57 | +mov rectangle.top, eax |
| 58 | +add eax, h |
| 59 | +mov rectangle.bottom, eax |
| 60 | + |
| 61 | +invoke FillRect, hdc, addr rectangle, brush |
| 62 | +ret |
| 63 | +BUILDRECT ENDP |
| 64 | + |
| 65 | +ProjectWndProc PROC, hWnd:HWND, message:UINT, wParam:WPARAM, lParam:LPARAM |
| 66 | + local paint:PAINTSTRUCT |
| 67 | + local hdc:HDC |
| 68 | + local brushcolouring:HBRUSH |
| 69 | + |
| 70 | + |
| 71 | + invoke GetAsyncKeyState, VK_LEFT |
| 72 | + cmp eax, 0 |
| 73 | + jne moveleft |
| 74 | + invoke GetAsyncKeyState, VK_RIGHT |
| 75 | + cmp eax, 0 |
| 76 | + jne moveright |
| 77 | + checkupdown: |
| 78 | + invoke GetAsyncKeyState, VK_UP |
| 79 | + cmp eax, 0 |
| 80 | + jne moveup |
| 81 | + invoke GetAsyncKeyState, VK_DOWN |
| 82 | + cmp eax, 0 |
| 83 | + jne movedown |
| 84 | + jmp endmovement |
| 85 | +moveleft: |
| 86 | + mov RECT_HEIGHT, RECT_HEIGHT_BACKUP |
| 87 | + mov RECT_WIDTH, RECT_WIDTH_BACKUP |
| 88 | + mov eax, PlayerX |
| 89 | + sub eax, VEL_X |
| 90 | + mov PlayerX, eax |
| 91 | + jmp checkupdown |
| 92 | +moveright: |
| 93 | + mov RECT_HEIGHT, RECT_HEIGHT_BACKUP |
| 94 | + mov RECT_WIDTH, RECT_WIDTH_BACKUP |
| 95 | + mov eax, PlayerX |
| 96 | + add eax, VEL_X |
| 97 | + mov PlayerX, eax |
| 98 | + jmp checkupdown |
| 99 | +movedown: |
| 100 | + mov RECT_HEIGHT, RECT_WIDTH_BACKUP |
| 101 | + mov RECT_WIDTH, RECT_HEIGHT_BACKUP |
| 102 | + mov eax, PlayerY |
| 103 | + add eax, VEL_Y |
| 104 | + mov PlayerY, eax |
| 105 | + jmp endmovement |
| 106 | +moveup: |
| 107 | + mov RECT_HEIGHT, RECT_WIDTH_BACKUP |
| 108 | + mov RECT_WIDTH, RECT_HEIGHT_BACKUP |
| 109 | + mov eax, PlayerY |
| 110 | + sub eax, VEL_X |
| 111 | + mov PlayerY, eax |
| 112 | + jmp endmovement |
| 113 | + |
| 114 | +endmovement: |
| 115 | + |
| 116 | + |
| 117 | + cmp message, WM_PAINT |
| 118 | + je painting |
| 119 | + cmp message, WM_CLOSE |
| 120 | + je closing |
| 121 | + ;cmp message, WM_KEYDOWN |
| 122 | + ;je movement |
| 123 | + ;cmp message, WM_KEYUP |
| 124 | + ;je stopmovement |
| 125 | + cmp message, WM_TIMER |
| 126 | + je timing |
| 127 | + jmp OtherInstances |
| 128 | + |
| 129 | + |
| 130 | + closing: |
| 131 | + invoke ExitProcess, 0 |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + painting: |
| 136 | + invoke BeginPaint, hWnd, addr paint |
| 137 | + mov hdc, eax |
| 138 | + invoke GetStockObject, DC_BRUSH |
| 139 | + mov brushcolouring, eax |
| 140 | + invoke SetDCBrushColor, hdc, 000000FF0000h |
| 141 | + mov brushcolouring, eax |
| 142 | + |
| 143 | + jmp endhere |
| 144 | + |
| 145 | +endhere: |
| 146 | + cmp PlayerY, 600 |
| 147 | + jge BottomBorder |
| 148 | + cmp PlayerY, 0 |
| 149 | + jle TopBorder |
| 150 | + cmp PlayerX, 800 |
| 151 | + jge RightBorder |
| 152 | + cmp PlayerX, 0 |
| 153 | + jle LeftBorder |
| 154 | + jmp realend |
| 155 | +BottomBorder: |
| 156 | + mov eax, 0 |
| 157 | + mov PlayerY, eax |
| 158 | + jmp realend |
| 159 | +TopBorder: |
| 160 | + mov eax, 600 |
| 161 | + mov PlayerY, eax |
| 162 | + jmp realend |
| 163 | +RightBorder: |
| 164 | + mov eax, 0 |
| 165 | + mov PlayerX, eax |
| 166 | + jmp realend |
| 167 | +LeftBorder: |
| 168 | + mov eax, 800 |
| 169 | + mov PlayerX, eax |
| 170 | + jmp realend |
| 171 | +realend: |
| 172 | + invoke BUILDRECT, PlayerX, PlayerY, RECT_HEIGHT, RECT_WIDTH, hdc, brushcolouring |
| 173 | + invoke EndPaint, hWnd, addr paint |
| 174 | + ret |
| 175 | + |
| 176 | + |
| 177 | +timing: |
| 178 | + invoke InvalidateRect, hWnd, NULL, TRUE |
| 179 | + ret |
| 180 | +OtherInstances: |
| 181 | + invoke DefWindowProc, hWnd, message, wParam, lParam |
| 182 | + ret |
| 183 | +ProjectWndProc ENDP |
| 184 | + |
| 185 | +main PROC |
| 186 | + |
| 187 | +LOCAL wndcls:WNDCLASSA ; Class struct for the window |
| 188 | +LOCAL hWnd:HWND ;Handle to the window |
| 189 | +LOCAL msg:MSG |
| 190 | +invoke RtlZeroMemory, addr wndcls, SIZEOF wndcls ;Empty the window class |
| 191 | +mov eax, offset ClassName |
| 192 | +mov wndcls.lpszClassName, eax ;Set the class name |
| 193 | +invoke GetStockObject, BLACK_BRUSH |
| 194 | +mov wndcls.hbrBackground, eax ;Set the background color as black |
| 195 | +mov eax, ProjectWndProc |
| 196 | +mov wndcls.lpfnWndProc, eax ;Set the procedure that handles the window messages |
| 197 | +invoke RegisterClassA, addr wndcls ;Register the class |
| 198 | +invoke CreateWindowExA, WS_EX_COMPOSITED, addr ClassName, addr windowTitle, WS_SYSMENU, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0 ;Create the window |
| 199 | +mov hWnd, eax ;Save the handle |
| 200 | +invoke ShowWindow, eax, SW_SHOW ;Show it |
| 201 | +invoke SetTimer, hWnd, MAIN_TIMER_ID, 20, NULL ;Set the repaint timer |
| 202 | + |
| 203 | +msgLoop: |
| 204 | + ; PeekMessage |
| 205 | +invoke GetMessage, addr msg, hWnd, 0, 0 ;Retrieve the messages from the window |
| 206 | +mov eax, 55 |
| 207 | +invoke DispatchMessage, addr msg ;Dispatches a message to the window procedure |
| 208 | +jmp msgLoop |
| 209 | +invoke ExitProcess, 1 |
| 210 | +main ENDP |
| 211 | +end main |
0 commit comments