Recent

Author Topic: Fairtris — a fair implementation of Classic Tetris®  (Read 36875 times)

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Fairtris — a fair implementation of Classic Tetris®
« on: September 08, 2021, 09:21:17 pm »
What is Fairtris?

Fairtris is a video game, a clone of the 32-year-old Tetris® game produced by Nintendo for the Famicom and NES consoles, designed for modern Windows systems. Fairtris is not an emulator — it is a full-fledged game, created from scratch in Free Pascal language and with OpenGL support via the SDL library. Thanks to this combination, it is super-fast and ultra-light. This project was initially created as a tool to test various RNG algorithms, but after some time it turned into a complete and rich video game that provides lots of fun.

You can download the game here — Fairtris 2.0.0.5 beta 2 (for Windows Vista, 7, 8, 8.1 and 10).

Also check out the project repository and the rich Fairtris wiki pages. If you want, you can also join a Discord server and take an active part in discussions and testing of the latest version of the game.


Important features:
  • implementation of gameplay mechanics compatible with the Nintendo Tetris® game,
  • extended mechanics with hard-drop and accumulation of soft-drop points,
  • support for EIGHT regional versions of the game, including original NTSC and PAL versions,
  • support for as many as SIX random piece generators, including the classic RNG,
  • the ability to start the game from any level up to the killscreen,
  • the ability to play on a keyboard or any USB controller (with input mapping support),
  • supports window mode and the low-resolution exclusive video mode,
  • support for additional meters, such as TRT, BRN or gain meter,
  • stores the best results for each game region and RNG type,
  • has a pause menu with the ability to quickly restart the game and change settings,
  • shows the game summary screen after each game,
  • support for two themes (minimalistic dark and classic skin),
  • possibility to use it with NestrisChamps and MaxoutClub,
  • it's light and very fast — should run smoothly even on a heavily loaded PC,
  • it is fully portable, no installation required,
  • and many more!

More detailed information on how to handle the game and its mechanics can be found on wiki pages. If you want, you can also check out the FAQ page where you will find answers to basic questions. Information on the license can be found in the LICENSE file. In short, it is entirely copylefted, so you can do what you want.

Considering the fact that the source code was not written from the beginning with the idea of creating a full-fledged game, its quality is not the best. It is true that I tried to write it so as not to get lost in it, but some things (especially menu operation) I solved using copy-paste. However, the most important thing is that the game works properly and, above all, very effectively.

If they are willing to test the current Windows version of the game, please give me some tests and feedback. If there is anyone here willing to fork the repository and prepare a port for Linux, FreeBSD, and macOS, I encourage you to do so. I'm not able to create them myself, because I don't know Linux and I don't have access to a device with macOS.

This game was created mainly to test various RNG algorithms and I didn't think about turning it into a full-fledged form, or about its continuous development. Therefore, please don't send pull requests to extend the game's functionality, only to fix bugs. If someone would like to port to other platforms, I suggest forking the repository and developing it separately. If it appears, I will put a link to the repository in the readme of my project.

So, have fun! 8)
« Last Edit: September 15, 2021, 11:23:48 pm by furious programming »
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

Seenkao

  • Hero Member
  • *****
  • Posts: 613
    • New ZenGL.
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #1 on: September 08, 2021, 11:34:33 pm »
Игре Тетрис уже 37 лет.

translate: The Tetris game is already 37 years old.  8-)
Tetris eng или Tetris rus
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #2 on: September 09, 2021, 12:15:46 am »
translate: The Tetris game is already 37 years old.  8-)

The first version for Electronika 60 computer was created in 1984, not for NES consoles.

By the way, the NES version was created in 1989, so it has 32 years old. So it needs to be corrected anyway.  8)
« Last Edit: September 10, 2021, 03:34:45 pm by furious programming »
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #3 on: September 15, 2021, 11:21:39 pm »
Will I have people willing to test the game here?

