News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

WIP - (Connect 4)

Started by zedd151, April 05, 2025, 02:44:20 PM

Previous topic - Next topic

zedd151

#30
Replaced the clunky code for the background and foreground painting...

        .elseif uMsg == WM_PAINT
          invoke BeginPaint, hWin, addr ps
          mov hDC, eax
          invoke GetClientRect, hWin, addr rct
          invoke CreateCompatibleDC, hDC
          mov mDC, eax
          invoke CreateCompatibleBitmap, hDC, rct.right, rct.bottom
          mov hBmp, eax
          invoke SelectObject, mDC, hBmp
          mov hBmp_old, eax
         
          invoke drawback, hWin, mDC
          invoke drawanim, hWin, mDC
          invoke drawboard, hWin, mDC
          invoke drawfore, hWin, mDC
         
          invoke BitBlt, hDC, 0, 0, rct.right, rct.bottom, mDC, 0, 0, SRCCOPY
          invoke SelectObject, mDC, hBmp_old
          invoke DeleteObject, hBmp
          invoke DeleteDC, mDC
          invoke EndPaint, hWin, addr ps

drawback procedure to draw the background, and drawfore procedure to draw the foreground
    drawback proc hWin:dword, mDC:dword
    local pDC:dword, rct:RECT, hBrush:dword, hBmp1:dword, hBmp_old1:dword
        invoke CreateCompatibleDC, mDC
        mov pDC, eax
        invoke GetClientRect, hWin, addr rct
        invoke CreateCompatibleBitmap, mDC, rct.right, rct.bottom
        mov hBmp1, eax
        invoke CreateSolidBrush, 00FF7F3Fh
        mov hBrush, eax
        invoke FillRect, mDC, addr rct, hBrush
        invoke DeleteObject, hBrush
        invoke SelectObject, pDC, hBack
        invoke StretchBlt, mDC, 40, 40, 560, 560, pDC, 0, 0, 1, 1, SRCCOPY
        invoke SelectObject, pDC, hBmp_old1
        invoke DeleteObject, hBmp1
        invoke DeleteDC, pDC
        ret
    drawback endp

    foreblit proc mDC:dword, xx:dword, yy:dword, pDC:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        mov eax, 80
        xor ecx, ecx
        invoke TransparentBlt, mDC, xx, yy, eax, eax, pDC, ecx, ecx, eax, eax, 00FF00FFh
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    foreblit endp

    drawfore proc hWin:dword, mDC:dword
    local pDC:dword, rct:RECT, hBrush:dword, hBmp1:dword, hBmp_old1:dword
        push esi
        push edi
        push ebx
        push edx
        push ecx
        invoke CreateCompatibleDC, mDC
        mov pDC, eax
        invoke GetClientRect, hWin, addr rct
        invoke CreateCompatibleBitmap, mDC, rct.right, rct.bottom
        mov hBmp1, eax
        invoke SelectObject, pDC, hBmp1
        mov hBmp_old1, eax
        invoke SelectObject, pDC, hFore
        lea esi, x1
        lea edi, y2
        xor edx, edx
      top1:
        xor ecx, ecx
      @@:
        mov eax, [esi+ecx*4]
        mov ebx, [edi+edx*4]
        invoke foreblit, mDC, eax, ebx, pDC
        inc ecx
        cmp ecx, 7
        jb @b
        inc edx
        cmp edx, 6
        jnz top1
        invoke SelectObject, pDC, hBmp_old1
        invoke DeleteObject, hBmp1
        invoke DeleteDC, pDC
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    drawfore endp

Had some issues when trying to only use FillRect to fill - first the client area of the dialog box - then fill the game background after adjusting the RECT structure. The results were not good. I checked and rechecked the RECT structure dimensions, used GetClientRect to refill the RECT structure with the client rectangle for subsequent blitting operations... to no avail. Wasted at least an hour...

In order to not waste any more time, I opted to shrink the bitmap previously used from 80x80 to 1x1 and used StretchBlt to fill the desired rectangle (game board background) with that instead. Weird.

I am pretty certain I had drawn rectangles on top of previously drawn rectangles before in an unrelated project.

executable only, in the attachment

zedd151

#31
I have cleaned up the rest of the previously untidy WM_PAINT related code.  :biggrin:

Commenting still a bit sparse for now, trying to get the rest of the code tidied up a first, and ready for the masses.  :tongue: 

Next: Is to make the WM_TIMER and WM_LBUTTONUP code somewhat cleaner and easier to follow.

Source code included in the attachment below.


zedd151

A little more cleanup in the source, moving code out of WM_TIMER into a seperate procedure, as well as moving code out of WM_LBUTTONUP into a separate procedure as well. Added some more commenting. Removed some unnecessary code.

I will rewrite the code for the timers and left mouse clicks at some point, as time permits. Although that code works as expected as is, it is lengthy and rather cumbersome.

zedd151

I will be integrating slick new graphics into the program, if there are no issues with the proposed code.


There is a demo here of how it will look when animating...  :eusa_dance:

zedd151

New example using the nice png graphics.

As before left click for red piece, right click for blue.

Let me know of any issues with the new graphics, i.e., flickering, etc. During my own testing, I had not encountered any issues thus far. I should be able to finish up the game very soon, indeed.  :eusa_dance:

jj2007


zedd151

While I cannot guarantee it will happen, I plan on finishing the code to the extent that the game will be playable by the end of this coming weekend.

There will undoubtedly still be bits of code that need some reworking (the overly lengthy code for the left mouse button and the timers - both could use loops to minimize the code, for instance).

But as I have other projects that I would like to get to, I really want to get this game finished to a playable state.  :smiley:  Even if that means putting off some improvements to the game graphics and image loading, and other misc. items. I can always revisit those changes at a later time.

So much to do... So little time...  :eusa_boohoo: