Esempio n. 1
0
/*
 * main
 */
int main(int argc, char** argv) {


    espace=init();
    SDL_Event event;
    int continuer=1;
    SDL_Init(SDL_INIT_VIDEO);
    ecran=SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);


    
    //char* fichier_dico = "dico.txt";
    //algo_1(fichier_dico, "asdfarbre");
    if (ecran == NULL)
    {
        fprintf(stderr, "Erreur d'initialisation de la SDL");
        exit(EXIT_FAILURE);
    }
     
    SDL_WM_SetCaption("Letter Boule Game !", NULL);
    SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format,0,0,0));
    initPolice();
    initLesBoules(espace);
    boolean refresh=TRUE;
    while (continuer) {
        SDL_WaitEvent(&event);
        switch(event.type) {
            case SDL_QUIT: continuer = 0;
        }
        
        if(refresh)
        {
            affichage();
            refresh=FALSE;
        }    
        if(nbBoules==0)
    {
        SDL_Color white={255,255,255};
        SDL_Surface *game=TTF_RenderText_Solid(police,"GAME OVER" , white);
        SDL_Rect position_game;
        position_game.y=320;
        position_game.x=240;
        SDL_BlitSurface(game, NULL, ecran, &position_game);  
    }
        SDL_Flip(ecran);
        refresh=tracerLigne();
        
        SDL_Flip(ecran);
    }   
    
    cpSpaceFree(espace);
    TTF_CloseFont(police);
    TTF_Quit();
    SDL_Quit();
  
    return (EXIT_SUCCESS);
}
Esempio n. 2
0
void refresh_fenetreRegles(SDL_Window* fenetre,SDL_Surface* ecran,int indicePageRegles,int indiceAnimation,SDL_Surface* boutonRetour,
                            SDL_Surface** regles,SDL_Surface** chiffres,SDL_Surface* pixel,SDL_Surface* flecheDroite,SDL_Surface* flecheGauche,
                            SDL_Surface** traitre,SDL_Surface** explosif,SDL_Surface** splash ,SDL_Surface* fondRegles,SDL_Surface* caseBloque,
                            SDL_Surface* flecheBombe,SDL_Surface* minerai,SDL_Surface** carteEvent,SDL_Surface* fondFenetre)
{

    SDL_Rect position,finDroite;
    int i,j;
    int rouge = rand()%2;
    int vert = rand()%2;

    SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,255,255,255));         //on efface l'ecran


//---------------------------------------------------------------------------------
//---------------------------- POSITIONNEMENT IMAGE -------------------------------
//---------------------------------------------------------------------------------

    position.x = 0;
    position.y = 0;
    SDL_BlitSurface(fondFenetre,NULL,ecran,&position);

 //Bouton Retour
    position.x = 380;
    position.y = 500;
    SDL_BlitSurface(boutonRetour,NULL,ecran,&position);

//Page de la regles
    position.x = 95;
    position.y = 50;
    SDL_BlitSurface(fondRegles,NULL,ecran,&position);
    position.x = 100;
    SDL_BlitSurface(regles[indicePageRegles],NULL,ecran,&position);

//compteur de page
    position.x = 955;
    position.y = 580;
    ecritureNombre(chiffres,&position,indicePageRegles+1,ecran);

    position.x = 965;
    position.y = 590;
    finDroite.x = 970;
    finDroite.y = 580;
    tracerLigne(position,finDroite,ecran,pixel);

    position.x = 972;
    position.y = 580;
    ecritureNombre(chiffres,&position,nbPage,ecran);

//fleche droite
    if(indicePageRegles!=nbPage-1){                         //si on est pas a la derniere page
        position.x = 920;
        position.y = 225;
        SDL_BlitSurface(flecheDroite,NULL,ecran,&position);
    }
//fleche gauche
    if(indicePageRegles!=0){                                //si on n'est pas a la premiere
        position.x = 20;
        position.y = 225;
        SDL_BlitSurface(flecheGauche,NULL,ecran,&position);
    }
