I am working on a game using pygame , I filled the background with a color and I want the background not to be boring and empty so i made some art and loaded it into the code using pygame.image.load() Function , now i want them to be placed at random places , I made a class for that , that looks like this:
class Backround_Cosmatics():
def __init__( self , bg ):
self.bg = bg
self.Random_bg = random.randint( 1 , 3 )
def DrawCosmatics(self , win):
if self.Random_bg == 1:
win.blit( flower , ( random.randint( 0 , SCREEN_WIDTH ) , random.randint( 0 , SCREEN_HEIGHT ) ))
self.bg += 1
if self.Random_bg == 2:
win.blit( stone , ( random.randint( 0 , SCREEN_WIDTH ) , random.randint( 0 , SCREEN_HEIGHT ) ))
self.bg += 1
if self.Random_bg == 3:
grass_type = random.randint( 1 , 2 )
if grass_type == 1:
win.blit( grass1 , (( random.randint( 0 , SCREEN_WIDTH ) , random.randint( 0 , SCREEN_HEIGHT ) )))
self.bg += 1
if grass_type == 2:
win.blit( grass2 , (( random.randint( 0 , SCREEN_WIDTH ) , random.randint( 0 , SCREEN_HEIGHT ) )))
self.bg += 1
in the init method I am defining what to place (stone or flower or grass)
in the drawcosmatics methods I am saying where to place them randomly grass are 2 types
In the while loop i am mentioning it like this:
if len(Backround_cosmatics_list) <= Backround_cosmetics_cap:
cosmatic = Backround_Cosmatics(0)
Backround_cosmatics_list.append(cosmatic)
for cosmatic in Backround_cosmatics_list:
cosmatic.DrawCosmatics( Win )
I have a cap and a list like this outside the loop:
Backround_cosmetics_cap = 15
Backround_cosmatics_list = []
but when I run the function the background objects are just changing places every tick