# Create a simple box sprite # Draw one instance of the sprite in the corner of the screen # Task: make the box purple # Task: move the box to the middle of the screen import sys, os, pygame from pygame.locals import * class Box(pygame.sprite.Sprite): def __init__(self, color, initial_position): # All sprite classes should extend pygame.sprite.Sprite. This # gives you several important internal methods that you probably # don't need or want to write yourself. pygame.sprite.Sprite.__init__(self) # Create the image that will be displayed and fill it with the # right color. In this case, we just make a square self.image = pygame.Surface([15, 15]) self.image.fill(color) # Make our top-left corner the passed-in location. self.rect = self.image.get_rect() self.rect.topleft = initial_position pygame.init() screen = pygame.display.set_mode([150, 150]) b = Box([255, 0, 0], [0, 0]) # Make the box red in the top left # Note: color is a list of three values representing red, green blue # Note: position is a list of two items: x and y screen.blit(b.image, b.rect) pygame.display.flip() def input(events): for event in events: if event.type == QUIT: return False return True going = True while going: going = input(pygame.event.get()) pygame.quit()