Would you like to join and create a port to other platforms? It doesn't require a lot of work — the core game mechanics and all menus are not platform specific. All you have to do is to remove the code for updating the button on the taskbar, make a few small corrections and just check how the game works on e.g. Linux or macOS. The game is based on the base classes and SDL, and this one is cross-platform. I can help if something is not understood.
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

Soner

  • Sr. Member
  • ****
  • Posts: 311
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #4 on: September 15, 2021, 11:40:57 pm »

nice.

When I press help button then screen resolution change and fairtress is very small image on the top left edge. Look picture 1.
And when I press help button again then fairtress is going to windowed mode. Look picture 2.

Lazarus 2.0.11, fpc 3.2.1 Win64.

Blade

  • Full Member
  • ***
  • Posts: 177
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #5 on: September 16, 2021, 12:31:38 am »

...If there is anyone here willing to fork the repository and prepare a port for Linux, FreeBSD, and macOS, I encourage you to do so. I'm not able to create them myself, because I don't know Linux and I don't have access to a device with macOS...

...If someone would like to port to other platforms, I suggest forking the repository and developing it separately...

When it comes to forking, I think it would be more interesting and something different, if someone could port it to iOS/iPhone.  In theory, it should be possible to use the SDL Library and the Free Pascal compiler.  This is an area where Free Pascal/Lazarus has very few examples, especially anything recent.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #6 on: September 16, 2021, 12:50:50 pm »
When I press help button then screen resolution change and fairtress is very small image on the top left edge. Look picture 1.

If you press the help button (i.e. F1 key) or select HELP from the main menu, the game window is minimized and the GitHub wiki opens in your browser. If video mode is active, after selecting HELP, video mode should be deactivated, resolution restored and the window minimized. It should look like the window shouldn't be visible, just a taskbar button.

The code that supports the help looks like this:

Code: Pascal  [Select][+][-]
  1. procedure TLogic.OpenHelp();
  2. begin
  3.   Sounds.PlaySound(SOUND_START);
  4.  
  5.   ShellExecute(0, 'open', 'https://github.com/furious-programming/fairtris/wiki', nil, nil, SW_SHOWNORMAL);
  6.   SDL_MinimizeWindow(Window.Window);
  7. end;

The last two instructions definitely need to be swapped, though on my computer the window always minimizes and restores properly. Although instead of minimizing the window, it is better to check if video mode is active and if so, turn on windowed mode, and if not, just open help in the browser (without any window manipulation). Video and windowed mode are quite hard to master. I'll try to fix it — thanks for tests.

How does the game behave after pressing F11? Video mode turns on and off well?


When it comes to forking, I think it would be more interesting and something different, if someone could port it to iOS/iPhone.

I can not see it. Even if technically possible, classic Tetris is too hard to play on a touchscreen. Note that, unlike modern, it doesn't support wall-kicks or sliding pieces when touch the stack. If the piece touches the stack, it's over — it sticks to it, and a new one appears at the top of the playing field. This is a clone of the console-only game, that's why today players only play it using the controllers (NES controllers and emulators on PC), and who doesn't have controller, play on a keyboard. Precise control is very important in this case, especially at levels 18+.

On the other hand, I've played modern Tetris for smartphones a couple of times and don't get it. I don't understand how anyone can play by touching the screen instead of pressing physical buttons. For me, the touch screen is not a device intended for gaming, it is useless on this topic. But that's just my opinion, I grew up on NES myself, I always played using the controllers, and as a last resort the keyboard. 8)
« Last Edit: January 07, 2022, 03:44:43 am by furious programming »
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

Soner

  • Sr. Member
  • ****
  • Posts: 311
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #7 on: September 16, 2021, 06:02:28 pm »
F11 ist okay, It does what it is supposed to do, switching windowed mode and fullscreen.
I put SDL_MinimizeWindow above ShellExecute. Now, when I press first help button it is working normal. But when I press it again then you can see black small window on the top left edge.

