Issue
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()
[...]
Solution
You call the function random.randint( SCREEN_WIDTH , SCREEN_HEIGHT )
But the function returns an integrer between the first and the second variable.
random.randint(0, 10)
would return a number between 0 and 10.
You probably want to call random.randint(0 , SCREEN_WIDTH)
and random.randint(0 , SCREEN_HEIGHT)
.
Answered By - Ome
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.