xix pug-pe - pygame game development

21
Pygame - Game Development Matheus Melo XIX PUG-PE

Upload: matheuscmpm

Post on 13-Jan-2015

3.166 views

Category:

Technology


5 download

DESCRIPTION

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

TRANSCRIPT

Page 1: XIX PUG-PE - Pygame game development

Pygame - Game Development

Matheus Melo XIX PUG-PE

Page 2: XIX PUG-PE - Pygame game development

Schedule Introduction

What is PyGame?

PyGame essential Elements

Developing games with Pygame

Page 3: XIX PUG-PE - Pygame game development

What is Pygame? Set of Python modules for writing games

Compatible with SDL

Free

Page 4: XIX PUG-PE - Pygame game development

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

Page 5: XIX PUG-PE - Pygame game development

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.

Page 6: XIX PUG-PE - Pygame game development

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 )

Page 7: XIX PUG-PE - Pygame game development

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

Page 8: XIX PUG-PE - Pygame game development

Surface – Color Depth 256 Colors

24 bpp RGB 3 Bytes per color

Page 9: XIX PUG-PE - Pygame game development

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

Page 10: XIX PUG-PE - Pygame game development

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?

Page 11: XIX PUG-PE - Pygame game development

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 )

Page 12: XIX PUG-PE - Pygame game development

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

Page 13: XIX PUG-PE - Pygame game development

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

Page 14: XIX PUG-PE - Pygame game development

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 ()

Page 15: XIX PUG-PE - Pygame game development

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

Page 16: XIX PUG-PE - Pygame game development

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

Page 17: XIX PUG-PE - Pygame game development

Event What is it?

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

Page 18: XIX PUG-PE - Pygame game development

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

Page 19: XIX PUG-PE - Pygame game development

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 ()

Page 20: XIX PUG-PE - Pygame game development

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

Page 21: XIX PUG-PE - Pygame game development

Contact Details Matheus Melo Work mail:

[email protected] Personal mail:

[email protected] Twitter:

@matheuscmpm Facebook

/matheuscmpm