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
| import pygame
clock = pygame.time.Clock()
pygame.init()
#Différentes couleurs
color_rect = (255, 0, 0)
color_surface = (37, 11, 11)
green_color = (100, 255, 100)
black_color = (0, 0, 0)
blue_color = (0, 255, 255)
#Titre fenêtre
pygame.display.set_caption("Mélissandre and Cie...")
#Dimensions surface
window_surface = pygame.display.set_mode([800, 600])
#Chargement du Perso
perso = pygame.image.load("head.jpg")
perso_x = 400
perso_y = 300
window_surface.blit(perso, [perso_x, perso_y])
pygame.display.flip()
#Boucle Infinie
continued = True
pygame.key.set_repeat(1, 1)
while continued:
window_surface.fill(color_surface)
# Ajout du mur de blocage:
rect_border = pygame.Rect(4, 3, 793, 595)
pygame.draw.rect(window_surface, color_rect, rect_border, 1)
rect_top = pygame.Rect(7, 6, 788, 30)
pygame.draw.rect(window_surface, green_color, rect_top, 1)
for event in pygame.event.get(): #Attente des évènements:
if event.type == pygame.QUIT:
continued = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
if perso_y:
perso_y -= 3
if event.key == pygame.K_DOWN:
if perso_y:
perso_y += 3
if event.key == pygame.K_LEFT:
if perso_x:
perso_x -= 3
if event.key == pygame.K_RIGHT:
if perso_x:
perso_x += 3
window_surface.blit(window_surface, (0, 0))
window_surface.blit(perso, [perso_x, perso_y])
clock.tick(63)
arial_font = pygame.font.SysFont("arial", 20)
text = arial_font.render(f"{clock.get_fps():.0f} FPS", True, blue_color)
window_surface.blit(text, [11, 8])
pygame.display.flip() |