1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
| from tkinter import *
#-------------------------------------------------------------- Move ( Déplacement du J1 et J2 grâce à des listes )
def move (event=None):
global move1,d1x,d1y, move2, d2x,d2y, move3,d3x,d3y, explosion,exploj1,exploj2,cptexplo
#-----j1
if 150<move1[1]<1015 and 130<move1[2]<570:# and ( move1[1]!= move2[1] and move1[2]!= move2[2]):
move1[1]=move1[1]+d1x
move1[2]=move1[2]+d1y
canvas1.coords(move1[0],move1[1],move1[2])
else :
#exploj1 0=explosion possible 1= explose , 2= explosion non possible
if exploj1==0:
canvas1.itemconfig(voitjr1,image=vide)
exploj1 = 1
cptexplo=0
explosion1()
#-----j2
if 185<move2[1]<1050 and 130<move2[2]<570 : #and ( move1[1]!= move2[1] and move1[2]!= move2[2]):
move2[1]=move2[1]+d2x
move2[2]=move2[2]+d2y
canvas1.coords(move2[0],move2[1],move2[2])
else:
if exploj2==0:
canvas1.itemconfig(voitjr2,image=vide)
exploj2 = 1
cptexplo=0
explosion2()
#-----Ballon
if 185<move3[1]<1050 and 130<move3[2]<570 :
if move1[1]== move3[1] :
d3x=d1x
move3[1]=move3[1]+d3x
move3[2]=move3[2]+d3y
canvas1.coords(move3[0],move3[1],move3[2],move3[1]+40,move3[2]+40)
fen.after(5,move)
#--------------------------------------------------------------Voiture 1 controls
def gauche1(event=None):
global d1x,d1y
d1x=-v1
d1y=0
canvas1.itemconfig(voitjr1,image=CLR1[3])
def droite1(event=None):
global d1x,d1y
d1x=+v1
d1y=0
canvas1.itemconfig(voitjr1,image=CLR1[0])
def haut1(event=None):
global d1x,d1y
d1x=0
d1y=-v1
canvas1.itemconfig(voitjr1,image=CLR1[1])
def bas1(event=None):
global d1x,d1y
d1x=0
d1y=+v1
canvas1.itemconfig(voitjr1,image=CLR1[2])
#----------------------------------------------------------------Voiture 2 controls
def gauche2(event=None):
global d2x,d2y
d2x=-v2
d2y=0
canvas1.itemconfig(voitjr2,image=CLR2[3])
def droite2(event=None):
global d2x,d2y
d2x=+v2
d2y=0
canvas1.itemconfig(voitjr2,image=CLR2[0])
def haut2(event=None):
global d2x,d2y
d2x=0
d2y=-v2
canvas1.itemconfig(voitjr2,image=CLR2[1])
def bas2(event=None):
global d2x,d2y
d2x=0
d2y=+v2
canvas1.itemconfig(voitjr2,image=CLR2[2])
#----------------------------------------------------------------Création Annimation
def animation(event=None):
global cpt,anim
if cpt < len(L):
canvas1.itemconfig(anim, image = L[cpt])
cpt+=1
canvas1.after(1000,animation)
else:
move()
def explosion1 ():
#exploj 0=explosion possible 1= explose , 2= explosion non possible
global cptexplo1,ListeExplosion,exploj1
if cptexplo1<=10:
if exploj1 == 1:
canvas1.itemconfig(voitjr1,image=ListeExplosion[cptexplo1])
cptexplo1=cptexplo1+1
canvas1.after(100,explosion1)
else:
exploj1=2
restart(1)
def explosion2 ():
#exploj 0=explosion possible 1= explose , 2= explosion non possible
global cptexplo2,ListeExplosion,exploj2
if cptexplo2<=10:
if exploj2 == 1:
canvas1.itemconfig(voitjr2,image=ListeExplosion[cptexplo2])
cptexplo2=cptexplo2+1
canvas1.after(100,explosion2)
else:
exploj2=2
restart(2)
def restart (joueur):
global exploj1,d1x,d1y,cptexplo1,exploj2,d2x,d2y,cptexplo2
if joueur==1:
cptexplo1=0
exploj1=0
d1x=0
d1y=0
move1[1]=270
move1[2]=350
canvas1.coords(move1[0],move1[1],move1[2])
canvas1.itemconfig(voitjr1,anchor=W,image=CLR1[0])
if joueur==2:
cptexplo2=0
exploj2=0
d2x=0
d2y=0
move2[1]=950
move2[2]=350
canvas1.coords(move2[0],move2[1],move2[2])
canvas1.itemconfig(voitjr2,anchor=E,image=CLR2[3])
#----------------------------------------------------------------Création Terrain
def terrain () :
global canvas1,x1,y1,x2,y2,move1,paletimg,d1x,d1y,d2x,d2y,move2,voitjr1,voitjr2,map1,anim,xb,yb,move3
terrain=canvas1.create_image(150,100,anchor=NW,image=map1)
anim=canvas1.create_image(600,258,image=L[0])
animation()
voitjr1=canvas1.create_image(x1,y1,anchor=W,image=CLR1[0])
voitjr2=canvas1.create_image(x2,y2,anchor=E,image=CLR2[3])
ballon=canvas1.create_oval(x3, y3, x3+40, y3+40, fill="red")
start.configure(text = "Pause", command=pause)
move1=[voitjr1,x1,y1]
move2=[voitjr2,x2,y2]
move3=[ballon,x3,y3]
#------------------------------------------------------------------Commande Stop
def pause(event=None):
global d1x,d2x,d2y,d1y
d1x=0
d1y=0
d2x=0
d2y=0
#------------------------------------------------------------------Commande des Options
def option ():
global fenop
fenop=Tk()
fenop.title("Option")
fenop.geometry("220x500")
fenop['bg']='grey'
pts5=Checkbutton(fenop,text="5 Points ").pack()
profil1=Button(fenop,text="profil J1",width=8,command=j1opt).pack()
profil2=Button(fenop,text="profil J2",width=8,command=j2opt).pack()
okopt=Button(fenop,text="Exit",width=8,command=fenop.destroy).pack(side=BOTTOM)
#------------------------------------------------------------------Couleur Option joueur 1
def j1opt ():
framej1=Frame(fenop,borderwidth=20,relief=GROOVE)
framej1['bg']='white'
framej1.pack(side=LEFT,padx=50)
j1cv = Button(framej1, text ='Couleur J1',relief=FLAT,bg='white',width=10).pack()
j1cvb = Button(framej1, text ='BLEU',relief=RAISED,bg='blue',width=10,command=j1bleu).pack()
j1cvg = Button(framej1, text ='GRIS',relief=RAISED,bg='grey',width=10,command=j1gris).pack()
j1cvm = Button(framej1, text ='MARRON',relief=RAISED,bg='brown',width=10,command=j1marron).pack()
j1cvr = Button(framej1, text ='ROUGE',relief=RAISED,bg='red',width=10,command=j1rouge).pack()
j1cvv = Button(framej1, text ='VERT',relief=RAISED,bg='green',width=10,command=j1vert).pack()
okj1 = Button(framej1, text =' OK ',relief=RAISED,width=10,command=framej1.destroy).pack()
#------------------------------------------------------------------Couleur Option joueur 2
def j2opt ():
framej2=Frame(fenop,borderwidth=20,relief=GROOVE)
framej2['bg']='white'
framej2.pack(side=LEFT,padx=50)
j2cv = Button(framej2, text ='Couleur J2',relief=FLAT,bg='white',width=10).pack()
j2cvb = Button(framej2, text ='BLEU',bg='blue',relief=RAISED,width=10,command=j2bleu).pack()
j2cvg = Button(framej2, text ='GRIS',bg='grey',relief=RAISED,width=10,command=j2gris).pack()
j2cvm = Button(framej2, text ='MARRON',bg='brown',relief=RAISED,width=10,command=j2marron).pack()
j2cvr = Button(framej2, text ='ROUGE',bg='red',relief=RAISED,width=10,command=j2rouge).pack()
j2cvv = Button(framej2, text ='VERT',bg='green',relief=RAISED,width=10,command=j2vert).pack()
okj2 = Button(framej2, text =' Ok ',relief=RAISED,width=10,command=framej2.destroy).pack()
#-------------------------------------------------------------------- Changement de couleur j1
def j1bleu():
global CLR1
CLR1=B
def j1gris():
global CLR1
CLR1=G
def j1marron():
global CLR1
CLR1=M
def j1rouge():
global CLR1
CLR1=R
def j1vert():
global CLR1
CLR1=V
#------------------------------------------------------------------ Changement de couleur J2
def j2bleu():
global CLR2
CLR2=B
def j2gris():
global CLR2
CLR2=G
def j2marron():
global CLR2
CLR2=M
def j2rouge():
global CLR2
CLR2=R
def j2vert():
global CLR2
CLR2=V
#------------------------------------------------------------------ Arret Joueur
def arretj1(event=None):
global d1x,d1y
d1x=0
d1y=0
def arretj2(event=None):
global d2x,d2y
d2x=0
d2y=0
#------------------------------------------------------------------ Acceleration Joueur
def accelj1(event=None):
global v1
v1=18
def accelj2(event=None):
global v2
v2=18
#------------------------------------------------------------------Code principal
fen=Tk()
fen.title("Zéro")
fen.geometry("1200x700")
fen['bg']='grey'
#-----------------------------------------Variables
map1=PhotoImage(file="map1.gif")
paletimg=PhotoImage(file="palet.gif")
un=PhotoImage(file="1.gif")
deux=PhotoImage(file="2.gif")
trois=PhotoImage(file="3.gif")
go=PhotoImage(file="go.gif")
vide=PhotoImage(file='vide.gif')
L=[vide,trois,deux,un,go,vide]
cpt=0 ## global
ex0=PhotoImage(file="./explosion/ex0.gif")
ex1=PhotoImage(file="./explosion/ex1.gif")
ex2=PhotoImage(file="./explosion/ex2.gif")
ex3=PhotoImage(file="./explosion/ex3.gif")
ex4=PhotoImage(file="./explosion/ex4.gif")
ex5=PhotoImage(file="./explosion/ex5.gif")
ex6=PhotoImage(file="./explosion/ex6.gif")
ex7=PhotoImage(file="./explosion/ex7.gif")
ex8=PhotoImage(file="./explosion/ex8.gif")
ex9=PhotoImage(file="./explosion/ex9.gif")
ListeExplosion=[ex0,ex1,ex2,ex3,ex4,ex5,ex6,ex7,ex8,ex9,vide]
cptexplo1=0
cptexplo2=0
exploj1=0
exploj2=0
#Voiture Bleu
bE=PhotoImage(file="./Voiture/VB/bE.gif")
bW=PhotoImage(file="./Voiture/VB/bW.gif")
bN=PhotoImage(file="./Voiture/VB/bN.gif")
bS=PhotoImage(file="./Voiture/VB/bS.gif")
#Voiture Grise
gE=PhotoImage(file="./Voiture/VG/gE.gif")
gW=PhotoImage(file="./Voiture/VG/gW.gif")
gN=PhotoImage(file="./Voiture/VG/gN.gif")
gS=PhotoImage(file="./Voiture/VG/gS.gif")
#Voiture Marron
mE=PhotoImage(file="./Voiture/VM/mE.gif")
mW=PhotoImage(file="./Voiture/VM/mW.gif")
mN=PhotoImage(file="./Voiture/VM/mN.gif")
mS=PhotoImage(file="./Voiture/VM/mS.gif")
#Voiture Rouge
rE=PhotoImage(file="./Voiture/VR/rE.gif")
rW=PhotoImage(file="./Voiture/VR/rW.gif")
rN=PhotoImage(file="./Voiture/VR/rN.gif")
rS=PhotoImage(file="./Voiture/VR/rS.gif")
#Voiture Verte
vE=PhotoImage(file="./Voiture/VVer/vE.gif")
vW=PhotoImage(file="./Voiture/VVer/vW.gif")
vN=PhotoImage(file="./Voiture/VVer/vN.gif")
vS=PhotoImage(file="./Voiture/VVer/vS.gif")
#-------------------------------------------------------------Liste Couleur voiture
B=[bE,bN,bS,bW]
G=[gE,gN,gS,gW]
M=[mE,mN,mS,mW]
R=[rE,rN,rS,rW]
V=[vE,vN,vS,vW]
CLR1=R
CLR2=B
explo = 2
coords1=(0,0)
#----------------Canvas du terrain
x1=250
y1=350
d1x=0
d1y=0
x2=950
y2=350
d2x=0
d2y=0
x3=580
y3=328
d3x=0
d3y=0
v1=13
v2=13
v3=0
canvas1=Canvas(fen,width=1800,height=600,bg='red')
canvas1.focus_set()
canvas1.bind('<Left>',gauche2)
canvas1.bind('<Right>',droite2)
canvas1.bind('<Up>',haut2)
canvas1.bind('<Down>',bas2)
canvas1.bind('<q>',gauche1)
canvas1.bind('<d>',droite1)
canvas1.bind('<z>',haut1)
canvas1.bind('<s>',bas1)
canvas1.bind('<v>',arretj1)
canvas1.bind('<b>',accelj1)
canvas1.bind('<!>',arretj2)
canvas1.bind('<:>',accelj2)
canvas1.bind('<space>',pause)
canvas1.pack(side=BOTTOM)
fond=PhotoImage(file="fond.gif")
canvas1.create_image(600,350,image=fond)
#-------Frame Menu
frame2=Frame(fen,bg='grey',width=1800,height=200)
frame2.pack()
start=Button(frame2,text="Start",command=terrain,width=60,height=1)
start.pack(side=TOP)
option=Button(frame2,text="Option",command=option,width=60,height=1)
option.pack(side=TOP)
quitter=Button(frame2,text="Quitter",cursor="pirate",command=fen.destroy,width=60,height=1)
quitter.pack(side=TOP) |
Partager