Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- import pdb;
- # Define some colors
- red = (255,0,0)
- green = (0,255,0)
- blue = (0,0,255)
- darkBlue = (0,0,128)
- white = (255,255,255)
- black = (0,0,0)
- pink = (255,200,200)
- pygame.init()
- class Rectangle():
- x = random.randrange(0, 701)
- y = random.randrange(0, 501)
- width = random.randrange(20,71)
- height = random.randrange(20,71)
- change_x = random.randrange(-3,4)
- change_y = random.randrange(-3,4)
- def move(self):
- self.x += self.change_x
- self.y += self.change_y
- def draw(self):
- pygame.draw.rect(screen, green, [self.x,self.y, self.width, self.height], 0)
- # Height/width of screen
- size = (700, 500)
- screen = pygame.display.set_mode(size)
- # Name the window
- pygame.display.set_caption("Awwshiet First Game Window")
- # Loop until close button is clicked
- done = False
- # Manages how fast screen updates
- clock = pygame.time.Clock()
- myList = []
- for i in range(10):
- myList.append(Rectangle())
- # ------- Main Program Loop -------#
- while done == False:
- # ALL EVENT PROCESSING BELOW THIS COMMENT
- for event in pygame.event.get(): # User did something
- if event.type == pygame.QUIT: # If user clicked close
- done = True # Flag as done so we exit this loop
- # ALL EVENT PROCESSING ABOVE THIS COMMENT
- # ALL GAME LOGIC BELOW THIS COMMENT
- # ALL GAME LOGIC ABOVE THIS COMMENT
- # ALL CODE TO DRAW BELOW THIS COMMENT
- screen.fill(black)
- for i in myList:
- i.draw()
- # ALL CODE TO DRAW ABOVE THIS COMMENT
- pygame.display.flip()
- # 20FPS
- clock.tick(20)
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement