Desenvolvendo jogos com Pygame

$whoami

 


 

  • Graduando em Análise e Desenvolvimento de Sistemas (Fatec SJC)
  • Desenvolvedor Python ( QMágico)
  • Entusiasta em desenvolvimento de jogos

 

O que é Pygame
 

"Conjunto de módulos python para desenvolver jogos."

Esses módulos fornecem acesso a diversos dispositivos de hardware como teclado, mouse, som, vídeo e etc.

Jogos feitos com Pygame

Instalando o pygame

yum install pygame # fedora

apt-get install pygame # ubuntu

Instalando o pygame

E para windows ou mac?

http://www.pygame.org/download.shtml

Inicializando o pygame

# coding: utf-8

import pygame
pygame.init()
WINDOW_HEIGHT, WINDOW_WIDTH = 800, 600
screen = pygame.display.set_mode((WINDOW_HEIGHT, WINDOW_WIDTH))
pygame.display.set_caption('Snake Game')

Desenhando objetos na tela

# coding: utf-8

import pygame

pygame.init()
WINDOW_HEIGHT, WINDOW_WIDTH = 800, 600
screen = pygame.display.set_mode((WINDOW_HEIGHT, WINDOW_WIDTH))
pygame.display.set_caption('Snake Game')

color_blue = (0, 0, 255)
surface = pygame.Surface([60, 60])
surface.fill(color_blue)

screen.blit(surface, (10, 10))
pygame.display.update()

 

Funcionamento de um jogo


while True:
    clock.tick(16)
    screen.fill((255, 255, 255))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit(0)
        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                rect.x -= 10
            if event.key == K_RIGHT:
                rect.x += 10
            if event.key == K_UP:
                rect.y -= 10
            if event.key == K_DOWN:
                rect.y += 10
    screen.blit(surface, rect)
    pygame.display.update()

Game Loop

event.key == K_UP

rect.y -= 10

screen.blit(surface, rect)
pygame.display.update()

Colisões

Snake Game

Onde encontrar materiais

http://www.pygame.org/hifi.html

http://programeempython.blog.br/

http://www.gamesindustry.biz/jobs

Obrigado!

https://github.com/IuryAlves

iuryalves20@gmail.com

desenvolvendo jogos com python e pygame

By Iury Alves de Souza

desenvolvendo jogos com python e pygame

Introdução ao desenvolvimento de jogos em python utilizando a biblioteca pygame.

  • 760