You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.5 KiB
85 lines
2.5 KiB
from threading import Thread
|
|
from time import sleep
|
|
class Pistolet():
|
|
def __init__ (self,unx,uny,uncanvas,uncolor):
|
|
self.x=unx
|
|
self.y=uny
|
|
self.c=uncanvas
|
|
self.u=uncolor
|
|
self.direction =True
|
|
self.pistol=self.c.create_rectangle(self.x,
|
|
self.y,
|
|
self.x+5,
|
|
self.y+5,
|
|
fill=self.u)
|
|
def deplace(self,dx,dy):
|
|
self.x=dx
|
|
self.y=dy
|
|
self.c.coords(self.pistol,self.x,
|
|
self.y,
|
|
self.x+5,
|
|
self.y+5)
|
|
|
|
def CreerBalle(self):
|
|
self.b=Balle(self.x,self.y,self.c)
|
|
|
|
class Balle():
|
|
def __init__ (self,unx,uny,uncanvas):
|
|
self.x=unx
|
|
self.y=uny
|
|
self.cote=5
|
|
self.c=uncanvas
|
|
self.ball=self.c.create_rectangle(self.x,self.y,self.x+self.cote,self.y+self.cote,fill="#ff0000")
|
|
|
|
|
|
def dessineballe(self):
|
|
self.ball=self.c.create_rectangle(self.x,self.y,self.x+self.cote,self.y+self.cote,fill="#ff0000")
|
|
|
|
def Tmilieu(self,direction):
|
|
if direction==True:
|
|
self.x=self.x+2
|
|
self.c.coords(self.ball,self.x,self.y,self.x+self.cote,self.y+self.cote)
|
|
else:
|
|
self.x=self.x-2
|
|
self.c.coords(self.ball,self.x,self.y,self.x+self.cote,self.y+self.cote)
|
|
|
|
def TdiagH(self,direction):
|
|
if direction==True:
|
|
self.x=self.x+2
|
|
self.y=self.y-2
|
|
else:
|
|
self.x=self.x-2
|
|
self.y=self.y-2
|
|
|
|
def TdiagB(self,direction):
|
|
if direction==True:
|
|
self.x=self.x+2
|
|
self.y=self.y+2
|
|
else:
|
|
self.x=self.x-2
|
|
self.y=self.y+2
|
|
|
|
class Tir_p(Thread):
|
|
def __init__ (self,uncanvas,unpistolet):
|
|
Thread.__init__(self)
|
|
self.c=uncanvas
|
|
self.cote=5
|
|
self.p=unpistolet
|
|
self.p.CreerBalle()
|
|
self.p.b.dessineballe()
|
|
print("c")
|
|
#balle créer
|
|
|
|
def run(self):
|
|
if self.p.direction==True:
|
|
|
|
while self.p.b.x+2<1900 :
|
|
self.p.b.Tmilieu(self.p.direction)
|
|
sleep(0.002)
|
|
|
|
else:
|
|
while self.p.b.x-2>0 :
|
|
self.p.b.Tmilieu(self.p.direction)
|
|
sleep(0.002)
|
|
self.c.delete(self.p.b.ball)
|
|
self.c.delete(self.p.b)
|