Advertisement
Guest User

fixmedaniel

a guest
Mar 5th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  14.  ;include \masm32\include\Comctl32.inc
  15.  ;include \masm32\include\comdlg32.inc
  16.  ;include \masm32\include\shell32.inc
  17.  ;include \masm32\include\oleaut32.inc
  18.  ;include \masm32\include\ole32.inc
  19.  ;include \masm32\include\msvcrt.inc
  20.  
  21.       include \masm32\include\dialogs.inc       ; macro file for dialogs
  22.       include \masm32\macros\macros.asm         ; masm32 macro file
  23.    includelib \masm32\lib\gdi32.lib
  24.      includelib \masm32\lib\user32.lib
  25.       includelib \masm32\lib\kernel32.lib
  26.       includelib \masm32\lib\Comctl32.lib
  27.       includelib \masm32\lib\comdlg32.lib
  28.       includelib \masm32\lib\shell32.lib
  29.       includelib \masm32\lib\oleaut32.lib
  30.       includelib \masm32\lib\ole32.lib
  31.       includelib \masm32\lib\msvcrt.lib
  32.  
  33. .const
  34. WINDOW_WIDTH equ 800
  35. WINDOW_HEIGHT equ 600
  36. MYWIDTH equ 20
  37. MYHEIGHT equ 20
  38. RIGHT equ 1
  39. DOWN equ 2
  40. LEFT equ 3
  41. UP  equ 4
  42. STOP equ 5
  43. MAIN_TIMER_ID equ 0
  44.  
  45. .data
  46. PlayerX DWORD 400
  47. PlayerY DWORD 400
  48. DestX DWORD 80
  49. DestY DWORD 60
  50. ClassName DB "TheClass",0
  51. windowTitle DB "A Game!",0
  52. facing DWORD 5
  53.  
  54. .code
  55. BUILDRECT PROC, x:DWORD, y:DWORD, h:DWORD, w:DWORD, hdc:HDC, brush:HBRUSH
  56. LOCAL rectangle:RECT
  57. mov eax, x
  58. mov rectangle.left, eax
  59. add eax, w
  60. mov rectangle.right, eax
  61. mov eax, y
  62. mov rectangle.top, eax
  63. add eax, h
  64. mov rectangle.bottom, eax
  65. invoke FillRect, hdc, addr rectangle, brush
  66. ret
  67. BUILDRECT ENDP
  68.  
  69. ProjectWndProc PROC, hWnd:HWND, message:UINT, wParam:WPARAM, lParam:LPARAM
  70. local paint:PAINTSTRUCT
  71. local hdc:HDC
  72. local brushcolouring:HBRUSH
  73.     cmp wParam, VK_ESCAPE
  74.     je closing
  75.     cmp message, WM_PAINT
  76.     je painting
  77.     cmp message, WM_CLOSE
  78.     je closing
  79.     cmp message, WM_KEYDOWN
  80.     je movement
  81.     cmp message, WM_TIMER
  82.     je timing
  83.     jmp OtherInstances
  84. closing:
  85.     invoke ExitProcess, 0
  86. painting:
  87.     cmp facing, LEFT
  88.     je moveleft
  89.     cmp facing, RIGHT
  90.     je moveright
  91.     cmp facing, DOWN
  92.     je movedown
  93.     cmp facing, UP
  94.     je moveup
  95.     cmp facing, STOP
  96.     je notdead
  97.     jmp endmovement
  98. moveleft:
  99.     cmp PlayerX, WINDOW_WIDTH-WINDOW_WIDTH
  100.     jle endmovement
  101.     mov eax, PlayerX
  102.     sub eax, 5
  103.     mov DestX, eax
  104.     jmp endmovement
  105. moveright:
  106.     cmp PlayerX, WINDOW_WIDTH-MYWIDTH
  107.     jge endmovement
  108.     mov eax, PlayerX
  109.     add eax, 5
  110.     mov DestX, eax
  111.     jmp endmovement
  112. movedown:
  113.     cmp PlayerY, WINDOW_HEIGHT-MYHEIGHT
  114.     jge endmovement
  115.     mov eax, PlayerY
  116.     add eax, 5
  117.     mov DestY, eax
  118.     jmp endmovement
  119. moveup:
  120.     cmp PlayerY, WINDOW_HEIGHT-WINDOW_HEIGHT
  121.     jle endmovement
  122.     mov eax, PlayerY
  123.     sub eax, 5
  124.     mov DestY, eax
  125. endmovement:
  126.     invoke BeginPaint, hWnd, addr paint
  127.     mov hdc, eax
  128.     pusha
  129.     invoke GetPixel, hdc, DestX, DestY
  130.     cmp eax, 000000ffffffh
  131.     je notdead
  132.     cmp eax, 000000000000h
  133.     je notdead
  134.     ;cmp eax, 00000000ffffh
  135.     ;je notdead
  136. dead:
  137.     popa
  138.     jmp closing
  139. notdead:
  140.     popa
  141.     mov eax, DestX
  142.     mov PlayerX, eax
  143.     mov eax, DestY
  144.     mov PlayerY, eax
  145.     invoke GetStockObject, DC_BRUSH
  146.     mov brushcolouring, eax
  147.     invoke SelectObject, hdc, brushcolouring
  148.     invoke SetDCBrushColor, hdc, 00FFFFh
  149.     mov brushcolouring, eax
  150.     invoke BUILDRECT, PlayerX, PlayerY,  MYHEIGHT, MYWIDTH,  hdc,  brushcolouring
  151.     invoke EndPaint, hWnd, addr paint
  152.     ret
  153.  
  154. movement:
  155.     cmp wParam, VK_LEFT
  156.     je cleft
  157.     cmp wParam, VK_RIGHT
  158.     je cright
  159.     cmp wParam, VK_UP
  160.     je cup
  161.     cmp wParam, VK_DOWN
  162.     je cdown
  163.     jmp endc
  164. cleft:
  165.     mov eax, LEFT
  166.     mov facing, eax
  167.     mov eax, PlayerX
  168.     sub eax, MYWIDTH
  169.     mov DestX, eax
  170.     mov eax, PlayerY
  171.     mov DestY, eax
  172.     jmp endc
  173. cright:
  174.     mov eax, RIGHT
  175.     mov facing, eax
  176.     mov eax, PlayerX
  177.     add eax, MYWIDTH
  178.     mov DestX, eax
  179.     mov eax, PlayerY
  180.     mov DestY, eax
  181.     jmp endc
  182. cdown:
  183.     mov eax, DOWN
  184.     mov facing, eax
  185.     mov eax, PlayerY
  186.     add eax, MYHEIGHT
  187.     mov DestY, eax
  188.     mov eax, PlayerX
  189.     mov DestX, eax
  190.     jmp endc
  191. cup:
  192.     mov eax, UP
  193.     mov facing, eax
  194.     mov eax, PlayerY
  195.     sub eax, MYHEIGHT
  196.     mov DestY, eax
  197.     mov eax, PlayerX
  198.     mov DestX, eax
  199. endc:
  200.     ret
  201.  
  202. timing:
  203.     invoke InvalidateRect, hWnd, NULL, FALSE
  204.     ret
  205. OtherInstances:
  206.     invoke DefWindowProc, hWnd, message, wParam, lParam
  207.     ret
  208.  
  209. ProjectWndProc ENDP
  210.  
  211. main PROC
  212.  
  213. LOCAL wndcls:WNDCLASSA ; Class struct for the window
  214.  
  215. LOCAL hWnd:HWND ;Handle to the window
  216.  
  217. LOCAL msg:MSG
  218.  
  219. invoke RtlZeroMemory, addr wndcls, SIZEOF wndcls ;Empty the window class
  220.  
  221. mov eax, offset ClassName
  222.  
  223. mov wndcls.lpszClassName, eax ;Set the class name
  224.  
  225. invoke GetStockObject, BLACK_BRUSH
  226.  
  227. mov wndcls.hbrBackground, eax ;Set the background color as black
  228.  
  229. mov eax, ProjectWndProc
  230.  
  231. mov wndcls.lpfnWndProc, eax ;Set the procedure that handles the window messages
  232.  
  233. invoke RegisterClassA, addr wndcls ;Register the class
  234.  
  235. invoke CreateWindowExA, WS_EX_COMPOSITED, addr ClassName, addr windowTitle, WS_SYSMENU, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0 ;Create the window
  236.  
  237. mov hWnd, eax ;Save the handle
  238. invoke ShowWindow, eax, SW_SHOW ;Show it
  239.  
  240. invoke SetTimer, hWnd, MAIN_TIMER_ID, 20, NULL ;Set the repaint timer
  241.  
  242. msgLoop:
  243.  
  244. ;PeekMessage
  245. invoke GetMessage, addr msg, hWnd, 0, 0 ;Retrieve the messages from the window
  246.  
  247. invoke DispatchMessage, addr msg ;Dispatches a message to the window procedure
  248.  
  249. jmp msgLoop
  250.  
  251. invoke ExitProcess, 1
  252.  
  253. main ENDP
  254.  
  255. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement