Skip to content

Commit 383bd70

Browse files
author
renzon
committed
rafactoring para não ficar dependente o path de imagens. Fases concentradas no pacote fases
1 parent 97dff1b commit 383bd70

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

images/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import unicode_literals

images/fases/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import unicode_literals

placa_grafica_tkinter.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from tkinter import PhotoImage, NW, Tk, Canvas
44
from tkinter.constants import ALL
55
import math
6+
from os import path
67
import atores
78

89
from fase import Fase
@@ -11,17 +12,18 @@
1112
ALTURA_DA_TELA = 600 # px
1213

1314
root = Tk()
14-
15-
PASSARO_VERMELHO = PhotoImage(file="images/passaro_vermelho.gif")
16-
PASSARO_AMARELHO = PhotoImage(file="images/passaro_amarelo.gif")
17-
PORCO = PhotoImage(file="images/porco.gif")
18-
PORCO_MORTO = PhotoImage(file="images/porco_morto.gif")
19-
OBSTACULO = PhotoImage(file="images/obstaculo.gif")
20-
TRANSPARENTE = PhotoImage(file="images/transparente.gif")
21-
BACKGROUND = PhotoImage(file="images/background.gif")
22-
PYTHONBIRDS_LOGO = PhotoImage(file="images/python-birds-logo.gif")
23-
VOCE_GANHOU = PhotoImage(file="images/python-birds-voce-ganhou-popup.gif")
24-
VOCE_PERDEU = PhotoImage(file="images/python-birds-voce-perdeu-popup.gif")
15+
IMAGES_PATH = path.dirname(__file__)
16+
IMAGES_PATH = path.join(IMAGES_PATH, 'images')
17+
PASSARO_VERMELHO = PhotoImage(file=path.join(IMAGES_PATH, "passaro_vermelho.gif"))
18+
PASSARO_AMARELHO = PhotoImage(file=path.join(IMAGES_PATH, "passaro_amarelo.gif"))
19+
PORCO = PhotoImage(file=path.join(IMAGES_PATH, "porco.gif"))
20+
PORCO_MORTO = PhotoImage(file=path.join(IMAGES_PATH, "porco_morto.gif"))
21+
OBSTACULO = PhotoImage(file=path.join(IMAGES_PATH, "obstaculo.gif"))
22+
TRANSPARENTE = PhotoImage(file=path.join(IMAGES_PATH, "transparente.gif"))
23+
BACKGROUND = PhotoImage(file=path.join(IMAGES_PATH, "background.gif"))
24+
PYTHONBIRDS_LOGO = PhotoImage(file=path.join(IMAGES_PATH, "python-birds-logo.gif"))
25+
VOCE_GANHOU = PhotoImage(file=path.join(IMAGES_PATH, "python-birds-voce-ganhou-popup.gif"))
26+
VOCE_PERDEU = PhotoImage(file=path.join(IMAGES_PATH, "python-birds-voce-perdeu-popup.gif"))
2527

2628
CARACTER_PARA__IMG_DCT = {'V': PASSARO_VERMELHO, 'A': PASSARO_AMARELHO, '@': PORCO, 'O': OBSTACULO,
2729
'+': PORCO_MORTO, ' ': TRANSPARENTE}
@@ -48,7 +50,8 @@ def _animar():
4850
tamanho_seta = 60
4951
angulo_rad = math.radians(-angulo)
5052

51-
camada_de_atores.create_line(52, 493, 52 + tamanho_seta*math.cos(angulo_rad), 493 + tamanho_seta*math.sin(angulo_rad), width=1.5)
53+
camada_de_atores.create_line(52, 493, 52 + tamanho_seta * math.cos(angulo_rad),
54+
493 + tamanho_seta * math.sin(angulo_rad), width=1.5)
5255
camada_de_atores.create_text(35, 493, text=u"%d°" % angulo)
5356
for ponto in fase.calcular_pontos(tempo):
5457
plotar(camada_de_atores, ponto)
@@ -79,6 +82,7 @@ def _ouvir_comandos_lancamento(evento):
7982
tela.mainloop()
8083
tela.after(passo, _animar)
8184

85+
8286
def rodar_fase(fase):
8387
root.title("Python Birds")
8488
root.geometry("800x600")
@@ -92,7 +96,6 @@ def rodar_fase(fase):
9296
animar(root, stage, fase)
9397

9498

95-
9699
if __name__ == '__main__':
97100
fase = Fase(intervalo_de_colisao=10)
98101
passaros = [PassaroVermelho(30, 30), PassaroAmarelo(30, 30), PassaroAmarelo(30, 30)]

0 commit comments

Comments
 (0)