xix pug-pe - pygame game development

Post on 13-Jan-2015

3.166 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

DESCRIPTION

PPT created for a presentation on XIX PUG-PE with the basic concept of Pygame

TRANSCRIPT

Pygame - Game Development

Matheus Melo XIX PUG-PE

Schedule Introduction

What is PyGame?

PyGame essential Elements

Developing games with Pygame

What is Pygame? Set of Python modules for writing games

Compatible with SDL

Free

Best Features No need to OpenGL setup Multi-core C/Assembler Core Functions Portable Easy to use Comunity

Problems Python is slow

But you can do something to turn this out.

You write too much

Isn’t a Game Engine, it’s a library.

Essential Elements Surface

What is surface? 2D and 3D planes.

Eg: tamanho = ( 640 , 480 ) cor = ( 255 , 0 , 0 ) # v e rme lho superficie = Surface ( tamanho ) superficie . set_at ( ( 10 , 20 ) , cor ) superficie . fill ( cor , ( 11 , 21 , 50 , 50 ) ) tela = pygame . display . set_mode ( tamanho )

Surface – Important Functions fill( color, area)

Fill a area with the selected color get_at( position )

Returns the color that was in the setted position

set_at( position, color) Set the color on that position

Surface – Color Depth 256 Colors

24 bpp RGB 3 Bytes per color

Surface - Transparency ColorKey

One color is chosen to be transparent Image Alpha

Can have his Translucency between 0 and 255

Can be used together with ColorKey Per-Pixel Alpha

Has a associated Alpha component. Cannot be used with another transparency

What is Blit ? Convert the current Surface Color Depth

to the next Surface Color Depth

It is a very costly function

What is the alternative?

Rect What is it?

Eg: r = Rect ( ( 10 , 10 , 50 , 100 ) ) print r.top , r. bottom # 1 0 1 1 0 print r.left , r. right # 1 0 6 0 print r.midtop , r. midleft # ( 3 5 , 1 0 ) ( 1 0 , 6 0 ) print r. center # ( 3 5 , 6 0 ) c1 = r. collidepoint ( 30 , 40 ) c2 = r. colliderect ( ( 0 , 0 , 100 , 200 ) ) r2 = r. inflate ( 10 , 10 ) r2. move_ip ( 5 , 5 )

Rect – Important Functions clamp (area)

Returns a new rectangle inside this area clip(area)

Returns a new rectangle with his area cliped to fill the new area

collidepoint(x, y) Check if the point is in the rectangle.

colliderect(area) Check if the area toch the current rectangle

Rect – Important Functions contains(area)

Check if the area is in the rectangle. inflate(x,y)

Returns a new rectangle with the dimensions of the current rectangle increased according to the passed value

move(x,y) Returns a new rectangle with the positions

ofcurrent rectangle driven by passed values

Display What is it?

Eg: modos = pygame . display . list_modes () tela = pygame . display . set_mode ( modos [ 0 ] ) rect = pygame . Rect ( 0 , 0 , 10 , 10 ) pygame . display . set_caption ( " Teste do PyGame " ) while tela . get_rect (). contains ( rect ): tela . fill ( ( 0 , 0 , 0 ) ) tela . fill ( ( 255 , 0 , 0 ) , rect ) rect . move_ip ( 10 , 10 ) pygame . display . flip ()

Display – Essential Functions flip()

Update all the screen content get_surface()

Return the current surface list_modes()

List possible resolutions/dimensions set_caption(title)

Change screen title

Display – Essential Functions set_mode(size)

Setup the screen with the passed size toggle_fullscreen()

Toggle to fullscreen update(rect_list)

Update certain areas of the screendepending of the passed list of rectangles

Event What is it?

There are two methods to handle the line of events Event Queued Direct consultation of devices

Event Queued

from pygame . locals import * for event in pygame . event .get ():

if event . type == QUIT : sys . exit ()

elif event . type == KEYDOWN : print event .key

Direct Consultation of Devices

from pygame . locals import * while not ( pygame . mouse . get_pressed ()[ 0

] or \ pygame .key . get_pressed ()[ K_SPACE ] ):

pygame . event . pump ()

References Python: http://www.python.org/ PyGame: http://www.pygame.org/ A Newbie Guide to pygame: http://www.pygame.org/docs/tut/newbieguide.html Introdução ao Pygame: http://www.pygame.org/docs/tut/intro/intro.html Dicas de Performance para Python: http: //www.python.org/moin/PythonSpeed/

PerformanceTips Introdução ao Módulo Sprite do PyGame: http://www.pygame.org/docs/tut/SpriteIntro.html

Contact Details Matheus Melo Work mail:

matheus.melo@idealizza.com.br Personal mail:

matheuscmpm@gmail.com Twitter:

@matheuscmpm Facebook

/matheuscmpm

top related