1 changed files with 77 additions and 14 deletions
@ -1,22 +1,85 @@ |
|||||
from threading import Thread |
from threading import Thread |
||||
from time import sleep |
from time import sleep |
||||
from Jeuxdetir(nom provisoire) import * |
class Pistolet(): |
||||
class Pistolet(Thread): |
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): |
def __init__ (self,unx,uny,uncanvas): |
||||
Thread.__init__(self) |
|
||||
self.x=unx |
self.x=unx |
||||
self.y=uny |
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.c=uncanvas |
||||
self.cote=5 |
self.cote=5 |
||||
self.r=self.c.create_rectangle(self.x,self.y,self.x+self.cote,self.y+self.cote,fill="#ff0000") |
self.p=unpistolet |
||||
|
self.p.CreerBalle() |
||||
|
self.p.b.dessineballe() |
||||
|
print("c") |
||||
|
#balle créer |
||||
|
|
||||
def run(self): |
def run(self): |
||||
while self.x>0 and self.x<1900 : |
if self.p.direction==True: |
||||
if direction==True: |
|
||||
self.x=self.x+1 |
while self.p.b.x+2<1900 : |
||||
sleep(0.001) |
self.p.b.Tmilieu(self.p.direction) |
||||
self.c.coords(self.r,self.x,self.y,self.x+self.cote,self.y+self.cote) |
sleep(0.002) |
||||
|
|
||||
else: |
else: |
||||
self.x=self.x-1 |
while self.p.b.x-2>0 : |
||||
sleep(0.001) |
self.p.b.Tmilieu(self.p.direction) |
||||
self.c.coords(self.r,self.x,self.y,self.x+self.cote,self.y+self.cote) |
sleep(0.002) |
||||
self.c.delete(self.r) |
self.c.delete(self.p.b.ball) |
||||
|
self.c.delete(self.p.b) |
Loading…
Reference in new issue