Recent

Author Topic: Puzzle! is a puzzle game using BGRABitmap  (Read 12761 times)

lainz

  • Guest
Puzzle! is a puzzle game using BGRABitmap
« on: December 28, 2012, 06:24:25 pm »
Who's that:
Puzzle! is a simple puzzle game that uses BGRABitmap to draw their minimalist style.. but you can easily edit the code to use image files or all the power of BGRABitmap.

How to play:
The objetive of the game is move the blocks to get them in growing order and put the empty block at the finish of the map.

You can move the blocks with the keyboard arrows and the keys w,s,a,d. Also you can move the blocks clicking with the lb mouse.

You can move only a block that is next to the empty block horizontally or vertically.

Other:

The map's i've added are 2x1 and 2x2, really easy game.. but you can add other map sizes.

I'm not good in math, so I've no idea how to calculate all possible playable maps, only i've seen that from the whole possibilities (in 2! 3! and 4!) only 1/2 are playable with the rules of the game.

Download: https://sourceforge.net/projects/lainz007/files/

puzzle.7z is a Windows executable
puzzle_source.7z is the source, you need BGRABitmap and BGRAControls. (btw: you can edit the code and use Lazarus factory drawing..).

LGPL, Author: me.

Also there is attached the source code and a screenshot of the game.
« Last Edit: December 30, 2012, 03:43:47 am by lainz »

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #1 on: December 28, 2012, 06:41:31 pm »
Interesting.

Well, I would suggest you to compute levels :
- first you set the level with its solved state (1234... up to n²-1)
- then you solve it using something like n² moves

So levels will always be solvable, and you can make them grow as much as you want.
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #2 on: December 28, 2012, 06:49:05 pm »
Damn, you really have nothing to do. Just kidding ;) . Great that you share new experiences with BGRABitmap. You should post it on bgrabitmap wiki tutorial. The best learning examples are working applications.
Now I'm angry that I'm delaying with new version of BGRA Controls. I'm working on something important now, so I don't have time, but this project bring new BGRA package ;)

lainz

  • Guest
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #3 on: December 28, 2012, 10:24:30 pm »
Thanks for your feedback, I'll try to generate the levels in that way, also I'll reuse the code to create other kind of games.

I'm learning more programming thanks to a child website  ::) their tutorials are really good http://www.pp4s.co.uk/

I get inspired by a pokemon game in their site.

About BGRAControls, I've not much time too.. I've started but not finished the BCImageButton, and I think that is just ok, not much optimized as I wish, btw It works and the code is more easy to understand and modify..

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #4 on: December 29, 2012, 11:42:06 am »
Hello Lainz,

Here is a modified version that has phong drawn blocks
« Last Edit: December 29, 2012, 11:44:37 am by circular »
Conscience is the debugger of the mind

lainz

  • Guest
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #5 on: December 29, 2012, 05:44:18 pm »
Amazing graphics!

Here another update move with joystick (D-Pad and Left Stick,... at least with an X-Box 360 joy works fine, the D-Pad works perfectly, the Left Stick requires that you move the stick to the extreme, I must set another range that the min and max...).

Code: [Select]
uses
...
{$IFDEF WINDOWS},
  mmsystem{$ENDIF};   

...

var
  // controls
  L1, R1, U1, D1, L2, R2, U2, D2: word;               

...

procedure TForm1.FormCreate(Sender: TObject);
begin
  L1 := VK_LEFT;
  R1 := VK_RIGHT;
  U1 := VK_UP;
  D1 := VK_DOWN;
  L2 := VK_A;
  R2 := VK_D;
  U2 := VK_W;
  D2 := VK_S;   

...

procedure TForm1.Timer1Timer(Sender: TObject);
var
  ...
  {$IFDEF WINDOWS}
  myJoy: TJoyInfoEx;
  myJoyCaps: TJoyCaps;
  ErrorResultC, ErrorResultP: MMRESULT;
  {$ENDIF}
