Mercurial > pygame-tutorial
changeset 0:3cdbf8e0d07b
Initial commit
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Thu, 14 Jun 2012 12:25:15 +0200 |
| parents | |
| children | ae5f8de62b25 |
| files | .hgignore 000/cup.png 000/template.py 000/test.py 001/game.py |
| diffstat | 5 files changed, 85 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Thu Jun 14 12:25:15 2012 +0200 @@ -0,0 +1,12 @@ +syntax: glob +*.pyc +*~ +.*.swp +build/ +dist/ +bin/ +lib/ +include/ +local +*.egg-info +*.DS_Store
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/000/template.py Thu Jun 14 12:25:15 2012 +0200 @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import pygame +import pygame.locals as pg + + +def initialize_screen(): + """Initialize pygame, create a window and fill it with gray. + Return the screen surface. + """ + screen = None + return screen + +def load_and_display_image(screen): + """Load the image and display it in the middle of the screen.""" + +def wait_for_quit(): + """Sit there doing nothing until the window is closed.""" + + +if __name__ == '__main__': + screen = initialize_screen() + load_and_display_image(screen) + wait_for_quit()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/000/test.py Thu Jun 14 12:25:15 2012 +0200 @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import pygame +import pygame.locals as pg + + +def initialize_screen(): + """Initialize pygame, create a window and fill it with gray. + Return the screen surface. + """ + pygame.display.init() + screen = pygame.display.set_mode((800, 600)) + screen.fill((0x66, 0x66, 0x66)) + pygame.display.update() + return screen + +def load_and_display_image(screen): + """Load the image and display it in the middle of the screen.""" + image = pygame.image.load('cup.png') + image = image.convert() + image.set_colorkey((0xff, 0x00, 0xff)) + screen_rect = screen.get_rect() + image_rect = image.get_rect() + screen.blit(image, ( + (screen_rect.width - image_rect.width) // 2, + (screen_rect.height - image_rect.height) // 2, + ) + ) + pygame.display.update() + +def wait_for_quit(): + """Sit there doing nothing until the window is closed.""" + clock = pygame.time.Clock() + while True: + event = pygame.event.wait() + if event.type == pg.QUIT: + return + clock.tick(60) + + +if __name__ == '__main__': + screen = initialize_screen() + load_and_display_image(screen) + wait_for_quit()
