#Importation des bibliothèques nécessaires
import pygame
from pygame.locals import *
global Deplacement
#====================================
Deplacement = True
def incassable(): #180,125
    #fenetre.blit(rocher,(105.125,100))
    #fenetre.blit(rocher,(285.25,100))
    #fenetre.blit(rocher,(465.375,100))
    #fenetre.blit(rocher,(645.5,100))
    #fenetre.blit(rocher,(825.625,100))
    #fenetre.blit(rocher,(1005.75,100))
    #fenetre.blit(rocher,(1185.875,100))
    count = 0
    #fenetre.blit(rocher,(105.125,280.125))
    #fenetre.blit(rocher,(285.25,280.125))
    #fenetre.blit(rocher,(465.375,280.125))
    #fenetre.blit(rocher,(645.5,280.125))
    #fenetre.blit(rocher,(825.625,280.125))
    #fenetre.blit(rocher,(1005.75,280.125))
    #fenetre.blit(rocher,(1185.875,280.125))
    rocherX = 105.125
    for z in range (7):

        rocherY = 100
        fenetre.blit(rocher,(rocherX,rocherY))
        rocherX = rocherX + 180.125
        print("t")


def stop() :
    global Deplacement
    for i in range (a):
        if playerX + 60 > hitboxX[i] and playerX + 60 < hitboxX[i] + 75:
            for k in range(b):
                if playerY + 90 > hitboxY[k] and playerY + 90 < hitboxY[k] + 75:
                    Deplacement = False

            print('TEST')
    return Deplacement








hitboxX = [105.125,285.25,465.375,645.5,825.625,1005.75,1185.875]
hitboxY = [100,280.125]


#Initialisation de la bibliothèque Pygame
pygame.init()

#Création de la fenêtre
fenetre = pygame.display.set_mode((1366,768), RESIZABLE)
continuer = 1
terrain = pygame.image.load("D:/Users/Corentin/Desktop/errain.jpg").convert()
rocher = pygame.image.load("D:/Users/Corentin/Desktop/rocher.png").convert()
personnage = pygame.image.load("D:/Users/Corentin/Desktop/bmface.png").convert_alpha()
facepasdroit = pygame.image.load("D:/Users/Corentin/Desktop/bmpasdroit.png").convert_alpha()
facepasgauche = pygame.image.load("D:/Users/Corentin/Desktop/bmpasgauche.png").convert_alpha()
bmdroite = pygame.image.load("D:/Users/Corentin/Desktop/bmdroite.png").convert_alpha()
bmgauche = pygame.image.load("D:/Users/Corentin/Desktop/bmgauche.png").convert_alpha()

fenetre.blit(terrain,(0,0))
fenetre.blit(personnage,(10,10))
#fenetre.blit(rocher,(200,200))
incassable()
a = len(hitboxX)
b = len(hitboxY)

playerX = 10
playerY = 10
position = personnage.get_rect()

while continuer == 1:
    pygame.display.flip()

    pygame.display.update()

    for event in pygame.event.get():
            # check if the event is the X button
            if event.type==pygame.QUIT:
                # if it is quit the game
                pygame.quit()
                exit(0)
                print("QUIT")
            if event.type == KEYDOWN and event.key == K_RIGHT:
	               for x in range(20):
                            fenetre.blit(terrain,(0,0))
                            global Deplacement
                            #effacer
                            #fenetre.blit(rocher,(200,200))
                            incassable()
                            playerX = playerX + 1#position = position.move(0, 2) #déplacer le joueur
                            stop()
                            if Deplacement == False:
                                playerX = playerX - 1
                            fenetre.blit(bmdroite,(playerX,playerY))                #dessiner un nouveau joueur
                            pygame.display.update()
                            Deplacement=True

                            #fenetre.blit(facepasgauche,(playerX,playerY))
                            #pygame.display.update()                     #afficher le tout
            if event.type == KEYDOWN and event.key == K_LEFT:
	               for x in range(20):
                            fenetre.blit(terrain,(0,0))     #effacer
                            incassable()
                            playerX = playerX - 1 #déplacer le joueur
                            fenetre.blit(bmgauche,(playerX,playerY))
                                            #dessiner un nouveau joueur
                            pygame.display.update()                      #afficher le tout
            if event.type == KEYDOWN and event.key == K_DOWN:
	               for x in range(20):
                            fenetre.blit(terrain,(0,0))     #effacer
                            incassable()
                            #fenetre.blit(rocher,(200,200))
                            playerY = playerY + 1#position = position.move(0, 2) #déplacer le joueur
                            fenetre.blit(personnage,(playerX,playerY))                #dessiner un nouveau joueur
                            pygame.display.update()                      #afficher le tout
            if event.type == KEYDOWN and event.key == K_UP:
	               for x in range(20):
                            fenetre.blit(terrain,(0,0))     #effacer
                            incassable()
                            #fenetre.blit(rocher,(200,200))
                            playerY = playerY - 1#position = position.move(0, 2) #déplacer le joueur
                            fenetre.blit(personnage,(playerX,playerY))                #dessiner un nouveau joueur
                            pygame.display.update()                      #afficher le tout








    #Je place continue ici pour pouvoir relancer la boucle infinie
                 #mais il est d'habitude remplacé par une suite d'instructions


#fond = pygame.image.load("background.jpg").convert()
#pygame.display.flip() = raffraichessement
