pygame boilerplate

Solutions on MaxInterview for pygame boilerplate by the best coders in the world

showing results for - "pygame boilerplate"
Christopher
23 Jan 2017
1#!/usr/bin/env python2
2
3import pygame
4import random
5
6
7WIDTH = 360
8HEIGHT = 480
9FPS = 30
10
11# Define Colors 
12WHITE = (255, 255, 255)
13BLACK = (0, 0, 0)
14RED = (255, 0, 0)
15GREEN = (0, 255, 0)
16BLUE = (0, 0, 255)
17
18## initialize pygame and create window
19pygame.init()
20pygame.mixer.init()  ## For sound
21screen = pygame.display.set_mode((WIDTH, HEIGHT))
22pygame.display.set_caption("<Your game>")
23clock = pygame.time.Clock()     ## For syncing the FPS
24
25
26## group all the sprites together for ease of update
27all_sprites = pygame.sprite.group()
28
29## Game loop
30running = True
31while running:
32
33    #1 Process input/events
34    clock.tick(FPS)     ## will make the loop run at the same speed all the time
35    for event in pygame.event.get():        # gets all the events which have occured till now and keeps tab of them.
36        ## listening for the the X button at the top
37        if event.type == pygame.QUIT:
38            running = False
39
40
41    #2 Update
42    all_sprites.update()
43
44
45    #3 Draw/render
46    screen.fill(BLACK)
47
48    
49
50    all_sprites.draw(screen)
51    ########################
52
53    ### Your code comes here
54
55    ########################
56
57    ## Done after drawing everything to the screen
58    pygame.display.flip()       
59
60pygame.quit()