Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 21/05/2015, à 19:43

Inzaguiz

[PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

Alors bonjour, j'ai encore besoin d'aide pour mon projet de SplinterCell python.

Voici ma liste :

CP =[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
         [1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1],
         [1,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,1,1,1],
         [1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
         [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1],
         [1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1],
         [1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,1],
         [1,0,1,1,0,0,1,0,1,1,1,1,1,0,1,0,0,1,1,1,1],           Où les 1 représentent les murs de mon labyrinthe et les 0, le sol.
         [1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
         [1,0,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
         [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
         [1,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1],
         [1,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,1],
         [1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
         [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]

Un chiffre représente un carré de 50 par 50 sur ma fenêtre

J'ai besoin de déterminer si mon Espion (se déplaçant de 6.25 à chaque pression sur les flèches du clavier [Ça tombe au centre des carrés]) est contre un mur ou plus simplement au centre du carré contre un mur.

Comme ça je lui interdit de se déplacer dans le mur.


PS : Je sais que c'est compliqué mais déjà si on me dis comment gérer un élément (obtenir son numéro)  d'une certaine liste de ma liste, C'est super ! Si vous me décoincez totalement en m'expliquant ce qu'il se passe c'est génial !
Je cherche de mon coté bien évidemment ^^

Hors ligne

#2 Le 21/05/2015, à 20:06

pingouinux

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

Bonjour,
Les murs sont-ils des blocs de même taille que les cellules vides ?
J'espère que les dimensions ne sont pas en pixels (à cause du 6.25).

Remarque : Utilise les balises-codes quand tu montres du code <>

pour obtenir ceci

Hors ligne

#3 Le 21/05/2015, à 20:42

Inzaguiz

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

Les murs = les vides

Je sais pas du tout si c'est un pixel mais le 6.25 me fais tomber à chaque fois sur le cente du carré. (car 6.25*4 = 25 qui est la moitié de 50)

Pour t'aider (ou vous aider) :

Le système de la liste marche déjà avec la patrouille des gardes qui se déplace aléatoirement après avoir touché un mur sur le labyrinthe sans rentrer dans les murs violemment ^^

Ma class Guard:

 class Guard():
    
    def __init__(self,position):
        self.v = 1
        self.range = 150
        self.x = position[0]
        self.y = position[1]
        self.t = 12.5
        self.vx=1
        self.vy=0
        
    def trace(self):
        x=self.x
        y=self.y
        r=12.5
        self.n=tableau.create_oval(x-r,y-r,x+r,y+r,width = 2,fill="blue")
        self.m=tableau.create_rectangle(x-24.75,y-24.75,x+24.75,y+24.75)
        
        
    def patrouille(self):
        
        CG =[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
            [1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1],
            [1,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,1,1,1],
            [1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1],
            [1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1],
            [1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,1],
            [1,0,1,1,0,0,1,0,1,1,1,1,1,0,1,0,0,1,1,1,1],
            [1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
            [1,0,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
            [1,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1],
            [1,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
            [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]


        ecrase=50
        future=0.5
       # print(self.x/ecrase+future*self.vx,'    ',self.y/ecrase+future*self.vy)
        futur=CG[min(14,int(self.y/ecrase+future*self.vy))][min(20,int(self.x/ecrase+future*self.vx))]
        
        while futur == 1 :

            direction=randint(0,3)

            if direction==0:
                self.vx=1
                self.vy=0
            elif direction==1:
                self.vx=-1
                self.vy=0
            elif direction==2:
                self.vx=0
                self.vy=1
            elif direction==3:
                self.vx=0
                self.vy=-1
            futur=CG[min(14,int(self.y/ecrase+future*self.vy))][min(20,int(self.x/ecrase+future*self.vx))]
                  
        self.x+=self.vx*self.v
        self.y+=self.vy*self.v
        #print(len(CG))

Bref j'ai des soucis pour mon petit "Yakusa" qui pour le moment traverse les murs..

Un 'tit screen (c'est moche oui mais bon ^^)

Code

C'est plus parlant... ^^

Dernière modification par Inzaguiz (Le 21/05/2015, à 21:03)

Hors ligne

#4 Le 21/05/2015, à 21:03

Inzaguiz

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

EDIT (précision)

Hors ligne

#5 Le 21/05/2015, à 21:38

pingouinux

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

Remarques :
1) Je m'étonne des valeurs non entières des paramètres transmis à create_oval et create_rectangle
2) Quand tu calcules futur=CG[...][...], tu n'empêches pas les indices de devenir négatifs
3)

            futur=CG[min(14,int(self.y/ecrase+future*self.vy))][min(20,int(self.x/ecrase+future*self.vx))]
        self.x+=self.vx*self.v
        self.y+=self.vy*self.v

Ça ne me paraît pas cohérent. Tu fais le test avec des valeurs qui ne sont pas celles que tu utilises ensuite.
Par exemple

self.y/ecrase+future*self.vy

et

self.y+=self.vy*self.v

4) Je ne comprends pas le système d'unités

Hors ligne

#6 Le 21/05/2015, à 22:06

Inzaguiz

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

A vrai dire c'est mon collègue qui l'a fait et j'ai absolument rien compris, mais les gardes patrouillent merveilleusement, Python ne crache pas et pas de glitch...

Bref laisse tomber les gardes je peux pas te dire...

Mais si je te donne cette liste :

CG =[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
    [1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1],
    [1,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,1,1,1],
    [1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1],
    [1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1],
    [1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,1],
    [1,0,1,1,0,0,1,0,1,1,1,1,1,0,1,0,0,1,1,1,1],
    [1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
    [1,0,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1],     
    [1,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
    [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]

Qui est en gros le "plan" du labyrinthe, est-ce que tu sera capable de m'aider pour gérer les collisions de mon Yakusa ?

Voici sa class :

class Yakusa():
    def __init__(self):
        self.positionx = 75
        self.positiony = 75
        self.score = 0
        self.Vx = 6.25
        self.Vy = 6.25
        self.taille = 12.5

Player = Yakusa()

Et son mouvement :

def fleche_haut(event):
    tableau.delete(p)
    Player.positiony += 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

def fleche_gauche(event):
    tableau.delete(p)
    Player.positiony += 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

def fleche_bas(event):
    tableau.delete(p)
    Player.positiony += 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

def fleche_droite(event):
    tableau.delete(p)
    Player.positiony += 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

fenetre.bind("<Up>", fleche_haut)
fenetre.bind("<Down>", fleche_bas)
fenetre.bind("<Left>", fleche_gauche)
fenetre.bind("<Right>", fleche_droite)

tableau.delete(p)
sprit(Player.positionx,Player.positiony,Player.taille)
sleep(1/60)

Dernière modification par Inzaguiz (Le 21/05/2015, à 22:11)

Hors ligne

#7 Le 21/05/2015, à 22:13

pingouinux

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

Qu'as-tu déjà écrit ?

Hors ligne

#8 Le 21/05/2015, à 22:13

Inzaguiz

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

Edit de partout décidément désolé....

Il te manque une fonction aussi :

def sprit(X,Y,R):
    global p
    p=tableau.create_oval(X-R,Y-R,X+R,Y+R,width = 2,fill='red')

Hors ligne

#9 Le 21/05/2015, à 22:14

Inzaguiz

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

Tu veux le programme en entier ? C'est un peu en chantier je te le fais un peu plus beau.

Hors ligne

#10 Le 21/05/2015, à 22:19

pingouinux

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

Tu as déjà fait un copier-coller malheureux dans la définition des fonctions fleche_xxxx(event)

Hors ligne

#11 Le 21/05/2015, à 22:22

Inzaguiz

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

Je te donne tout je galère c'est un chantier ^^

Tiens : (il marche lui)

EDIT : la flèche haut le fait cracher (évidemment)

from tkinter import *
from math import *
from time import *
from random import *

class Yakusa():
    def __init__(self):
        self.positionx = 75
        self.positiony = 75
        self.score = 0
        self.Vx = 6.25
        self.Vy = 6.25
        self.taille = 12.5

class Guard():
    
    def __init__(self,position):
        self.v = 1
        self.range = 150
        self.x = position[0]
        self.y = position[1]
        self.t = 12.5
        self.vx=1
        self.vy=0
        
    def trace(self):
        x=self.x
        y=self.y
        r=12.5
        self.n=tableau.create_oval(x-r,y-r,x+r,y+r,width = 2,fill="blue")
        self.m=tableau.create_rectangle(x-24.75,y-24.75,x+24.75,y+24.75)
        
        
    def patrouille(self):

   ############1 2 3 4 5 6 7 8 9 
##        CG = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]
        
        CG =[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
            [1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1],
            [1,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,1,1,1],
            [1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1],
            [1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1],
            [1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,1],
            [1,0,1,1,0,0,1,0,1,1,1,1,1,0,1,0,0,1,1,1,1],
            [1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
            [1,0,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
            [1,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1],
            [1,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
            [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]


        ecrase=50
        future=0.5
       # print(self.x/ecrase+future*self.vx,'    ',self.y/ecrase+future*self.vy)
        futur=CG[min(14,int(self.y/ecrase+future*self.vy))][min(20,int(self.x/ecrase+future*self.vx))]
        
        while futur == 1 :

            direction=randint(0,3)

            if direction==0:
                self.vx=1
                self.vy=0
            elif direction==1:
                self.vx=-1
                self.vy=0
            elif direction==2:
                self.vx=0
                self.vy=1
            elif direction==3:
                self.vx=0
                self.vy=-1
            futur=CG[min(14,int(self.y/ecrase+future*self.vy))][min(20,int(self.x/ecrase+future*self.vx))]
                  
        self.x+=self.vx*self.v
        self.y+=self.vy*self.v
        #print(len(CG))

def sprit(X,Y,R):
    global p
    p=tableau.create_oval(X-R,Y-R,X+R,Y+R,width = 2,fill='red')
    
fenetre = Tk(className = 'Splinter stealth')

tableau=Canvas(fenetre, width=1050, height=750)

tableau.create_rectangle(50,50,1000,700,fill='grey')

tableau.create_rectangle(50,150,150,200,fill='black')#1 coli
tableau.create_rectangle(200,50,250,200,fill='black')#2 coli
tableau.create_rectangle(50,250,250,300,fill='black')#3 coli
tableau.create_rectangle(350,500,300,300,fill='black')#4 coli
tableau.create_rectangle(100,350,200,400,fill='black')#5 coli
tableau.create_rectangle(150,400,200,450,fill='black')#6 coli
tableau.create_rectangle(100,450,200,500,fill='black')#7 coli
tableau.create_rectangle(100,550,350,600,fill='black')#8 coli
tableau.create_rectangle(300,600,350,650,fill='black')#9 coli
tableau.create_rectangle(300,150,400,200,fill='black')#10 coli
tableau.create_rectangle(350,100,400,150,fill='black')#11 coli
tableau.create_rectangle(800,100,1000,150,fill='black')#12 coli
tableau.create_rectangle(850,200,900,300,fill='black')#13 coli
tableau.create_rectangle(450,600,600,650,fill='black')#14 coli
tableau.create_rectangle(600,550,650,700,fill='black')#15 coli
tableau.create_rectangle(500,250,550,500,fill='red')#16 coli
tableau.create_rectangle(400,350,650,400,fill='red')#17 coli
tableau.create_rectangle(650,200,750,250,fill='black')#18
tableau.create_rectangle(900,200,1000,250,fill='black')#19 coli
tableau.create_rectangle(950,250,1000,400,fill='black')#20 coli
tableau.create_rectangle(850,350,950,400,fill='black')#21 coli
tableau.create_rectangle(900,550,1000,600,fill='black')#22
tableau.create_rectangle(800,550,850,700,fill='black')#23
tableau.create_rectangle(700,250,750,500,fill='black')#24
tableau.create_rectangle(650,50,700,100,fill='black')#25
tableau.create_rectangle(500,100,700,150,fill='black')#26
tableau.create_rectangle(0,0,1050,50,fill='blue')#top coli
tableau.create_rectangle(1000,00,1050,750,fill='blue')#right coli
tableau.create_rectangle(0,700,1050,750,fill='blue')#bottom coli
tableau.create_rectangle(0,0,50,700,fill='blue')#left coli


tableau.create_rectangle(50,50,150,150,fill="#00B800")#safe zone
    
tableau.pack()
tableau.update()

Player = Yakusa()

guarde=[ Guard([575,525]),
         Guard([775,325]),
         Guard([975,475])]

#for i in range(100):
#   guarde.append(Guard([150,150]))

sprit(Player.positionx,Player.positiony,Player.taille)

#---------------------------------------------DEPLACEMENT ET COLISIONS--------------------------------------------

CP =[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
    [1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1],
    [1,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,1,1,1],
    [1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1],
    [1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1],
    [1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,1],
    [1,0,1,1,0,0,1,0,1,1,1,1,1,0,1,0,0,1,1,1,1],
    [1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
    [1,0,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1],
    [1,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
    [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]

def fleche_haut(event):
    
    ecrase=50
    Avenire=1
    # print(self.x/ecrase+future*self.vx,'    ',self.y/ecrase+future*self.vy)
    Avenir=CP[min(14,int(Player.positiony/ecrase+Avenire*((Player.positiony-6.25)/ecrase)))][min(20,int(Player.positionx/ecrase+Avenire*((Player.positiony-6.25)/ecrase)))]
        
    while Avenir == 1 :
        tableau.delete(p)
        sprit(Player.positionx,Player.positiony,Player.taille)

    tableau.delete(p)
    Player.positiony -= 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)
        
    
def fleche_gauche(event):
    tableau.delete(p)
    Player.positionx -= 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

def fleche_bas(event):
    tableau.delete(p)
    Player.positiony += 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

def fleche_droite(event):
    tableau.delete(p)
    Player.positionx += 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)


while True :
        
    fenetre.bind("<Up>", fleche_haut)
    fenetre.bind("<Down>", fleche_bas)
    fenetre.bind("<Left>", fleche_gauche)
    fenetre.bind("<Right>", fleche_droite)

    tableau.delete(p)
    sprit(Player.positionx,Player.positiony,Player.taille)
    sleep(1/60)
    for i in guarde:
        i.trace()
        i.patrouille()
    tableau.pack()
    tableau.update()
    for i in guarde:
        tableau.delete(i.n)
        tableau.delete(i.m)
    
mainloop()

Bon voila. Il y a sûrement des trucs contestables mais je suis sur des valeurs floats ect... Tout est comme je veux. Mais je galère pour les collisions. J'ai déjà fais des collisions avec pas moins de 120 elif et c'est moche. Donc voila je reprend tout...

Dernière modification par Inzaguiz (Le 21/05/2015, à 22:31)

Hors ligne

#12 Le 21/05/2015, à 22:25

Inzaguiz

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

je te remercie de m'aider au passage c'est super gentil ! ^^

Dernière modification par Inzaguiz (Le 21/05/2015, à 22:29)

Hors ligne

#13 Le 21/05/2015, à 22:54

pingouinux

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

1) Tu ne testes les murs que dans fleche_haut
2) Tu n'empêches pas les indices de GC de devenir négatifs
3) Quand tu rencontres un mur, tu traces la même chose indéfiniment
4) Je ne vois pas comment tu sors de la boucle while juste avant mainloop
5) Il ne faut pas mettre les bind dans une boucle

Hors ligne

#14 Le 21/05/2015, à 23:13

Inzaguiz

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

1) Tu ne testes les murs que dans fleche_haut
C'est normal je fais mes tests que sur celle-ci pour l'instant

2) Tu n'empêches pas les indices de GC de devenir négatifs
La c'est bon ?

3) Quand tu rencontres un mur, tu traces la même chose indéfiniment
Ben je savais pas quoi mettre alors il delete puis le remet on même endroit...

4) Je ne vois pas comment tu sors de la boucle while juste avant mainloop
Corrigé (ça marchais avant et ça marche toujours... Je sais pas pourquoi...).  c'est prévu pour pas en sortir justement..

5) Il ne faut pas mettre les bind dans une boucle
Ils y sont plus


Mais les collisions sur la flèche haut ne marchent toujours pas hmm et il plante si on appui un certain nombre de fois... (lié a l'altitude je suis pas sûr)

from tkinter import *
from math import *
from time import *
from random import *

class Yakusa():
    def __init__(self):
        self.positionx = 75
        self.positiony = 75
        self.score = 0
        self.Vx = 6.25
        self.Vy = 6.25
        self.taille = 12.5

class Guard():
    
    def __init__(self,position):
        self.v = 1
        self.range = 150
        self.x = position[0]
        self.y = position[1]
        self.t = 12.5
        self.vx=1
        self.vy=0
        
    def trace(self):
        x=self.x
        y=self.y
        r=12.5
        self.n=tableau.create_oval(x-r,y-r,x+r,y+r,width = 2,fill="blue")
        self.m=tableau.create_rectangle(x-24.75,y-24.75,x+24.75,y+24.75)
        
        
    def patrouille(self):

   ############1 2 3 4 5 6 7 8 9 
##        CG = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]
        
        CG =[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
            [1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1],
            [1,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,1,1,1],
            [1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1],
            [1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1],
            [1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,1],
            [1,0,1,1,0,0,1,0,1,1,1,1,1,0,1,0,0,1,1,1,1],
            [1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
            [1,0,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
            [1,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1],
            [1,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
            [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]


        ecrase=50
        future=0.5
       # print(self.x/ecrase+future*self.vx,'    ',self.y/ecrase+future*self.vy)
        futur=CG[min(14,int(self.y/ecrase+future*self.vy))][min(20,int(self.x/ecrase+future*self.vx))]
        
        while futur == 1 :

            direction=randint(0,3)

            if direction==0:
                self.vx=1
                self.vy=0
            elif direction==1:
                self.vx=-1
                self.vy=0
            elif direction==2:
                self.vx=0
                self.vy=1
            elif direction==3:
                self.vx=0
                self.vy=-1
            futur=CG[min(14,int(self.y/ecrase+future*self.vy))][min(20,int(self.x/ecrase+future*self.vx))]
                  
        self.x+=self.vx*self.v
        self.y+=self.vy*self.v
        #print(len(CG))

def sprit(X,Y,R):
    global p
    p=tableau.create_oval(X-R,Y-R,X+R,Y+R,width = 2,fill='red')
    
fenetre = Tk(className = 'Splinter stealth')

tableau=Canvas(fenetre, width=1050, height=750)

tableau.create_rectangle(50,50,1000,700,fill='grey')

tableau.create_rectangle(50,150,150,200,fill='black')#1 coli
tableau.create_rectangle(200,50,250,200,fill='black')#2 coli
tableau.create_rectangle(50,250,250,300,fill='black')#3 coli
tableau.create_rectangle(350,500,300,300,fill='black')#4 coli
tableau.create_rectangle(100,350,200,400,fill='black')#5 coli
tableau.create_rectangle(150,400,200,450,fill='black')#6 coli
tableau.create_rectangle(100,450,200,500,fill='black')#7 coli
tableau.create_rectangle(100,550,350,600,fill='black')#8 coli
tableau.create_rectangle(300,600,350,650,fill='black')#9 coli
tableau.create_rectangle(300,150,400,200,fill='black')#10 coli
tableau.create_rectangle(350,100,400,150,fill='black')#11 coli
tableau.create_rectangle(800,100,1000,150,fill='black')#12 coli
tableau.create_rectangle(850,200,900,300,fill='black')#13 coli
tableau.create_rectangle(450,600,600,650,fill='black')#14 coli
tableau.create_rectangle(600,550,650,700,fill='black')#15 coli
tableau.create_rectangle(500,250,550,500,fill='red')#16 coli
tableau.create_rectangle(400,350,650,400,fill='red')#17 coli
tableau.create_rectangle(650,200,750,250,fill='black')#18
tableau.create_rectangle(900,200,1000,250,fill='black')#19 coli
tableau.create_rectangle(950,250,1000,400,fill='black')#20 coli
tableau.create_rectangle(850,350,950,400,fill='black')#21 coli
tableau.create_rectangle(900,550,1000,600,fill='black')#22
tableau.create_rectangle(800,550,850,700,fill='black')#23
tableau.create_rectangle(700,250,750,500,fill='black')#24
tableau.create_rectangle(650,50,700,100,fill='black')#25
tableau.create_rectangle(500,100,700,150,fill='black')#26
tableau.create_rectangle(0,0,1050,50,fill='blue')#top coli
tableau.create_rectangle(1000,00,1050,750,fill='blue')#right coli
tableau.create_rectangle(0,700,1050,750,fill='blue')#bottom coli
tableau.create_rectangle(0,0,50,700,fill='blue')#left coli


tableau.create_rectangle(50,50,150,150,fill="#00B800")#safe zone
    
tableau.pack()
tableau.update()

Player = Yakusa()

guarde=[ Guard([575,525]),
         Guard([775,325]),
         Guard([975,475])]

#for i in range(100):
#   guarde.append(Guard([150,150]))

sprit(Player.positionx,Player.positiony,Player.taille)

#---------------------------------------------DEPLACEMENT ET COLISIONS--------------------------------------------

CP =[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
    [1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1],
    [1,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,1,1,1],
    [1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1],
    [1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1],
    [1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,1],
    [1,0,1,1,0,0,1,0,1,1,1,1,1,0,1,0,0,1,1,1,1],
    [1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
    [1,0,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
    [1,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1],
    [1,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,1],
    [1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
    [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]

def fleche_haut(event):
    
    ecrase=50
    Avenire=1
    # print(self.x/ecrase+future*self.vx,'    ',self.y/ecrase+future*self.vy)
    indice1 = int(Player.positiony/ecrase+Avenire*((Player.positiony-6.25)/ecrase))
    indice2 = int(Player.positionx/ecrase+Avenire*((Player.positiony-6.25)/ecrase))

    if indice1 < 0:
        indice1 = -indice1
        
    if indice2 < 0:
        indice2 = -indice2
        
    Avenir=CP[min(14,indice1)][min(20,indice2)]
        
    while Avenir == 1 :
        tableau.delete(p)
        sprit(Player.positionx,Player.positiony,Player.taille)

    tableau.delete(p)
    Player.positiony -= 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)
        
    
def fleche_gauche(event):
    tableau.delete(p)
    Player.positionx -= 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

def fleche_bas(event):
    tableau.delete(p)
    Player.positiony += 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

def fleche_droite(event):
    tableau.delete(p)
    Player.positionx += 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

fenetre.bind("<Up>", fleche_haut)
fenetre.bind("<Down>", fleche_bas)
fenetre.bind("<Left>", fleche_gauche)
fenetre.bind("<Right>", fleche_droite)

while True :
        
    tableau.delete(p)
    sprit(Player.positionx,Player.positiony,Player.taille)
    sleep(1/60)
    for i in guarde:
        i.trace()
        i.patrouille()
    tableau.pack()
    tableau.update()
    for i in guarde:
        tableau.delete(i.n)
        tableau.delete(i.m)
    
    mainloop()

Dernière modification par Inzaguiz (Le 21/05/2015, à 23:15)

Hors ligne

#15 Le 22/05/2015, à 07:51

pingouinux

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

1) Je pense qu'il faut remplacer

    while Avenir == 1 :
        tableau.delete(p)
        sprit(Player.positionx,Player.positiony,Player.taille)

par

    if Avenir == 1 : return

2) Il faudrait revoir le calcul des coordonnées, car ton Yakusa s'arrête au milieu du mur
3) L'appel à mainloop ne doit pas être dans la boucle while
mais
4) S'il est après la boucle, il n'est jamais appelé. Je suis perplexe… Peut-être ta boucle while fait-elle office de boucle principale ???

Hors ligne

#16 Le 24/05/2015, à 13:21

Inzaguiz

Re : [PYTHON] [TKINTER] Des listes de listes / gérer les éléments.

Alors d'abord merci pour tes conseils ! J'ai réussit a faire des collision "potables" malgré quelques bugs/problèmes persistants mais je crois qu'il n'y a pas de solution..

from tkinter import *
from math import *
from time import *
from random import *

class Yakusa():
    def __init__(self):
        self.positionx = 75
        self.positiony = 75
        self.score = 0
        self.Vx = 6.25
        self.Vy = 6.25
        self.taille = 12.5

class Guard():
    
    def __init__(self,position):
        self.v = 1
        self.range = 150
        self.x = position[0]
        self.y = position[1]
        self.t = 12.5
        self.vx=1
        self.vy=0
        
    def trace(self):
        x=self.x
        y=self.y
        r=12.5
        self.n=tableau.create_oval(x-r,y-r,x+r,y+r,width = 2,fill="blue")
        self.m=tableau.create_rectangle(x-24.75,y-24.75,x+24.75,y+24.75)
        
        
    def patrouille(self):

   ############1 2 3 4 5 6 7 8 9 
##        CG = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
##              [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]
        
        CG =[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
            [1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1],
            [1,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,1,1,1,1,1],
            [1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1],
            [1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,1],
            [1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,1],
            [1,0,1,1,0,0,1,0,1,1,1,1,1,0,1,0,0,1,1,1,1],
            [1,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
            [1,0,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
            [1,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1],
            [1,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,1],
            [1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
            [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]


        ecrase=50
        future=0.5
       # print(self.x/ecrase+future*self.vx,'    ',self.y/ecrase+future*self.vy)
        futur=CG[min(14,int(self.y/ecrase+future*self.vy))][min(20,int(self.x/ecrase+future*self.vx))]
        
        while futur == 1 :

            direction=randint(0,3)

            if direction==0:
                self.vx=1
                self.vy=0
            elif direction==1:
                self.vx=-1
                self.vy=0
            elif direction==2:
                self.vx=0
                self.vy=1
            elif direction==3:
                self.vx=0
                self.vy=-1
            futur=CG[min(14,int(self.y/ecrase+future*self.vy))][min(20,int(self.x/ecrase+future*self.vx))]
                  
        self.x+=self.vx*self.v
        self.y+=self.vy*self.v
        #print(len(CG))

def sprit(X,Y,R):
    global p
    p=tableau.create_oval(X-R,Y-R,X+R,Y+R,width = 2,fill='red')
    
fenetre = Tk(className = 'Splinter stealth')

tableau=Canvas(fenetre, width=1050, height=750)

tableau.create_rectangle(50,50,1000,700,fill='grey')

tableau.create_rectangle(50,150,150,200,fill='black')#1 coli
tableau.create_rectangle(200,50,250,200,fill='black')#2 coli
tableau.create_rectangle(50,250,250,300,fill='black')#3 coli
tableau.create_rectangle(350,500,300,300,fill='black')#4 coli
tableau.create_rectangle(100,350,200,400,fill='black')#5 coli
tableau.create_rectangle(150,400,200,450,fill='black')#6 coli
tableau.create_rectangle(100,450,200,500,fill='black')#7 coli
tableau.create_rectangle(100,550,350,600,fill='black')#8 coli
tableau.create_rectangle(300,600,350,650,fill='black')#9 coli
tableau.create_rectangle(300,150,400,200,fill='black')#10 coli
tableau.create_rectangle(350,100,400,150,fill='black')#11 coli
tableau.create_rectangle(800,100,1000,150,fill='black')#12 coli
tableau.create_rectangle(850,200,900,300,fill='black')#13 coli
tableau.create_rectangle(450,600,600,650,fill='black')#14 coli
tableau.create_rectangle(600,550,650,700,fill='black')#15 coli
tableau.create_rectangle(500,250,550,500,fill='red')#16 coli
tableau.create_rectangle(400,350,650,400,fill='red')#17 coli
tableau.create_rectangle(650,200,750,250,fill='black')#18
tableau.create_rectangle(900,200,1000,250,fill='black')#19 coli
tableau.create_rectangle(950,250,1000,400,fill='black')#20 coli
tableau.create_rectangle(850,350,950,400,fill='black')#21 coli
tableau.create_rectangle(900,550,1000,600,fill='black')#22
tableau.create_rectangle(800,550,850,700,fill='black')#23
tableau.create_rectangle(700,250,750,500,fill='black')#24
tableau.create_rectangle(650,50,700,100,fill='black')#25
tableau.create_rectangle(500,100,700,150,fill='black')#26
tableau.create_rectangle(0,0,1050,50,fill='blue')#top coli
tableau.create_rectangle(1000,00,1050,750,fill='blue')#right coli
tableau.create_rectangle(0,700,1050,750,fill='blue')#bottom coli
tableau.create_rectangle(0,0,50,700,fill='blue')#left coli


tableau.create_rectangle(50,50,150,150,fill="#00B800")#safe zone
    
tableau.pack()
tableau.update()

Player = Yakusa()

guarde=[ Guard([575,525]),
         Guard([775,325]),
         Guard([975,475])]

#for i in range(100):
#   guarde.append(Guard([150,150]))

sprit(Player.positionx,Player.positiony,Player.taille)

#---------------------------------------------DEPLACEMENT ET COLISIONS--------------------------------------------

CP =[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],#1
     [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],#1
     [1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1],#2
     [1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1],#2
     [1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1],#3
     [1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1],#3
     [1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1],#4
     [1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1],#4
     [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1],#5
     [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1],#5
     [1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,1,1],#6
     [1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,1,1],#6
     [1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1],#7
     [1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1],#7
     [1,1,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1],#8
     [1,1,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1],#8
     [1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1],#9
     [1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1],#9
     [1,1,0,0,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1],#10
     [1,1,0,0,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1],#10
     [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1],#11
     [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1],#11
     [1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,1,1,1,1,1,1],#12
     [1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,1,1,1,1,1,1],#12
     [1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1],#13
     [1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1],#13
     [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1],#14
     [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1],#14
     [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],#15
     [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]#15


def fleche_haut(event):
    
    ecrase=25
    Avenire=0.5
    indice1 = int(Player.positiony/ecrase-Avenire)
    indice2 = int(Player.positionx/ecrase)

    if indice1 < 0:
        indice1 = 0
        
    if indice2 < 0:
        indice2 = 0
        
    Avenir=CP[min(28,indice1)][min(40,indice2)]
    print(Avenir)
        
    while Avenir == 1 :
        return

    tableau.delete(p)
    Player.positiony -= 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)
        
    
def fleche_gauche(event):
    
    ecrase=25
    Avenire=0.5
    indice1 = int(Player.positiony/ecrase)
    indice2 = int(Player.positionx/ecrase-Avenire)

    if indice1 < 0:
        indice1 = 0
        
    if indice2 < 0:
        indice2 = 0
        
    Avenir=CP[min(28,indice1)][min(40,indice2)]
    print(Avenir)
            
    while Avenir == 1 :
        return

    tableau.delete(p)
    Player.positionx -= 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

def fleche_bas(event):
    
    ecrase=25
    Avenire=0.5
    indice1 = int(Player.positiony/ecrase+Avenire)
    indice2 = int(Player.positionx/ecrase)

    if indice1 < 0:
        indice1 = 0
        
    if indice2 < 0:
        indice2 = 0
        
    Avenir=CP[min(28,indice1)][min(40,indice2)]
    print(Avenir)
            
    while Avenir == 1 :
        return

    tableau.delete(p)
    Player.positiony += 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

def fleche_droite(event):
    
    ecrase=25
    Avenire=0.5
    indice1 = int(Player.positiony/ecrase)
    indice2 = int(Player.positionx/ecrase+Avenire)

    if indice1 < 0:
        indice1 = 0
        
    if indice2 < 0:
        indice2 = 0        
    Avenir=CP[min(28,indice1)][min(40,indice2)]
    print(Avenir)
            
    while Avenir == 1 :
        return

    tableau.delete(p)
    Player.positionx += 6.25
    sprit(Player.positionx,Player.positiony,Player.taille)

fenetre.bind("<Up>", fleche_haut)
fenetre.bind("<Down>", fleche_bas)
fenetre.bind("<Left>", fleche_gauche)
fenetre.bind("<Right>", fleche_droite)

while True :
        
    tableau.delete(p)
    sprit(Player.positionx,Player.positiony,Player.taille)
    sleep(1/60)
    for i in guarde:
        i.trace()
        i.patrouille()
    tableau.pack()
    tableau.update()
    for i in guarde:
        tableau.delete(i.n)
        tableau.delete(i.m)
    
mainloop()

Voila la ça marche mieux smile

Hors ligne