Mercurial > pygame-tutorial
changeset 1:ae5f8de62b25
The first program
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Thu, 14 Jun 2012 12:48:47 +0200 |
| parents | 3cdbf8e0d07b |
| children | ee28ba29d97e |
| files | 000/000.py 000/001.py 000/002.py 000/003.py 000/004.py 000/005.py 000/006.py 000/template.py 000/test.py |
| diffstat | 9 files changed, 258 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/000/000.py Thu Jun 14 12:48:47 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/001.py Thu Jun 14 12:48:47 2012 +0200 @@ -0,0 +1,31 @@ +#!/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)) + 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.""" + while True: + event = pygame.event.wait() + if event.type == pg.QUIT: + return + + +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/002.py Thu Jun 14 12:48:47 2012 +0200 @@ -0,0 +1,34 @@ +#!/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.""" + +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()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/000/003.py Thu Jun 14 12:48:47 2012 +0200 @@ -0,0 +1,37 @@ +#!/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') + screen.blit(image, (0, 0)) + 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()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/000/004.py Thu Jun 14 12:48:47 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()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/000/005.py Thu Jun 14 12:48:47 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()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/000/006.py Thu Jun 14 12:48:47 2012 +0200 @@ -0,0 +1,41 @@ +#!/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)) + 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() + image_rect.center = screen_rect.center + screen.blit(image, image_rect) + +def wait_for_quit(): + """Sit there doing nothing until the window is closed.""" + clock = pygame.time.Clock() + pygame.display.update() + 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()
--- a/000/template.py Thu Jun 14 12:25:15 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -#!/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()
--- a/000/test.py Thu Jun 14 12:25:15 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -#!/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()
