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
|
import os, pygame
from pygame.locals import *
def main():
pygame.init() #initialisation
screen = pygame.display.set_mode((800, 600)) #Création de la fenêtre
imgList = []
droitePossible = [1,0,0,0,1,0]
gauchePossible = [0,1,0,0,1,0]
facePossible = [1,0,1,1,0,1]
for i in range(0,6):#Indexage des images
string = "Image" + chr(i+48) + ".jpg"
img = pygame.image.load(string).convert()
imgList.append(img)
rectangle = pygame.Rect( 0 , 0 , 800 , 600 )#Création du rectangle
screen.blit( imgList[0] , rectangle)
pygame.display.flip()#Affichage
clock = pygame.time.Clock()
clock.tick(10)
imgPos = 0
imgCote = 0
zone = imgList[imgPos]
while 1:#Boucle infinie
for e in pygame.event.get():
if e.type == QUIT:
return
if e.type == 2:#touche enfoncée
if(e.key == K_s):#touche S
if(imgPos%2 == 0):
imgPos = imgPos + 1
else: imgPos = imgPos - 1
zone = imgList[imgPos]
if((e.key == K_w) and (facePossible[imgPos] == 1)):#touche Z
if(imgPos%2 == 0):
imgPos = imgPos + 2
else: imgPos = imgPos -2
zone = imgList[imgPos]
if((e.key == K_a) and (gauchePossible[imgPos] == 1)):#touche Q
if(imgPos%2 == 0):
imgGauche = pygame.image.load("Image" + chr(imgPos + 48) + "droite.jpg").convert()
else: imgGauche = pygame.image.load("Image" + chr(imgPos-1 + 48) + "gauche.jpg").convert()
zone = imgGauche
if((e.key == K_d) and (droitePossible[imgPos] == 1)):#touche D
if(imgPos%2 == 0):
imgDroite = pygame.image.load("Image" + chr(imgPos + 48) + "gauche.jpg").convert()
else: imgDroite = pygame.image.load("Image" + chr(imgPos-1 + 48) + "droite.jpg").convert()
zone = imgDroite
screen.blit( zone, rectangle)
pygame.display.flip()
main() |
Partager