Tutorial 01: Full sourcecode

#!/usr/bin/python
# This example runs in Python 2.6 and 3.1 using Pygame 1.9

import pygame
from pygame.locals import *

def main():
    # Initialize pygame
    pygame.init()
    window = pygame.display.set_mode((300, 300))
    pygame.display.set_caption('Basic Window')

    # Fill background
    background = pygame.Surface(window.get_size())
    background = background.convert()
    background.fill((250, 250, 250))

    # Display some text-using the included font from pygame
    font = pygame.font.Font(None, 36)
    text = font.render('Not very exciting.', 1, (10, 10, 10))
    text2 = font.render('Yet...', 1, (10, 10, 10))
    txtposition = text.get_rect()
    txtposition.centerx = background.get_rect().centerx
    background.blit(text, txtposition)
    txtposition2 = text2.get_rect()
    txtposition2.centerx = background.get_rect().centerx
    txtposition2.centery = background.get_rect().centery
    background.blit(text2, txtposition2)

    # Blit everything to the window
    window.blit(background, (0, 0))
    pygame.display.flip()

    # Event loop - in future examples this will be the game loop.
    while 1:
        for event in pygame.event.get():
            if event.type == QUIT:
                return

        window.blit(background, (0, 0))
        pygame.display.flip()


if __name__ == '__main__':
     main()
Advertisements
  1. Note about tutorials « Savalia Studios

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: