Creació de jocs amb PyBadge

Programació Dades pràctiques     Recursos CITCEA
Tutorial Exemples Projectes   Inici

Guerra de tancs

En aquest joc tenim un tanc que està envoltat de tancs enemics que haurà d'anar eliminant. Per poder-se protegir, també hi ha algunes parets.

Les imatges que fa servir el joc són les que comentem tot seguit. La primera mostra les instruccions i les peces de la imatge següent formen part de les pantalles inicials.

instruccions       menu

També tenim els dos tancs en totes les posicions possibles i les bales.

tancs       bales

El programa també fa servir dos fitxers de so, un per al dispar, pew.wav, i un per quan es toca un tanc, boom.wav.

El programa és el següent:

import displayio
import time
import board
import adafruit_imageload
import ugame
import terminalio
import random
from adafruit_display_text import label
lll=[True,False]
# Creem un objecte per a la pantalla
font = terminalio.FONT
pant = board.DISPLAY
pew_sound = open("pew.wav", 'rb')
boom_sound = open("boom.wav", 'rb')
sound = ugame.audio
sound.mute(False)
z_text = label.Label(font, text="", color=0xFF0000 )
z_text.x = 0
z_text.y = 5
u_text = label.Label(font, text="Mou el tank sobre el mapa", color=0xFF0000 )
u_text.x = 0
u_text.y = 5
dos_text = label.Label(font, text="Normandia", color=0xFF0000 )
dos_text.x = 30
dos_text.y = 32
tres_text = label.Label(font, text="Varsovia", color=0xFF0000 )
tres_text.x = 30
tres_text.y = 90
tresvides = label.Label(font, text="Vides <3<3<3", color=0x00FF00 )
tresvides.x = 0
tresvides.y = 5
dosvides = label.Label(font, text="Vides <3<3", color=0x00FF00 )
dosvides.x = 0
dosvides.y = 5
unavida = label.Label(font, text="Vides <3", color=0x00FF00 )
unavida.x = 0
unavida.y = 5
pausa = label.Label(font, text="Pausa", color=0xFF0000 )
pausa.x = 64
pausa.y = 69
# Mostrem el text
# Carreguem el fitxer amb la imatge
imatge, palette = adafruit_imageload.load("/cara_rient.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
ima, pale = adafruit_imageload.load("/tank.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
imaf, palef = adafruit_imageload.load("/bala.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
imm,paa=adafruit_imageload.load("/mapa_ini.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
# Creem l'sprites/Mosaic
mapa = displayio.TileGrid(imatge, pixel_shader=palette,
                            width =1 , height = 1,
                            tile_width = 160, tile_height = 128)
mapi = displayio.TileGrid(imm, pixel_shader=paa,
                            width =1 , height = 1,
                            tile_width = 160, tile_height = 128)
tank = displayio.TileGrid(ima, pixel_shader=pale,
                            width =1 , height = 1,
                            tile_width = 12, tile_height = 12)
tank_enemic1 = displayio.TileGrid(ima, pixel_shader=pale,
                            width =1 , height = 1,
                            tile_width = 12, tile_height = 12)
tank_enemic2 = displayio.TileGrid(ima, pixel_shader=pale,
                            width =1 , height = 1,
                            tile_width = 12, tile_height = 12)
tank_enemic3 = displayio.TileGrid(ima, pixel_shader=pale,
                            width =1 , height = 1,
                            tile_width = 12, tile_height =12)
tank_enemic4 = displayio.TileGrid(ima, pixel_shader=pale,
                            width =1 , height = 1,
                            tile_width = 12, tile_height =12)
bala = displayio.TileGrid(imaf, pixel_shader=palef,
                            width =1 , height = 1,
                            tile_width = 4, tile_height = 4)
bala_enemiga1 = displayio.TileGrid(imaf, pixel_shader=palef,
                            width =1 , height = 1,
                            tile_width = 4, tile_height = 4)
bala_enemiga2 = displayio.TileGrid(imaf, pixel_shader=palef,
                            width =1 , height = 1,
                            tile_width = 4, tile_height = 4)
bala_enemiga3 = displayio.TileGrid(imaf, pixel_shader=palef,
                            width =1 , height = 1,
                            tile_width = 4, tile_height = 4)
bala_enemiga4 = displayio.TileGrid(imaf, pixel_shader=palef,
                            width =1 , height = 1,
                            tile_width = 4, tile_height = 4)
# Definim un grup per el tank i el mapa
grup = displayio.Group()
grup_mapa = displayio.Group()
grup_mapa.append(mapa)
# Definim posicio ini
grup.append(grup_mapa)
g_mapi = displayio.Group()
g_mapi.append(mapi)
grup_bala = displayio.Group()
grup_bala.append(bala)
grup.append(grup_bala)
gb_enemiga1 = displayio.Group()
gb_enemiga1.append(bala_enemiga1)
bala_enemiga1[0,0]=1
gb_enemiga2 = displayio.Group()
gb_enemiga2.append(bala_enemiga2)
bala_enemiga2[0,0]=1
gb_enemiga3 = displayio.Group()
gb_enemiga3.append(bala_enemiga3)
bala_enemiga3[0,0]=1
gb_enemiga4 = displayio.Group()
gb_enemiga4.append(bala_enemiga4)
bala_enemiga4[0,0]=1
gt_enemic1 = displayio.Group()
gt_enemic1.append(tank_enemic1)
gt_enemic2 = displayio.Group()
gt_enemic2.append(tank_enemic2)
gt_enemic3 = displayio.Group()
gt_enemic3.append(tank_enemic3)
gt_enemic4 = displayio.Group()
gt_enemic4.append(tank_enemic4)
grup_tank = displayio.Group()
grup_tank.append(tank)
# Definim posicio ini
(tx, grup_tank.x) = (64,64)
(ty, grup_tank.y) = (64,64)
(bx,grup_bala.x) = (-100,-100)
(by,grup_bala.y) = (-100,-100)
grup.append(grup_tank)
pale.make_transparent(8)
pant.show(grup)
abans = 0
ori="a"
instanteInicial=0
zup=False
zdown=False
zleft=False
zright=False
tboto = 2
varimapa=1
temp=0
estat=0
vari_ini=0
grup.append(u_text)
grup.append(dos_text)
grup.append(tres_text)
pant.show(grup)
perdut=False
tanks_m=0
lrec=['0','0','0']
vel=1
txoc=0
while estat==0:
    boto = ugame.buttons.get_pressed()# Llegeix els boto
    if perdut:
        vel=1
        perdut_text = label.Label(font, text= "Millors resultats" +"\n" + lrec[0]+"\n" +lrec[1]+"\n"+lrec[2]+"\n" + "El teu resultat"+"\n" +str(tanks_m), color=0xFF0000 )
        perdut_text.x = 20
        perdut_text.y = 10
        if tanks_m>int(lrec[2]):
            if tanks_m>int(lrec[1]):
                if tanks_m>int(lrec[0]):
                    lrec[2]=lrec[1]
                    lrec[1]=lrec[0]
                    lrec[0]=str(tanks_m)
                else:
                    lrec[2]=lrec[1]
                    lrec[1]=str(tanks_m)

            else:
                lrec[2]=str(tanks_m)
        mapi[0,0]=1
        grup.append(g_mapi)
        grup.append(perdut_text)
        while (boto & ugame.K_START)==False:
            boto = ugame.buttons.get_pressed()
            perdut=False
        grup.remove(perdut_text)
        grup.remove(g_mapi)
        tanks_m=0
    if vari_ini==0:
        mapi[0,0]=0
        grup.append(g_mapi)
        grup.append(z_text)
        while (boto & ugame.K_START)==False:
            boto = ugame.buttons.get_pressed()
            vari_ini=1
        grup.remove(z_text)
        grup.remove(g_mapi)
    if (time.monotonic()-temp)>0.15:
        temp=time.monotonic()
        if varimapa%2==1:
            mapa[0,0]=2
            varimapa+=1
        else:
            mapa[0,0]=3
            varimapa+=1
    if (time.monotonic()-tboto)>0.05 and boto & ugame.K_RIGHT:
        tboto=time.monotonic()
        tank[0,0]=0
        ori="a"
        if 152<= grup_tank.x:
            pass
        else:
            grup_tank.x+=2
            tx+=2
    if (time.monotonic()-tboto)>0.05 and boto & ugame.K_LEFT:
        tboto=time.monotonic()
        tank[0,0]=2
        ori="b"
        if 0>= grup_tank.x:
            pass
        else:
            grup_tank.x-=2
            tx-=2
    if (time.monotonic()-tboto)>0.05 and boto & ugame.K_DOWN:
        tboto=time.monotonic()
        tank[0,0]=3
        ori="c"
        grup_tank.y+=2
        ty+=2
    if (time.monotonic()-tboto)>0.05 and boto & ugame.K_UP:
        tboto=time.monotonic()
        tank[0,0]=1
        ori="d"
        if 0>= grup_tank.y:
            pass
        else:
            grup_tank.y-=2
            ty-=2
    if tx>90 and ty>55:
        mapa[0,0]=1
        nivell=1
        estat=2
    if tx>90 and ty<75:
        mapa[0,0]=0
        nivell=1
        estat=2
    if ty>120:
        grup_tank.y=0
        ty=0
        estat=3
    if not abans & ugame.K_X and boto & ugame.K_X:
        time.sleep(0.2)
        pepsi=True
        abans = boto
        grup.append(pausa)
        while pepsi:
            boto = ugame.buttons.get_pressed()
            if not abans & ugame.K_X and boto & ugame.K_X:
                pepsi=False
            abans = boto
        grup.remove(pausa)
    abans = boto
    while estat==3:
        boto = ugame.buttons.get_pressed()# Llegeix els botons
        if (time.monotonic()-tboto)>0.05*vel and boto & ugame.K_RIGHT:
            tboto=time.monotonic()
            tank[0,0]=0
            ori="a"
            if 152<= grup_tank.x:
                pass
            else:
                grup_tank.x+=2
                tx+=2
        if (time.monotonic()-tboto)>0.05*vel and boto & ugame.K_LEFT:
            tboto=time.monotonic()
            tank[0,0]=2
            ori="b"
            if 0>= grup_tank.x:
                pass
            else:
                grup_tank.x-=2
                tx-=2
        if (time.monotonic()-tboto)>0.05*vel and boto & ugame.K_DOWN:
            tboto=time.monotonic()
            tank[0,0]=3
            ori="c"
            if 120<= grup_tank.y:
                pass
            else:
                grup_tank.y+=2
                ty+=2
        if (time.monotonic()-tboto)>0.05*vel and boto & ugame.K_UP:
            tboto=time.monotonic()
            tank[0,0]=1
            ori="d"
            if -10>= grup_tank.y:
                pass
            else:
                grup_tank.y-=2
                ty-=2
        if tx>90 and ty>55:
            mapa[0,0]=1
            estat=2
            nivell=1
        if tx>90 and ty<75:
            mapa[0,0]=0
            estat=2
            nivell=1
        if ty<-2:
            estat=0
            grup_tank.y=117
            ty=117
        if not abans & ugame.K_X and boto & ugame.K_X:
            time.sleep(0.2)
            pepsi=True
            abans = boto
            grup.append(pausa)
            while pepsi:
                boto = ugame.buttons.get_pressed()
                if not abans & ugame.K_X and boto & ugame.K_X:
                    pepsi=False
                abans = boto
            grup.remove(pausa)
        abans = boto
    while estat==2:
        if nivell==1:
            abans = 0
            ori="a"
            dire1,dire2,dire3,dire4="a","a","a","a"
            instanteInicial=0
            zup=False
            zdown=False
            zleft=False
            zright=False
            (bey1,bey2,bey3,bey4,bex1,bex2,bex3,bex4)=(1,1,1,1,1,1,1,1)
            trestav =0
            tbalaa=2
            tboto = 2
            tEnemicx1= 2
            tEnemicx2= 2
            tEnemicx3= 2
            tEnemicx4= 2
            tEnemicy1= 2
            tEnemicx2= 2
            tEnemicy3= 2
            tEnemicy4= 2
            tbalaEnemic1=2
            tbalaEnemic2=2
            tbalaEnemic3=2
            tbalaEnemic4=2
            tdiparsEnemic1=4
            tdiparsEnemic2=4
            tdiparsEnemic3=4
            tdiparsEnemic4=4
            vides=3
            grup.remove(u_text)
            grup.remove(dos_text)
            grup.remove(tres_text)
            grup.append(tresvides)
            grup.append(dosvides)
            grup.append(unavida)
            grup.append(gt_enemic1)
            grup.append(gb_enemiga1)
            grup.append(gt_enemic2)
            grup.append(gb_enemiga2)
            grup.append(gt_enemic3)
            grup.append(gb_enemiga3)
            grup.append(gt_enemic4)
            grup.append(gb_enemiga4)
            tank_enemic1[0,0]=4
            tank_enemic2[0,0]=4
            tank_enemic3[0,0]=4
            tank_enemic4[0,0]=4
            (gt_enemic1.x,tex1)=(10,10)
            (gt_enemic1.y,tey1)=(10,10)
            (gt_enemic2.x,tex2)=(150,150)
            (gt_enemic2.y,tey2)=(10,10)
            (gt_enemic3.x,tex3)=(150,150)
            (gt_enemic3.y,tey3)=(110,110)
            (gt_enemic4.x,tex4)=(10,10)
            (gt_enemic4.y,tey4)=(110,110)
            (gb_enemiga1.x,bex1)=(-10,-10)
            (gb_enemiga1.y,bey1)=(-10,-10)
            (gb_enemiga2.x,bex2)=(-10,-10)
            (gb_enemiga2.y,bey2)=(-10,-10)
            (gb_enemiga3.x,bex3)=(-10,-10)
            (gb_enemiga3.y,bey3)=(-10,-10)
            (gb_enemiga4.x,bex4)=(-10,-10)
            (gb_enemiga4.y,bey4)=(-10,-10)
            pant.show(grup)
        while nivell==1:
            boto = ugame.buttons.get_pressed()  # Llegeix els botons
            if (time.monotonic()-tboto)>0.02 and boto & ugame.K_RIGHT:
                tboto=time.monotonic()
                tank[0,0]=0
                ori="a"
                if 152<= grup_tank.x:
                    pass
                else:
                    grup_tank.x+=1
                    tx+=1
            if (time.monotonic()-tboto)>0.02 and boto & ugame.K_LEFT:
                tboto=time.monotonic()
                tank[0,0]=2
                ori="b"
                if 0>= grup_tank.x:
                    pass
                else:
                    grup_tank.x-=1
                    tx-=1
            if (time.monotonic()-tboto)>0.02 and boto & ugame.K_DOWN:
                tboto=time.monotonic()
                tank[0,0]=3
                ori="c"
                if 120<= grup_tank.y:
                    pass
                else:
                    grup_tank.y+=1
                    ty+=1
            if (time.monotonic()-tboto)>0.02 and boto & ugame.K_UP:
                tboto=time.monotonic()
                tank[0,0]=1
                ori="d"
                if 0>= grup_tank.y:
                    pass
                else:
                    grup_tank.y-=1
                    ty-=1
            if not abans & ugame.K_O and boto & ugame.K_O and ori=="d" and (time.monotonic()-instanteInicial)>1.8*vel:
                sound.play(pew_sound)
                zup=True
                instanteInicial = time.monotonic()
                grup_bala.x =tx
                grup_bala.y = ty
                by=ty
                bx=tx
            if zup and (time.monotonic()-tbalaa)>0.01:
                tbalaa = time.monotonic()
                grup_bala.y-=1
                by-=1
                if grup_bala.y<=-8:
                    zup=False
            if not abans & ugame.K_O and boto & ugame.K_O and ori=="a"and (time.monotonic()-instanteInicial)>1.8*vel:
                sound.play(pew_sound)
                zright=True
                instanteInicial = time.monotonic()
                grup_bala.x = tx
                grup_bala.y = ty
                by=ty
                bx=tx
            if zright and (time.monotonic()-tbalaa)>0.01:
                tbalaa = time.monotonic()
                grup_bala.x+=1
                bx+=1
                if grup_bala.x>=170:
                    zright=False
            if not abans & ugame.K_O and boto & ugame.K_O and ori=="b"and (time.monotonic()-instanteInicial)>1.8*vel:
                sound.play(pew_sound)
                zleft=True
                instanteInicial = time.monotonic()
                grup_bala.x = tx
                grup_bala.y = ty
                by=ty
                bx=tx
            if zleft and (time.monotonic()-tbalaa)>0.01:
                tbalaa = time.monotonic()
                grup_bala.x-=1
                bx-=1
                if grup_bala.x<=-7:
                    zleft=False
            if not abans & ugame.K_O and boto & ugame.K_O and ori=="c"and (time.monotonic()-instanteInicial)>1.8*vel:
                sound.play(pew_sound)
                zdown=True
                instanteInicial = time.monotonic()
                grup_bala.x = tx
                grup_bala.y = ty
                by=ty
                bx=tx
            if zdown and (time.monotonic()-tbalaa)>0.01:
                tbalaa = time.monotonic()
                grup_bala.y+=1
                by+=1
                if grup_bala.y>=135:
                    zdown=False
            if not abans & ugame.K_X and boto & ugame.K_X:
                time.sleep(0.2)
                pepsi=True
                abans = boto
                grup.append(pausa)
                pausa.x = 64
                pausa.y = 85
                while pepsi:
                    boto = ugame.buttons.get_pressed()
                    if not abans & ugame.K_X and boto & ugame.K_X:
                        pepsi=False
                    abans = boto
                grup.remove(pausa)
            if tey1<ty and (time.monotonic()-tEnemicy1)>0.2*vel*vel and random.choice([True,False])and ((tey1<tey2-12) or tex1<tex2-10 or tex1>tex2+10)and((tey1<tey3-12) or tex1<tex3-10 or tex1>tex3+10)and((tey1<tey4-12) or tex1<tex4-10 or tex1>tex4+10)and((tey1<ty-12) or tex1<tx-10 or tex1>tx+10):
                tEnemicy1=time.monotonic()
                tey1+=1
                gt_enemic1.y+=1
                tank_enemic1[0,0]=7
            if tey1>ty and (time.monotonic()-tEnemicy1)>0.2*vel*vel and random.choice([True,False])and ((tey1>tey2+12) or tex1<tex2-10 or tex1>tex2+10)and((tey1>tey3+12) or tex1<tex3-10 or tex1>tex3+10)and((tey1>tey4+12) or tex1<tex4-10 or tex1>tex4+10)and((tey1>ty+12) or tex1<tx-10 or tex1>tx+10):
                tEnemicy1=time.monotonic()
                tey1-=1
                gt_enemic1.y-=1
                tank_enemic1[0,0]=5
            if tex1<tx and (time.monotonic()-tEnemicx1)>0.2*vel*vel and random.choice([True,False])and ((tex1<tex2-12) or tey1<tey2-10 or tey1>tey2+10)and((tex1<tex3-12) or tey1<tey3-10 or tey1>tey3+10)and((tex1<tex4-12) or tey1<tey4-10 or tey1>tey4+10)and((tex1<tx-12) or tey1<ty-10 or tey1>ty+10):
                tEnemicx1=time.monotonic()
                tex1+=1
                gt_enemic1.x+=1
                tank_enemic1[0,0]=4
            if tex1>tx and (time.monotonic()-tEnemicx1)>0.2*vel*vel and random.choice([True,False])and ((tex1>tex2+12) or tey1<tey2-10 or tey1>tey2+10)and((tex1>tex3+12) or tey1<tey3-10 or tey1>tey3+10)and((tex1>tex4+12) or tey1<tey4-10 or tey1>tey4+10)and((tex1>tx+12) or tey1<ty-10 or tey1>ty+10):
                tEnemicx1=time.monotonic()
                tex1-=1
                gt_enemic1.x-=1
                tank_enemic1[0,0]=6
            if tex2<tx and (time.monotonic()-tEnemicx2)>0.2*vel*vel and ((tex2<tex1-12) or tey2<tey1-10 or tey2>tey1+10)and((tex2<tex3-12) or tey2<tey3-10 or tey2>tey3+10)and((tex2<tex4-12) or tey2<tey4-10 or tey2>tey4+10)and((tex2<tx-12) or tey2<ty-10 or tey2>ty+10):
                tEnemicx2=time.monotonic()
                tex2+=1
                gt_enemic2.x+=1
                tank_enemic2[0,0]=4
            if tex2>tx and (time.monotonic()-tEnemicx2)>0.2*vel*vel and ((tex2>tex1+12) or tey2<tey1-10 or tey2>tey1+10)and((tex2>tex3+12) or tey2<tey3-10 or tey2>tey3+10)and((tex2>tex4+12) or tey2<tey4-10 or tey2>tey4+10)and((tex2>tx+12) or tey2<ty-10 or tey2>ty+10):
                tEnemicx2=time.monotonic()
                tex2-=1
                gt_enemic2.x-=1
                tank_enemic2[0,0]=6
            if tey2<ty and (time.monotonic()-tEnemicx2)>0.2*vel*vel and ((tey2<tey1-12) or tex2<tex1-10 or tex2>tex1+10)and((tey2<tey3-12) or tex2<tex3-10 or tex2>tex3+10)and((tey2<tey4-12) or tex2<tex4-10 or tex2>tex4+10)and((tey2<ty-12) or tex2<tx-10 or tex2>tx+10):
                tEnemicx2=time.monotonic()
                tey2+=1
                gt_enemic2.y+=1
                tank_enemic2[0,0]=7
            if tey2>ty and (time.monotonic()-tEnemicx2)>0.2*vel*vel and ((tey2>tey1+12) or tex2<tex1-10 or tex2>tex1+10)and((tey2>tey3+12) or tex2<tex3-10 or tex2>tex3+10)and((tey2>tey4+12) or tex2<tex4-10 or tex2>tex4+10)and((tey2>ty+12) or tex2<tx-10 or tex2>tx+10):
                tEnemicx2=time.monotonic()
                tey2-=1
                gt_enemic2.y-=1
                tank_enemic2[0,0]=5
            if tey3<ty and (time.monotonic()-tEnemicy3)>0.2*vel*vel and ((tey3<tey1-12) or tex3<tex1-10 or tex3>tex1+10)and((tey3<tey2-12) or tex3<tex2-10 or tex3>tex2+10)and((tey3<tey4-12) or tex3<tex4-10 or tex3>tex4+10)and((tey3<ty-12) or tex3<tx-10 or tex3>tx+10):
                tEnemicy3=time.monotonic()
                tey3+=1
                gt_enemic3.y+=1
                tank_enemic3[0,0]=7
            if tey3>ty and (time.monotonic()-tEnemicy3)>0.2*vel*vel and ((tey3>tey1+12) or tex3<tex1-10 or tex3>tex1+10)and((tey3>tey2+12) or tex3<tex2-10 or tex3>tex2+10)and((tey3>tey4+12) or tex3<tex4-10 or tex3>tex4+10)and((tey3>ty+12) or tex3<tx-10 or tex3>tx+10):
                tEnemicy3=time.monotonic()
                tey3-=1
                gt_enemic3.y-=1
                tank_enemic3[0,0]=5
            if tex3<tx and (time.monotonic()-tEnemicy3)>0.2*vel*vel and ((tex3<tex1-12) or tey3<tey1-10 or tey3>tey1+10)and((tex3<tex2-12) or tey3<tey2-10 or tey3>tey2+10)and((tex3<tex4-12) or tey3<tey4-10 or tey3>tey4+10)and((tex3<tx-12) or tey3<ty-10 or tey3>ty+10):
                tEnemicy3=time.monotonic()
                tex3+=1
                gt_enemic3.x+=1
                tank_enemic3[0,0]=4
            if tex3>tx and (time.monotonic()-tEnemicy3)>0.2*vel*vel and ((tex3>tex1+12) or tey3<tey1-10 or tey3>tey1+10)and((tex3>tex2+12) or tey3<tey2-10 or tey3>tey2+10)and((tex3>tex4+12) or tey3<tey4-10 or tey3>tey4+10)and((tex3>tx+12) or tey3<ty-10 or tey3>ty+10):
                tEnemicy3=time.monotonic()
                tex3-=1
                gt_enemic3.x-=1
                tank_enemic3[0,0]=6
            if tex4<tx and (time.monotonic()-tEnemicx4)>0.2*vel*vel and random.choice([True,False])and ((tex4<tex1-12) or tey4<tey1-10 or tey4>tey1+10)and((tex4<tex2-12) or tey4<tey2-10 or tey4>tey2+10)and((tex4<tex3-12) or tey4<tey3-10 or tey4>tey3+10)and((tex4<tx-12) or tey4<ty-10 or tey4>ty+10):
                tEnemicx4=time.monotonic()
                tex4+=1
                gt_enemic4.x+=1
                tank_enemic4[0,0]=4
            if tex4>tx and (time.monotonic()-tEnemicx4)>0.2*vel*vel and random.choice([True,False]) and ((tex4>tex1+12) or tey4<tey1-10 or tey4>tey1+10)and((tex4>tex2+12) or tey4<tey2-10 or tey4>tey2+10)and((tex4>tex3+12) or tey4<tey3-10 or tey4>tey3+10)and((tex4>tx+12) or tey4<ty-10 or tey4>ty+10):
                tEnemicx4=time.monotonic()
                tex4-=1
                gt_enemic4.x-=1
                tank_enemic4[0,0]=6
            if tey4<ty and (time.monotonic()-tEnemicy4)>0.2*vel*vel and random.choice([True,False])and ((tey4<tey1-12) or tex4<tex1-10 or tex4>tex1+10)and((tey4<tey2-12) or tex4<tex2-10 or tex4>tex2+10)and((tey4<tey3-12) or tex4<tex3-10 or tex4>tex3+10)and((tey4<ty-12) or tex4<tx-10 or tex4>tx+10):
                tEnemicy4=time.monotonic()
                tey4+=1
                gt_enemic4.y+=1
                tank_enemic4[0,0]=7
            if tey4>ty and (time.monotonic()-tEnemicy4)>0.2*vel*vel and random.choice([True,False]) and ((tey4>tey1+12) or tex4<tex1-10 or tex4>tex1+10)and((tey4>tey2+12) or tex4<tex2-10 or tex4>tex2+10)and((tey4>tey3+12) or tex4<tex3-10 or tex4>tex3+10)and((tey4>ty+12) or tex4<tx-10 or tex4>tx+10):
                tEnemicy4=time.monotonic()
                tey4-=1
                gt_enemic4.y-=1
                tank_enemic4[0,0]=5
            if (time.monotonic()-tdiparsEnemic4)>3*vel and -4<tey4<124 and -4<tex4<164:
                vex,vey=(tx-tex4,ty-tey4)
                if vex>2*vey and vex>-2*vey:
                    tdiparsEnemic4=time.monotonic()
                    gb_enemiga4.x=tex4
                    bex4=tex4
                    gb_enemiga4.y=tey4
                    bey4=tey4
                    dire4="rdreta"
                if vex<-2*vey and vex<2*vey:
                    tdiparsEnemic4=time.monotonic()
                    gb_enemiga4.x=tex4
                    bex4=tex4
                    gb_enemiga4.y=tey4
                    bey4=tey4
                    dire4="resquerre"
                if vey>2*vex and vey>-2*vex:
                    tdiparsEnemic4=time.monotonic()
                    gb_enemiga4.x=tex4
                    bex4=tex4
                    gb_enemiga4.y=tey4
                    bey4=tey4
                    dire4="ravall"
                if vey<-2*vex and vey<2*vex:
                    tdiparsEnemic4=time.monotonic()
                    gb_enemiga4.x=tex4
                    bex4=tex4
                    gb_enemiga4.y=tey4
                    bey4=tey4
                    dire4="ramunt"
            if (time.monotonic()-tbalaEnemic4)>0.01:
                tbalaEnemic4=time.monotonic()
                if dire4=="rdreta":
                    gb_enemiga4.x+=1
                    bex4+=1
                if dire4=="resquerre":
                    gb_enemiga4.x-=1
                    bex4-=1
                if dire4=="ravall":
                    gb_enemiga4.y+=1
                    bey4+=1
                if dire4=="ramunt":
                    gb_enemiga4.y-=1
                    bey4-=1
            if (time.monotonic()-tdiparsEnemic3)>3*vel and -4<tey3<124 and -4<tex3<164:
                vex,vey=(tx-tex3,ty-tey3)
                if vex>2*vey and vex>-2*vey:
                    tdiparsEnemic3=time.monotonic()
                    gb_enemiga3.x=tex3
                    bex3=tex3
                    gb_enemiga3.y=tey3
                    bey3=tey3
                    dire3="rdreta"
                if vex<-2*vey and vex<2*vey:
                    tdiparsEnemic3=time.monotonic()
                    gb_enemiga3.x=tex3
                    bex3=tex3
                    gb_enemiga3.y=tey3
                    bey3=tey3
                    dire3="resquerre"
                if vey>2*vex and vey>-2*vex:
                    tdiparsEnemic3=time.monotonic()
                    gb_enemiga3.x=tex3
                    bex3=tex3
                    gb_enemiga3.y=tey3
                    bey3=tey3
                    dire3="ravall"
                if vey<-2*vex and vey<2*vex:
                    tdiparsEnemic3=time.monotonic()
                    gb_enemiga3.x=tex3
                    bex3=tex3
                    gb_enemiga3.y=tey3
                    bey3=tey3
                    dire3="ramunt"
            if (time.monotonic()-tbalaEnemic3)>0.01:
                tbalaEnemic3=time.monotonic()
                if dire3=="rdreta":
                    gb_enemiga3.x+=1
                    bex3+=1
                if dire3=="resquerre":
                    gb_enemiga3.x-=1
                    bex3-=1
                if dire3=="ravall":
                    gb_enemiga3.y+=1
                    bey3+=1
                if dire3=="ramunt":
                    gb_enemiga3.y-=1
                    bey3-=1
            if (time.monotonic()-tdiparsEnemic2)>3*vel and -4<tey2<124 and -4<tex2<164:
                vex,vey=(tx-tex2,ty-tey2)
                if vex>2*vey and vex>-2*vey:
                    tdiparsEnemic2=time.monotonic()
                    gb_enemiga2.x=tex2
                    bex2=tex2
                    gb_enemiga2.y=tey2
                    bey2=tey2
                    dire2="rdreta"
                if vex<-2*vey and vex<2*vey:
                    tdiparsEnemic2=time.monotonic()
                    gb_enemiga2.x=tex2
                    bex2=tex2
                    gb_enemiga2.y=tey2
                    bey2=tey2
                    dire2="resquerre"
                if vey>2*vex and vey>-2*vex:
                    tdiparsEnemic2=time.monotonic()
                    gb_enemiga2.x=tex2
                    bex2=tex2
                    gb_enemiga2.y=tey2
                    bey2=tey2
                    dire2="ravall"
                if vey<-2*vex and vey<2*vex:
                    tdiparsEnemic2=time.monotonic()
                    gb_enemiga2.x=tex2
                    bex2=tex2
                    gb_enemiga2.y=tey2
                    bey2=tey2
                    dire2="ramunt"
            if (time.monotonic()-tbalaEnemic2)>0.01:
                tbalaEnemic2=time.monotonic()
                if dire2=="rdreta":
                    gb_enemiga2.x+=1
                    bex2+=1
                if dire2=="resquerre":
                    gb_enemiga2.x-=1
                    bex2-=1
                if dire2=="ravall":
                    gb_enemiga2.y+=1
                    bey2+=1
                if dire2=="ramunt":
                    gb_enemiga2.y-=1
                    bey2-=1
            if (time.monotonic()-tdiparsEnemic1)>3*vel and -4<tey1<124 and -4<tex1<164:
                vex,vey=(tx-tex1,ty-tey1)
                if vex>2*vey and vex>-2*vey:
                    tdiparsEnemic1=time.monotonic()
                    gb_enemiga1.x=tex1+4
                    bex1=tex1+4
                    gb_enemiga1.y=tey1+4
                    bey1=tey1+4
                    dire1="rdreta"
                if vex<-2*vey and vex<2*vey:
                    tdiparsEnemic1=time.monotonic()
                    gb_enemiga1.x=tex1+4
                    bex1=tex1+4
                    gb_enemiga1.y=tey1+4
                    bey1=tey1+4
                    dire1="resquerre"
                if vey>2*vex and vey>-2*vex:
                    tdiparsEnemic1=time.monotonic()
                    gb_enemiga1.x=tex1+4
                    bex1=tex1+4
                    gb_enemiga1.y=tey1+4
                    bey1=tey1+4
                    dire1="ravall"
                if vey<-2*vex and vey<2*vex:
                    tdiparsEnemic1=time.monotonic()
                    gb_enemiga1.x=tex1+4
                    bex1=tex1+4
                    gb_enemiga1.y=tey1+4
                    bey1=tey1+4
                    dire1="ramunt"
            if (time.monotonic()-tbalaEnemic1)>0.01:
                tbalaEnemic1=time.monotonic()
                if dire1=="rdreta":
                    gb_enemiga1.x+=1
                    bex1+=1
                if dire1=="resquerre":
                    gb_enemiga1.x-=1
                    bex1-=1
                if dire1=="ravall":
                    gb_enemiga1.y+=1
                    bey1+=1
                if dire1=="ramunt":
                    gb_enemiga1.y-=1
                    bey1-=1
            if (time.monotonic()-trestav)>0.45 and ((-2<(bey1-ty)<10 and  -2<(bex1-tx)<10) or (-2<(bey2-ty)<10 and  -2<(bex2-tx)<10) or (-2<(bey3-ty)<10 and  -2<(bex3-tx)<10) or (-2<(bey4-ty)<10 and  -2<(bex4-tx)<10)):
                trestav=time.monotonic()
                vides -=1
                sound.play(boom_sound)
                passat=tank[0,0]
                tank[0,0]=8
                time.sleep(0.15)
                tank[0,0]=passat
                if vides==2:
                    grup.remove(tresvides)
                if vides==1:
                    grup.remove(dosvides)
                if vides==0:
                    grup.remove(unavida)
                    estat=1
                    nivell=69
                    abans = 0
                    ori="a"
                    instanteInicial=0
                    zup=False
                    zdown=False
                    zleft=False
                    zright=False
                    tboto = 2
                    varimapa=1
                    temp=0
                    estat=0
                    grup.append(u_text)
                    grup.append(dos_text)
                    grup.append(tres_text)
                    grup.remove(gt_enemic1)
                    grup.remove(gb_enemiga1)
                    grup.remove(gt_enemic2)
                    grup.remove(gb_enemiga2)
                    grup.remove(gt_enemic3)
                    grup.remove(gb_enemiga3)
                    grup.remove(gt_enemic4)
                    grup.remove(gb_enemiga4)
                    pant.show(grup)
                    (tx, grup_tank.x) = (64,64)
                    (ty, grup_tank.y) = (64,64)
                    (grup_bala.x , grup_bala.y, bx, by)=(-1000,-1000,-1000,-1000)
                    vari_ini=0
                    perdut=True
            if (time.monotonic()-txoc)>2 and ((-10<(tey1-ty)<10 and  -10<(tex1-tx)<10) or (-10<(tey2-ty)<10 and  -10<(tex2-tx)<10) or (-10<(tey3-ty)<10 and  -10<(tex3-tx)<10) or (-10<(tey4-ty)<10 and  -10<(tex4-tx)<10)):
                txoc=time.monotonic()
                vides -=1
                sound.play(boom_sound)
                passat=tank[0,0]
                tank[0,0]=8
                time.sleep(0.15)
                tank[0,0]=passat
                if vides==2:
                    grup.remove(tresvides)
                if vides==1:
                    grup.remove(dosvides)
                if vides==0:
                    grup.remove(unavida)
                    estat=1
                    nivell=69
                    abans = 0
                    ori="a"
                    instanteInicial=0
                    zup=False
                    zdown=False
                    zleft=False
                    zright=False
                    tboto = 2
                    varimapa=1
                    temp=0
                    estat=0
                    grup.append(u_text)
                    grup.append(dos_text)
                    grup.append(tres_text)
                    grup.remove(gt_enemic1)
                    grup.remove(gb_enemiga1)
                    grup.remove(gt_enemic2)
                    grup.remove(gb_enemiga2)
                    grup.remove(gt_enemic3)
                    grup.remove(gb_enemiga3)
                    grup.remove(gt_enemic4)
                    grup.remove(gb_enemiga4)
                    pant.show(grup)
                    (tx, grup_tank.x) = (64,64)
                    (ty, grup_tank.y) = (64,64)
                    (grup_bala.x , grup_bala.y, bx, by)=(-1000,-1000,-1000,-1000)
                    vari_ini=0
                    perdut=True
            if -2<by-tey1<10 and  -2<bx-tex1<10:
                gt_enemic1.x=-90
                gt_enemic1.y=-90
                tex1=-90
                tey1=-90
                tanks_m+=1
                vel=vel-vel*0.05
            if -2<by-tey2<10 and  -2<bx-tex2<10:
                gt_enemic2.x=-90
                gt_enemic2.y=200
                tex2=-90
                tey2=200
                tanks_m+=1
                vel=vel-vel*0.05
            if -2<by-tey3<10 and  -2<bx-tex3<10:
                gt_enemic3.x=230
                gt_enemic3.y=130
                tex3=230
                tey3=130
                tanks_m+=1
                vel=vel-vel*0.05

            if -2<by-tey4<10 and  -2<bx-tex4<10:
                gt_enemic4.x=230
                gt_enemic4.y=-70
                tex4=230
                tey4=-70
                tanks_m+=1
                vel=vel-vel*0.05
            abans = boto

 

 

 

 

 

 

 

 

 

 

Licencia de Creative Commons
Esta obra de Oriol Boix está licenciada bajo una licencia no importada Creative Commons Reconocimiento-NoComercial-SinObraDerivada 3.0.