Pygame uses the C/C++ game library SDL.
Pygame does not come with the CPython Interpreter from python.org.
You will have to install it if you have not already.
Go to pygame.org and download the binary related to your version of Python and your operating system.
Now to begin.
Okay to start you have to import pygame and any other imports you might want.
We will start with a simple Tic-Tac-Toe game for our example.
So first we will import:
import pygame import sys import time from pygame import *
and before you can use ANY pygame functions, you must initialize pygame.
So now we will initialize pygame and set up the screen.
pygame.init()
ttt = pygame.display.set_mode((300,325))
pygame.display.set_caption('Tic-Tac-Toe')
pygame.display.set_mode takes a tuple(a group of numbers, variables, and/or other Python objects) pertaining to the size of the rectangular box that your game is in.
Now leave enough space for the functions at the top and we will begin the main loop.
# Loop control variable running = True while (running == True): for event in pygame.event.get(): if event.type is pygame.QUIT: running = False
We initialize a variable to control the loop although break would work fine.
The for loop gets all the events that happen and our if statement makes sure if we click that little red X in the top-right that the loop stops and the screen shuts down.
Now try the code that you have and see that it works!(even if it is a bit useless)
Now that we have the basics of a pygame program down, let's go to part 2!
Edited by spyder, 25 July 2010 - 09:12 AM.


Sign In
Create Account


Back to top









