Bonjour voila aujourd'hui je vous sollicite pour mon épreuve oral d'isn. J'ai crée un jeu avec mes 2 collègues qui est un space invaders modifié donc on a tout ce qu'il faut le personnage , le laser ,les ennemis qui se déplacent automatiquement mais malheureusement je n'ai pas trouvé comment faire le système de collision en gros je voudrai que lorsque le laser touche l'ennemi celui ci disparaît :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
from tkinter import *
import time
#fonctions déplacement
 
def chemin():
    can1.create_line(0,10,450,10,width=20,fill='white')
    can1.create_line(445,10,445,50,width=10,fill='white')
    can1.create_line(450,50,0,50,width=20,fill='white')
    can1.create_line(0,50,0,100,width=20,fill='white')
    can1.create_line(0,100,450,100,width=20,fill='white')
    can1.create_line(450,100,450,150,width=20,fill='white')
    can1.create_line(450,150,0,150,width=20,fill='white')
    can1.create_line(0,150,0,200,width=20,fill='white')
    can1.create_line(0,200,450,200,width=20,fill='white')
    can1.create_line(450,200,450,250,width=20,fill='white')
 
 
 
 
def ennemiEtChemin2():
    global liste_ennemis,liste_x3,liste_y3,mort
    liste_x3.append(0)
    liste_y3.append(0)
    ennemi=can1.create_oval(0,0,15,15,width=20,fill='blue')
    liste_ennemis.append(ennemi)
    mort.append(0)
 
def ennemiEtChemin():
    global liste_ennemis,liste_x3,liste_y3,i,presenceEnnemi,ennemi,c
    i=0
 
 
 
    while i<len(liste_ennemis):
        can1.delete(liste_ennemis[i])
        if (liste_y3[i]==0 and liste_x3[i]<400):
            liste_x3[i]=liste_x3[i]+1
        if (liste_x3[i]==400 and liste_y3[i]>=0 and liste_y3[i]<=50):
            liste_y3[i]=liste_y3[i]+1
        if (liste_y3[i]==50 and liste_x3[i]>0):
            liste_x3[i]=liste_x3[i]-1
        if (liste_x3[i]==0 and liste_y3[i]>=50 and liste_y3[i]<=100):
            liste_y3[i]=liste_y3[i]+1
        if (liste_y3[i]==100 and liste_x3[i]<400):
            liste_x3[i]=liste_x3[i]+1
        if (liste_x3[i]==400 and liste_y3[i]>=100 and liste_y3[i]<=150):
            liste_y3[i]=liste_y3[i]+1
        if (liste_y3[i]==150 and liste_x3[i]>0):
            liste_x3[i]=liste_x3[i]-1
        if (liste_x3[i]==0 and liste_y3[i]>=150 and liste_y3[i]<=200):
            liste_y3[i]=liste_y3[i]+1
        if (liste_x3[i]==0 and liste_y3[i]==200):
            champ_label=Label(fen1,text="Game over",bg="red") and can1.delete(liste_ennemis)
            champ_label.pack()
 
 
 
        liste_ennemis[i]=can1.create_oval(liste_x3[i],liste_y3[i],liste_x3[i]+30,liste_y3[i]+30,width=2,fill='red')
        i=i+1
        depltir()
 
 
    fen.after(10,ennemiEtChemin)
 
 
def depltir():
    global x1, y1
    for i in range (len(lasers)):
            y1=y1*-1
            can1.move(lasers[i],0,-10)
            can1.update()
 
def gauche(evt):
    global x1
    if x1>10:
        can1.move(rectangle1,-10,0)
        x1=x1-10
 
def droite(evt):
    global x1
    if x1<415:
        can1.move(rectangle1,10,0)
        x1=x1+10
 
def pew(evt):
    global y1,lasers
    lsr=lasers.append(can1.create_rectangle(x1+12,y1,x1+14,y1+15,width=1,fill='red'))
    depltir()
    fen1.after(50,depltir)
 
def apparaitre():
    fen1.deiconify()
def disparaitre():
    fen1.destroy()
    fen.destroy()
x1, y1 = 215, 215
 
 
fen = Tk()
fen.title('Space Invaders')
fen.geometry('480x320')
fen['bg'] ='Black'
 
labelSP= Label(fen,text='Space Invaders',bg='Orange',font=('Arial',20))
labelSP.place(x=50,y=100)
 
boutonGo = Button(fen,text='Lancer', command= apparaitre)
boutonGo.place(x=50,y=250)
boutonQ = Button(fen,text='Quitter',command= disparaitre)
boutonQ.place(x=150,y=250)
fen1 = Tk()
global liste_ennemis,liste_x3,liste_y3
liste_ennemis=[]
liste_x3=[]
liste_y3=[]
 
lasers=[]
 
fen.title=("Space invaders")
can1=Canvas(fen1, height=250,width=450,bg='grey')
can1.pack(side=LEFT)
bou1=Button(fen1,text="Quitter",command=disparaitre)
bou1.pack(side=RIGHT)
bou2=Button(fen1,text="fais apparaitre un ennemi",command=ennemiEtChemin2)
bou2.pack(side=RIGHT)
rectangle1 = can1.create_rectangle(x1, y1, x1+30, y1+30, width=2, fill='orange',outline='white')
fen1.bind_all("<Left>",gauche)
fen1.bind_all("<Right>",droite)
fen1.bind_all("<Up>",pew)
fen1.after(10,depltir)
ennemiEtChemin()
fen1.mainloop()
Je dois rendre le projet très bientôt et même si on n'est pas forcément obligé d'avoir le projet terminé j'ai le soucis du détail donc si vous pouvez m'aider cela serai sympas merci