Maybe you should use OpenURL instead of ShellExecute when you want to release it on other systems than Windows.

If you are a fan of classic arcade games then check out this page.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #8 on: September 16, 2021, 09:08:09 pm »
I put SDL_MinimizeWindow above ShellExecute. Now, when I press first help button it is working normal. But when I press it again then you can see black small window on the top left edge.

Currently, there is no condition in the code to check if the video mode is active, or if the window is already minimized. This code must be secured anyway so that it doesn't try to minimize twice. But the window does not have to be minimized - it is enough to deactivate the video mode, because the browser should appear above the game window anyway.

I checked this, added a condition to disable video mode instead of minimizing, but the window appears in the top left corner of the screen instead of in the middle of it (or where it was before). Once again, there is a problem with setting the size and position of the window — SDL ignores these instructions and doesn't change anything, so the window is in a corner and has the wrong size.

Handling the help with modifications should look like this:

Code: Pascal  [Select][+][-]
  1. procedure TLogic.OpenHelp();
  2. begin
  3.   Sounds.PlaySound(SOUND_START);
  4.  
  5.   if Placement.VideoEnabled then
  6.     Placement.ToggleVideoMode();
  7.  
  8.   ShellExecute(0, 'open', 'https://github.com/furious-programming/fairtris/wiki', nil, nil, SW_SHOWNORMAL);
  9. end;

This works as it is supposed to, which is to disable video mode and open help in the browser. But damn it doesn't want to change the size and position of the window. It doesn't want to do this even though the Placement.ToggleVideoMode method is being used for the F11 key and always works fine. And here it does half the job.

ShellExecute is the problem here — when I comment it out, everything works fine. WTF.
« Last Edit: September 16, 2021, 09:09:56 pm by furious programming »
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #9 on: September 16, 2021, 09:20:50 pm »
Ok, I found a temporary solution — call ShellExecute in a separate thread. In this case, the video mode deactivates correctly, the window receives the correct dimensions and position, and the browser help opens. Stupid, but it works. So not stupid.

@Soner: if you have a minute, please test the fresh sources and let me know how it works now.
« Last Edit: September 16, 2021, 09:39:50 pm by furious programming »
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

Soner

  • Sr. Member
  • ****
  • Posts: 311
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #10 on: September 19, 2021, 09:25:19 am »
It is okay now. It is doing what you describe abow.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #11 on: September 19, 2021, 02:56:32 pm »
Ok, thank you very much for testing and feedback. Anyone else found any problems?
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #12 on: September 23, 2021, 05:47:43 pm »
New version available for download — Fairtris 2.0.0.6 beta 3

There were no big changes — only slight fixes for several menu screens, making it easier, for example, to resume and restart the game. I also changed the behavior after pressing the help button. Previously, the window would minimize and the browser help would open, but for some users, the window would not minimize properly when exclusive video mode was active. Therefore, I gave up minimization in favor of switching to windowed mode. I've also added code to open a specific wiki page based on the current scene, so you can get helpful information faster.
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #13 on: October 14, 2021, 06:16:12 pm »
The final, stable version has been released — Fairtris 2.0.0.7

Final and stable version, implementing all fixes and improvements from the three previous beta versions. The last modification is the rendering of the window just after waiting for the next frame, which better imitates the NMI of the NES console (get input, handle logic, wait for the interrupt and then display the image on the screen).

This release is designed for 64-bit Windows only (Vista, 7, 8, 8.1, 10 and further).

If there is anyone willing to port the project to platforms other than Windows, I still encourage you.

End of development

Fairtris was created mainly to test, in conditions similar to the original NES console, whether the classic Tetris® could be better by implementing a different and better RNG, as well as introducing changes to the gravity system in the PAL region. In one sentence, it allows you to check different variations of the same game and choose what's best for it. Considering the job is done, the development of this game is complete — all plans have been fully realized.

