pygame is
Simple DirectMedia Layer is
Site Swing
Falling Tetrominos

Falling Tetrominos - 0.3

Nicholas Crafford (nicklt77)



A simple Tetris clone written while on vacation.


Some fixes to help Python 2.4 Compatability. Still needs a major fixen'.


Home Page:
Source: svn checkout python-pygame-tetris-read-only


click to view original size


Falling Tetrominos - 0.3 - Jul 11, 2008
Falling Tetrominos - 0.2 - Jul 5, 2008
Falling Tetrominos - 0.1 - Jul 5, 2008 account Comments

If you wish to leave a comment with your account, please sign in first.

July 12, 2008 10:25am - Jordan Trudgett - nickname: (tgfcoder)
Vitor: for some odd reason, whenever I use the clock.tick() method of controlling the game time, it becomes really slow and inconsistent (whilst using as much CPU as it can) I'm sure it works for some people, and perhaps I was just using it wrong somehow (it was a while back, my first attempts with pygame) but it made games impossible to make with for me, so I stuck to time.sleep(time_in_seconds). Hopefully time.sleep can wait thousandths of seconds on all machines. :)
July 12, 2008 9:06am - Vitor Bosshard - nickname: (algorias)
The other way to control ticks it to create a clock object just after pygame init:

clock = pygame.time.Clock()

and below that:

While 1 (or whatever):
clock.tick(30) #sets your framerate to 30.
do the rest of the loop as illustrated below
optional: wait 1-2 ms to free CPU

Hope this helps.
July 11, 2008 5:55am - Jordan Trudgett - nickname: (tgfcoder)
The mixer error is not a python error, it was because my sound card could not produce the settings you wanted, and when I let it make its own settings, it ran fine.

You'll want something like..

WHILE loop:
Do game logic
for ev in pygame.event.get():
(check each event ev and see if it does anything)
Update display
Wait for a little while
END while loop.

That "little while" should be somewhere around 5-20 ms depending on what framerate you want. You also have to accommodate for computers that take longer to do the logic and displaying, so at the start of each loop, get a variable

ti = pygame.time.get_ticks()

then at the end, find pygame.time.get_ticks() - ti
which will be the total milliseconds it took to do all the stuff in one game loop, then you can wait a certain amount of milliseconds to make the game loop a minimum amount of milliseconds, for example,..

Say on my computer, each loop takes 3 or 4ms.
I will then wait for 16 or 17ms.

Then on a slower computer, each loop takes 19ms-21ms.
I would wait either 1ms or 0.

This makes the game speed consistent among computers (which can do the loop in 20ms of course.)

Not saying this is the only way to do it, but it should give you some ideas on how to control your game.
Hope this helps, and I can definitely help more if you need!
July 11, 2008 4:24am - Nicholas Crafford - nickname: (nicklt77)
Thanks for the feedback!!

Yep, it was done in Python 2.5. To be proper it should be class Tetromino(object) .

Hmm... I never experienced the mixer error. Is this another Python 2.4 issue?

The space bar increments the rate that the blocks are falling at. It is only in for testing playable speeds. That should probably be moved to a more obscure key or entirely.

Yep, the way it's handling movement is retarded. I'm currently changing all of the movements to move one grid square on KEYDOWN and then hopefully allow the constant movement as well when the key is held down for more than a short time.
How would one go about implementing this properly without trying to make it time based (This is the root of the weirdness. It only reads the keystroke at a timed interval currently)?

Never, thought of the game tick issue :). I assume this means it would be proper to pause shorty in each iteration of the main game loop to help free up the CPU?

Thanks again, this is my first Pygame and pretty much first game programming attempt so I'm trying to learn quickly.
July 10, 2008 3:54am - Jordan Trudgett - nickname: (tgfcoder) - 2/5
Ah, ok.

*plays the game, to make the first intelligible comment!*

File "", line 24
class Tetromino():
SyntaxError: invalid syntax

This was expected... you wrote it with Python 2.5, right? 2.4 only accepts
class Tetromino:
for some deranged reason.

Fixed that.. now..

pygame.error: Couldn't find any hardware audio formats

pygame.mixer.init(self.freq, self.bitsize, self.channels, self.buffer)

fixed that up.

First issue: Holding down space for more than 0.5 seconds results in a grizly game over.
Second issue: Rotating is inconsistent. Sometimes pressing up does nothing, sometimes it rotates it twice.
Third issue: it uses 100% (and a bit more actually) of one of my CPUs.
Why is there no delay between game ticks? Aaah!

Not bad for a beginner though. :)
July 7, 2008 10:45pm - Nicholas Crafford - nickname: (nicklt77)
Believe it or not it's actually 20x24 :) .
July 7, 2008 9:52am - Jordan Trudgett - nickname: (tgfcoder)
Is it really 20x30? That's massive!

our projects welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
recent releases
Feb 21, 2017

Jan 31, 2017

Jan 24, 2017

Jan 18, 2017

Jan 7, 2017

Dec 30, 2016

Dec 8, 2016

Nov 28, 2016

Nov 27, 2016

... more!
for pygame related questions, comments, and suggestions, please see help (lists, irc)