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 124 125 126 127 128 129
| #This python file uses the following encoding: utf-8
#Game project
import pygame,sys
from pygame.locals import*
pygame.init()
def game():
screen = pygame.display.set_mode((600,600)) #Définition de l'écran
pygame.display.set_caption('DK Maze')
dk_bas = pygame.image.load('dk_bas.png')
dk_haut = pygame.image.load('dk_haut.png')
dk_gauche = pygame.image.load('dk_gauche.png')
#Définition des images à afficher
dk_droite = pygame.image.load('dk_droite.png')
end = pygame.image.load('end.png')
mur = pygame.image.load('mur.png')
start = pygame.image.load('start.png')
fond = pygame.image.load('fond.png')
fond = pygame.transform.scale(fond,[600,600])
home_screen = pygame.image.load('home.png')
home_screen = pygame.transform.scale(home_screen,[600,600])
image_vide=pygame.image.load("vide.png")
image_fond = home_screen
screen.blit(fond,(0,0))
screen.blit(start,(0,0))
screen.blit(end,(550,550))
screen.blit(home_screen,(0,0))
x = 0
y = 0
dk_bas_pos = dk_bas.get_rect() #Transformation en .rect du personnage
screen.blit(dk_bas,dk_bas_pos)
screen.blit(dk_bas,(x,y))
dk_haut_pos = dk_haut.get_rect()
screen.blit(dk_haut,dk_haut_pos)
screen.blit(dk_haut,(x,y))
dk_gauche_pos = dk_gauche.get_rect()
screen.blit(dk_gauche,dk_gauche_pos)
screen.blit(dk_gauche,(x,y))
dk_droite_pos = dk_droite.get_rect()
screen.blit(dk_droite,dk_droite_pos)
screen.blit(dk_droite,(x,y))
while True: #Menu
screen.blit(image_fond,(0,0))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
#Choix du niveau 1
if event.type == KEYDOWN and event.key == K_F1:
image_fond= image_vide
screen.blit(fond,(0,0))
screen.blit(start,(0,0))
screen.blit(end,(435,435))
screen.blit(dk_bas,dk_bas_pos)
screen.blit(dk_bas,(x,y))
pygame.display.update(screen.blit(fond,(0,0)))
pygame.display.update(screen.blit(end,(550,550)))
pygame.display.update(screen.blit(start,(0,0)))
pygame.display.update(screen.blit(dk_bas,dk_bas_pos))
pygame.display.update(screen.blit(dk_bas,(x,y)))
#Déplacement à droite
if event.type == KEYDOWN and event.key == K_RIGHT:
x=+10
screen.blit(dk_droite,dk_droite_pos)
screen.blit(dk_droite,(x,y))
dk_droite_pos = dk_droite_pos.move(x,y)
pygame.display.update(screen.blit(dk_droite,dk_droite_pos))
pygame.display.update(screen.blit(dk_droite,(x,y)))
pygame.display.update(fond,(0,0))
#Déplacement à gauche
if event.type == KEYDOWN and event.key == K_LEFT:
x=-10
screen.blit(dk_gauche,dk_gauche_pos)
screen.blit(dk_gauche,(x,y))
dk_gauche_pos = dk_gauche_pos.move(x,y)
pygame.display.update(screen.blit(dk_gauche,(x,y)))
pygame.display.update(screen.blit(dk_gauche,dk_gauche_pos))
pygame.display.update(fond,(0,0))
#Déplacement en bas
if event.type == KEYDOWN and event.key == K_DOWN:
y=+10
screen.blit(dk_bas,dk_bas_pos)
screen.blit(dk_bas,(x,y))
dk_bas_pos = dk_bas_pos.move(x,y)
pygame.display.update(screen.blit(dk_bas,dk_bas_pos))
pygame.display.update(screen.blit(dk_bas,(x,y)))
pygame.display.update(fond,(0,0))
#Déplacement en haut
if event.type == KEYDOWN and event.key == K_UP:
y=-10
screen.blit(dk_haut,dk_haut_pos)
screen.blit(dk_haut,(x,y))
dk_bas_pos = dk_haut_pos.move(x,y)
pygame.display.update(screen.blit(dk_haut,dk_haut_pos))
pygame.display.update(screen.blit(dk_haut,(x,y)))
pygame.display.update(fond,(0,0))
y=y
if __name__ == '__main__':
game() |
Partager