bolerplate code would depend on each person and how far they are into the learning process. For example, this is mostly my boiler plate code when i start a new game (minus the movie)
https://github.com/Mekire/pygame-mutisce...with-movie
Also you should use pygame rects instead. This will help tremendously as your game gets more and more complex the more you add. As you can see it is much easier to read and understand. This is an example of your post modified to such that.
https://github.com/Mekire/pygame-mutisce...with-movie
Also you should use pygame rects instead. This will help tremendously as your game gets more and more complex the more you add. As you can see it is much easier to read and understand. This is an example of your post modified to such that.
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) screen_rect = screen.get_rect() 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([25,45]) test_surface_rect = test_surface.get_rect(center=screen_rect.center) test_surface.fill(WHITE) 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)) screen.blit(test_surface, test_surface_rect) pygame.draw.aaline(screen, RED, test_surface_rect.bottomleft, test_surface_rect.topright) # flip() updates the screen to make our changes visible pygame.display.flip() # how many updates per second clock.tick(60) pygame.quit()
Recommended Tutorials: