Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Pentris - a Tetris clone

by Crian (Curate)
on Aug 23, 2004 at 11:45 UTC ( [id://385060] : sourcecode . print w/replies, xml ) Need Help??
Category: Fun Stuff
Author/Contact Info Crian
Description: is a rewritten Tetris clone I wrote 1993 in Fortran 77

I used Perl/Tk this time, the Version 0.0.2 I show in here is the work of one weekend.

A webpage for Pentris can be found here: (it is a german page)

I put the code under the licenses of perl itself, see pod.

The comments and variables in my program are in english, only very few comments are in german, I will translate them later.

UPDATE: Version 0.0.3 is online, that one has a parameter 'nogrid' that disables the grid.

UPDATE: Version 0.0.4 is online, now you can switch the grid on/off via F3 (and via Menu) even while you are playing.
sorry, it fails to fill in the code here, get it from here:

(its too long to fit in here)
Replies are listed 'Best First'.
Re: Pentris - a Tetris clone
by tachyon (Chancellor) on Aug 23, 2004 at 12:29 UTC

    Very nice. A couple of comments. Default height is too large for my monitor (1152x864) so I guess you must run 1280x1024+....

    I did not like the grid. Having had a quick RTFS I changed withgrid => 1 to zero. This has multiple effects, but in short it does not remove the grid and it does destroy the geometry. If you just add a return in the draw_grid() function if withdgrid => 0 then you can lose the grid but see the undesirable side effects on the geometry (rotating the blocks is interesting). The easiest way to remove the grid (and retain the geometry) is simply to make it the same as the board colour.

    my $gridcolor = $NO_GRID ? '#000000' : '#FFFFFF';

    The grid still gets drawn but is invisible, and all the withgrid code is redundant and can be removed. That saves fixing it ;-) I like the grid through the blocks anyway as it looks as I remember tetris looking.



Re: Pentris - a Tetris clone
by tachyon (Chancellor) on Aug 23, 2004 at 14:12 UTC

    I have patched the code to toggle the grid and added it to the menu. Most of the text is now in English as well. A couple of notes:

    1. Most of your functions take args $mw,$fld,$width,$height,$C{rows},$C{cols},$C{rowpix},$C{colpix} - passing these as an object or just in the %C hash would make sense - they are all effectively constants AFAIK.
    2. You have lots of code that essentially does just this: die "function X did not get Y arguments!\n" unless @_ == Y except you are using unless .... and .... and .... and ....

    Here is the code (sorry to get it to fit within the space that PM allows I had to strip the comments out)

Re: Pentris - a Tetris clone
by Crian (Curate) on Aug 24, 2004 at 14:40 UTC
    Yes, the possibility to switch the grid on and off is (or was) not completed, the withgrid value only was a preparation for doing so.

    Could you please send me the diff to the original (to crian AT duehl DOT de), because I worked at the code for myself since my last post here, then I can put your changes into it. And perhaps I could add a language option to the menue as well.

    Many thanks for enabling that option, I just had lost it out of my mind =)

    "Default height is too large for my monitor (1152x864) so I guess you must run 1280x1024+" Yes right, I wrote in the history window how to change it, but in german. Just lower the values of 'colpix' and 'rowpix' in the global hash %C at top of the code.

    Perhaps I should add a possibility to change this out of the menue.

    UPDATE: I changed the calculations myself, so that the grid can be switched on and off. Per default grid is on, if you start the game with the parameter 'nogrid', the grid will disappear.

    Perhaps I add a switch in the menu too, but therefor i would have to start the program all over again, because the game field is shown already at that time.

    I will upload the code later this evening (it's not possible at the moment) and update the link above.

    UPDATE: I wrote a menue entry that toggled the grid and a function to toggle it at every moment, but it is buggy at the moment and i comment out the Menue entry and the binding. Perhaps I can add it later, but I hav no more time at the moment.

    UPDATE: Now I changed the hole program in the way, that I don't move the Informations around from function to function. I use a global configuration hash now. That made things much easier, and now the grid toggle works even during the game. You can now (in version 0.0.4) toggle the grid with the key F3 all the time.

    I am sorry, but I can not upload the script now, but perhaps it fits in the window, because the code is a good piece smaller by this changes. If not, it will be available this evening (I will update the first post then.)

    UPDATE: Now I uploaded the program in Version 0.0.4, have fun :-)