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
| while(continuDescente) {
while(SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT :
exit(0);
break;
case SDL_KEYDOWN :
switch (event.key.keysym.sym) {
case SDLK_RIGHT :
// On incremente x et on vérifie qu'il est dans les limites+
// qu'il ne chevauche aucun bloc.
positionSuivante.x=positionCentre.x+1;
positionSuivante.y=positionCentre.y;
positionDessous.x=positionCentre.x+1;
positionDessous.y=positionSuivante.y+19;
if ((!toucheDroite(piece,terrain,positionSuivante))&&
(!toucheDroite(piece,terrain,positionDessous))){
afficherPiece(piece,ecran,fenetreJeu,bloc_effacement,positionCentre);
positionCentre.x++;
}
break;
case SDLK_LEFT :
// Le pb est le mm que pour la droite!
break;
case SDLK_UP :
//Dans la fonction rotation on bouge le bloc et on vérifie qu'il est dans
//les limites et qu'il ne chevauche aucun bloc. Si ce n'est pas le cas on renvoie
//le bloc qui n'a pas tourné.
rotationDroite(piece,terrain,positionCentre);
afficherPiece(piece,ecran, fenetreJeu,imageBloc, positionCentre);
break;
case SDLK_DOWN :
SDL_WaitEvent(&event);
SDL_WaitEvent(&event);
break;
}
}
}
}
/* temporisation */
tempsActuel = SDL_GetTicks();
if (tempsActuel - tempsPrecedent > 10) {
tempsPrecedent=tempsActuel;
positionSuivante.x=positionCentre.x;
positionSuivante.y=positionCentre.y+1;
if (!toucheBas(piece,terrain,positionSuivante)){
/* effacement de la piece */
afficherPiece(piece,ecran, fenetreJeu,bloc_effacement, positionCentre);
positionCentre.y++;
afficherPiece(piece,ecran, fenetreJeu,imageBloc, positionCentre);
}
else{
continuDescente=0;
afficherPiece(piece,ecran, fenetreJeu,imageBloc, positionCentre);
miseJourTerrain(piece,terrain,positionCentre,couleur);
}
}
else
SDL_Delay(10 - (tempsActuel - tempsPrecedent));
SDL_Flip(ecran);
} |
Partager