def __init__(self, canvas, vitesse, taille, mw, Xpos, Ypos, image_alien, image_tir, vaisseau, obstacle1, obstacle2, obstacle3, obstacle4, obstacle5): self.vitesse = vitesse self.taille = taille self.fenetre = mw self.descente = 0 self.xpos_tir = xpos_tir_alien self.ypos_tir = ypos_tir_alien self.canvas = canvas coord = 10, 50, 240, 210 self.alien = PhotoImage(file=image_alien) self.laser = PhotoImage(file=image_tir) self.vaisseau = vaisseau self.arc = C.create_image(100, 100, image=self.alien) self.X = Xpos - 50 self.Y = Ypos self.sens = 1 self.canShoot = True self.obstacle1 = obstacle1 self.obstacle2 = obstacle2 self.obstacle3 = obstacle3 self.obstacle4 = obstacle4 self.obstacle5 = obstacle5 #Creation du tir self.mouvement() self.creation_tir() position_vaisseau = C.coords(self.vaisseau.imageVaisseau)[0] collision = True
def droite(self, event): posx = 10 posy = 0 self.xpos = self.xpos + posx if self.xpos < lar_canv: C.move(self.imageVaisseau, posx, posy) else: self.xpos = lar_canv - 10
def gauche(self, event): posx = -10 posy = 0 self.xpos = self.xpos + posx if self.xpos > 33: C.move(self.imageVaisseau, posx, posy) else: self.xpos = 35
def tir_vaisseau( self): #Deplacement du tir a partir du moment ou il est envoye self.xpos_tir = self.xpos self.ypos_tir = self.ypos #self.ypos_tir=self.ypos_tir-10 #C.move(self.tir, self.xpos_tir, self.ypos_tir) #C.coords(self.tir ,self.xpos_tir-20,self.ypos_tir-20,self.xpos_tir+20,self.ypos_tir+20) C.move(self.tir, 0, -10) mw.after(50, self.tir_vaisseau) '''if self.ypos_tir>haut_canv:
def creation_tir(self): #Crée le tir à l'endroit ou est l'alien self.xpos_tir = self.X self.ypos_tir = self.Y self.tir = C.create_image(self.xpos_tir, self.ypos_tir, image=self.laser) if self.canShoot: self.tir_alien() self.canShoot = False #Mettre ici des conditions pour supprimer la boule (si vaisseau touché) #self.fenetre.after(1000,lambda: C.delete(self.tir)) self.fenetre.after(random.randint(3100, 3500), self.creation_tir) if self.ypos_tir > 300: C.delete(self.tir)
def mouvement(self): print(C.coords(self.vaisseau.imageVaisseau)[1]) if self.X + self.taille > lar_canv: self.sens = -1 if self.X - self.taille / 2 < 0: self.sens = 1 self.descente = 1 if self.descente == 1: self.Y += 70 self.descente = 0 self.X = self.X + self.vitesse * self.sens C.coords(self.arc, self.X - self.taille, self.Y - self.taille) #Y-self.taille # mise a jour self.fenetre.after(80, self.mouvement) '''if C.coords(self.tir)[0] > C.coords(self.vaisseau.imageVaisseau)[0] and C.coords(self.tir)[0] < C.coords(self.vaisseau.imageVaisseau)[2] and C.coords(self.tir)[3] > C.coords(self.vaisseau.imageVaisseau)[1]:
def creation_tir(self, event): #self.tir1=PhotoImage(file="Images/tir2.png") #self.imageTir = C.create_image(self.xpos, self.ypos, image=self.tir1) self.tir = C.create_image(self.xpos_tir, self.ypos, image=self.imageTir) '''self.tir = C.create_arc(self.xpos, self.ypos, 275, 75, start=-270, extent=359, fill="yellow") self.xpos_tir=self.xpos self.ypos_tir=self.ypos if self.canShoot==True: self.tir_vaisseau() self.canShoot=False self.shoot=False''' #self.tir = C.create_arc(self.xpos, self.ypos, 275, 75, start=-270, extent=359, fill="yellow") self.tir_vaisseau() #self.ypos_tir=self.ypos mw.after(1500, lambda: C.delete(self.tir)) '''if self.canShoot: self.tir_vaisseau() mw.after(1500, lambda: C.delete(self.tir)) self.canShoot = False''' self.tir_vaisseau() mw.after(2000, lambda: C.delete(self.tir))
def __init__(self, vitesse_de_tir, taille_vaisseau): self.tir = vitesse_de_tir self.taille = taille_vaisseau self.xpos = lar_canv / 2 self.ypos = 480 self.xpos_tir = xpos_tir_vaisseau self.ypos_tir = ypos_tir_vaisseau self.vaisseau = PhotoImage(file="Images/vaisseau2.png") self.imageTir = PhotoImage(file="Images/tir2.png") self.canShoot = True self.shoot = True #Creation du tir #self.tir = C.create_arc(self.xpos_tir, self.ypos_tir, 275, 275, start=-270, extent=359, fill="yellow") #self.tir_vaisseau() self.imageVaisseau = C.create_image(self.xpos - self.taille, self.ypos_tir - self.taille, image=self.vaisseau) mw.bind('<Right>', self.droite) mw.bind('<Left>', self.gauche) mw.bind('<space>', self.creation_tir)
def __init__(self, posX, posY): self.obs_x = posX self.obs_y = posY self.obs = PhotoImage(file="Images/obstacle.png") self.obstacle = C.create_image(self.obs_x, self.obs_y, image=self.obs)
def tir_alien( self): #Deplacement du tir a partir du moment ou il est envoye self.ypos_tir = self.ypos_tir + 1.4 C.coords(self.tir, self.xpos_tir - 20, self.ypos_tir) self.fenetre.after(8, self.tir_alien) if self.ypos_tir > haut_canv - 50: C.delete(self.tir) if (self.xpos_tir >= self.obstacle1.obs_x - 30) and ( self.xpos_tir <= self.obstacle1.obs_x + 50) and ( self.ypos_tir >= self.obstacle1.obs_y): print("Obstacle1 touché") C.delete(self.tir) C.delete(self.obstacle1.obstacle) if (self.xpos_tir >= self.obstacle2.obs_x - 30) and ( self.xpos_tir <= self.obstacle2.obs_x + 30) and ( self.ypos_tir >= self.obstacle2.obs_y): print("Obstacle2 touché") C.delete(self.tir) C.delete(self.obstacle2.obstacle) if (self.xpos_tir >= self.obstacle3.obs_x - 30) and ( self.xpos_tir <= self.obstacle3.obs_x + 30) and ( self.ypos_tir >= self.obstacle3.obs_y): print("Obstacle3 touché") C.delete(self.tir) C.delete(self.obstacle3.obstacle) if (self.xpos_tir >= self.obstacle4.obs_x - 30) and ( self.xpos_tir <= self.obstacle4.obs_x + 30) and ( self.ypos_tir >= self.obstacle4.obs_y): print("Obstacle4 touché") C.delete(self.tir) C.delete(self.obstacle4.obstacle) if (self.xpos_tir >= self.obstacle5.obs_x - 30) and ( self.xpos_tir <= self.obstacle5.obs_x + 30) and ( self.ypos_tir >= self.obstacle5.obs_y): print("Obstacle5 touché") C.delete(self.tir) C.delete(self.obstacle5.obstacle) if (self.xpos_tir >= C.coords(self.vaisseau.imageVaisseau)[0] - 50 ) and (self.xpos_tir <= C.coords(self.vaisseau.imageVaisseau)[0] + 50) and (self.ypos_tir >= C.coords( self.vaisseau.imageVaisseau)[1]): print("- 1 vie") C.delete(self.tir) #C.delete(self.vaisseau.imageVaisseau) '''if collision:
from main import C inst = C() inst.method(42)
def run_checks_class_C(): c = C() assert (c.X == "Class A atribute X") assert (c.Z == "Class C atribute Z extend class A")
def already_existing1(): pass def already_existing2(): pass from main import C C().method() def already_existing3(): pass