Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Import the needed libraries
- import pygame, random
- # Set up a clock
- clock = pygame.time.Clock()
- # Set up your game display
- windowHeight, windowWidth = 600, 1000
- gameDisplay = pygame.display.set_mode((windowWidth, windowHeight))
- # Make a list called allBalloons.
- allBalloons = []
- # Start a for loop that will go around 25 times. (This is the number of balloons you will get)
- for i in range(25):
- # Set up 3 variables for red, green and blue. These will each have a random value between 0 and 255.
- redAmount = random.randrange(0, 255)
- greenAmount = random.randrange(0, 255)
- blueAmount = random.randrange(0, 255)
- # Create a variable called balloonColour and make it equal to the red, green and blue values.
- balloonColour = [redAmount, greenAmount, blueAmount]
- # Set up 2 variables for balloonXPos and balloonYPos. These will each have a random value between 0 and what you set the width and height as.
- balloonXPos = random.randrange(50, windowWidth-50)
- balloonYPos = random.randrange(350, windowHeight-50)
- # Set up a variable called balloonSize. This will have random value between 30 and 50.
- balloonSize = random.randrange(30, 50)
- # Append all these values to the allBalloons list.
- allBalloons.append([balloonColour,balloonXPos,balloonYPos,balloonSize, i])
- # Fetch the collisionCheck function from another game.
- def collisionCheck(x,y,w,h,x2,y2,w2,h2, balloonNumber):
- if (x < (x2 + w2) and (x + w) > x2 and y < (y2 + h2) and (h + y) > y2):
- print ("Clicked on balloon number", balloonNumber)
- #del allBalloons[balloonNumber] #<---- THIS IS WHERE MY PROBLEM IS
- # Create a function called gameLoop.
- def gameLoop():
- # Set a variable to true and then use that to start a while loop going.
- gameRunning = True
- while gameRunning == True:
- # You need the for event in pygame.event.get() code here. Pull it from a previous game.
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- quit()
- if event.type == pygame.MOUSEBUTTONUP:
- #Call the collision check function here on all the balloons.
- for i in range(len(allBalloons)):
- collisionCheck(allBalloons[i][1], allBalloons[i][2], allBalloons[i][3], allBalloons[i][3], mouseX, mouseY, 1, 1, i)
- # Fill the game display in here with a colour. You can use the RGB values instead of defining colours.
- gameDisplay.fill([255, 255, 255])
- # Create a for loop that uses all the values from allBalloons to create some circles. (pygame.draw.circle)
- for i in range(len(allBalloons)):
- oneBalloon = pygame.draw.circle(gameDisplay, allBalloons[i][0], (allBalloons[i][1],allBalloons[i][2]), allBalloons[i][3])
- # Make the balloons float up by minusing 3 from its Y Pos value.
- allBalloons[i][2] = allBalloons[i][2] - 1
- # Create 2 variables called mouseX and mouseY and use the pygame.mouse.get_pos() feature to set them to the mouses location.
- mouseX = pygame.mouse.get_pos()[0]
- mouseY = pygame.mouse.get_pos()[1]
- # Update the screen and tick the clock.
- pygame.display.update()
- clock.tick(30)
- # Call the gameLoop function here.
- gameLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement