'Pygame, A Bit Racey tutorial: Calling the same function to draw the same object multiple times

In the "A Bit Racey" tutorial for Pygame, a sprite of a car has to avoid block objects. The tutorial shows how to draw and call one instance of this block. The author gives a challenge to make multiple blocks appear without hardcoding more blocks. I have not been able to figure this code out and am hoping there's a simple solution out there someone sees.

The tutorial's code can be found here: https://pythonprogramming.net/adding-score-pygame-video-game/

Code for creating the block object

def things(thingx, thingy, thingw, thingh, color):
    pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw, thingh])

Code for setting the location of the block on the screen

thing_startx = random.randrange(0, display_width)
thing_starty = -600
thing_speed = 4
thing_width = 100
thing_height = 100

Code for counting the number of blocks

thingCount = 1

Code that calls the block into the game

things(thing_startx, thing_starty, thing_width, thing_height, block_color)

Code that determines if the block crossed the entire screen without colliding with the car

        if thing_starty > display_height:
        thing_starty = 0 - thing_height
        thing_startx = random.randrange(0,display_width)
        dodged += 1
        thing_speed += 1

What I have tried and isn't working... I increased thingCount when the block crossed the screen without collision. If the thingCount is less than six, I call the things function again to draw another block. I am pretty sure the appropriate number of blocks is getting called, but I think the blocks are being drawn on top of one another. I have tried increasing the value of the first argument of the 'things' function with addition, but this seems adjust the horizontal position of all the blocks. Or new blocks are not being drawn at all.

if thing_start_y > display_height:
        thing_start_y = 0 - thing_height
        thing_start_x = random.randrange(0, display_width)
        dodged += 1
        thing_speed += 1
        thingCount += 1
        if thingCount < 6:
            things(thing_start_x, thing_start_y, thing_width, thing_height, block_color)
            thing_start_y += thing_speed

Any ideas? Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source