| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent be1cca3 commit 7aa51b8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,10 @@ | |||
| 1 | 1 | # coding: utf-8 | |
| 2 | 2 | import time | |
| 3 | + from tkinter import PhotoImage, NW, Tk, Canvas | ||
| 4 | + from tkinter.constants import ALL | ||
| 3 | 5 | ||
| 4 | - from tkinter import * | ||
| 5 | - from tkinter import ttk | ||
| 6 | 6 | from fase import Fase | |
| 7 | 7 | from atores import PassaroVermelho, PassaroAmarelo, Porco, Obstaculo | |
| 8 | - from fase_tkinter import FaseTk | ||
| 9 | 8 | ||
| 10 | 9 | ||
| 11 | 10 | def get_angulo(event): | |
@@ -27,45 +26,57 @@ def get_angulo(event): | |||
| 27 | 26 | # b = Button(popup_angulo, text="OK", command=get_angulo) | |
| 28 | 27 | # b.pack(pady=5) | |
| 29 | 28 | ||
| 29 | + root = Tk() | ||
| 30 | 30 | ||
| 31 | + PASSARO_VERMELHO = PhotoImage(file="images/passaro_vermelho.gif") | ||
| 32 | + PASSARO_AMARELHO = PhotoImage(file="images/passaro_amarelo.gif") | ||
| 33 | + PORCO = PhotoImage(file="images/porco.gif") | ||
| 34 | + PORCO_MORTO = PhotoImage(file="images/porco_morto.gif") | ||
| 35 | + OBSTACULO = PhotoImage(file="images/obstaculo.gif") | ||
| 36 | + TRANSPARENTE = PhotoImage(file="images/transparente.gif") | ||
| 37 | + BACKGROUND = PhotoImage(file="images/background.gif") | ||
| 31 | 38 | ||
| 39 | + CARACTER_PARA__IMG_DCT = {'D': PASSARO_VERMELHO, '>': PASSARO_AMARELHO, '@': PORCO, 'O': OBSTACULO, | ||
| 40 | + '+': PORCO_MORTO, ' ': TRANSPARENTE} | ||
| 32 | 41 | ||
| 33 | 42 | ||
| 34 | - | ||
| 35 | - def plotar(canvas, ponto): | ||
| 43 | + def plotar(camada_de_atores, ponto): | ||
| 36 | 44 | multiplicador = 10 # 10 px/m | |
| 37 | 45 | x = multiplicador * ponto.x | |
| 38 | - y = ALTURA_DA_TELA - ponto.y * multiplicador - 11 * multiplicador | ||
| 39 | - canvas.coords(ponto.canvas_img_id, (x, y)) | ||
| 46 | + y = ALTURA_DA_TELA - ponto.y * multiplicador - 12 * multiplicador | ||
| 47 | + image = CARACTER_PARA__IMG_DCT.get(ponto.caracter, TRANSPARENTE) | ||
| 48 | + camada_de_atores.create_image((x, y), image=image, anchor=NW) | ||
| 49 | + # camada_de_atores.create_rectangle(x, y, 150, 75, fill="blue") | ||
| 50 | + | ||
| 40 | 51 | ||
| 52 | + def animar(tela, camada_de_atores, fase, passo=0.1, delta_t=0.1): | ||
| 53 | + tempo = 0 | ||
| 54 | + passo = int(1000 * passo) | ||
| 41 | 55 | ||
| 42 | - def animar(tela,fase,passo=0.1, delta_t=0.1): | ||
| 43 | - tempo=0 | ||
| 44 | 56 | def _animar(): | |
| 57 | + camada_de_atores.delete(ALL) | ||
| 58 | + camada_de_atores.create_image((0, 0), image=BACKGROUND, anchor=NW) | ||
| 45 | 59 | nonlocal tempo | |
| 46 | 60 | tempo += delta_t | |
| 47 | - time.sleep(passo) | ||
| 48 | 61 | for ponto in fase.calcular_pontos(tempo): | |
| 49 | - plotar(fase.canvas, ponto) | ||
| 50 | - tela.after(1, _animar) | ||
| 51 | - | ||
| 62 | + plotar(camada_de_atores, ponto) | ||
| 63 | + tela.after(passo, _animar) | ||
| 52 | 64 | ||
| 53 | - | ||
| 54 | - tela.after(1, _animar) | ||
| 65 | + camada_de_atores.pack() | ||
| 66 | + _animar() | ||
| 55 | 67 | tela.mainloop() | |
| 56 | 68 | ||
| 69 | + tela.after(passo, _animar) | ||
| 70 | + | ||
| 57 | 71 | ||
| 58 | 72 | if __name__ == '__main__': | |
| 59 | - root = Tk() | ||
| 60 | 73 | root.title("Python Birds") | |
| 61 | 74 | root.geometry("800x600") | |
| 62 | 75 | root.resizable(0, 0) | |
| 63 | 76 | ||
| 64 | 77 | stage = Canvas(root, width=800, height=ALTURA_DA_TELA) | |
| 65 | - bg_image = PhotoImage(file="images/background.gif") | ||
| 66 | - stage.create_image((0, 0), image=bg_image, anchor=NW) | ||
| 67 | - stage.pack() | ||
| 68 | - fase = FaseTk(stage) | ||
| 78 | + | ||
| 79 | + fase = Fase() | ||
| 69 | 80 | passaros = [PassaroVermelho(3, 3), PassaroAmarelo(3, 3), PassaroAmarelo(3, 3)] | |
| 70 | 81 | porcos = [Porco(75, 1), Porco(70, 1)] | |
| 71 | 82 | obstaculos = [Obstaculo(31, 10)] | |
@@ -75,9 +86,9 @@ def _animar(): | |||
| 75 | 86 | fase.adicionar_obstaculo(*obstaculos) | |
| 76 | 87 | ||
| 77 | 88 | fase.lancar(45, 1) | |
| 78 | - fase.lancar(64, 2) | ||
| 89 | + fase.lancar(63.5, 2) | ||
| 79 | 90 | fase.lancar(23, 3) | |
| 80 | 91 | ||
| 81 | - animar(root,fase) | ||
| 92 | + animar(root, stage, fase) | ||
| 82 | 93 | ||
| 83 | 94 | # root.wait_window(popup_angulo) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments