Bloxed - A tetris game

Discussions related to graphics (2D and 3D), animation and games programming
jgroenendaal
Posts: 23
Joined: Fri 15 Nov 2024, 14:40

Re: Bloxed - A tetris game

Post by jgroenendaal »

Richard Russell wrote: Wed 15 Jan 2025, 09:27 o illustrate how fast it is, here's an animated version:
Thank you.
Yes. It is! It's running very smooth.
I managed to re-write my routines, only using GFXLib and not pre GFXLib examples.
My original try took 556 TIME to change 10 images and my rewrite approach took 194 TIME for the same images.
And yes, that's what I believe is the fastest I can get, most time is spent on converting the JPEG images.
And you're demo believes I even didn't need to do any pre-calculation of the blur, either!

Your example also shows another thing that I pesonally really like, the gfxBoxBlurNxN you did in the example much more than the GaussianBlur3x3 I used.

Thank you for this example.
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Bloxed - A tetris game

Post by Richard Russell »

jgroenendaal wrote: Wed 15 Jan 2025, 18:07 Your example also shows another thing that I pessonally really like, the gfxBoxBlurNxN you did in the example much more than the GaussianBlur3x3 I used.
Actually I used both (see code below) but I don't think the Gaussian Blur added much. The Box Blur can do a lot of blurring very quickly, but it's not at all realistic because in the real world the aperture won't be square! So if a realistic blur is important the Box Blur doesn't fit the bill.

Of course if you have the luxury of doing the blurring accurately, but slowly, offline (using Photoshop or similar), which you probably do in this case, the resulting quality will be better. But sometimes it has to be done in real time and compromises are necessary.

Code: Select all

      VDU 23,22,720;720;8,16,16,0

      INSTALL @lib$ + "aagfxlib"
      INSTALL @lib$ + "gfxlib"
      PROC_gfxInit

      REM Load original texture (e.g. 3000 x 2000)
      dice%% = FN_gfxLoadTexture(@dir$ + "virtual.jpg", FALSE)

      REM Define mask:
      DIM x(12), y(12)
      x() = 400, 1040, 1040,  930,  930, 1040, 1040,  400,  400,  510,  510,  400, 400
      y() = 100,  100, 1060, 1060, 1110, 1110, 1340, 1340, 1110, 1110, 1060, 1060, 100

      REM Blur:
      PROC_gfxPlotScale(dice%%, 1080, 720, -180, 0)
      PROC_gfxGaussianBlur3x3(720, 720, 0, 0)
      PROC_gfxBoxBlurNxN(720, 720, 0, 0, 32)

      REM Copy blurred image to texture:
      blur%% = FN_gfxCreateTexture(720, 720)
      PROC_gfxCopy(blur%%, 720, 720, 0, 0)

      REM Mask blurred image::
      mask%% = FN_gfxCreateTexture(720, 720)
      PROC_gfxSaveAndSetDispVars(g{}, mask%%)
      PROC_aapolygon(12, x(), y(), &FF000000)
      PROC_gfxReversePlotScale(blur%%, 720, 720, 0, 0)
      PROC_gfxRestoreDispVars(g{})

      REM Combine and add border:
      PROC_gfxPlotScale(dice%%, 1080, 720, -180, 0)
      PROC_gfxPlotScale(mask%%, 720, 720, 0, 0)
      PROC_aapolyline(13, x(), y(), 4, &FFB0B0B0, 0)

      REM Destroy temporary textures:
      PROC_gfxDestroyTexture(blur%%)
      PROC_gfxDestroyTexture(mask%%)
jgroenendaal
Posts: 23
Joined: Fri 15 Nov 2024, 14:40

Re: Bloxed - A tetris game

Post by jgroenendaal »

It are some crazy weeks at my work, so I had less time to work on my game.
But I think I am in the final steps....
I got some music, AI generated one. My son complains it sounds like it's a AI generated. So maybe I will catch up via via if I can get a more proper background song.

Beside that, the drawing routines for the background are now I think mostly optimized thanks to the code of Richard.

I wrote some PHP that will handle the online hiscore mechanism, including some custom made encryption.

It's always amazing that the actual Tetris type of game is coded within a few days, it's all the rest it's the most of the coding and finetuning progress.
Because I want to have this project more widely playable ( e.g. Joysticks / touch screens ) I also need to make some different ways of input of names.
With the minimal lines of code, I think my virtual keyboard looks good enough.
The virtual keyboard can be used with touch screen or joystick beside the traditional keyboard input.
Image
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Bloxed - A tetris game

