IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

problème position personnage


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2019
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2019
    Messages : 33
    Par défaut problème position personnage
    bonjour a tous,

    je fais un jeu labyrinthe , mais j'ai un problème tout bête, quand je n'arrive pas a positionner mon personnage sur le point de départ
    je précise que j'ai un fichier.txt pour mon labyrinthe

    j'ai essayé de faire plusieurs solution sans réussite

    fichier dk.py :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
     
    """
    Jeu Donkey Kong Labyrinthe
    Jeu dans lequel on doit déplacer DK jusqu'aux bananes à travers un labyrinthe.
     
    Script Python
    Fichiers : dklabyrinthe.py, classes.py, constantes.py, n1, n2 + images
    """
    # -*-coding:Utf-8 -*
    from pygame.locals import *
    import os
    from const import *
    from classs import * 
    import pygame
    pygame.init()
     
    fenetre = pygame.display.set_mode((tailleFenetre, tailleFenetre), RESIZABLE)
     
    pygame.event.pump()
     
    maCarte = Niveau()
    maCarte.niveau()
    maCarte.carte()
     
     
     
    continuer = 1
    continuer_accueil = 1
    continuer_partie = 1
    while continuer:
     
    	pygame.time.Clock().tick(30)
     
    	accueil = pygame.image.load(image_accueil).convert()
    	fenetre.blit(accueil, (0, 0))
    	pygame.display.flip()
     
     
    	while continuer_accueil:
     
     
    		for event in pygame.event.get():
    			if event.type == KEYDOWN and event.key == K_ESCAPE:
    				continuer_accueil = 0
    				continuer = 0
    				continuer_partie = 0
     
     
    			if event.type == KEYDOWN:
     
    				if event.key == K_F1:
    					num = 0
    					continuer_accueil = 0
     
    				if event.key == K_F2:
    					num = 1
    					continuer_accueil = 0
     
     
     
     
    		fond = pygame.image.load(image_fond).convert_alpha()
     
    		fenetre.blit(fond, (0, 0))
     
     
    		print(maCarte.position_depart)
     
    		dk = pygame.image.load(dk_bas).convert_alpha()
    		mur = pygame.image.load(image_mur).convert_alpha()
    		depart = pygame.image.load(image_depart).convert_alpha()
    		arrivee = pygame.image.load(image_arrivee).convert_alpha()
    		position_perso = dk.get_rect()
    		fenetre.blit(dk, position_perso)
    		pygame.key.set_repeat(300, 20)
    		sortie = maCarte.position_arrivee
    	while continuer_partie:
     
     
    		for event in pygame.event.get():
    			if event.type == QUIT: 
    				continuer = 0
     
    			if event.type == KEYDOWN and event.key == K_ESCAPE:
     
    				continuer_partie = 0
     
     
    			if event.type == KEYDOWN:
     
    				if event.key == K_DOWN:
    					position_perso = position_perso.move(0, 1)
    					dk = pygame.image.load(dk_bas).convert_alpha()
     
    				if event.key == K_UP:
    					position_perso = position_perso.move(0, -1)
    					dk = pygame.image.load(dk_haut).convert_alpha()
     
    				if event.key == K_LEFT:
    					position_perso = position_perso.move(-1, 0)
    					dk = pygame.image.load(dk_gauche).convert_alpha()
     
    				if event.key == K_RIGHT:
    					position_perso = position_perso.move(1, 0)
    					dk = pygame.image.load(dk_droite).convert_alpha()
     
     
     
     
    		fenetre.blit(fond, (0, 0))
     
     
    		for position_mur in maCarte.liste_position_mur:
    			fenetre.blit(mur, position_mur)
     
    		for position_depart in maCarte.position_depart:
    			fenetre.blit(depart, position_depart)
     
     
    		for position_arrivee in maCarte.position_arrivee:
    			fenetre.blit(arrivee, position_arrivee)
    		fenetre.blit(dk, position_perso)
    		pygame.display.flip()
    fichier const.py:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
     
    # -*-coding:Utf-8 -*
    import os
    import pygame
    pygame.init()
     
     
    # fenetre
     
    nbCote = 15
    tailleSprite = 30
    tailleFenetre = nbCote * tailleSprite
     
     
    # image du jeu 
     
    image_accueil = "images/accueil.jpg"
    image_arrivee = "images/arrivee.png"
    image_depart = "images/depart.png"
    dk_bas = "images/dk_bas.png"
    dk_haut = "images/dk_haut.png"
    dk_gauche = "images/dk_gauche.png"
    dk_droite = "images/dk_droite.png"
    image_fond = "images/fond.jpg"
    image_mur = "images/mur.png"

    fichier classs.py :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
     
    # -*-coding:Utf-8 -*
    import os 
    from const import *
    from pygame.locals import *
     
    class Niveau: 
     
    	def __init__(self):
    		self.liste_position_mur = []
    		self.position_depart = []
    		self.position_arrivee = []
     
    	def niveau(self):
     
    		niveau = os.listdir("niveau")
    		num = 0
     
     
     
    		niveauFile = open("./niveau/"+niveau[num], "r")
    		self.enregistrement = niveauFile.read().splitlines()
     
     
     
     
    	def carte(self):
     
    		self.liste_position_mur = []
    		self.position_depart = []
    		self.position_arrivee = []
     
    		for i, ligne in  enumerate(self.enregistrement):
    			for j, case in enumerate(ligne):
     
    				if case == "O":
    					mur = pygame.image.load(image_mur).convert_alpha()
    					position_mur = mur.get_rect()
    					position_mur.x = i * tailleSprite
    					position_mur.y = j * tailleSprite
     
    					self.liste_position_mur.append(position_mur)
     
     
    				if case == "X":
    					depart = pygame.image.load(image_depart).convert_alpha()
    					position_depart = depart.get_rect()
    					position_depart.x = i * tailleSprite
    					position_depart.y = j * tailleSprite
     
    					self.position_depart.append(position_depart)
     
    				if case == "G":
    					arrivee = pygame.image.load(image_arrivee).convert_alpha()
    					position_arrivee = arrivee.get_rect()
    					position_arrivee.x = i * tailleSprite
    					position_arrivee.y = j * tailleSprite
     
    					self.position_arrivee.append(position_arrivee)
     
     
    	def passage(self, depart, arrive, mur):
     
    		self.depart = pygame.image.load(depart).convert_alpha()
    		self.arrivee = pygame.image.load(arrivee).convert_alpha()
    		self.mur = pygame.image.load(mur).convert_alpha()
     
    	def personnage(self, haut, bas, gauche, droite):
     
     
    		self.haut = pygame.image.load(dk_droite).convert_alpha()
    		self.bas = pygame.image.load(dk_bas).convert_alpha()
    		self.gauche = pygame.image.load(dk_gauche).convert_alpha()
    		self.droite = pygame.image.load(dk_droite).convert_alpha()

  2. #2
    Membre Expert

    Homme Profil pro
    Ingénieur calcul scientifique
    Inscrit en
    Mars 2013
    Messages
    1 229
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur calcul scientifique

    Informations forums :
    Inscription : Mars 2013
    Messages : 1 229
    Par défaut
    Il va falloir élaguer un peu pour présenter le coeur de votre problème. Car personne n'ira lire tout ce pavé de code pour voir où est le truc. Qui plus est on ne peut pas l'éxécuter puisque comme vous le dites il requiert des fichiers d'entrée, que l'on n'a pas.

Discussions similaires

  1. Gridview : problème position N° de page
    Par Anne1969 dans le forum ASP.NET
    Réponses: 1
    Dernier message: 07/10/2009, 15h23
  2. problème position slider
    Par atomicJo dans le forum MFC
    Réponses: 2
    Dernier message: 28/11/2007, 22h44
  3. [MDI] Problème : Position Image SetBitmap
    Par nicob56 dans le forum MFC
    Réponses: 1
    Dernier message: 21/02/2006, 16h26
  4. [CSS] problème position div
    Par krfa1 dans le forum Mise en page CSS
    Réponses: 7
    Dernier message: 18/05/2005, 17h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo