Mon programme:
import pygame
from pygame.locals import *
pygame.init()
#Ouverture de la fenêtre Pygame
fenetre = pygame.display.set_mode((1366,768))
icone = pygame.image.load("Icone.gif" )
pygame.display.set_icon(icone)
pygame.display.set_caption("Weez!" )
#Chargement et collage du fond
fond = pygame.image.load("fondecran.jpg" ).convert()
fenetre.blit(fond,(0,0))
#Chargement et collage du tonneau
tonneau = pygame.image.load("tonneau.gif" ).convert_alpha()
tonneau_rect = pygame.Rect(60,400,100,20)
fenetre.blit(tonneau, tonneau_rect)
etat_tonneau = 0
#Chargement et collage de la gamelle
gamelle = pygame.image.load("gamelle.gif" ).convert_alpha()
gamelle_rect = pygame.Rect(65,620,10,30)
fenetre.blit(gamelle, gamelle_rect)
#Chargement et collage du lit
lit = pygame.image.load("lit.gif" ).convert_alpha()
lit_rect = pygame.Rect(1100,450,100,150)
fenetre.blit(lit, lit_rect)
#Chargement et collage du personnage
perso = pygame.image.load("perso_bas.gif" ).convert_alpha()
perso_rect = pygame.Rect(235,565,73,150)
fenetre.blit(perso, perso_rect)
ma_police = pygame.font.SysFont ("Arial",16)
mon_texte = ma_police.render("Premier Test",True, (0,0,0),(255,255,255))
#Rafraîchissement de l'écran
pygame.display.flip()
pygame.key.set_repeat(200, 15)
collision_1 = perso_rect.colliderect(tonneau_rect)== True
#BOUCLE INFINIE
continuer = 1
dialogue = 0
while continuer:
for event in pygame.event.get():
if event.type == QUIT:
continuer = 0
#Deplacements du perso
if event.type == KEYDOWN:
if event.key == K_DOWN:
fenetre.blit(fond, (0,0))
perso = pygame.image.load("perso_bas.gif" ).convert_alpha()
perso_rect.y+=4
if event.key == K_UP :
fenetre.blit(fond, (0,0))
perso = pygame.image.load("perso_haut.gif" ).convert_alpha()
perso_rect.y-=4
if event.key == K_LEFT:
fenetre.blit(fond, (0,0))
perso = pygame.image.load("perso_gauche.gif" ).convert_alpha()
perso_rect.x-=4
if event.key == K_RIGHT:
fenetre.blit(fond, (0,0))
perso = pygame.image.load("perso_droite.gif" ).convert_alpha()
perso_rect.x+=4
#Õn fixe les limites au personnage dans sa zone de deplacement
if perso_rect.y<350:
fenetre.blit(fond, (0,0))
perso = pygame.image.load("perso_haut.gif" ).convert_alpha()
perso_rect.y+=4
if perso_rect.x<0:
fenetre.blit(fond, (0,0))
perso = pygame.image.load("perso_gauche.gif" ).convert_alpha()
perso_rect.x+=4
if perso_rect.x>1339:
fenetre.blit(fond, (0,0))
perso = pygame.image.load("perso_droite.gif" ).convert_alpha()
perso_rect.x-=4
if perso_rect.y>600:
fenetre.blit(fond, (0,0))
perso = pygame.image.load("perso_bas.gif" ).convert_alpha()
perso_rect.y-=4
#Gestion des collisions
if perso_rect.colliderect(tonneau_rect)== True and etat_tonneau == 0 :
perso = pygame.image.load("perso_boit.gif" ).convert_alpha()
tonneau = pygame.image.load("tonneau_vide.gif" ).convert_alpha()
etat_tonneau = 1
if perso_rect.colliderect(gamelle_rect)== True :
perso = pygame.image.load("perso_mange.gif" ).convert_alpha()
if perso_rect.colliderect(lit_rect)== True :
perso = pygame.image.load("perso_dort.gif" ).convert_alpha()
#Re-collage
fenetre.blit(fond, (0,0))
fenetre.blit (tonneau, tonneau_rect)
fenetre.blit (gamelle, gamelle_rect)
fenetre.blit (lit, lit_rect)
fenetre.blit(perso, perso_rect)
#if dialogue == 1 :
# fenetre.blit(mon_texte, (200,200))
#Rafraichissement
pygame.display.flip()