def __init__(self): """ Construtor: __init__() -> instancia de jogo """ pygame.init() self.tela = pygame.display.set_mode((800, 600), FULLSCREEN) self.cenario = Cenario(self.tela) self.cenario.area.fill((65, 171, 73)) self.cenario.construir()
class Jogo: """ Classe Jogo """ def __init__(self): """ Construtor: __init__() -> instancia de jogo """ pygame.init() self.tela = pygame.display.set_mode((800, 600)) self.cenario = Cenario(self.tela) def criar_atores(self): """ Cria os atores """ self.joyce = Ator(0, 200) self.joyce.inserir_estado("EsqDir") for x in range(1, 5): self.joyce.inserir_pose("imagens/joyce_ED_%02i.png" % x) self.grupo_atores = pygame.sprite.RenderPlain((self.joyce)) def atualizar_atores(self): """ Atualiza os atores """ retangulo = self.tela.get_rect() if (self.joyce.rect.x < retangulo.width - 64): self.joyce.rect.x += 8 def repintar_tela(self): """ Repinta a tela """ self.tela.fill((65, 171, 73)) self.cenario.reconstruir_cenario() # <-- custo elevado :-( self.grupo_atores.update() self.grupo_atores.draw(self.tela) pygame.display.flip() def tratar_evento_teclado(self, evento): """ Observa e trata os eventos """ tecla = evento.key if ((tecla == K_ESCAPE) or (tecla == K_q)): raise SystemExit def tratar_eventos(self): """ Observa e trata os eventos """ for evento in pygame.event.get(): if (evento.type == QUIT): raise SystemExit if (evento.type == KEYDOWN): self.tratar_evento_teclado(evento) def rodar(self): """ Roda o jogo """ self.criar_atores() FPS = 8 relogio = pygame.time.Clock() while (True): self.tratar_eventos() self.atualizar_atores() self.repintar_tela() relogio.tick(FPS)
def __init__(self): pygame.init() self.tela = model.Tela() self.pacman = PacMan(tamanho=model.TAMANHO_ATORES, linha=1, coluna=1, eixo_x=model.LARGURA // 2, eixo_y=model.ALTURA // 2, velocidade_eixo_x=0, velocidade_eixo_y=0) qtd_linhas = 600 // 30 self.cenario = Cenario(tela=self.tela(), pacman=self.pacman, tamanho=qtd_linhas)
class Jogo: """ Classe Jogo """ def __init__(self): """ Construtor: __init__() -> instancia de jogo """ pygame.init() self.tela = pygame.display.set_mode((800, 600)) #, FULLSCREEN) self.cenario = Cenario(self.tela) self.cenario.construir() def criar_atores(self): """ Cria os atores """ self.joyce = Ator(400, 300) self.joyce.inserir_estado("EsqDir") for x in range(1, 5): self.joyce.inserir_pose("imagens/joyce_ED_%02i.png" % x) self.joyce.inserir_estado("DirEsq") for x in range(1, 5): self.joyce.inserir_pose("imagens/joyce_DE_%02i.png" % x) self.joyce.inserir_estado("CimaBaixo") for x in range(1, 5): self.joyce.inserir_pose("imagens/joyce_CB_%02i.png" % x) self.joyce.inserir_estado("BaixoCima") for x in range(1, 5): self.joyce.inserir_pose("imagens/joyce_BC_%02i.png" % x) self.grupo_atores = pygame.sprite.RenderPlain((self.joyce)) def atualizar_atores(self): """ Atualiza os atores """ retangulo = self.tela.get_rect() if (self.joyce.estado == "EsqDir"): if (self.joyce.rect.x < retangulo.width - 64 - 36): self.joyce.rect.x += 4 self.cenario.mover(4, 0) elif (self.joyce.estado == "CimaBaixo"): if (self.joyce.rect.y < retangulo.height - 100 - 36): self.joyce.rect.y += 4 self.cenario.mover(0, 4) elif (self.joyce.estado == "DirEsq"): if (self.joyce.rect.x > 36): self.joyce.rect.x -= 4 self.cenario.mover(-4, 0) elif (self.joyce.estado == "BaixoCima"): if (self.joyce.rect.y > 36): self.joyce.rect.y -= 4 self.cenario.mover(0, -4) def repintar_tela(self): """ Repinta a tela """ self.cenario.repintar() self.grupo_atores.update() self.grupo_atores.draw(self.tela) pygame.display.flip() def tratar_evento_teclado(self, evento): """ Observa e trata os eventos """ tecla = evento.key if ((tecla == K_ESCAPE) or (tecla == K_q)): raise SystemExit elif (evento.type == KEYDOWN): if (evento.key == K_UP): self.joyce.estado = "BaixoCima" elif (evento.key == K_DOWN): self.joyce.estado = "CimaBaixo" elif (evento.key == K_LEFT): self.joyce.estado = "DirEsq" elif (evento.key == K_RIGHT): self.joyce.estado = "EsqDir" def tratar_eventos(self): """ Observa e trata os eventos """ for evento in pygame.event.get(): if (evento.type == QUIT): raise SystemExit if (evento.type == KEYDOWN): self.tratar_evento_teclado(evento) def rodar(self): """ Roda o jogo """ self.criar_atores() FPS = 8 relogio = pygame.time.Clock() while (True): self.tratar_eventos() self.atualizar_atores() self.repintar_tela() relogio.tick(FPS)
def __init__(self): """ Construtor: __init__() -> instancia de jogo """ pygame.init() self.tela = pygame.display.set_mode((800, 600)) self.cenario = Cenario(self.tela)
class Jogo: """ Classe Jogo """ def __init__(self): """ Construtor: __init__() -> instancia de jogo """ pygame.init() self.tela = pygame.display.set_mode((800, 600), FULLSCREEN) self.cenario = Cenario(self.tela) self.cenario.area.fill((65, 171, 73)) self.cenario.construir() def criar_atores(self): """ Cria os atores """ self.joyce = Ator(400, 300) self.joyce.inserir_estado("EsqDir") for x in range(1, 5): self.joyce.inserir_pose("imagens/joyce_ED_%02i.png" % x) self.joyce.inserir_estado("DirEsq") for x in range(1, 5): self.joyce.inserir_pose("imagens/joyce_DE_%02i.png" % x) self.joyce.inserir_estado("CimaBaixo") for x in range(1, 5): self.joyce.inserir_pose("imagens/joyce_CB_%02i.png" % x) self.joyce.inserir_estado("BaixoCima") for x in range(1, 5): self.joyce.inserir_pose("imagens/joyce_BC_%02i.png" % x) self.grupo_atores = pygame.sprite.RenderPlain((self.joyce)) def atualizar_atores(self): """ Atualiza os atores """ retangulo = self.tela.get_rect() if (self.joyce.estado == "EsqDir"): if (self.joyce.rect.x < retangulo.width - 64 - 36): self.joyce.rect.x += 4 self.cenario.mover(4, 0) elif (self.joyce.estado == "CimaBaixo"): if (self.joyce.rect.y < retangulo.height - 100 - 36): self.joyce.rect.y += 4 self.cenario.mover(0, 4) elif (self.joyce.estado == "DirEsq"): if (self.joyce.rect.x > 36): self.joyce.rect.x -= 4 self.cenario.mover(-4, 0) elif (self.joyce.estado == "BaixoCima"): if (self.joyce.rect.y > 36): self.joyce.rect.y -= 4 self.cenario.mover(0, -4) def repintar_tela(self): """ Repinta a tela """ self.cenario.repintar() self.grupo_atores.update() self.grupo_atores.draw(self.tela) pygame.display.flip() def tratar_evento_teclado(self, evento): """ Observa e trata os eventos """ tecla = evento.key if ((tecla == K_ESCAPE) or (tecla == K_q)): raise SystemExit elif (evento.type == KEYDOWN): if (evento.key == K_UP): self.joyce.estado = "BaixoCima" elif (evento.key == K_DOWN): self.joyce.estado = "CimaBaixo" elif (evento.key == K_LEFT): self.joyce.estado = "DirEsq" elif (evento.key == K_RIGHT): self.joyce.estado = "EsqDir" def tratar_eventos(self): """ Observa e trata os eventos """ for evento in pygame.event.get(): if (evento.type == QUIT): raise SystemExit if (evento.type == KEYDOWN): self.tratar_evento_teclado(evento) def rodar(self): """ Roda o jogo """ self.criar_atores() FPS = 8 relogio = pygame.time.Clock() while (True): self.tratar_eventos() self.atualizar_atores() self.repintar_tela() relogio.tick(FPS)
from fantasma import Fantasma from constants import * pygame.init() screen = pygame.display.set_mode((800, 600), 0) if __name__ == "__main__": size = 600 // 30 clock = pygame.time.Clock() pacman = Pacman(size) blinky = Fantasma(VERMELHO, size) inky = Fantasma(CIANO, size) clyde = Fantasma(LARANJA, size) pinky = Fantasma(ROSA, size) cenario = Cenario(size, pacman) cenario.adicionar_movivel(pacman) cenario.adicionar_movivel(blinky) cenario.adicionar_movivel(inky) cenario.adicionar_movivel(clyde) cenario.adicionar_movivel(pinky) while True: # Calcular as regras if cenario.estado == JOGANDO: pacman.calcular_regras() blinky.calcular_regras() inky.calcular_regras() clyde.calcular_regras() pinky.calcular_regras() cenario.calcular_regras()
class Jogo: def __init__(self): pygame.init() self.tela = model.Tela() self.pacman = PacMan(tamanho=model.TAMANHO_ATORES, linha=1, coluna=1, eixo_x=model.LARGURA // 2, eixo_y=model.ALTURA // 2, velocidade_eixo_x=0, velocidade_eixo_y=0) qtd_linhas = 600 // 30 self.cenario = Cenario(tela=self.tela(), pacman=self.pacman, tamanho=qtd_linhas) def game_loop(self): blinky = Fantasma(cor=model.VERMELHO, tamanho=model.TAMANHO_ATORES) inky = Fantasma(cor=model.CIANO, tamanho=model.TAMANHO_ATORES) clyde = Fantasma(cor=model.LARANJA, tamanho=model.TAMANHO_ATORES) pinky = Fantasma(cor=model.ROSA, tamanho=model.TAMANHO_ATORES) self.cenario.adicionar_ator(self.pacman) self.cenario.adicionar_ator(blinky) self.cenario.adicionar_ator(inky) self.cenario.adicionar_ator(clyde) self.cenario.adicionar_ator(pinky) while True: # Calcular regras self.cenario.calcular_regras() blinky.calcular_regras(self.cenario.estado) inky.calcular_regras(self.cenario.estado) clyde.calcular_regras(self.cenario.estado) pinky.calcular_regras(self.cenario.estado) self.pacman.calcular_regras() # Pinta self.tela().fill(model.PRETO) self.cenario.pintar(self.tela()) self.pacman.pintar(self.tela()) blinky.pintar(self.tela()) inky.pintar(self.tela()) clyde.pintar(self.tela()) pinky.pintar(self.tela()) pygame.display.update() pygame.time.delay(100) # Eventos eventos = pygame.event.get() self.cenario.processar_eventos(eventos) self.pacman.processar_eventos(eventos, self.cenario.estado)