Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pygame boilerplate

#!/usr/bin/env python2

import pygame
import random


WIDTH = 360
HEIGHT = 480
FPS = 30

# Define Colors 
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

## initialize pygame and create window
pygame.init()
pygame.mixer.init()  ## For sound
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("<Your game>")
clock = pygame.time.Clock()     ## For syncing the FPS


## group all the sprites together for ease of update
all_sprites = pygame.sprite.group()

## Game loop
running = True
while running:

    #1 Process input/events
    clock.tick(FPS)     ## will make the loop run at the same speed all the time
    for event in pygame.event.get():        # gets all the events which have occured till now and keeps tab of them.
        ## listening for the the X button at the top
        if event.type == pygame.QUIT:
            running = False


    #2 Update
    all_sprites.update()


    #3 Draw/render
    screen.fill(BLACK)

    

    all_sprites.draw(screen)
    ########################

    ### Your code comes here

    ########################

    ## Done after drawing everything to the screen
    pygame.display.flip()       

pygame.quit()
Comment

PREVIOUS NEXT
Code Example
Python :: how to make a resizable pygame window 
Python :: python iterate through date range 
Python :: python pip install matplotlib 
Python :: pandas see all columns 
Python :: python b to string 
Python :: sort dataframe by column 
Python :: vowel and consonant list python 
Python :: why is python hard 
Python :: python read json file 
Python :: string to datetime convert 
Python :: cv2.cvtcolor grayscale 
Python :: time it python 
Python :: warning ignore python 
Python :: pygame play sound 
Python :: pip install error 
Python :: check filed exist in object python 
Python :: python format seconds to hh mm ss 
Python :: python iterate directory 
Python :: update anaconda from cmd 
Python :: how to create a superuser in django 
Python :: format python number with commas 
Python :: sns title 
Python :: record the amount of time ittales for code to run python 
Python :: save plot as image python 
Python :: show image in tkinter pillow 
Python :: install matplotlib.pyplot mac python 3 
Python :: pandas update with condition 
Python :: pandas remove char from column 
Python :: selenium find button by text 
Python :: index in zip python 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =