Tanks.py peut engendrer des erreurs.
Si jamais vous avez une erreur du type MemoryError: memory allocation failed, allocating 348 bytes
sur le jeu tanks original . Testez celui-ci
#Jeu commence par ANTARCTUS le 2/2/21 #Avancee le 23/2/21 from random import * from kandinsky import * from ion import * from time import * l=[0,4,8,12,16,16,16,16,16,12,8,4,0,0,0,0] touches=[KEY_EXP,KEY_BACKSPACE,KEY_ZERO,KEY_EXE,KEY_SEVEN,KEY_RIGHTPARENTHESIS] spawn=[[50,50],[250,50],[50,150],[250,150],[150,50],[150,150]] color=[(255,0,0),(0,0,255),(0,255,0),(255,255,0),(255,0,255),(0,255,255)] def draw_tank(tank): x=tank[0][0] y=tank[0][1] o=tank[2] color=tank[4] color_roue=(0,)*3 color_roue=(200*sup_pouv(tank,1),50*sup_pouv(tank,1),0) if sup_pouv(tank,0): fill_rect(x-4,y-4,28,28,(0,155,155)) fill_rect(x-2,y-2,24,24,(0,255,255)) if sup_pouv(tank,3): color=(255,)*3 for i in range(2,15,4): fill_rect(x+l[(o+i)%16],y+l[(o+i+4)%16],4,4,color_roue) fill_rect(x+3,y+3,14,14,color) fill_rect(x+l[(o+12)%16]-1,y+l[o%16]-1,6,6,(50,)*3) if sup_pouv(tank,2): fill_rect(x+l[(o+12-1)%16],y+l[(o-1)%16],4,4,(100,)*3) fill_rect(x+l[(o+12+1)%16],y+l[(o+1)%16],4,4,(100,)*3) def draw_caisse(caisse): for i in range(3): fill_rect(caisse[0][0]-[5,2,5][i],caisse[0][1]-[5,5,2][i],[10,4,10][i],[10,10,4][i],caisse[1][i]) stades_anim=[ (250,0,0), (250,60,0), (200,60,0), (0,)*3 ] tanks=[ #[[50,50],[],0,KEY_SHIFT,(255,0,0),False,1,[]], #[[270,50],[],0,KEY_BACKSPACE,(0,0,255),False,1,[]], #[[50,170],[],0,KEY_EXE,(0,255,0),False,1,[]], #[[270,170],[],0,KEY_ZERO,(255,255,0),False,1,[]] ] #[x, y],[spawnX,spawnY], orientation, touche, couleur(equipe) #, a tire, sens de rotation, #superpouvoirs boulets=[] scores={} animations=[] caisses=[] #[x,y],[coul1,2,3],[[effet1,prob],[eff2,prob]] def dist(tank,coord,dist_min): return ((((tank[0][0]+8)-coord[0])**2+((tank[0][1]+8)-coord[1])**2)**(1/2))<dist_min def sup_pouv(tank,n): for i in tank[7]: if i[0]==n: return True return False def draw_menu(mode=0,n_joueur=1): fill_rect(0,0,320,222,(0,)*3) # for i in range(1,6): # fill_rect(200+i*2,i*2,120-i*4,120-i*4,(51*i,)*3) # for tank in (([270,40],[],0,0,(255,0,0),0,1,[]),([220,70],[],11,0,(0,0,255),0,1,[]),): # draw_tank(tank) # fill_rect(260,60,6,6,(0,0,255)) # draw_caisse([[250,20],[(200,100,0),(200,80,0),(220,120,20)],[]]) draw_string("Mode de jeu:",20,10) for i in range(5): draw_string([" equipe "," zombi "," deathmatch "," chacun pour soi "," conquerant "][i],30,30+20*i,(255,)*3,(0+(60*(mode==i)),)*3) draw_string("Nombre de joueurs:",20,140) for i in range(1,7): draw_string("123456"[i-1],50+20*(i-1),160,(255,)*3,(0+(60*(i==n_joueur)),)*3) draw_string(" JOUER ",100,190,(0,)*3,(255,0,0)) def setup(mode_id,players): global tanks # tanks=[] for i in range(players): tanks.append([ spawn[i][:], [spawn[i][:],spawn[i][:],[-1000,-2500],spawn[i][:],spawn[i][:]][mode_id], 0,touches[i], color[i%[2,1,6,6,6][mode_id]]*(i!=0 or mode_id!=1)+(0,255,0)*(i==0 and mode_id==1), False,1, [[-1,32000*((mode_id==1 and i==0)or mode_id==4)],] ]) scores[color[i%[2,1,6,6,6][mode_id]]*(i!=0 or mode_id!=1)+(0,255,0)*(i==0 and mode_id==1)]=0 def decompte(): for i in range(select[1]+1): draw_string(["e^x","clear","zero","exe","seven","parenthesis"][i],spawn[i][0]+10,spawn[i][1]+10) for i in (((0,0,40,10),(0,15,40,10),(0,30,40,10),(30,0,10,40)),((0,0,40,10),(30,0,10,15),(0,15,40,10),(0,25,10,15),(0,30,40,10)),((20,0,20,10),(30,0,10,40))): fill_rect(140,91,40,40,(255,)*3) for j in i: fill_rect(j[0]+140,j[1]+91,j[2],j[3],(0,)*3) sleep(1) select=[0,0] draw_menu() while not keydown(KEY_OK): for i in range(0,4): if keydown(i): select[1]+=[-1,0,0,1][i] select[0]+=[0,-1,1,0][i] select[1]%=6 select[0]%=5 draw_menu(select[0],select[1]+1) sleep(0.1) setup(select[0],select[1]+1) while True: t=monotonic() fill_rect(0,0,320,222,(255,)*3) for i in range(len(tanks)): if keydown(tanks[i][3]): tanks[i][0][0]+=int((l[(tanks[i][2]+12)%16]-8)/2)*(1+sup_pouv(tanks[i],4)) tanks[i][0][1]+=int((l[(tanks[i][2] )%16]-8)/2)*(1+sup_pouv(tanks[i],4)) for j in range(2): if sup_pouv(tanks[i],1): tanks[i][0][j]=(tanks[i][0][j]+10)%[320,222][j]-10 else: tanks[i][0][j]=tanks[i][0][j]*(tanks[i][0][j]>0)*(tanks[i][0][j]<[300,202][j])+[300,202][j]*(tanks[i][0][j]>=[300,202][j]) if tanks[i][5]==False: tanks[i][5]=True for j in range(2): tanks[i][0][j]-=int((l[(tanks[i][2]+(1-j)*12)%16]-8)/2)*2 # tanks[i][0][0]-=int((l[(tanks[i][2]+12)%16]-8)/2)*2 # tanks[i][0][1]-=int((l[(tanks[i][2] )%16]-8)/2)*2 for varia in range(0-sup_pouv(tanks[i],2),1+sup_pouv(tanks[i],2),1): boulets.append( [tanks[i][0][0]+l[(tanks[i][2]+12)%16], tanks[i][0][1]+l[tanks[i][2]%16], (tanks[i][2]+varia)%16,tanks[i][4],sup_pouv(tanks[i],-1)]) tanks[i][6]*=-1 else: tanks[i][2]=(tanks[i][2]+tanks[i][6])%16 tanks[i][5]=False draw_tank(tanks[i]) for i in range(len(animations)-1,-1,-1): fill_rect(animations[i][0],animations[i][1],animations[i][2],animations[i][2],stades_anim[animations[i][3]]) animations[i][3]+=1 if animations[i][3]==len(stades_anim): del animations[i] for i in range(len(caisses)-2,-1,-1): draw_caisse(caisses[i]) for j in range(len(tanks)-1,-1,-1): if dist(tanks[j],caisses[i][0],15): tanks[j][7]+=caisses[i][2][:] del caisses[i] for i in range(len(boulets)-1,-1,-1): for j in range(2): boulets[i][j]+=l[(boulets[i][2]+((1-j)*12))%16]-8 # boulets[i][0]+=l[(boulets[i][2]+12)%16]-8 # boulets[i][1]+=l[(boulets[i][2] )]-8 if not(0<boulets[i][0]<320 and 0<boulets[i][1]<222): del boulets[i] continue fill_rect(boulets[i][0],boulets[i][1],6,6,boulets[i][3]) for j in range(len(tanks)): if tanks[j][4]==boulets[i][3]: continue if dist(tanks[j],boulets[i],15): if sup_pouv(tanks[j],0): del boulets[i] for pouv in tanks[j][7]: if pouv[0]==0: pouv[1]=-5 break animations.append([tanks[j][0][0],tanks[j][0][1],20,0]) tanks[j][0]=tanks[j][1][:] tanks[j][3]*=(select[0]!=2) tanks[j][7].append([0,3]) scores[boulets[i][3]]+=1 if boulets[i][4]: tanks[j][4]=boulets[i][3] tanks[j][7].append([-1,32000]) del boulets[i] break for i in scores.items(): draw_string(str(i[1]),10,20*[(255,0,0),(0,255,0),(0,0,255),(0,255,255),(255,0,255),(255,255,0)].index(i[0]),i[0]) for i in range(len(tanks)): for j in range(len(tanks[i][7])-1,-1,-1): tanks[i][7][j][1]-=0.1 if tanks[i][7][j][1]<0: del tanks[i][7][j] if randint(0,79)==0: r=randint(0,15) r=2-(r in [1,2,3])-2*(r==0) caisses.append([ [randint(10,290),randint(10,192)], [[(250,100,0),(250,230,0),(250,200,100)],[(60,)*3,(0,0,120),(0,0,150)],[(200,100,0),(200,80,0),(220,120,20)]][r], [[[0,6],[1,6],[2,6],[3,6],[4,6]], [[randint(0,4),16],], [[randint(0,4),8],]][r] ]) sleep((0.1+t-monotonic())*((0.1+t-monotonic())>0)) try: decompte() del decompte except: pass