Pygame
il faut l'importer au début du programme.
xxxxxxxxxx
import pygame as pg
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame")
fin = False
while not fin:
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
pg.init()
permet d'initialiser la fenêtre Pygame
.
pg.display.set_caption("Pygame")
affiche un titre pour la fenêtre Pygame
.
fin = False
définit une variable booléenne (ici fausse) qui permettra de déclencher l'arrêt du programme.
while
s'exécute tant que la variable fin
est fausse. Ainsi à chaque tour de boucle la variable ev
, qui attend de voir qu'elle évènement peut survenir, sera associée à l'évènement QUIT
lorsqu'on clique sur la croix de la fenêtre. À ce moment la variable fin
devientVraie
et on quitte donc la boucle pour exécuter la commande pq.quit()
qui permet de fermer la fenêtre Pygame
.
Pygame
.
pg.display.set_mode((largeur, hauteur))
.
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame")
ecran = pg.display.set_mode((400, 150))
fin = False
while not fin:
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
ecran
ainsi créée va pouvoir être utilisée pour attribuer des propriétés à la fenêtre de jeu. Par exemple pour donner une couleur de fond :
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame")
ecran = pg.display.set_mode((400, 150))
vert = (0,255,200)
fin = False
while not fin:
ecran.fill(vert)
pg.display.update()
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
pg.draw.lines( display, couleur, fermeture (True ou False) , [(abs1,ord1), (abs2,ord3), etc. ] )
:
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame : ligne")
ecran = pg.display.set_mode((400, 150))
vert = (0,255,200)
fin = False
while not fin:
ecran.fill(vert)
pg.draw.lines(ecran, [0,0,0], False, [(0,0),(200,50)], 1)
pg.display.update()
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame : lignes")
ecran = pg.display.set_mode((400, 150))
vert = (0,255,200)
fin = False
while not fin:
ecran.fill(vert)
pg.draw.lines(ecran,[255,0,0],True,[(0,130),(200,50),(220,80),(250,60)],5)
pg.display.update()
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
pg.draw.rect( display, couleur, [abs, ord, largeur, hauteur], épaisseur )
:
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame : rectangle")
ecran = pg.display.set_mode((400, 150))
vert = (0,255,100)
fin = False
while not fin:
ecran.fill(vert)
pg.draw.rect(ecran,[255,150,150],[150,25,100,100])
pg.display.update()
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
pg.draw.circle(display, couleur, (abs,ord), rayon, épaisseur)
:
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame : cercle")
ecran = pg.display.set_mode((400, 150))
vert = (0,255,100)
fin = False
while not fin:
ecran.fill(vert)
pg.draw.circle(ecran,[0,0,0],[200,75],30,3)
pg.display.update()
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame : cercle")
ecran = pg.display.set_mode((400, 150))
vert = (0,255,100)
fin = False
while not fin:
ecran.fill(vert)
pg.draw.circle(ecran,[0,0,0],[200,75],30,0)
pg.display.update()
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame : cercle")
ecran = pg.display.set_mode((400, 150))
vert = (0,255,100)
fin = False
while not fin:
ecran.fill(vert)
pg.draw.circle(ecran,[255,0,0],[200,75],30,0)
pg.draw.circle(ecran,[0,0,0],[200,75],30,4)
pg.display.update()
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
pg.draw.ellipse(display, couleur, (abs,ord,largeur,hauteur), épaisseur)
.
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame : ellipse")
ecran = pg.display.set_mode((400, 150))
vert = (0,255,100)
fin = False
while not fin:
ecran.fill(vert)
pg.draw.ellipse(ecran,[0,0,0],[150,30,100,80],2)
pg.display.update()
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame : ellipse")
ecran = pg.display.set_mode((400, 150))
vert = (0,255,100)
fin = False
while not fin:
ecran.fill(vert)
pg.draw.ellipse(ecran,[0,0,0],[150,30,100,80],0)
pg.display.update()
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
pg.draw.arc(display, couleur, (abs,ord,largeur,hauteur), angle de départ, angle de fin, épaisseur)
. Les angles sont exprimés en radians.
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Pygame : arc")
ecran = pg.display.set_mode((400, 150))
vert = (0,255,100)
fin = False
while not fin:
ecran.fill(vert)
pg.draw.arc(ecran,[0,0,0],[150,30,100,80],0,3.14159,2)
pg.display.update()
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
pygame.font
et ensuite initialiser la prise en charge des polices de caractères avec pg.font.init()
.
myfont = pg.font.SysFont('Arial', 30)
. La police s'appelle myfont
et elle utilise Arial
(mais on peut saisir celle que l'on souhaite) et la taille des caractères est de 20px.
textsurface = myfont.render('GAME OVER', False, (0, 0, 200))
qui crée la surface textsurface
sur laquelle on écrit « GAME OVER » avec la couleur (0,0,200)
qui correspond à du bleu.
Pygame
on saisit ecran.blit(textsurface,(30,80))
pour la placer à l'abscisse 30 et l'ordonnée 80.
xxxxxxxxxx
import pygame as pg
import pygame.font
pg.font.init()
myfont = pg.font.SysFont('Arial', 20)
pg.init()
pg.display.set_caption("Texte")
ecran = pg.display.set_mode((200, 200))
textsurface = myfont.render('GAME OVER', False, (0, 0, 200))
ecran.blit(textsurface,(30,80))
pg.display.update()
fin = False
while not fin:
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 10
dx = 5
while True:
clock.tick(20)
ecran.fill(pg.Color("black"))
x += dx
pg.draw.circle(ecran,[255,255,255],[x,75],10,0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 10
dx = 5
while True:
clock.tick(20)
ecran.fill(pg.Color("black"))
if x > 390:
dx = -5
if x < 10:
dx = 5
x += dx
pg.draw.circle(ecran,[255,255,255],[x,75],10,0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
y = 10
dy = 5
while True:
clock.tick(20)
ecran.fill(pg.Color("black"))
if y > 140:
dy = -5
if y < 10:
dy = 5
y += dy
pg.draw.circle(ecran,[255,255,255],[200,y],10,0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 30
dx = 5
y = 10
dy = 5
while True:
clock.tick(40)
ecran.fill(pg.Color("black"))
if x > 390:
dx = -5
if x < 10:
dx = 5
x += dx
if y > 140:
dy = -5
if y < 10:
dy = 5
y += dy
pg.draw.circle(ecran,[150,150,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.key.set_repeat(50, 25)
pg.display.set_caption("Clavier")
ecran = pg.display.set_mode((400, 400))
(x, y) = (200, 200)
(dx, dy) = (10, 10)
mvt = {pg.K_LEFT: (-dx, 0),
pg.K_RIGHT: (dx, 0),
pg.K_DOWN: (0, dy),
pg.K_UP: (0, -dy)}
dessin = True
fin = False
while not fin:
if dessin:
ecran.fill(pg.Color("black"))
pg.draw.circle(ecran,[255,255,255],[x,y],30,0)
pg.display.update()
dessin = False
ev = pg.event.wait()
if ev.type == pg.QUIT:
fin = True
if ev.type == pg.KEYDOWN:
if ev.key in mvt:
(DX, DY) = mvt[ev.key]
x += DX
y += DY
dessin = True
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 10
y = 100
dx = 0
dy = 0
mvt = {pg.K_LEFT: -5, pg.K_RIGHT: 5}
while True:
x += dx
y += dy
clock.tick(40)
ecran.fill([220,220,255])
pg.draw.rect(ecran,[0,200,50],[0,107,400,150])
pg.draw.circle(ecran,[100,110,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[x-8,110,18,5],0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
break
if e.type == pg.KEYDOWN:
if e.key in mvt:
dx = mvt[e.key]
if e.key == pg.K_UP:
dy = -10
else:
dx = 0
if dy < 0 and y < 50:
dy = 10
y = 50
if dy > 0 and y>95:
dy = 0
y = 100
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 10
y = 100
dx = 0
dy = 0
saut = False
while True:
x += dx
y += dy
clock.tick(40)
ecran.fill([220,220,255])
pg.draw.rect(ecran,[0,200,50],[0,107,400,150])
pg.draw.circle(ecran,[100,110,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[x-8,110,18,5],0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
break
if e.type == pg.KEYDOWN:
if e.key == pg.K_LEFT:
dx = -5
if e.key == pg.K_RIGHT:
dx = 5
if e.key == pg.K_UP and not saut:
dy = -10
saut = True
if e.type == pg.KEYUP:
if e.key == pg.K_LEFT or e.key == pg.K_RIGHT:
dx = 0
if saut:
if dy < 0 and y < 50:
dy = 10
y = 50
if dy > 0 and y>95:
dy = 0
y = 100
saut = False
pg.quit()
xxxxxxxxxx
import pygame as pg
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 10
y = 100
dx = 0
dy = 0
saut = False
gauche = False
droite = False
while True:
y += dy
if gauche and dx<0:
x += dx
if droite and dx>0:
x += dx
clock.tick(40)
ecran.fill([220,220,255])
pg.draw.rect(ecran,[0,200,50],[0,107,400,150])
pg.draw.circle(ecran,[100,110,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[x-8,110,18,5],0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
break
if e.type == pg.KEYDOWN:
if e.key == pg.K_LEFT:
dx = -5
if e.key == pg.K_RIGHT:
dx = 5
xxxxxxxxxx
import pygame as pg
from random import*
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 10
y = 100
dx = 0
dy = 0
saut = False
gauche = False
droite = False
mechant = False
xm = 500
ym = 100
dxm = 0
dym = 0
while True:
y += dy
if gauche and dx<0:
x += dx
if droite and dx>0:
x += dx
xm += dxm
ym += dym
clock.tick(40)
ecran.fill([220,220,255])
pg.draw.rect(ecran,[0,200,50],[0,107,400,150])
pg.draw.circle(ecran,[100,110,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[x-8,110,18,5],0)
pg.draw.circle(ecran,[255,0,0],[xm,ym],10,0)
pg.draw.circle(ecran,[255,255,255],[xm-4,ym-4],2,0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
break
if e.type == pg.KEYDOWN:
if e.key == pg.K_LEFT:
dx = -5
xxxxxxxxxx
import pygame as pg
from random import*
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 10
y = 100
dx = 0
dy = 0
saut = False
gauche = False
droite = False
mechant = False
xm = 500
ym = 100
dxm = 0
dym = 0
collision = False
while True:
if abs(x-xm)<20 and abs(y-ym)<20:
collision = True
y += dy
if gauche and dx<0:
x += dx
if droite and dx>0:
x += dx
xm += dxm
ym += dym
clock.tick(40)
ecran.fill([220,220,255])
pg.draw.rect(ecran,[0,200,50],[0,107,400,150])
pg.draw.circle(ecran,[100,110,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[x-8,110,18,5],0)
pg.draw.circle(ecran,[255,0,0],[xm,ym],10,0)
pg.draw.circle(ecran,[255,255,255],[xm-4,ym-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[xm-8,110,18,5],0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
break
if e.type == pg.KEYDOWN:
xxxxxxxxxx
import pygame as pg
from random import*
pg.init()
pg.font.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 10
y = 100
dx = 0
dy = 0
saut = False
gauche = False
droite = False
mechant = False
xm = 500
ym = 100
dxm = 0
dym = 0
vies = 5
collision = False
while True:
if vies == -1:
pg.quit()
if abs(x-xm)<20 and abs(y-ym)<20:
collision = True
y += dy
if gauche and dx<0:
x += dx
if droite and dx>0:
x += dx
xm += dxm
ym += dym
clock.tick(40)
ecran.fill([220,220,255])
pg.draw.rect(ecran,[200,100,100],[5,5,vies*10,10])
pg.draw.rect(ecran,[0,200,50],[0,107,400,150])
pg.draw.circle(ecran,[100,110,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[x-8,110,18,5],0)
pg.draw.circle(ecran,[255,0,0],[xm,ym],10,0)
pg.draw.circle(ecran,[255,255,255],[xm-4,ym-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[xm-8,110,18,5],0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
break
xxxxxxxxxx
import pygame as pg
import pygame.font
from random import*
pg.font.init()
myfont = pg.font.SysFont('Arial', 30)
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 10
y = 100
dx = 0
dy = 0
saut = False
gauche = False
droite = False
mechant = False
xm = 500
ym = 100
dxm = 0
dym = 0
vies = 5
collision = False
score = 0
jeu = True
while jeu:
score += 1
if vies == -1:
jeu = False
if abs(x-xm)<20 and abs(y-ym)<20:
collision = True
y += dy
if gauche and dx<0:
x += dx
if droite and dx>0:
x += dx
xm += dxm
ym += dym
clock.tick(40)
ecran.fill([220,220,255])
if jeu:
pg.draw.rect(ecran,[200,100,100],[5,5,vies*10,10])
else:
myfont1 = pg.font.SysFont('Arial', 30)
textsurface1 = myfont1.render('GAME OVER', False, (0, 0, 0))
ecran.blit(textsurface1,(100,20))
myfont2 = pg.font.SysFont('Arial', 20)
textsurface2 = myfont2.render('SCORE : '+str(score), False, (0, 0, 0))
ecran.blit(textsurface2,(135,70))
pg.draw.rect(ecran,[0,200,50],[0,107,400,150])
pg.draw.circle(ecran,[100,110,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[x-8,110,18,5],0)
pg.draw.circle(ecran,[255,0,0],[xm,ym],10,0)
pg.draw.circle(ecran,[255,255,255],[xm-4,ym-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[xm-8,110,18,5],0)
xxxxxxxxxx
import pygame as pg
import pygame.font
from random import*
pg.font.init()
myfont = pg.font.SysFont('Arial', 30)
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 200
y = 100
dx = 0
dy = 0
saut = False
gauche = False
droite = False
mechant = False
xm = 500
ym = 100
dxm = 0
dym = 0
vies = 5
collision = False
score = 0
jeu = True
while jeu:
score += 1
if vies == -1:
jeu = False
if abs(x-xm)<20 and abs(y-ym)<20:
collision = True
y += dy
if gauche and dx<0:
x += dx
if droite and dx>0:
x += dx
xm += dxm
ym += dym
clock.tick(40)
ecran.fill([220,220,255])
if jeu:
pg.draw.rect(ecran,[200,100,100],[5,5,vies*10,10])
else:
myfont1 = pg.font.SysFont('Arial', 30)
textsurface1 = myfont1.render('GAME OVER', False, (0, 0, 0))
ecran.blit(textsurface1,(100,20))
myfont2 = pg.font.SysFont('Arial', 20)
textsurface2 = myfont2.render('SCORE : '+str(score), False, (0, 0, 0))
ecran.blit(textsurface2,(135,70))
pg.draw.rect(ecran,[0,200,50],[0,107,400,150])
pg.draw.circle(ecran,[100,110,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[x-8,110,18,5],0)
pg.draw.circle(ecran,[255,0,0],[xm,ym],10,0)
pg.draw.circle(ecran,[255,255,255],[xm-4,ym-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[xm-8,110,18,5],0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
xxxxxxxxxx
import pygame as pg
import pygame.font
from random import*
pg.font.init()
myfont = pg.font.SysFont('Arial', 30)
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 200
y = 100
dx = 0
dy = 0
saut = False
gauche = False
droite = False
mechant = False
xm = 500
ym = 100
dxm = 0
dym = 0
vies = 5
collision = False
score = 0
jeu = True
while jeu:
score += 1
if vies == -1:
jeu = False
if abs(x-xm)<20 and abs(y-ym)<20:
collision = True
y += dy
if gauche and dx<0:
x += dx
if droite and dx>0:
x += dx
xm += dxm
ym += dym
clock.tick(40)
ecran.fill([220,220,255])
if jeu:
pg.draw.rect(ecran,[200,100,100],[5,5,vies*10,10])
else:
myfont1 = pg.font.SysFont('Arial', 30)
textsurface1 = myfont1.render('GAME OVER', False, (0, 0, 0))
ecran.blit(textsurface1,(100,20))
myfont2 = pg.font.SysFont('Arial', 20)
textsurface2 = myfont2.render('SCORE : '+str(score), False, (0, 0, 0))
ecran.blit(textsurface2,(135,70))
pg.draw.rect(ecran,[0,200,50],[0,107,400,150])
pg.draw.circle(ecran,[100,110,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[x-8,110,18,5],0)
pg.draw.circle(ecran,[255,0,0],[xm,ym],10,0)
pg.draw.circle(ecran,[255,255,255],[xm-4,ym-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[xm-8,110,18,5],0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
xxxxxxxxxx
import pygame as pg
import pygame.font
from random import*
pg.font.init()
myfont = pg.font.SysFont('Arial', 30)
pg.init()
pg.display.set_caption("Animation")
clock = pg.time.Clock()
ecran = pg.display.set_mode((400, 150))
x = 200
y = 100
dx = 0
dy = 0
saut = False
gauche = False
droite = False
mechant = False
xm = 500
ym = 100
dxm = 0
dym = 0
vies = 5
collision = False
score = 0
jeu = True
while jeu:
score += 1
if vies == -1:
jeu = False
if abs(x-xm)<20 and abs(y-ym)<20:
collision = True
y += dy
if gauche and dx<0:
x += dx
if droite and dx>0:
x += dx
xm += dxm
ym += dym
clock.tick(40)
ecran.fill([220,220,255])
if jeu:
pg.draw.rect(ecran,[200,100,100],[5,5,vies*10,10])
else:
myfont1 = pg.font.SysFont('Arial', 30)
textsurface1 = myfont1.render('GAME OVER', False, (0, 0, 0))
ecran.blit(textsurface1,(100,20))
myfont2 = pg.font.SysFont('Arial', 20)
textsurface2 = myfont2.render('SCORE : '+str(score), False, (0, 0, 0))
ecran.blit(textsurface2,(135,70))
pg.draw.rect(ecran,[0,200,50],[0,107,400,150])
pg.draw.circle(ecran,[100,110,255],[x,y],10,0)
pg.draw.circle(ecran,[255,255,255],[x-4,y-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[x-8,110,18,5],0)
pg.draw.circle(ecran,[255,0,0],[xm,ym],10,0)
pg.draw.circle(ecran,[255,255,255],[xm-4,ym-4],2,0)
pg.draw.ellipse(ecran,[20,150,20],[xm-8,110,18,5],0)
pg.display.update()
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
break
if e.type == pg.KEYDOWN:
xxxxxxxxxx
from random import*
import pygame as pg
import pygame.font
pg.font.init()
myfont = pg.font.SysFont('Arial', 30)
pg.init()
clock = pg.time.Clock()
pg.key.set_repeat(10, 5)
pg.display.set_caption("Labyrinthe")
ecran = pg.display.set_mode((640, 360))
global niveau, xp1, yp1, mvtp1, objp1, perso, jeu, finjeu
bg = pg.image.load("https://www.sarmate.xyz//Cours/Informatique/pygame/exemples/labyrinthe/lave.png").convert_alpha()
bg = pg.transform.scale(bg , (640,360) )
perso1 = pg.image.load("https://www.sarmate.xyz//Cours/Informatique/pygame/exemples/labyrinthe/e1.png").convert_alpha()
perso1 = pg.transform.scale(perso1 , (20,20) )
perso2 = pg.image.load("https://www.sarmate.xyz//Cours/Informatique/pygame/exemples/labyrinthe/e2.png").convert_alpha()
perso2 = pg.transform.scale(perso2 , (20,20) )
perso3 = pg.image.load("https://www.sarmate.xyz//Cours/Informatique/pygame/exemples/labyrinthe/e3.png").convert_alpha()
perso3 = pg.transform.scale(perso3 , (20,20) )
perso4 = pg.image.load("https://www.sarmate.xyz//Cours/Informatique/pygame/exemples/labyrinthe/e4.png").convert_alpha()
perso4 = pg.transform.scale(perso4 , (20,20) )
path = pg.image.load("https://www.sarmate.xyz//Cours/Informatique/pygame/exemples/labyrinthe/path.png").convert_alpha()
path = pg.transform.scale(path , (20,20) )
fin = pg.image.load("https://www.sarmate.xyz//Cours/Informatique/pygame/exemples/labyrinthe/fin.png").convert_alpha()
fin = pg.transform.scale(fin , (20,20) )
niveaux =[
[
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0],
[0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,1,1,0,1,0,1,0],
[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,0,1,0,1,0,1,0],
[0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,1,1,1,0,0,1,0,1,0,1,0],
[0,0,1,0,0,1,0,0,0,0,0,0,1,1,1,1,0,1,0,1,1,0,0,0,0,0,1,0,1,0,1,0],
[0,0,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,1,0,1,0,1,0],
[0,0,1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,0,1,0,1,0],
[0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,2,1,1,0,1,0],
[0,0,0,0,1,0,0,1,0,1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,0,0,0,0,0,1,0],
[0,0,0,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,0,1,1,1,0,1,0],
[0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,0,1,0,1,1,1,0,0,1,0,1,0,1,1,1,0],
[0,0,1,1,1,1,0,1,1,1,1,1,1,0,0,0,0,1,0,1,0,1,0,0,1,0,1,0,0,1,0,0],
[0,0,1,0,1,0,1,0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