Post by Richard Russell »

jgroenendaal wrote: Wed 29 Jan 2025, 18:13 Beside that, the drawing routines for the background are now I think mostly optimized thanks to the code of Richard.
I look forward to trying it.
jgroenendaal
Posts: 23
Joined: Fri 15 Nov 2024, 14:40

Re: Bloxed - A tetris game

Post by jgroenendaal »

Hello all,

I created a newer version of Bloxed.
I just discovered this version can not run completely online.
I gives on error on reading the online stores hiscore table.
https://wasm.bbcbasic.net/bbcsdl.html?a ... bloxed.bbb

Though, I copied the knowledge from Vapiki, I probably missing something. But I do not have a clue why it isn't working.
... if it could work. Maybe I should go to an offline hiscore, perhaps it's better.

You can also download as an Windows executable.
Windows Executable file

This version included a different font.
The previous font had some dancing in the scaled down variants of the font and I discovered that back in 2015 I recreated them by scaling every single character to 6%7, 50%, or lower percentages, but with dynamic width and heigh they would have a different ratio per letter, making it not possible to fix it properly.

I think the new font fits the game better anyway.
Luckily all the tooling I used to convert a PNG to 32 bitmap to my own Gesprite format still exists and is working ( in BBC Basic for Windows ).
Anyway, for future games I really like to do with PNG sprite sheets like ( https://www.codeandweb.com/free-sprite-sheet-packer ) to have the ability to put multiple PNG files into one. Some output formats are also widely accepted by other pixel gaming platform tools.

The game also have a new background song.
I still like to do some caching of the background sprites by saving the SDL Background image to a memory dump - this allows me to load the bitmaps in blocks in the background during gameplay - not sure if this is possible, but I think I could do that some way.

As most features are now finished ... the game is almost ready for a first release!
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Bloxed - A tetris game

Post by Richard Russell »

jgroenendaal wrote: Mon 10 Feb 2025, 21:08 But I do not have a clue why it isn't working.
Any attempt to access an online resource, such as a hiscore table, is bound to fail when running in a browser unless you've set up a websockets server. Browsers don't provide access to conventional TCP/IP sockets, only to websockets.

Another approach, specific to running in a browser, might be to run some JavaScript code from your BASIC program, if what you want to do can be achieved with JavaScript.
The previous font had some dancing in the scaled down variants of the font
Sounds like aliasing. Fonts should be anti-aliased for best results (ideally everything should be anti-aliased!).
As most features are now finished ... the game is almost ready for a first release!
Excellent.
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Bloxed - A tetris game

Post by Richard Russell »

Richard Russell wrote: Mon 10 Feb 2025, 21:23 Any attempt to access an online resource, such as a hiscore table, is bound to fail when running in a browser unless you've set up a websockets server.
I know of two Websockets-to-TCP bridge applications: Websockify and Web2Tcp. You might be interested in investigating one or other of those as a way to make your hiscore table work when running in a browser.
jgroenendaal
Posts: 23
Joined: Fri 15 Nov 2024, 14:40

Re: Bloxed - A tetris game

Post by jgroenendaal »

Richard, thank you for you recommendations.
Currently it's all hosted via one.com, which is very limited.

There are some free web socket services around, but reading from forums the experience is not very positive.
As I have zero experience with this services, I will skip the online hiscore table.
jgroenendaal
Posts: 23
Joined: Fri 15 Nov 2024, 14:40

Re: Bloxed - A tetris game

Post by jgroenendaal »

Hello all,

There it is. The final beta version.
The initial version will be released in a couple of days via itch.io and my own website,
https://wasm.bbcbasic.net/bbcsdl.html?a ... bloxed.bbb


The game is now fully playable with joystick, keyboard and touch screen.

I planned to make a separate version of Android which will have a slightly different gameplay, later on.
The final version will probably hold different backgrounds than the current selection, and I forgot to add credits after the help sequence.
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Bloxed - A tetris game

Post by Richard Russell »

jgroenendaal wrote: Wed 19 Feb 2025, 21:09 There it is. The final beta version.
It's beautiful, well done!

A couple of minor things I spotted:
  1. There's no 'Go back' selection on the High Scores page, I had to guess what to do to get back to the front page.
  2. The 'hot spots' for clicking on the menu items are offset vertically. It's easy to select the item above the one you want.
Hopefully these are easy to fix.