def quebratijolos(matriz,bola,tela,vet): tijolo = [] for col in range (len(matriz)): for lin in range (len(matriz[col])): posbola = tela.bbox(bola) tijolo = tela.bbox(matriz[col][lin]) if posbola != None and tijolo != None: sobreposto = TP.sobreposicao_planos(posbola,tijolo) if tijolo != None and sobreposto != None: vet = TB.dir_bola(vet,sobreposto,posbola) tela.delete(matriz[col][lin]) matriz[col][lin]=[0,0,0,0] return vet
def quebratijolos(matriz, bola, tela, vet): tijolo = [] for col in range(len(matriz)): for lin in range(len(matriz[col])): posbola = tela.bbox(bola) tijolo = tela.bbox(matriz[col][lin]) if posbola != None and tijolo != None: sobreposto = TP.sobreposicao_planos(posbola, tijolo) if tijolo != None and sobreposto != None: vet = TB.dir_bola(vet, sobreposto, posbola) tela.delete(matriz[col][lin]) matriz[col][lin] = [0, 0, 0, 0] return vet
def barras_laterais(barras,boll,vet,tela): for elem in range(len(barras)): posbola = tela.bbox(boll) sobreposto = TP.sobreposicao_planos(posbola,barras[elem]) if sobreposto != None: vet = TB.dir_bola(vet,sobreposto,posbola) return vet #### #~ def movecomando(janela,comando): #~ ws = janela.winfo_screenwidth() #~ hs = janela.winfo_screenheight() #~ x = janela.winfo_pointerxy()[0] #~ print(x, ws,hs) #~ input() janela.move(comando,x)
def barras_laterais(barras, boll, vet, tela): for elem in range(len(barras)): posbola = tela.bbox(boll) sobreposto = TP.sobreposicao_planos(posbola, barras[elem]) if sobreposto != None: vet = TB.dir_bola(vet, sobreposto, posbola) return vet #### # ~ def movecomando(janela,comando): # ~ ws = janela.winfo_screenwidth() # ~ hs = janela.winfo_screenheight() # ~ x = janela.winfo_pointerxy()[0] # ~ print(x, ws,hs) # ~ input() janela.move(comando, x)
def main(): ############## tkinter criando janelas janela = tkinter.Tk() # canvas_altura = 600 # canvas_largura = 620 # tela = tkinter.Canvas(janela, bg='white', width=canvas_largura, height=canvas_altura) # ############### ######## paredes plano1= TP.cria_plano("0 0 620 10") plano2= TP.cria_plano("0 0 10 600") plano3= TP.cria_plano("610 0 620 600") plano4= TP.cria_plano("0 590 620 600") ################### mapa #~ matriz=[[0]] matriz = [ [0,0,1,1,1,0,0,0,0,0,0],\ [1,1,1,1,1,1,0,0,0,0,0],\ [1,1,1,1,1,1,1,0,0,0,0],\ [1,1,1,1,1,1,1,1,0,0,0],\ [0,1,1,1,1,1,1,1,1,0,0],\ [0,0,1,1,1,1,1,1,1,1,1],\ [0,1,1,1,1,1,1,1,1,1,0],\ [0,1,1,1,1,1,1,1,1,0,0],\ [1,1,1,1,1,1,1,1,0,0,0],\ [1,1,1,1,1,1,1,0,0,0,0],\ [1,1,1,1,1,1,0,0,0,0,0],\ [0,0,1,1,1,0,0,0,0,0,0]] mat = cria_obstaculos(matriz,tela) ################## mapa tela.create_rectangle(plano1,width=0,fill="black") tela.create_rectangle(plano2,width=0,fill="black") tela.create_rectangle(plano3,width=0,fill="black") tela.create_rectangle(plano4,width=0,fill="black") ###barra do jogador: comando = tela.create_rectangle([300,580,400,600],width=0,fill="purple") ######## paredes # bola bola = TB.cria_bola(20,400,500) boll = tela.create_oval(bola,width=1,fill="green") #img = tela.create_image(10,10,image="pkb.png") # bola tela.pack(padx=10, pady=10) ## fisica da bola barra= None vet = "SO" barras=[plano1,plano2,plano3,plano4] tela.delete(boll) while 1: boll = tela.create_oval(bola,width=2,fill="black") ### moldura vet = barras_laterais(barras,boll,vet,tela) ### tijolinhos vet = quebratijolos(mat,boll,tela,vet) ### TB.move_bola(bola,vet) ##comando #~ movecomando(tela,comando) ## tela.update() time.sleep(.005) tela.delete(boll) ## fisica da bola ################### escrevendo janela com tkinter # janela.mainloop() # #################### return 0
def main(): ############## tkinter criando janelas janela = tkinter.Tk() # canvas_altura = 600 # canvas_largura = 620 # tela = tkinter.Canvas(janela, bg="white", width=canvas_largura, height=canvas_altura) # ############### ######## paredes plano1 = TP.cria_plano("0 0 620 10") plano2 = TP.cria_plano("0 0 10 600") plano3 = TP.cria_plano("610 0 620 600") plano4 = TP.cria_plano("0 590 620 600") ################### mapa # ~ matriz=[[0]] matriz = [ [0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0], ] mat = cria_obstaculos(matriz, tela) ################## mapa tela.create_rectangle(plano1, width=0, fill="black") tela.create_rectangle(plano2, width=0, fill="black") tela.create_rectangle(plano3, width=0, fill="black") tela.create_rectangle(plano4, width=0, fill="black") ###barra do jogador: comando = tela.create_rectangle([300, 580, 400, 600], width=0, fill="purple") ######## paredes # bola bola = TB.cria_bola(20, 400, 500) boll = tela.create_oval(bola, width=1, fill="green") # img = tela.create_image(10,10,image="pkb.png") # bola tela.pack(padx=10, pady=10) ## fisica da bola barra = None vet = "SO" barras = [plano1, plano2, plano3, plano4] tela.delete(boll) while 1: boll = tela.create_oval(bola, width=2, fill="black") ### moldura vet = barras_laterais(barras, boll, vet, tela) ### tijolinhos vet = quebratijolos(mat, boll, tela, vet) ### TB.move_bola(bola, vet) ##comando # ~ movecomando(tela,comando) ## tela.update() time.sleep(0.005) tela.delete(boll) ## fisica da bola ################### escrevendo janela com tkinter # janela.mainloop() # #################### return 0
def main(): ############## tkinter criando janelas janela = tkinter.Tk() # canvas_altura = 600 # canvas_largura = 600 # tela = tkinter.Canvas(janela, bg='white', width=canvas_largura, height=canvas_altura) # ############### ######## paredes plano1= TP.cria_plano("0 0 600 2") plano2= TP.cria_plano("0 0 2 600") plano3= TP.cria_plano("598 0 600 600") plano4= TP.cria_plano("0 598 600 600") plano_A= TP.cria_plano("200 200 202 600") plano_B= TP.cria_plano("300 300 600 302") tela.create_rectangle(plano_B,width=0,fill="red") tela.create_rectangle(plano_A,width=0,fill="red") tela.create_rectangle(plano1,width=0,fill="red") tela.create_rectangle(plano2,width=0,fill="red") tela.create_rectangle(plano3,width=0,fill="red") tela.create_rectangle(plano4,width=0,fill="red") ######## paredes # bola bola = TB.cria_bola(50,10,100) boll = tela.create_oval(bola,width=0,fill="red") # bola tela.pack() ## fisica da bola barra= None vet = "SE" barras=[plano1,plano2,plano3,plano4,plano_A,plano_B] while 1: for elem in barras: if TP.sobreposicao_planos(bola,elem) != None: barra = TP.direcao_parede(elem) vet = TB.vet_bola(vet,barra) print(vet,barra) TB.move_bola(bola,vet) boll = tela.create_oval(bola,width=2,fill="red") tela.update() time.sleep(.01) #~ if TB.vet_bola(vet,barra) == "NO": #~ tela.move(boll,-1,-1) #~ tela.update() #~ time.sleep(.01) #~ if TB.vet_bola(vet,barra) == "SE": #~ tela.move(boll,1,1) #~ tela.update() #~ time.sleep(.01) #~ if TB.vet_bola(vet,barra) == "SO": #~ tela.move(boll,-1,1) #~ tela.update() #~ time.sleep(.01) ## fisica da bola ################### escrevendo janela com tkinter # janela.mainloop() # #################### return 0