Question

I'm making Tetris and im trying to make a line clear function. I have a way to do this that is a bit complicated and im looking to simplify.

My idea is to check some pixel RGB values and see if they're not black (the color of the background). Is there a quick way to get the RGB value of a pixel on the screen?

Was it helpful?

Solution

pygame.PixelArray should do the trick. You can use it on the screen surface.

But personally, I wouldn't recommend that you use the pixels as a reference. Handling everything logically is a lot better.

OTHER TIPS

As Icfseth noted "Handling everything logically is a lot better."

Tetris is an array of blocks that occupy a logical space that has a granularity larger than a pixel. Your game model should operate in "block coordinates" and detect whether a space is open or filled based on that. The screen is just a representation or "view" of the block space.

Try first just moving a 16px square around a 320x320px screen in steps of 16px. You could keep track of every pixel, but it makes much more sense to have have the block position ranging from x = [0..20], y = [0..20], and let the display code worry about how to show a block at position (2,3).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top