If there is ever a demand for a PC version to replace the NES consoles, the code for this project can be used to create a worthy successor. In this case, the only need will be to select one or invent fair but challenging RNG and select NTSC region (possibly additionally PAL, if players care about it), implement the correct transition calculation and avoid any bugs in the game mechanics that exist in the original.
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

flowCRANE

  • Hero Member
  • *****
  • Posts: 885
Re: Fairtris — a fair implementation of Classic Tetris®
« Reply #14 on: November 19, 2021, 09:41:27 pm »
I decided to break the compatibility with this Nintendo crap and fix the mechanics to create responsive controls. This will allow the player to focus entirely on stacking, rather than thinking about whether the DAS is charged or not (and if not, what to do to charge it). The original DAS is just as shitty as the controls in Prince of Persia — the player feels like pulling a charcoal cart rather than shifting small pieces.

The latest version is now available for download — Fairtris 2.2.0.1


Repaired DAS

In the original game, DAS is clunky to use, preventing smooth play at levels 19 and above, which effectively limits the player from maximizing scores. To keep the DAS charged, you need to use the "wall charge" frequently. But wall charge was implemented to make the tucks possible, and using it to load the DAS so you can move piece quickly is nothing more than exploit.

Therefore, I decided to fix this mechanism so that it does not hinder the player's gameplay. DAS works as in the original, but is additionally fully charged during the "entry delay" if the player is holding the left/right button. Since the player is holding the left/right button before a new piece spawns, it means the player want to move it as quickly as possible after spawning and should be able to do so.

This solution makes the controls responsive, but on the other hand, it is backward compatible — the basic technique of playing is still "skill stop", but thanks to the fix, "slow-tap" can be used without fear that it will not be possible to quickly move the next piece.


Spin buffering

In the original game, it is possible to make tucks in two ways — either by pressing the left/right button at the right moment (when the piece is on the desired row), or in advance (in a buffered manner). The second method makes it possible to "rub" the piece against a fragment of the stack, and in the first frame of the game, in which the piece is on the desired row, it is automatically slid into the slot. Unfortunately, in the case of spins, their buffering is not implemented.

In order to make the mechanics consistent and encourage the player to undertake advanced stacking techniques, spin buffering has been implemented. Thanks to this change, it is possible to press the rotation button a little earlier, and the piece will be rotated in the first frame in which it will be possible (similar to the case of tucks).


Wall kick

The original game has such poor control mechanics that a piece that is pushed against the stack frame cannot be rotated in certain configurations (because after rotation, a part of the piece would be outside the stack frame). This means that some spins, e.g. allowing you to burn a line in order to prepare for a tetris, are not available at all. For example — "S-spin" on the right edge is possible and often used, but not on the left, and would be very helpful.

In order to expand the spin pool and give the player more room for maneuver, a basic "wall kick" has been implemented.

However, the wall kick has been implemented in its basic form, i.e. the piece can only bounce off the walls of the stack and only changes its position horizontally. It is impossible to bounce off the contents of the stack, and the unrealistic, overcomplicated spins and twists, known from modern Tetrises, are also unavailable. Thanks to all of this, the controls are comfortable, intuitive and powerful, giving the player tons of possibilities, while maintaining the classic style (which is important in this case).


New RNG algorithm

The last thing added is a new generator — called BALANCED. This generator works very similar to the classic one, however, it prevents droughts by checking drought counters for each type of Tetrimino, and also prevents flooding by keeping a short spawn history.

The operation of this generator is similar to the classic one, but it is balanced in such a way as not to hinder the gameplay unfairly. The generated sequences are unpredictable, the distribution of pieces does not seek equality, which makes the game challenging. However, on the other hand, it does not prevent the player from stacking perfectly, although only a few (the best stackers in the world) will be able to get to the killscreen without burning a single line.

IMO, this is the best generator available in Fairtris.
Lazarus 3.6 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL.

 

TinyPortal © 2005-2018