From 562172dc6d12992d0139b2505b7a68b3c0b2a41e Mon Sep 17 00:00:00 2001 From: "philippot.m" <> Date: Sat, 29 Mar 2025 13:09:27 +0100 Subject: [PATCH] =?UTF-8?q?Le=20jeu=20pas=20fini=20=C3=A0=20finir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cubeshot.py | 353 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100644 cubeshot.py diff --git a/cubeshot.py b/cubeshot.py new file mode 100644 index 0000000..c6214db --- /dev/null +++ b/cubeshot.py @@ -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.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) + 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 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) + + 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) + +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() \ No newline at end of file