//animation
    switch(indicePageRegles){
        case 0:
                for(i=380 ; i<=510 ; i+=30){
                    position.x = i;
                    for(j=280 ; j <=400; j+=60){                                        //pion qui prend
                        position.y = j;
                        if(i==440 && j==340){                                           //on enleve le pion du milieu 2 image sur 3
                            if(indiceAnimation==2){
                            SDL_BlitSurface(traitre[1],NULL,ecran,&position);
                            }
                        }
                        else{
                            SDL_BlitSurface(traitre[1],NULL,ecran,&position);
                        }
                    }
                    for(j=310 ; j <=370 ; j+=30){                                               //pion qui sont pris
                        position.y = j;
                        if((i==410 || i==440 || i==470) && (!(i==440 && j==340)) ){             //sur les 3 lignes internes mais pas le centre
                            SDL_BlitSurface(traitre[indiceAnimation/2],NULL,ecran,&position);
                        }
                    }
                }

            break;
        case 1://animation bombes explosif
                position.x = 820-(explosif[indiceAnimation]->w/2);
                position.y = 200-(explosif[indiceAnimation]->h/2);
                SDL_BlitSurface(explosif[indiceAnimation],NULL,ecran,&position); //indice animation vaut 0,1 ou 2

                //case bloque
                position.x = 820;
                position.y = 300;
                SDL_BlitSurface(caseBloque,NULL,ecran,&position);

                //laser
                position.x = 750;
                position.y = 400;
                finDroite.x = position.x+100;
                finDroite.y = position.y;
                SDL_FillRect(pixel,NULL,SDL_MapRGB(pixel->format,rouge*255,vert*255,((vert+2*rouge+1)%2)*255));         //color la surface

                for(i=0 ; i<10 ; i++){
                   tracerLigne(position,finDroite,ecran,pixel);
                   position.y += pixel->h;
                    finDroite.y = position.y;
                }
                SDL_FillRect(pixel,NULL,SDL_MapRGB(pixel->format,0,0,0));
            break;
        case 2://animation bombes splash
                position.x = 780-(splash[indiceAnimation]->w/2);
                position.y = 350-(splash[indiceAnimation]->h/2);
                SDL_BlitSurface(splash[indiceAnimation],NULL,ecran,&position); //indice animation vaut 0,1 ou 2

                //bombe fleche
                position.x = 780;
                position.y = 150;
                SDL_BlitSurface(flecheBombe,NULL,ecran,&position);
            break;
        case 3: position.x = 470;//animation traitre
                position.y = 350;
                SDL_BlitSurface(traitre[indiceAnimation],NULL,ecran,&position); //indice animation vaut 0,1 ou 2
            break;
        case 4:  //minerai
                position.x = 800;
                position.y = 110;
                SDL_BlitSurface(minerai,NULL,ecran,&position);

                //carte bloc
                position.y = 210;
                SDL_BlitSurface(carteEvent[0],NULL,ecran,&position);

                //carte Swap
                position.y = 280;
                SDL_BlitSurface(carteEvent[1],NULL,ecran,&position);

                //carte 2x
                position.y = 380;
                SDL_BlitSurface(carteEvent[2],NULL,ecran,&position);
            break;
        case 5:position.x = 800;

                //carte peinture
                position.y = 60;
                SDL_BlitSurface(carteEvent[5],NULL,ecran,&position);

                //carte anti traitre
                position.y = 130;
                SDL_BlitSurface(carteEvent[4],NULL,ecran,&position);

                //carte anti pion
                position.y = 220;
                SDL_BlitSurface(carteEvent[3],NULL,ecran,&position);

                //carte aide moi
                position.y = 280;
                SDL_BlitSurface(carteEvent[6],NULL,ecran,&position);

                //carte ouups
                position.y = 380;
                SDL_BlitSurface(carteEvent[7],NULL,ecran,&position);
            break;
        default:
            break;
    }



}