Created
June 1, 2017 23:54
-
-
Save triton11/14149c902bf8b18a3093fb2471fb43bc to your computer and use it in GitHub Desktop.
Revisions
-
triton11 created this gist
Jun 1, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,76 @@ import pygame import random # Define some colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) class Rectangle(): def __init__(self): self.x = random.randrange(700) self.y = random.randrange(500) self.change_x = random.randrange(-3,4) self.change_y = random.randrange(-3,4) self.size_x= random.randrange(20,71) self.size_y= random.randrange(20,71) self.color = [0,255,0] def move(self): self.x += self.change_x self.y += self.change_y def draw(self, screen): pygame.draw.rect(screen, self.color, [self.x, self.y, self.size_x, self.size_y],0) rectanglelist = [] for i in range(10): x = Rectangle() rectanglelist.append(x) pygame.init() # Set the width and height of the screen [width, height] size = (700, 500) screen = pygame.display.set_mode(size) pygame.display.set_caption("My Game") # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() # -------- Main Program Loop ----------- while not done: # --- Main event loop for event in pygame.event.get(): if event.type == pygame.QUIT: done = True # --- Game logic should go here # --- Screen-clearing code goes here # Here, we clear the screen to white. Don't put other drawing commands # above this, or they will be erased with this command.\ for i in rectanglelist: i.move() # If you want a background image, replace this clear with blit'ing the # background image. screen.fill(BLACK) for i in rectanglelist: i.draw(screen) # --- Drawing code should go here # --- Go ahead and update the screen with what we've drawn. pygame.display.flip() # --- Limit to 60 frames per second clock.tick(60) # Close the window and quit. pygame.quit()