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
|
def avance(): # ma fonction avance est pas très claire, elle l'est pour moi au moins, je cherche tout les objets qui sont en mouvement, je les met dans un buffer, et ensuite dans ma matrice je les change en "rien"
global M, H, L # ensuite je les descend tous d'un indice. ( entre temps je regarde si je peux avancer, en effet si en dessous de ma pièce il y a une autre pièce je ne peux pas avancer)
buffer=[]
bloque=False
for i in range(H):
for j in range(L):
if M[i][j][2]==1:
buffer.append([i,j])
for couple in buffer:
i,j=couple
if M[i-1][j][2]==0 and (M[i-1][j][0]==1 or M[i-1][j][0]==-1):
bloque=True
if bloque:
for couple in buffer:
i,j=couple
M[i][j]=[1,M[i][j][1],0,0,0]
else:
buffer=[]
for i in range(H):
for j in range(L):
if M[i][j][2]==1:
buffer.append([i-1,j,M[i][j][1],M[i][j][3],M[i][j][4]])
M[i][j]=[0,0,0,0,0]
for quintuplet in buffer:
i,j,couleur,fig,position=quintuplet
M[i][j]=[1,couleur,1,fig,position]
time.sleep(0.7) ####### mon time.sleep() est ici !
glutPostRedisplay()
def init():
global H, L
glClearColor(1, 1, 1, 1.0)
gluOrtho2D(0,L,0,H-3)
def specialkeys( key, x, y):
if key == GLUT_KEY_LEFT:
translation(0) # translate la pièce vers la gauche
if key == GLUT_KEY_RIGHT:
translation(1)
glutPostRedisplay()
def display_plateau():
global M, touche
glClear(GL_COLOR_BUFFER_BIT)
spawn_figure()
avance()
colorie_matrice()
glutSwapBuffers()
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE)
glutInitWindowPosition(0,0)
glutInitWindowSize(480,720)
glutCreateWindow(b"TETRIS")
init()
glutDisplayFunc(display_plateau)
glutSpecialFunc(specialkeys)
glutMainLoop()
main() |
Partager