#Importation des bibliothèques nécessaires
import pygame
from pygame import*
import time
global Deplacement
#===============================================================================
def incassable():
    rocherX = 85.11
    rocherY = 93.2
    for z in range (8):#8 rocher
        fenetre.blit(rocher,(rocherX,rocherY))
        rocherX = rocherX + 160.11      #85.11+75(ecart entre 2 objets + largeur du rochet)
def incassable2():
    rocherX = 85.11         #766/9=Largeur de l'écran divisé par nombre de vide
    rocherY = 261.4 #93.2 + 168.2( 93.2 + 75  départ + hauteur du rocher )
    for z in range (8):#8 rocher
        fenetre.blit(rocher,(rocherX,rocherY))
        rocherX = rocherX + 160.11

def incassable3():
    rocherX = 85.11         #766/9=Largeur de l'écran divisé par nombre de vide
    rocherY = 430 #yPrécédent (passage + hauteur rocher)
    for z in range (8):#8 rocher
        fenetre.blit(rocher,(rocherX,rocherY))
        rocherX = rocherX + 160.11

def incassable4():
    rocherX = 85.11         #766/9=Largeur de l'écran divisé par nombre de vide
    rocherY = 598  #yPrécédent (passage + hauteur rocher)
    for z in range (8):#8 rocher
        fenetre.blit(rocher,(rocherX,rocherY))
        rocherX = rocherX + 160.11

def incassableall():
    incassable()
    incassable2()
    incassable3()
    incassable4()

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

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

    return Deplacement

def stopbas() :
    global Deplacement
    for i in range (a):
        if playerX +0.1> hitboxX[i] and playerX +0.1< hitboxX[i] +70:
            for k in range(b):
                if playerY+ 80> hitboxY[k] and playerY + 80 < hitboxY[k] +75:
                    Deplacement = False
    return Deplacement

def stophaut() :
    global Deplacement
    for i in range (a):
        if playerX+0.1 > hitboxX[i] and playerX +0.1 < hitboxX[i] +70:
            for k in range(b):
                if playerY> hitboxY[k] and playerY< hitboxY[k] +75:
                    Deplacement = False
    return Deplacement


def mapstart():
    fenetre.blit(terrain,(0,0))
    fenetre.blit(personnage,(10,10))
    incassableall()

def mapbase():
    fenetre.blit(terrain,(0,0))
    incassableall()
hitboxX = [85.11,245,22,405.33,565.44,725.55,885.66,1045.77,1205,88]
hitboxY = [100.2,268.4,438.6,604.8]
#pour Y +168,2 car 93,2+75(hauteur du rocher + écart)
#===============================================================================
#Initialisation de la bibliothèque Pygame
pygame.init()

#Création de la fenêtre & importation des images
fenetre = pygame.display.set_mode((1366,768)) #resolution
pygame.display.set_caption("Bomberman") #titre

"Map"
terrain = pygame.image.load("G:\Project_ISN\\errain.jpg").convert()
rocher = pygame.image.load ("G:\Project_ISN\\rocher.png").convert()

"Personnage 4 directions"
personnage = pygame.image.load("G:\Project_ISN\\bmfacet.png").convert_alpha()
bmdos = pygame.image.load("G:\Project_ISN\\bmdos.png").convert_alpha()
bmdroite = pygame.image.load("G:\Project_ISN\\bmdroitet.png").convert_alpha()
bmgauche = pygame.image.load("G:\Project_ISN\\bmgauchet.png").convert_alpha()


"Kame 4 directions"
kamehaut = pygame.image.load("G:\Project_ISN\\kamehaut.png").convert_alpha()
kamebas = pygame.image.load("G:\Project_ISN\\kamebas.png").convert_alpha()
kamedroit = pygame.image.load("G:\Project_ISN\\kamedroit.png").convert_alpha()
kamegauche = pygame.image.load("G:\Project_ISN\\kamegauche.png").convert_alpha()







#Déclaration variables
playerX =10 #spawn
playerY =10
position = personnage.get_rect()
game_over = False
a = len(hitboxX)
b = len(hitboxY)
Deplacement = True

mapstart() #on génère le terrain

"Boucle Mère"
while not game_over:
    pygame.display.flip()
    pygame.display.update()
    for event in pygame.event.get(): #Deplacement
            if event.type==pygame.QUIT: #croix quitter
                pygame.quit()
                exit(0)

            "Deplacements 4 Directions"
            if event.type == KEYDOWN and event.key == K_RIGHT: #droite
	               for x in range(80):
                            fenetre.blit(terrain,(0,0)) #terrain par dessus
                            Deplacement #global
                            incassableall() #rochers
                            playerX=playerX+40 #pour check stopdroite()
                            stopdroite()
                            playerX=playerX-40
                            if Deplacement == True:
                                playerX = playerX +1 #1*80pixels
                            fenetre.blit(bmdroite,(playerX,playerY)) #dessiner un nouveau joueur
                            pygame.display.update()
                            Deplacement=True

            if event.type == KEYDOWN and event.key == K_LEFT: #gauche
	               for x in range(80):
                        fenetre.blit(terrain,(0,0))
                        Deplacement
                        incassableall()
                        playerX=playerX-40
                        stopgauche()
                        playerX=playerX+40
                        if Deplacement == True:
                            playerX = playerX -1
                        fenetre.blit(bmgauche,(playerX,playerY))
                        pygame.display.update()
                        Deplacement=True

            if event.type == KEYDOWN and event.key == K_DOWN: #bas
	               for x in range(84):
                        fenetre.blit(terrain,(0,0))
                        Deplacement
                        incassableall()
                        playerY=playerY+42
                        stopbas()
                        playerY=playerY-42
                        if Deplacement == True:
                            playerY = playerY +1
                        fenetre.blit(personnage,(playerX,playerY))
                        pygame.display.update()
                        Deplacement = True

            if event.type == KEYDOWN and event.key == K_UP: #haut
	               for x in range(84):
                        fenetre.blit(terrain,(0,0))
                        Deplacement
                        incassableall()
                        playerY=playerY-42
                        stophaut()
                        playerY=playerY+42
                        if Deplacement==True:
                            playerY = playerY - 1
                        fenetre.blit(bmdos,(playerX,playerY))
                        pygame.display.update()
                        Deplacement = True

            "Attaque 4 Directions"
            if event.type == KEYDOWN and event.key == K_KP8:
                mapbase()
                fenetre.blit(bmdos,(playerX,playerY))
                fenetre.blit(kamehaut, (playerX-15, playerY-175))

            if event.type == KEYDOWN and event.key == K_KP2:
                mapbase()
                fenetre.blit(personnage,(playerX,playerY))
                fenetre.blit(kamebas, (playerX-15, playerY+80))

            if event.type == KEYDOWN and event.key == K_KP4:
                mapbase()
                fenetre.blit(bmgauche,(playerX,playerY))
                fenetre.blit(kamegauche, (playerX-175, playerY))

            if event.type == KEYDOWN and event.key == K_KP6:
                mapbase()
                fenetre.blit(bmdroite,(playerX,playerY))
                fenetre.blit(kamedroit, (playerX+75, playerY))

            if game_over == True: #GameOver
                print("Coucou")























            "Sortie de Map"
            if playerY >766 :
                playerY = 10
                fenetre.blit(personnage,(playerX,playerY))

            if playerY <0 :
                playerY = 756
                fenetre.blit(personnage,(playerX,playerY))

            if playerX >1366 :
                playerX = 10
                fenetre.blit(bmdroite,(playerX,playerY))

            if playerX <0 :
                playerX = 1366
                fenetre.blit(personnage,(playerX,playerY))
