How can I move a section of my screen down by x pixels?

170 views Asked by At

I am making a tetris remake in Pygame and need to move all of the blocks down by 31 pixels whenever a line is cleared. How can I take a capture of the screen above the line and move it down by 31 pixels?

I have managed to make a rect around the area I want to move, but am totally lost as to how I can copy the surface with it then move it down and place it back onto the surface, please help!

Here is my (unsuccessful) snippet of what I have so far:

if bc1 == "16070":
    height_to_move = 659

else:
    height_to_move = 659 - int(bc1[3:])

movable_sheet = pygame.Rect(160, 70, 279, height_to_move)

movedsheet = screen.subsurface(movable_sheet).copy()


screen.blit(screen, (160,101), (160, 70, 279, height_to_move))
2

There are 2 answers

0
lilmessi42 On

I am not an expert in pygame or python, but you can create an integer y and an integer dy, with y being your original value and dy being 31, and have the area you want to move's y coordinate be y - dy. Hope this helped!

0
ninMonkey On

Where blocks is a list of Sprites

def draw():
    for b in blocks:
        screen.blit(b.image, b.rect, None)

def line_clear():
    for b in blocks:
        b.rect.top += 31