Sep-19-2016, 09:12 PM
Boilerplate is the basic code you need in order for something to work. The bare minimum, with a little added on top to help you understand how to use it. Anytime you start a new script, boilerplate code is what you start with, and you make your modifications based upon that.
Here's my version of pygame boilerplate. There's some setup and teardown, and also a basic surface is added to demonstrate how drawing works, and how to blit things to the screen.
Here's my version of pygame boilerplate. There's some setup and teardown, and also a basic surface is added to demonstrate how drawing works, and how to blit things to the screen.
import pygame WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) # initialize pygame pygame.init() screen_size = (700, 500) # create a window screen = pygame.display.set_mode(screen_size) pygame.display.set_caption("pygame Test") # clock is used to set a max fps clock = pygame.time.Clock() # create a demo surface, and draw a red line diagonally across it surface_size = (25, 45) test_surface = pygame.Surface(surface_size) test_surface.fill(WHITE) pygame.draw.aaline(test_surface, RED, (0, surface_size[1]), (surface_size[0], 0)) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False #clear the screen screen.fill(BLACK) # draw to the screen # YOUR CODE HERE x = (screen_size[0]/2) - (surface_size[0]/2) y = (screen_size[1]/2) - (surface_size[1]/2) screen.blit(test_surface, (x, y)) # flip() updates the screen to make our changes visible pygame.display.flip() # how many updates per second clock.tick(60) pygame.quit()If you run it, you'll see this (click for full size): [attachment=3]