Python aide jeu dinosaure (pygame)
Aiiko22
Messages postés
3
Statut
Membre
-
Aiiko22 Messages postés 3 Statut Membre -
Aiiko22 Messages postés 3 Statut Membre -
Bonjour, j'ai besoin de votre aide pour un programme python, codé à l'aide de pygame (c'est un devoir pour la NSI), le problème est que celui ci ne se lance pas dutout, c'est pour ça que j'ai besoin de vous ! Merci !! (il y a des traces d'essaies de débugage dans le code donc n'y faite pas attention)
import pygame
import os
import random
pygame.init()
FRAMERATE = 30
SCREEN_HEIGHT = 600
SCREEN_WIDTH = 1100
taille_ecran = (SCREEN_WIDTH, SCREEN_HEIGHT)
ecran = pygame.display.set_mode(taille_ecran)
class ninja:
global ecran
RUN = [pygame.image.load(os.path.join("./ninjav2.png")),
pygame.image.load(os.path.join("perso1.png"))]
JUMP = [pygame.image.load(os.path.join("ninja en saut.png"))]
BAMBOU = [pygame.image.load(os.path.join("perso1.png"))]
BACKGROUND = [pygame.image.load(os.path.join("sol.png"))]
X_POS = 80
Y_POS = 310
JUMP_VEL = 8.5
def init(self):
self.run_img = RUN
self.jump_img = JUMP
self.ninja_run = True
self.ninja_jump = False
self.step_index = 0
self.jump_vel = self.JUMP_VEL
self.image = self.run_img[0]
"""définition de la hitbox"""
self.ninja_rect = self.image.get_rect()
self.ninja_rect.x = self.X_POS
self.ninja_rect.y = self.Y_POS
def maj(self, userInput):
if self.ninja_run:
self.run()
if self.ninja_jump:
self.jump()
if self.step_index >= 10:
self.step_index = 0
""" Changement d'état du ninja"""
if userInput[pygame.K_UP] and not self.ninja_jump:
self.ninja_run = False
self.ninja_jump = True
elif not (self.ninja_jump or userInput[pygame.K_DOWN]):
self.ninja_run = True
self.ninja_jump = False
def run(self):
self.image = self.run_img[self.step_index//5]
self.ninja_rect = self.image.get_rect()
self.ninja_rect.x = self.X_POS
self.ninja_rect.y = self.Y_POS
self.step_index += 1
def jump(self):
"""vélocité du saut"""
self.image = self.jump_img
if self.ninja_jump:
self.ninja_rect.y -= self.jump_vel * 4
self.jump_vel -= 0.8
if self.jump_vel < - self.JUMP_VEL:
self.ninja_jump = False
self.jump_vel = self.JUMP_VEL
def draw(self, SCREEN):
ecran.blit(self.init().image, (self.ninja_rect.x, self.ninja_rect.y))
def main():
global taille_ecran
print("debug")
global game_speed, x_pos_bg, y_pos_bg, points
run = True
print("debug")
clock = pygame.time.Clock()
joueur = ninja()
game_speed = 14
x_pos_bg = 380
y_pos_bg = 400
points = 0
font = pygame.font.Font('freesansbold.ttf',20)
def score ():
global points, game_speed
points += 1
if points % 100 == 0 :
game_speed += 1
"""Affichage du score sur l'écran"""
text = fond.render("Score : " + str(points), True, (0, 0, 0))
textRect = text.get_rect()
textRect.center = (1000, 40)
ecran.blit(text, textRect)
print("debug")
def background ():
global x_pos_bg, y_pos_bg
image_width = BACKGROUND.get_width()
ecran.blit(BACKGROUND, (x_pos_bg, y_pos_bg))
ecran.blit(BACKGROUND, (image_width + x_pos_bg, y_pos_bg))
"""boucle terrain"""
if x_pos_bg <= -image_width:
ecran.blit(BACKGROUND, (image_width + x_pos_bg, y_pos_bg))
x_pos_bg = 0
x_pos_bg -= game_speed
print("debug")
"""boucle infinie qui fait tourner le jeu tant que rien ne se produise"""
jeu_en_cours = True
while jeu_en_cours :
#for event in pygame.event.get():
#if event.type == pygame.QUIT:
# jeu_en_cours = False
# if event.type == pygame.KEYDOWN:
# if event.key == pygame.K_ESCAPE:
# jeu_en_cours = False
ecran.fill((255, 255, 255))
userInput = pygame.key.get_pressed()
joueur.draw(ecran)
joueur.update(userInput)
score()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
jeu_en_cours = False
background()
pygame.display.update()
pygame.quit()
if __name__ == "__main__":
main()
Configuration: Windows / Chrome 101.0.4951.54
A voir également:
- Python aide jeu dinosaure (pygame)
- 94 jeu - Télécharger - Puzzle & Réflexion
- 94 degrés jeu - Télécharger - Divers Jeux
- Citizen code python avis - Accueil - Outils
- Jeu zuma - Télécharger - Jeux vidéo
- Jeu logo - Télécharger - Jeux vidéo
3 réponses
yg_be
Messages postés
24281
Date d'inscription
Statut
Contributeur
Dernière intervention
Ambassadeur
1 585
bonjour, tu n'as aucun message d'erreur?
Non je j’ai juste un écran noir qui s’ouvre et si je le ferme alors tout le logiciel crash.