jeudi 28 juillet 2022

Random.randient is Showing error when called in a Function

hey I am making a game in pygame I made a function in pygame that if bg_object is smaller than equal to the cap of the number objects allowed , I implemented this quickly, but I ran into a problem , the problem is whenever I try to blit a image in screen it is showing an error , I know to put it in a class for multiple objects in a background but I am testing this

Here is the Function:


# Backround Cosmetics
FlowerPos = [random.randint( SCREEN_WIDTH , SCREEN_HEIGHT ) , random.randint( SCREEN_WIDTH , SCREEN_HEIGHT )]
StonePos = [random.randint( SCREEN_WIDTH , SCREEN_HEIGHT ) , random.randint( SCREEN_WIDTH , SCREEN_HEIGHT )]
Grass1Pos = [random.randint( SCREEN_WIDTH , SCREEN_HEIGHT ) , random.randint( SCREEN_WIDTH , SCREEN_HEIGHT )]
Grass2Pos = [random.randint( SCREEN_WIDTH , SCREEN_HEIGHT ) , random.randint( SCREEN_WIDTH , SCREEN_HEIGHT )]

def Backround_cosmetics():
    bg = 0
    if bg <= Backround_cosmetics_cap:
        Random_bg = (random.randint( 1 , 3 ))

        if Random_bg == 1:
            Win.blit( flower , ( FlowerPos[0] , FlowerPos[1] ))
            bg += 1

        if Random_bg == 2:
            Win.blit( stone , ( StonePos[0] , StonePos[1] ))
            bg += 1

        if Random_bg == 3:

            grass_type = random.randint( 1 , 2 )
            if grass_type == 1:
                Win.blit( grass1 , (( Grass1Pos[0] , Grass1Pos[1] )))
                bg += 1

            if grass_type == 2:
                Win.blit( grass2 , (( Grass2Pos[0] , Grass2Pos[1] )))
                bg += 1
            

I am mentioning the Function in the loop like this:

while Running:
    [...]
    Backround_cosmetics()
    [...]



Aucun commentaire:

Enregistrer un commentaire