Author Topic: Simple Game using three techniques  (Read 13356 times)

0000

  • Member
  • ****
  • Posts: 872
Simple Game using three techniques
« on: November 04, 2015, 09:33:25 AM »
Three versions of a simple game.

I call the game 4x4. The game is a 4x4 grid containing randomly
generated game pieces numbered from 1-15.

Object of the game is to rearrange them in sequence.

The original version used seperate windows for each bitmap used.
While this worked, it was rather clunky and added a lot of redundant code.

So I decided to strip down the program, rewriting the essential elements.

The result of the first rewrite is the console version. I tweaked each function
for size. Speed is not a big issue here but I felt the need to tweak some-
thing
. I decided to make the game as small as possible.

The next step was to remake a windows version. This time I tried my hand
at using BitBlt (and related functions). I had never used BitBlt, and device
contexts directly before so this was new for me.

Also I retweaked some of the functions used.

All versions use arrays where possible. Also in the BitBlt version, only one
string is used for the image paths. It is simply overwritten with the name
of the next image in the sequence, saving data space.

I rate these little experiments a success. The BitBlt version is not quite finished,
but it works as is and is completely playable. I intend on adding buttons for
'help', 'about', and 'exit' just as in the original version. I will be experimenting
using BitBlt with 'SetTimer' to acheive the button up/down simulation.





4x4 game     :icon_rolleyes:
« Last Edit: July 20, 2018, 04:19:25 AM by zedd151 »

TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: Simple Game using three techniques
« Reply #1 on: November 04, 2015, 08:52:31 PM »
The code need to be rewrite
There is many proc who don't preserve esi edi ebx register.

start:      must be followed by an invoke WinMain (add uses esi edi ebx)
The assume directive isn't followed by assume Nothing
There is no tab use to show the If endif .
With no surprise,he don't work for me
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 11551
  • Assembler is fun ;-)
    • MasmBasic
Re: Simple Game using three techniques
« Reply #2 on: November 04, 2015, 11:02:46 PM »
Tested the win32 version, and it works like a charm on Win7-64 :t

The painting proc uses non-volatile regs and should preserve them:

    painting proc uses esi edi ebx hWin:dword


This is relevant only for callback functions, but painting gets called by one: WndProc, so the rules say you must preserve them.

caballero

  • Member
  • *****
  • Posts: 1616
  • Matrix - Noah
    • abre ojos ensamblador
Re: Simple Game using three techniques
« Reply #3 on: November 05, 2015, 12:56:26 AM »
Doesn't work for me neither :(.
[...] Nevertheless it seems to be a nice game, thank you for the code.
Regards
The logic of the error is hidden among the most unexpected lines of the program

0000

  • Member
  • ****
  • Posts: 872
Re: Simple Game using three techniques
« Reply #4 on: November 05, 2015, 02:05:40 AM »
oops my bad. I posted the prototype version of 4x4 win32

here is the final version...

And it is also commented. :)


4x4 game
« Last Edit: July 20, 2018, 04:20:26 AM by zedd151 »

Siekmanski

  • Member
  • *****
  • Posts: 2365
Re: Simple Game using three techniques
« Reply #5 on: November 05, 2015, 02:19:11 AM »
Nice, it's working now. ( windows 8.1 )
Creative coders use backward thinking techniques as a strategy.

caballero

  • Member
  • *****
  • Posts: 1616
  • Matrix - Noah
    • abre ojos ensamblador
Re: Simple Game using three techniques
« Reply #6 on: November 05, 2015, 02:26:39 AM »
Aha! Much better now :t. Very nice. Only a few things:

* If you click on a button, quit the region, and release the mouse button, the button remains pressed
* Still use many magic numbers
* Not possible to move the window anywhere

Regards
The logic of the error is hidden among the most unexpected lines of the program

0000

  • Member
  • ****
  • Posts: 872
Re: Simple Game using three techniques
« Reply #7 on: November 05, 2015, 02:32:49 AM »
 :dazzled:

Yes, still a little work to be done. But as it is my first attempt at using BitBlt and company,
I think it turned out fairly well.

But will look into the few remaining bugs.

0000

  • Member
  • ****
  • Posts: 872
Re: Simple Game using three techniques
« Reply #8 on: November 05, 2015, 03:37:31 AM »
* If you click on a button, quit the region, and release the mouse button, the button remains pressed
Simple don't wander away from the button prior to releasing it. :P Or even better, be sure you really want to press a button.  :lol:

No, seriously I had foregone the use of GetCapture and ReleaseCapture to save some
code. One of my goals was to make the game as small as possible.

Quote
* Still use many magic numbers
nothing magical here ...

Quote
* Not possible to move the window anywhere

Can't please everyone.


TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: Simple Game using three techniques
« Reply #9 on: November 05, 2015, 04:57:19 AM »

Much better now Windows,seems there is still some preserve error and too many
        ;invoke painting, hWin                   ; update current window state
help and about buttons don't work
Fa is a musical note to play with CL

0000

  • Member
  • ****
  • Posts: 872
Re: Simple Game using three techniques
« Reply #10 on: November 05, 2015, 05:02:01 AM »
help and about buttons don't work

What version of windows are you running?

I only have XP here and cannot test it myself on other platforms.


TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: Simple Game using three techniques
« Reply #11 on: November 05, 2015, 05:12:51 AM »

I have Windows 10
You don't use the WM_COMMAND message.
It's the better way with the handle of the button to use it.

   .elseif uMsg == WM_COMMAND
      HIWORD wParam,edx   ;controls events
      LOWORD wParam,eax   ;ID of command
      mov ebx,lParam   ; handle du controle
      
Fa is a musical note to play with CL

TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: Simple Game using three techniques
« Reply #12 on: November 05, 2015, 07:59:39 PM »

Found the reason of the trouble.
I have made some usual modifies and get this curious effect.
The reason is that the normal paint message is never call.
It's for that there is  need of the DefWindowProc after each message.
Just add the normal beginpaint and there is no need to recall the defwindowProc for each message
Win of time.

Quote
                Local:retour
                mov retour,0
                .if uMsg ...
                .
                 .
      .elseif uMsg == WM_PAINT
         invoke painting, hWin                       ; update window display
         .if wParam == 0      
            invoke BeginPaint,hWin,ADDR Ps     
            ;mov hdc, eax
            invoke EndPaint,hWin,ADDR Ps
         .endif         
      .elseif uMsg == WM_CLOSE
         invoke GlobalFree, hlptxt
         invoke GlobalFree, abttxt
         invoke PostQuitMessage, NULL
      .else
         invoke DefWindowProc, hWin, uMsg, wParam, lParam
         mov retour,eax
      .endif
      mov eax,retour
Fa is a musical note to play with CL

FORTRANS

  • Member
  • *****
  • Posts: 1109
Re: Simple Game using three techniques
« Reply #13 on: November 06, 2015, 01:12:42 AM »
Hi,

   Blank blue rectangle on Windows 2000 and Windows XP.  Alt-F4
does close it.

Regards,

Steve N.

TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: Simple Game using three techniques
« Reply #14 on: November 06, 2015, 01:58:08 AM »
Quote
Blank blue rectangle on Windows 2000 and Windows XP.  Alt-F4
does close it.

Must search the bmp file (pix\*.bmp), they are not in the resource.
Fa is a musical note to play with CL