import pyxel
from fonction import collision
from joueur import*
from sound import*
class Objet:
    def __init__(self,x,y,sorte="piece"):
        self.x=x
        self.y=y
        self.type=sorte
        self.son=Sounds()
    def collision(self,joueur,liste):
        x=self.x-joueur.camera_x
        y=self.y-joueur.camera_y
        x_j=joueur.x-joueur.camera_x
        y_j=joueur.y-joueur.camera_y
        if collision(x,y,x+8,y+8,x_j,y_j,x_j+8,y_j+8):
            if self.type=="piece":
                joueur.score+=1
                joueur.pv+=20
                self.son.play_piece_collision()
            else:
                joueur.nb_cles+=1
                self.son.play_cle_collision()
            liste.remove(self)
    def draw(self,j):
        if self.type=="piece":
            if pyxel.frame_count%50<25:
                pyxel.blt(self.x-j.camera_x,self.y-j.camera_y,0,40,160,8,8,5)
            else:
                pyxel.blt(self.x-j.camera_x,self.y-j.camera_y,0,48,160,8,8,5)
        else:
            pyxel.blt(self.x-j.camera_x,self.y-j.camera_y,0,32,192,8,8,5)
class DoubleTeleporteur:
    def __init__(self,x,y,x2,y2,ecartement_1er=10,ecartement_2eme=10):
        self.ecartement_1er=ecartement_1er
        self.ecartement_2eme=ecartement_2eme
        self.x=x*8
        self.y=y*8
        self.x2=x2*8
        self.y2=y2*8
    def collision(self,joueur):
        x=self.x-joueur.camera_x
        y=self.y-joueur.camera_y
        x2=self.x2-joueur.camera_x
        y2=self.y2-joueur.camera_y
        x_j=joueur.x-joueur.camera_x
        y_j=joueur.y-joueur.camera_y
        if collision(x+3,y,x+6,y+8,x_j,y_j,x_j+8,y_j+8):
            joueur.x=self.x2+self.ecartement_2eme
            joueur.y=self.y2
        elif collision(x2+3,y2,x2+6,y2+8,x_j,y_j,x_j+8,y_j+8):
            joueur.x=self.x+self.ecartement_1er
            joueur.y=self.y
        
    def draw(self,j):
        
        pyxel.blt(self.x-j.camera_x,self.y-j.camera_y,0,160,96,8,8,5)
        pyxel.blt(self.x2-j.camera_x,self.y2-j.camera_y,0,160,96,8,8,5)
        
            
