Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .486 ; create 32 bit code
- .model flat, stdcall ; 32 bit memory model
- option casemap :none ; case sensitive
- include \masm32\include\windows.inc
- include \masm32\include\kernel32.inc
- include \masm32\include\user32.inc
- include \masm32\include\gdi32.inc
- include \masm32\include\Advapi32.inc
- ;include \masm32\include\masm32rt.inc
- include \masm32\include\winmm.inc
- includelib \masm32\lib\winmm.lib
- ;include \masm32\include\Comctl32.inc
- ;include \masm32\include\comdlg32.inc
- ;include \masm32\include\shell32.inc
- ;include \masm32\include\oleaut32.inc
- ;include \masm32\include\ole32.inc
- ;include \masm32\include\msvcrt.inc
- include \masm32\include\dialogs.inc ; macro file for dialogs
- include \masm32\macros\macros.asm ; masm32 macro file
- includelib \masm32\lib\gdi32.lib
- includelib \masm32\lib\user32.lib
- includelib \masm32\lib\kernel32.lib
- includelib \masm32\lib\Comctl32.lib
- includelib \masm32\lib\comdlg32.lib
- includelib \masm32\lib\shell32.lib
- includelib \masm32\lib\oleaut32.lib
- includelib \masm32\lib\ole32.lib
- includelib \masm32\lib\msvcrt.lib
- .const
- WINDOW_WIDTH equ 800
- WINDOW_HEIGHT equ 600
- MYWIDTH equ 20
- MYHEIGHT equ 20
- RIGHT equ 1
- DOWN equ 2
- LEFT equ 3
- UP equ 4
- STOP equ 5
- MAIN_TIMER_ID equ 0
- .data
- PlayerX DWORD 400
- PlayerY DWORD 400
- DestX DWORD 80
- DestY DWORD 60
- ClassName DB "TheClass",0
- windowTitle DB "A Game!",0
- facing DWORD 5
- .code
- BUILDRECT PROC, x:DWORD, y:DWORD, h:DWORD, w:DWORD, hdc:HDC, brush:HBRUSH
- LOCAL rectangle:RECT
- mov eax, x
- mov rectangle.left, eax
- add eax, w
- mov rectangle.right, eax
- mov eax, y
- mov rectangle.top, eax
- add eax, h
- mov rectangle.bottom, eax
- invoke FillRect, hdc, addr rectangle, brush
- ret
- BUILDRECT ENDP
- ProjectWndProc PROC, hWnd:HWND, message:UINT, wParam:WPARAM, lParam:LPARAM
- local paint:PAINTSTRUCT
- local hdc:HDC
- local brushcolouring:HBRUSH
- cmp wParam, VK_ESCAPE
- je closing
- cmp message, WM_PAINT
- je painting
- cmp message, WM_CLOSE
- je closing
- cmp message, WM_KEYDOWN
- je movement
- cmp message, WM_TIMER
- je timing
- jmp OtherInstances
- closing:
- invoke ExitProcess, 0
- painting:
- cmp facing, LEFT
- je moveleft
- cmp facing, RIGHT
- je moveright
- cmp facing, DOWN
- je movedown
- cmp facing, UP
- je moveup
- cmp facing, STOP
- je notdead
- jmp endmovement
- moveleft:
- cmp PlayerX, WINDOW_WIDTH-WINDOW_WIDTH
- jle endmovement
- mov eax, PlayerX
- sub eax, 5
- mov DestX, eax
- jmp endmovement
- moveright:
- cmp PlayerX, WINDOW_WIDTH-MYWIDTH
- jge endmovement
- mov eax, PlayerX
- add eax, 5
- mov DestX, eax
- jmp endmovement
- movedown:
- cmp PlayerY, WINDOW_HEIGHT-MYHEIGHT
- jge endmovement
- mov eax, PlayerY
- add eax, 5
- mov DestY, eax
- jmp endmovement
- moveup:
- cmp PlayerY, WINDOW_HEIGHT-WINDOW_HEIGHT
- jle endmovement
- mov eax, PlayerY
- sub eax, 5
- mov DestY, eax
- endmovement:
- invoke BeginPaint, hWnd, addr paint
- mov hdc, eax
- pusha
- invoke GetPixel, hdc, DestX, DestY
- cmp eax, 000000ffffffh
- je notdead
- cmp eax, 000000000000h
- je notdead
- ;cmp eax, 00000000ffffh
- ;je notdead
- dead:
- popa
- jmp closing
- notdead:
- popa
- mov eax, DestX
- mov PlayerX, eax
- mov eax, DestY
- mov PlayerY, eax
- invoke GetStockObject, DC_BRUSH
- mov brushcolouring, eax
- invoke SelectObject, hdc, brushcolouring
- invoke SetDCBrushColor, hdc, 00FFFFh
- mov brushcolouring, eax
- invoke BUILDRECT, PlayerX, PlayerY, MYHEIGHT, MYWIDTH, hdc, brushcolouring
- invoke EndPaint, hWnd, addr paint
- ret
- movement:
- cmp wParam, VK_LEFT
- je cleft
- cmp wParam, VK_RIGHT
- je cright
- cmp wParam, VK_UP
- je cup
- cmp wParam, VK_DOWN
- je cdown
- jmp endc
- cleft:
- mov eax, LEFT
- mov facing, eax
- mov eax, PlayerX
- sub eax, MYWIDTH
- mov DestX, eax
- mov eax, PlayerY
- mov DestY, eax
- jmp endc
- cright:
- mov eax, RIGHT
- mov facing, eax
- mov eax, PlayerX
- add eax, MYWIDTH
- mov DestX, eax
- mov eax, PlayerY
- mov DestY, eax
- jmp endc
- cdown:
- mov eax, DOWN
- mov facing, eax
- mov eax, PlayerY
- add eax, MYHEIGHT
- mov DestY, eax
- mov eax, PlayerX
- mov DestX, eax
- jmp endc
- cup:
- mov eax, UP
- mov facing, eax
- mov eax, PlayerY
- sub eax, MYHEIGHT
- mov DestY, eax
- mov eax, PlayerX
- mov DestX, eax
- endc:
- ret
- timing:
- invoke InvalidateRect, hWnd, NULL, FALSE
- ret
- OtherInstances:
- invoke DefWindowProc, hWnd, message, wParam, lParam
- ret
- ProjectWndProc ENDP
- main PROC
- LOCAL wndcls:WNDCLASSA ; Class struct for the window
- LOCAL hWnd:HWND ;Handle to the window
- LOCAL msg:MSG
- invoke RtlZeroMemory, addr wndcls, SIZEOF wndcls ;Empty the window class
- mov eax, offset ClassName
- mov wndcls.lpszClassName, eax ;Set the class name
- invoke GetStockObject, BLACK_BRUSH
- mov wndcls.hbrBackground, eax ;Set the background color as black
- mov eax, ProjectWndProc
- mov wndcls.lpfnWndProc, eax ;Set the procedure that handles the window messages
- invoke RegisterClassA, addr wndcls ;Register the class
- invoke CreateWindowExA, WS_EX_COMPOSITED, addr ClassName, addr windowTitle, WS_SYSMENU, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0 ;Create the window
- mov hWnd, eax ;Save the handle
- invoke ShowWindow, eax, SW_SHOW ;Show it
- invoke SetTimer, hWnd, MAIN_TIMER_ID, 20, NULL ;Set the repaint timer
- msgLoop:
- ;PeekMessage
- invoke GetMessage, addr msg, hWnd, 0, 0 ;Retrieve the messages from the window
- invoke DispatchMessage, addr msg ;Dispatches a message to the window procedure
- jmp msgLoop
- invoke ExitProcess, 1
- main ENDP
- end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement