1 changed files with 353 additions and 0 deletions
@ -0,0 +1,353 @@ |
|||
from tkinter import * |
|||
from time import sleep |
|||
from random import randint |
|||
from threading import Thread |
|||
from math import * |
|||
shotgun=False |
|||
|
|||
class Plateforme: |
|||
def __init__(self,unx,uny,uncotex,uncotey,uncanvas,color,): |
|||
self.x=unx |
|||
self.y=uny |
|||
self.cotex=uncotex |
|||
self.canvas=uncanvas |
|||
self.couleur=color |
|||
self.cotey=uncotey |
|||
self.plat=self.canvas.create_rectangle(self.x, |
|||
self.y, |
|||
self.x+self.cotex, |
|||
self.y+self.cotey, |
|||
fill=(self.couleur)) |
|||
################################Perso################################ |
|||
|
|||
class Personnage: |
|||
def __init__ (self,unx,uny,uncote,uncanvas,unfenetre,unvie,color): |
|||
self.x=unx |
|||
self.y=uny |
|||
self.cote=uncote |
|||
self.canvas=uncanvas |
|||
self.f=unfenetre |
|||
self.couleur=color |
|||
self.v=unvie |
|||
self.bondit=False |
|||
self.r=self.canvas.create_rectangle(self.x, |
|||
self.y, |
|||
self.x+self.cote, |
|||
self.y+self.cote, |
|||
fill=(self.couleur)) |
|||
|
|||
self.p=Pistolet(self.x+self.cote, |
|||
self.y, |
|||
self.canvas, |
|||
self.couleur) |
|||
|
|||
def deplace(self,dx,dy): |
|||
self.x= dx |
|||
self.y= dy |
|||
self.canvas.coords(self.r,self.x, |
|||
self.y, |
|||
self.x+self.cote, |
|||
self.y+self.cote) |
|||
if self.p.direction==True: |
|||
self.p.deplace(self.x+self.cote,self.y) |
|||
else: |
|||
self.p.deplace(self.x-5,self.y) |
|||
|
|||
def droit(self,droit): |
|||
self.p.direction=True |
|||
self.deplace(self.x+droit,self.y) |
|||
|
|||
|
|||
def gauche(self,droit): |
|||
self.p.direction=False |
|||
self.deplace(self.x-droit,self.y) |
|||
|
|||
def tomber(self,tomber): |
|||
while self.y+self.cote !=900: |
|||
self.deplace(self.x,self.y+tomber) |
|||
sleep(0.001) |
|||
self.f.update() |
|||
|
|||
def vatoucheplat(self,dx,dy,plat): |
|||
if dx>=0 and dy>=0 : |
|||
if plat.x<=self.x+self.cote+dx<=plat.x+plat.cotex and plat.y<=self.y+self.cote+dy<=plat.y+plat.cotey: |
|||
if self.x+self.cote<= plat.x: |
|||
return "tomber" |
|||
else : |
|||
return "poser" |
|||
if plat.x<=self.x+self.cote+dx<=plat.x+plat.cotex and plat.y<=self.y+dy<=plat.y+plat.cotey: |
|||
return "tomber" |
|||
if plat.x<=self.x+dx<=plat.x+plat.cotex and plat.y<=self.y+self.cote+dy<=plat.y+plat.cotey: |
|||
return "poser" |
|||
return "continue" |
|||
if dx<0 and dy>=0 : |
|||
if plat.x<=self.x+dx<=plat.x+plat.cotex and plat.y<=self.y+self.cote+dy<=plat.y+plat.cotey: |
|||
if self.x>=plat.x+plat.cotex: |
|||
return "tomber" |
|||
else : |
|||
return "poser" |
|||
if plat.x<=self.x+dx<=plat.x+plat.cotex and plat.y<=self.y+dy<=plat.y+plat.cotey: |
|||
return "tomber" |
|||
if plat.x<=self.x+self.cotex+dx<=plat.x+plat.cotex and plat.y<=self.y+self.cote+dy<=plat.y+plat.cotey: |
|||
return "poser" |
|||
return "continue" |
|||
def dead(self): |
|||
self.canvas.delete(self.r) |
|||
|
|||
|
|||
class Saut(Thread): |
|||
def __init__ (self,unrayon,personnage): |
|||
Thread.__init__(self) |
|||
self.r=unrayon |
|||
self.character=personnage |
|||
|
|||
|
|||
def run(self): |
|||
###########Initialisation des variable######## |
|||
self.a=0.025 |
|||
sauter=0.025 |
|||
x=self.character.x |
|||
y=self.character.y |
|||
self.character.bondit=True |
|||
|
|||
################Pendant le saut########## |
|||
if self.character.p.direction==True: |
|||
while self.a<pi and self.character.x+self.character.cote<1899 : |
|||
self.a = self.a+sauter |
|||
self.character.deplace(x+self.r-self.r*cos(self.a),y-self.r*sin(self.a)) |
|||
sleep(0.01) |
|||
else: |
|||
while self.a<pi and self.character.x>0: |
|||
self.a = self.a+sauter |
|||
self.character.deplace(x-self.r+self.r*cos(self.a),y-self.r*sin(self.a)) |
|||
sleep(0.01) |
|||
|
|||
######################Après le saut########## |
|||
|
|||
if self.character.x+self.character.cote<1899 and self.character.x>0 : |
|||
if self.character.p.direction==True: |
|||
self.a=pi |
|||
self.character.deplace(x+self.r-self.r*cos(self.a),y-self.r*sin(self.a)) |
|||
|
|||
else: |
|||
self.a=pi |
|||
self.character.deplace(x-self.r+self.r*cos(self.a),y-self.r*sin(self.a)) |
|||
|
|||
##################Si il touche un mur################### |
|||
else: |
|||
while self.character.y+self.character.cote <900: |
|||
self.character.deplace(self.character.x,self.character.y+1) |
|||
sleep(0.01) |
|||
|
|||
self.character.bondit=False |
|||
|
|||
mouvement=2 |
|||
def Right1(event): |
|||
if perso1.bondit==False: |
|||
if perso1.x+mouvement + cotecorp1 <1900 : |
|||
perso1.droit(mouvement) |
|||
|
|||
def left1(event): |
|||
if perso1.bondit==False: |
|||
if perso1.x-mouvement >0 : |
|||
perso1.gauche(mouvement) |
|||
|
|||
def Right2(event): |
|||
if perso2.bondit==False: |
|||
if perso2.x+mouvement + cotecorp2 <1900 : |
|||
perso2.droit(mouvement) |
|||
|
|||
def left2(event): |
|||
if perso2.bondit==False: |
|||
if perso2.x-mouvement >0 : |
|||
perso2.gauche(mouvement) |
|||
|
|||
def Jump1(event): |
|||
if perso1.bondit==False: |
|||
saut=Saut(350,perso1) |
|||
saut.start() |
|||
|
|||
def Jump2(event): |
|||
if perso2.bondit==False: |
|||
saut=Saut(325,perso2) |
|||
saut.start() |
|||
|
|||
def Dash1(event): |
|||
perso1.foncer(10) |
|||
|
|||
|
|||
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): |
|||
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): |
|||
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,perso): |
|||
Thread.__init__(self) |
|||
self.c=uncanvas |
|||
self.cote=5 |
|||
self.p=unpistolet |
|||
self.perso=perso |
|||
self.p.CreerBalle() |
|||
self.p.b.dessineballe() |
|||
print("c") |
|||
#balle créer |
|||
|
|||
def run(self): |
|||
if self.p.direction==True: |
|||
|
|||
while not (self.perso.x <self.p.b.x+2 <self.perso.x +100 and self.perso.y<self.p.b.y+2 <self.perso.y+100) and self.p.b.x+2<1900 : |
|||
#teste si la balle n'est pas dans le perso |
|||
print("c") |
|||
self.p.b.Tmilieu(self.p.direction) |
|||
sleep(0.002) |
|||
|
|||
else: |
|||
while not (self.perso.x<self.p.b.x-2 <self.perso.x+100 and self.perso.y<self.p.b.y-2 <self.perso.y+100 ) and self.p.b.x-2>0 : |
|||
self.p.b.Tmilieu(self.p.direction) |
|||
sleep(0.002) |
|||
|
|||
################# teste si la balle touche le joueur################## |
|||
if self.perso.x<self.p.b.x+2<self.perso.x+100: |
|||
self.perso.v=self.perso.v-1 |
|||
print (self.perso.v) |
|||
if self.perso.v<0: |
|||
self.perso.dead() |
|||
|
|||
if self.perso.x<self.p.b.x-2<self.perso.x+100: |
|||
|
|||
self.perso.v=self.perso.v-1 |
|||
print (self.perso.v) |
|||
if self.perso.v<0: |
|||
self.perso.dead() |
|||
self.c.delete(self.p.b.ball) |
|||
self.c.delete(self.p.b) |
|||
|
|||
def shoot1(event): |
|||
chevrotine1 = Tir_p(c,perso1.p,perso2) |
|||
chevrotine1.start() |
|||
|
|||
def shoot2(event): |
|||
chevrotine2 = Tir_p(c,perso2.p,perso1) |
|||
chevrotine2.start() |
|||
|
|||
def fall(): |
|||
perso1.tomber(1) |
|||
perso2.tomber(1) |
|||
|
|||
c.bind_all('<q>', left1) |
|||
c.bind_all('<d>', Right1) |
|||
c.bind_all('<space>', Jump1) |
|||
|
|||
if shotgun ==False: |
|||
c.bind_all('<f>',shoot1) |
|||
|
|||
if shotgun ==True: |
|||
c.bind_all('<f>',shoot1) |
|||
c.bind_all('<Button-1>',shoot2) |
|||
#flèche |
|||
|
|||
c.bind_all('<Left>', left2) |
|||
c.bind_all('<Right>', Right2) |
|||
c.bind_all('<Up>', Jump2) |
|||
c.bind_all('<k>', Dash1) |
|||
|
|||
lst_objet=[] |
|||
|
|||
tir= Tk() |
|||
|
|||
c= Canvas(width =1900,height =900,bg="black") |
|||
c.pack() |
|||
xcorp1 =500 |
|||
ycorp1 =500 |
|||
cotecorp1 = 100 |
|||
xcorp2 =1100 |
|||
ycorp2 =500 |
|||
cotecorp2 = 100 |
|||
cotebas = 50 |
|||
xGB,yB,xDB,xDH,yH,xMB,yMB,yMH=200,600,1450,1250,400,775,225,625 |
|||
cotePx=250 |
|||
cotePlaty=15 |
|||
|
|||
#Personnage |
|||
perso1=Personnage(xcorp1,ycorp1,cotecorp1,c,tir,30,"#ff0000") |
|||
perso2=Personnage(xcorp2,ycorp2,cotecorp2,c,tir,30,"#0000ff") |
|||
|
|||
#Platforme |
|||
PlateformeGB=Plateforme(xGB,yB,cotePx,cotePlaty,c,"#ffff00") |
|||
PlateformeDB=Plateforme(xDB,yB,cotePx,cotePlaty,c,"#ffff00") |
|||
PlateformeGH=Plateforme(yH,yH,cotePx,cotePlaty,c,"#ffff00") |
|||
PlateformeDH=Plateforme(xDH,yH,cotePx,cotePlaty,c,"#ffff00") |
|||
PlateformeMB=Plateforme(xMB,yMB,cotePx,cotePlaty,c,"#ffff00") |
|||
PlateformeMH=Plateforme(xMB,yMH,cotePx,cotePlaty,c,"#ffff00") |
|||
|
|||
listxplat=[] |
|||
listxplat.append(xGB) |
|||
listxplat.append(xDB) |
|||
listxplat.append(xDH) |
|||
listxplat.append(xMB) |
|||
|
|||
listyplat=[] |
|||
listyplat.append(yB) |
|||
listyplat.append(yH) |
|||
listyplat.append(yMB) |
|||
listyplat.append(yMH) |
|||
|
|||
b=Button(text="Commencer",command=fall) |
|||
b.pack() |
|||
tir.mainloop() |
Loading…
Reference in new issue