Ejemplo n.º 1
0
void GestionTouche(int snake[TAILLE_SNAKE][2],int direction[2], int* done){
  unsigned int touchePress;
  /*Deplacement à droite*/
  if (ToucheEnAttente()==1){
    touchePress=Touche();
    if(touchePress==XK_Escape){
      FermerGraphique();
      *done=1;
    }else
    if(touchePress==XK_space){
      while(Touche()!=XK_space);
    }
    /******UPDATE DIRECTION********/
    if(touchePress==XK_Right && direction[0]==0){
      direction[0]=1;
      direction[1]=0;
    }else
    /*Deplacement à gauche*/
    if (touchePress==XK_Left && direction[0]==0){
      direction[0]=-1;
      direction[1]=0;
    }else
    /*Deplacement en haut*/
    if(touchePress==XK_Up && direction[1]==0){
      direction[0]=0;
      direction[1]=-1;
    }else
    /*Deplacement en bas*/
    if(touchePress==XK_Down && direction[1]==0){
      direction[0]=0;
      direction[1]=1;
    }
  }
}
Ejemplo n.º 2
0
void GestionTouche(int snake[TAILLE_SNAKE][2],int direction[2]){
  unsigned int touchePress;
  /*Deplacement à droite*/
  if (ToucheEnAttente()==1){
    touchePress=Touche();
    if(touchePress==XK_Right){
      direction[0]=1;
      direction[1]=0;
    }
    /*Deplacement à gauche*/
    if (touchePress==XK_Left){
      direction[0]=-1;
      direction[1]=0;
    }
    /*Deplacement en haut*/
    if(touchePress==XK_Up){
      direction[0]=0;
      direction[1]=-1;
    }
    /*Deplacement en bas*/
    if(touchePress==XK_Down){
      direction[0]=0;
      direction[1]=1;
    }
  }
}
Ejemplo n.º 3
0
int DirectionSerpent(int direction,int* etatJeu, int* etatPartie) // Permet de determiner dans quelle direction l'utilisateur veut faire diriger le serpent
{
  int touche = 0;
  if(ToucheEnAttente()) // Si le joueur a presser une touche 
    {
      touche = Touche();
      if(touche== XK_Up && direction != DOWN)
	{
	  direction = UP;
	}
      if(touche == XK_Down && direction != UP)
	{
	  direction = DOWN;
	}
      if(touche == XK_Left && direction != RIGHT)
	{
	  direction = LEFT;
	}
      if(touche == XK_Right && direction != LEFT)
	{
	  direction = RIGHT;
	}
      if(touche == XK_space)
	{
	  MettrePause(etatJeu,etatPartie);
	}
      if(touche == XK_Escape) // Pour quitter le jeu
	{
	  QuitterPartie(etatJeu,etatPartie);
	}
    } // Dans le cas où le joueur n'a rien pressé, on renvoit la même valeur que celle donnée en argument
  return direction;
}
Ejemplo n.º 4
0
int MettrePause(){
  int touche = 0;
  while(ToucheEnAttente() != 1 && touche != XK_space)
    {
      touche = Touche();
    }
}
Ejemplo n.º 5
0
int MettrePause(int* etatJeu, int* etatPartie){
  int touche = 0;
  while(ToucheEnAttente() != 1 && touche != XK_space)
    {
      touche = Touche();
      if(touche == XK_Escape) // Pour quitter le jeu
	{
	  QuitterPartie(etatJeu,etatPartie);
	  break;
	}
    }
}
Ejemplo n.º 6
0
int pressanykey (void)
{
	KeySym k;
	int nb=0;
	while(ToucheEnAttente())
	{
		nb++;
		k=Touche();
		if(k==XK_Escape)
			return QUITTER_AFFICHAGE;
	}
	return nb;
}
Ejemplo n.º 7
0
int actions_sur_pression_touche_combat (void)
{
	KeySym k;
	int actions_realisees=0;
	while(ToucheEnAttente())
	{
		actions_realisees++;
		k=Touche();
		switch (k)
		{
			case XK_Left:
				action (BTN_G);
				buff_changemode(); 
				buff_waitingtime(); // Changement de mode peux impliquer un changement d'affichage du temps de pause
				flip();
				break;
			
			case XK_Right:
				action (BTN_D);
				buff_changemode(); 
				buff_waitingtime(); // Changement de mode peux impliquer un changement d'affichage du temps de pause
				flip();
				break;
			
			case XK_Up:
				action (BTN_H);
				buff_waitingtime();
				break;
			
			case XK_Down:
				action (BTN_B);
				buff_waitingtime();
				break;
			
			case XK_Escape:
				return QUITTER_AFFICHAGE;
		}
		
		// printf("touche %d\n",k);
		
	}
	return actions_realisees;
}
Ejemplo n.º 8
0
int main(void) {
  int snake[300][2],
      len_snake=10,
      pommes[20][2],
      len_pommes=5,
      i;
  unsigned long int temps = Microsecondes();
  initSnake(snake);
  initPommes(pommes);
  
  srand(time(NULL));
  InitialiserGraphique();
  CreerFenetre(BORD,BORD,600+2*BORD,400+BORD+40);

  printTerrain(snake, len_snake, pommes, len_pommes);
  printTime(temps);
    
  Touche();
  FermerGraphique();
  return EXIT_SUCCESS;
}
Ejemplo n.º 9
0
  int main(void) {

    srand((unsigned int)time(NULL));
    int snake[TAILLE_SNAKE][2],
        len_snake=10,
        pommes[TAILLE_POMME][2],
        len_pommes=5,
        direction[2]={0,-1};
    int* score;
    *score=0;
    const unsigned long int tempsDepart=Microsecondes();
    unsigned long int prochainAffichage=0,prochainDeplacement=0;
    initSnake(snake,len_snake);
    initPommes(pommes,len_pommes);
    InitialiserGraphique();
    CreerFenetre(BORD,BORD,60*TAILLE_CASE+2*BORD,40*TAILLE_CASE+BORD+40);
    ChoisirEcran(1);


    /*EffacerEcran(CouleurParNom("black"));
    */
    while(1){
      if(Microsecondes()>prochainAffichage){
        printScreen(snake, len_snake,  pommes, len_pommes, tempsDepart, &score);
        prochainAffichage=Microsecondes()+CYCLE;
      }
      GestionTouche(snake,direction);
      if(Microsecondes()>prochainDeplacement){
        DeplacementSnake(snake,len_snake,direction);
        CheckCollisionBord(snake);
        CheckCollisionPomme(len_pommes,pommes,snake,score);
        prochainDeplacement=Microsecondes()+100000;
      }
      if(ToucheEnAttente()==1 && Touche()==XK_Escape){
        FermerGraphique();
        return EXIT_SUCCESS;
      }
    }
  }