begin
  {$IFDEF WINDOWS}
  ErrorResultC := joyGetDevCaps(joystickid1, @myJoyCaps, sizeof(myJoyCaps));
  ErrorResultP := joyGetPosEx(joystickid1, @MyJoy);
  if (ErrorResultC = JOYERR_NOERROR) and (ErrorResultP = JOYERR_NOERROR) then
  begin
    if (myJoy.dwPOV = JOY_POVFORWARD) or (myJoy.wYpos = myJoyCaps.wYmin) then
      FormKeyDown(nil, U1, [])
    else if (myJoy.dwPOV = JOY_POVBACKWARD) or (myJoy.wYpos = myJoyCaps.wYmax) then
      FormKeyDown(nil, D1, [])
    else if (myJoy.dwPOV = JOY_POVLEFT) or (myJoy.wXpos = myJoyCaps.wXmin) then
      FormKeyDown(nil, L1, [])
    else if (myJoy.dwPOV = JOY_POVRIGHT) or (myJoy.wXpos = myJoyCaps.wXmax) then
      FormKeyDown(nil, R1, []);
  end;
  {$ENDIF}
                                   

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #6 on: December 29, 2012, 10:25:24 pm »
I have no joystick so I cannot test this.  :-\
Conscience is the debugger of the mind

lainz

  • Guest
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #7 on: December 29, 2012, 10:42:30 pm »
Oh you need one to play your favorite retro games ;)

eny

  • Hero Member
  • *****
  • Posts: 1665
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #8 on: December 29, 2012, 10:43:38 pm »
I have no joystick so I cannot test this.  :-\
Working with my SideWinder ;)
I would simplify the code though and not introduce all these local variables:
Code: [Select]
procedure TForm1.Timer1Timer(Sender: TObject);

  {$IFDEF WINDOWS}
  procedure JoyDown(const pKey: word);
  var Key: word;
  begin
    Key := pKey;
    FormKeyDown(nil, Key, [])
  end;
  {$ENDIF}     

...
     if (myJoy.dwPOV = JOY_POVFORWARD) or (myJoy.wYpos = myJoyCaps.wYmin) then
       JoyDown(U1)
     else if (myJoy.dwPOV = JOY_POVBACKWARD) or (myJoy.wYpos = myJoyCaps.wYmax) then
       JoyDown(D1)
     else if (myJoy.dwPOV = JOY_POVLEFT) or (myJoy.wXpos = myJoyCaps.wXmin) then
       JoyDown(L1)
     else if (myJoy.dwPOV = JOY_POVRIGHT) or (myJoy.wXpos = myJoyCaps.wXmax) then
       JoyDown(R1)
All posts based on: Win11; stable Lazarus 4_4  (x64) 2026-02-12 (unless specified otherwise...)

lainz

  • Guest
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #9 on: December 30, 2012, 03:42:58 am »
Thanks =)

Well I've added 'Level 13' (i've played this about 4~5 minutes the first time, i'm not good in this game, lol, the second time takes me less than 30 seconds)and the joystick in this source. I'll add more things later.

Thanks circular and eny for your code!

It would be good to add to bgracontrols or bgrabitmap as example?
« Last Edit: December 30, 2012, 04:03:11 am by lainz »

eny

  • Hero Member
  • *****
  • Posts: 1665
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #10 on: December 30, 2012, 12:05:40 pm »
A nice addition would be a sliding effect, that you see a piece smoothly slide into place  8)
All posts based on: Win11; stable Lazarus 4_4  (x64) 2026-02-12 (unless specified otherwise...)

lainz

  • Guest
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #11 on: December 30, 2012, 06:32:19 pm »
That would be nice...
At this time I've added a sound effect when you do a move (Windows only, but if you know how to use you can use SDL that comes with Lazarus and support more OS's) and FullScreen.

Fullscreen works:
- Stretch or proportional, so you can use or override the blockW and blockH aspect ratio.
- Centered or not.
(Any combination of Stretch, Center and Proportional).

FullScreen ToDo:
- CreateMetalFloorTexture doesn't works, at least tested in the Level1.
- If you rotate your monitor 90° or 270º you need to restart the game to apply the scaling to fullscreen... 180º works =)
- If you press F11 isn't restored to a Windowed format according to aspect ratio settings...

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #12 on: December 30, 2012, 09:35:19 pm »
Cool. With such big blocks, you need to use :
Code: [Select]
  tile3D := CreateRectanglePreciseMap(map.BlockW, map.BlockH, h, []);
Conscience is the debugger of the mind

lainz

  • Guest
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #13 on: December 31, 2012, 02:50:59 am »
Oh now I see that it keeps the quality.

I've added the game source in BGRAControls SVN to be available for all BGRA users.

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Puzzle! is a puzzle game using BGRABitmap
« Reply #14 on: January 01, 2013, 03:20:38 pm »
Good idea
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018