Hacker News new | past | comments | ask | show | jobs | submit login

Here's another really old Tetris sample for pygame I wrote half a decade ago (174 non-blank lines):

http://web.archive.org/web/20060208230531/http://www.cryptop...

Looking at it now, the code has some warts. It was written on an airplane ride and I just noticed I mistakingly left out S and Z tetrominoes. Oops! It's also interesting to compare the difference in block representations with my C program; I definitely think my C representation (offsets rather than masks) is cleaner. With the Python mask representation, I use a nested list transpose to take care of rotations: list(reversed(zip(*shape))). While that's a neat APL-style idiom, Python isn't really giving me any leverage over C. For example, for clearing rows in Python I use list slice lvalues. Those are useful, but here C gets the job done just as conveniently with memmove and bzero.

Anyway, it could be a lot better, but it's still simpler than most of the tutorial-style game samples littering the net.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: