diff --git a/cubeshot.py b/cubeshot.py index c6214db..7da5d2c 100644 --- a/cubeshot.py +++ b/cubeshot.py @@ -4,24 +4,67 @@ from random import randint from threading import Thread from math import * shotgun=False +from pistolet import * -class Plateforme: - def __init__(self,unx,uny,uncotex,uncotey,uncanvas,color,): +class Corp_boss: + def __init__(self,unx,uny,unlong,unlarge,uncanvas,uncolor): 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)) + self.long=unlong + self.larg=unlarge + self.col=uncolor + self.c=uncanvas + self.base=self.c.create_rectangle(self.x, + self.y+self.larg, + self.x+self.larg, + self.y+self.long, + outline=self.col) + + self.tete=self.c.create_rectangle(self.x-15, + self.y-30, + self.x+self.larg+15, + self.y+self.larg, + outline=self.col) + + self.eye_1=self.c.create_line(self.x,self.y,self.x+30,self.y+20, + self.x+30,self.y+20,self.x+23,self.y+42, + self.x+23,self.y+42,self.x-10,self.y+25, + self.x-10,self.y+25,self.x,self.y, + fill=self.col) + decalage_eye=70 + self.eye_2=self.c.create_line(self.x+decalage_eye,self.y,self.x-30+decalage_eye,self.y+20, + self.x-30+decalage_eye,self.y+20,self.x-23+decalage_eye,self.y+42, + self.x-23+decalage_eye,self.y+42,self.x+10+decalage_eye,self.y+25, + self.x+10+decalage_eye,self.y+25,self.x+decalage_eye,self.y, + fill=self.col) + self.lst_l=[] + for dec in range(0,self.long,110): + ligne=self.c.create_line(self.x, + self.y+self.larg+dec, + self.x+self.larg, + self.y+self.larg+dec, + fill=self.col) + self.lst_l.append(ligne) + +class Canon: + def __init__(self,unx,uny): + self.x=unx + self.y=uny + +class Sword: + def __init__(self,unx,uny): + self.x=unx + self.y=uny + +class Boss: + def __init__(self,unx,uny,unlong,unlarge,uncanvas,uncolor,unvie): + self.corp=Corp_boss(unx,uny,unlong,unlarge,uncanvas,uncolor) + self.c=uncanvas + self.canon=Canon(0,0) ################################Perso################################ class Personnage: - def __init__ (self,unx,uny,uncote,uncanvas,unfenetre,unvie,color): + def __init__ (self,unx,uny,uncote,uncanvas,unfenetre,unvie,color,unvitesse,unacceleration): self.x=unx self.y=uny self.cote=uncote @@ -35,12 +78,13 @@ class Personnage: self.x+self.cote, self.y+self.cote, fill=(self.couleur)) - self.p=Pistolet(self.x+self.cote, self.y, self.canvas, self.couleur) - + self.vitesse=unvitesse + self.acceleration=unacceleration + def deplace(self,dx,dy): self.x= dx self.y= dy @@ -61,293 +105,70 @@ class Personnage: 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 - +class Graviter(Thread): + def __init__(self,unperso): + Thread.__init__(self) + self.perso=unperso + 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.a0: - 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) + while True: + while self.perso.y+self.perso.cote <900 or self.perso.vitesse!=1: + self.perso.bondit=True + self.perso.deplace(self.perso.x,self.perso.y+self.perso.acceleration-self.perso.vitesse) sleep(0.01) + if self.perso.vitesse!=1: + self.perso.vitesse=self.perso.vitesse-1 + self.perso.f.update() - self.character.bondit=False - -mouvement=2 -def Right1(event): - if perso1.bondit==False: - if perso1.x+mouvement + cotecorp1 <1900 : - perso1.droit(mouvement) + self.perso.bondit=False + self.perso.f.update() -def left1(event): - if perso1.bondit==False: - if perso1.x-mouvement >0 : - perso1.gauche(mouvement) +mouvement=10 +def right(event): + if perso.x+mouvement + cotecorp1 <1900 : + perso.droit(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 left(event): + if perso.x-mouvement >0 : + perso.gauche(mouvement) -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 0 : - self.p.b.Tmilieu(self.p.direction) - sleep(0.002) - - ################# teste si la balle touche le joueur################## - if self.perso.x', left1) - c.bind_all('', Right1) - c.bind_all('', Jump1) - +def shoot(event): if shotgun ==False: - c.bind_all('',shoot1) - - if shotgun ==True: - c.bind_all('',shoot1) - c.bind_all('',shoot2) - #flèche - - c.bind_all('', left2) - c.bind_all('', Right2) - c.bind_all('', Jump2) - c.bind_all('', Dash1) + chevrotine = Tir_p(c,perso.p) + chevrotine.start() -lst_objet=[] +def fall(): + saut=Graviter(perso) + saut.start() tir= Tk() - c= Canvas(width =1900,height =900,bg="black") c.pack() +c.bind_all('', left) +c.bind_all('', right) +c.bind_all('', jump) +c.bind_all('',shoot) + +#flèche +c.bind_all('', dash) + 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 +boss=Corp_boss(250,500,600,70,c,"#9c33ff") #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() +perso=Personnage(xcorp1,ycorp1,cotecorp1,c,tir,30,"#ff0000",1,10) +fall() tir.mainloop() \ No newline at end of file