Ejemplo n.º 10
0
int QuitterSnake(){
  if(ToucheEnAttente()==1 && Touche()==XK_Escape){
    FermerGraphique();
    return EXIT_SUCCESS;
  }
}
Ejemplo n.º 11
0
int main() // Fonction principale
{
  int carre = NB_PIXEL_X_JEU/60;
  unsigned long suivant;
  suivant= Microsecondes()+delta;
  int i = 0;
  int etatJeu = 1;
  int score = 0;
  int direction = 0;
  int seconde = 0;
  int minute = 0;
  int tailleSerpent = 10;
  Coordonnees serpent[20];
  serpent[0].x = CENTRE_X_GRILLE;
  serpent[0].y = CENTRE_Y_GRILLE;
  Coordonnees queue;
  Pomme tabPomme[NB_POMME] = {};
  Obstacles tabObstacle[NB_OBSTACLE] = {};
  Coordonnees tete;
  InitialiserGraphique();
  CreerFenetre(10,10,NB_PIXEL_X_FENETRE,NB_PIXEL_Y_FENETRE);
  while(etatJeu){
    InitialiserVariable(&score,&direction,&tailleSerpent,&seconde,&minute,serpent);
    for (i = 0 ; i < NB_POMME; i++) // Initialisation du serpent
      {
	tabPomme[i].x = -1;
	tabPomme[i].y = -1;
	tabPomme[i].flagP = 0;
      }
    for (i = 1 ; i < TAILLE_MAX_SNAKE; i++) // Initialisation du serpent
      {
	serpent[i].x = -1;
	serpent[i].y = -1;
      }
    NettoyerEcran();
    RemplirRectangle(0,NB_PIXEL_Y_JEU,1080,carre*3); // Bande noir en bas
    for(i = 0; i < tailleSerpent; i++)
      {
	ChoisirCouleurDessin(CouleurParComposante(27,94,32));
	RemplirRectangle(serpent[i].x*carre,serpent[i].y*carre,carre,carre);
      }
    AfficherScore(score);
    AfficherTemps(seconde,minute,carre,&score);
    CreerObstacles(carre,tabObstacle);
    while(ToucheEnAttente() != 1)
      {
      }
    while(1)//Boucle principale
      {
	// DessinerGrille(carre);
	direction = DirectionSerpent(direction);
	if (Microsecondes()>suivant) // Si une seconde est passé
	  {
	    suivant=Microsecondes()+delta;
	    seconde++;
	    if(seconde == 60){
	      seconde = 0;
	      minute++;
	    }
	    AfficherTemps(seconde,minute,carre,&score);
	  }
	queue = DeplacerSerpent(carre,direction,serpent,tailleSerpent);
	tete = serpent[0];
	tailleSerpent = VerifieManger(&score,tete,tabPomme,tailleSerpent);
	CreerPomme(carre,tabPomme,tabObstacle,tailleSerpent,serpent);
	if(VerifieCollisionSerpent(tete,serpent,tailleSerpent,tabObstacle)){// Touche un mur => GAME OVER
	  break;
	}
	AfficherSerpent(serpent,tailleSerpent,carre,queue);
      }
    while(ToucheEnAttente() != 1)
      { 
	ChoisirCouleurDessin(CouleurParNom("red"));
	EcrireTexte(340,260,"Vous avez perdu !",2);	
	EcrireTexte(120,290,"Appuyez sur n'importe quelle touche pour recommencer",2);
	EcrireTexte(260,320,"Appuyez sur Echap pour quitter",2);	
      }
    if(Touche() == XK_Escape)
      {
	break;
      }
  }
  FermerGraphique();
  return EXIT_SUCCESS;
}