当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_Flip函数代码示例

本文整理汇总了C++中SDL_Flip函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_Flip函数的具体用法?C++ SDL_Flip怎么用?C++ SDL_Flip使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_Flip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........

  if (load_files() == false) return 1;

  // Spawn Tadpole
  //  Tadpole myTad;
  std::vector<Tadpole> myTad(MAX_PLAYERS);


  // Spawn fly
  xfly = 10+drand48()*(SCREEN_WIDTH-LEADER_WIDTH-HISCORE_WIDTH-20)+LEADER_WIDTH;
  yfly = 10+drand48()*(SCREEN_HEIGHT-BANNER_HEIGHT-20) + BANNER_HEIGHT;
  Fly myfly( xfly, yfly );

  // Spawn Frogs
  std::vector<Frog> myfrogs(nfrogs);


  for(i = 0; i < nfrogs; i++ ) {
    xfrog = drand48()*(SCREEN_WIDTH-LEADER_WIDTH-HISCORE_WIDTH-20)+LEADER_WIDTH;
    yfrog = drand48()*(SCREEN_HEIGHT-BANNER_HEIGHT-20) + BANNER_HEIGHT;
    if(distance(xfrog, yfrog, mmtadx, mmtady) < (SCREEN_HEIGHT-BANNER_HEIGHT)/4) {
      i--;
    }
    myfrogs[i].Frog_set(xfrog, yfrog, sp, a_i);
  }


  for(i=0; i<nfrogs; i++)
    myfrogs[i].show(sp);

  myfly.show();


  if(SDL_Flip(screen) == -1) return 1;

  SDL_Delay(500);

  gameclock.start();
  
#ifdef PRINT_MESSAGES  
  printf("Tadpole server is up!\n");
#endif
  

#ifdef WITH_SOUND
//    if(Mix_PlayMusic(ambience, -1) == -1)
    if(Mix_FadeInMusic(ambience, -1, 2000) == -1)
	return 1;
#endif
  

  // Game Server loop
  while (running) {

    fps.start();

    // Listen for connections, argument 0 means no wait-time
    int numActiveSockets = SDLNet_CheckSockets(socketSet, 0);

    if(numActiveSockets > 0) {

      // Check help socket. If activity detected, then open temporary socket and dump help text. Then close socket.
      int helpSocketActivity = SDLNet_SocketReady(helpSocket);
      if(helpSocketActivity != 0) {
	TCPsocket tempSock = SDLNet_TCP_Accept(helpSocket);
	SDLNet_TCP_Send(tempSock,(void*)reply,strlen(reply)+1);
开发者ID:dileepvr,项目名称:Tadpole_SDL,代码行数:67,代码来源:main.cpp

示例2: main

int
main(int argc, char *argv[])
{
	putenv("SDL_VIDEODRIVER=dga");

	if (SDL_Init(SDL_INIT_VIDEO) == -1) {
		fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}
	SDL_ClearError();
	printf("SDL initialized\n");

	atexit(end_SDL);


	/* Creat a SDL window, and get the window's surface. */
	/* PS: use hardware--> SDL_HWSURFACE */
	SDL_Surface *screen = NULL;
	screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
	if (screen == NULL) {
		fprintf(stderr, "SDL_SetVideoMode() failed: %\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}

	/* Show the SDL window's surface */
	if (SDL_Flip(screen) == -1) {
		fprintf(stderr, "SDL_Flip() failed: %\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}


	char name[30];
	if (SDL_VideoDriverName(name, 30) == NULL) {
		fprintf(stderr, "SDL_VideoDriverName() failed: %s", SDL_GetError());
		exit(EXIT_FAILURE);
	}
	printf("name = %s\n", name);


	const SDL_VideoInfo *info = SDL_GetVideoInfo();
	printf("Is it possible to create hardware surfaces: %d\n",
		info->hw_available);
	printf("Is there a window manager available: %d\n",
		info->wm_available);
	printf("Are hardware to hardware blits accelerated: %d\n",
		info->blit_hw);
	printf("Are hardware to hardware colorkey blits accelerated: %d\n",
		info->blit_hw_CC);
	printf("Are hardware to hardware alpha blits accelerated: %d\n",
		info->blit_hw_A);
	printf("Are software to hardware blits accelerated: %d\n",
		info->blit_sw);
	printf("Are software to hardware colorkey blits accelerated: %d\n",
		info->blit_sw_CC);
	printf("Are software to hardware alpha blits accelerated: %d\n",
		info->blit_sw_A);
	printf("Are color fills accelerated: %d\n", info->blit_fill);
	printf("Total amount of video memory in Kilobytes: %d\n",
		info->video_mem);
	printf("Width of the current video mode: %d\n",
		info->current_w);
	printf("Height of the current video mode: %d\n",
		info->current_h);


	press_ESC_to_quit();

	return 0;
}
开发者ID:LXiong,项目名称:blog_tmp,代码行数:69,代码来源:ex4.c

示例3: main


//.........这里部分代码省略.........
					button_quitter_2(&menu,clicX,clicY,i);
			else if (menu == 7 && !retour_bouton)
					button_quitter(&menu,&continuer,clicX,clicY,i);
			else if (menu == 8)
				button_winner(&menu, clicX,clicY,i);
				    
                    }
                    break;
                case SDL_KEYDOWN:
                    key_pressed = event.key.keysym.sym; // on récupère la touche
                    switch (key_pressed)
                    {
                    	case SDLK_ESCAPE: /* Esc keypress quits the app... */
                     		if (menu == 4)
					menu = 7;
				else
					continuer=0;
                        break;
                    }
                    break;
                case SDL_QUIT:
                    	if (menu == 4)
				menu = 7;
			else
				continuer=0;
                    break;
                default:
			if(menu==1)
				default_menu1(ecran);
			else if(menu==2)
				default_choix_adversaire(ecran);
			else if(menu==3)
				default_choix_difficulte(ecran);
			else if(menu==4)
			{
				if(!afficher_rolldice)
					default_roll_dice(ecran);
				if((!afficher_resultat)&&(afficher_rolldice))
				{
					default_roll_resultat(ecran,de1,de2);
					afficher_resultat++;
				}
				if((afficher_resultat)&&(afficher_rolldice)&&(!afficher_valider))
					default_valider(ecran,de1,de2);
				if((afficher_resultat)&&(afficher_rolldice)&&(afficher_valider))
					default_jouer(ecran,i, qui_commence, &menu);
			}
			else if(menu == 5)
			{
				default_historique(ecran,i);
			}
			else if (menu == 6)
				default_charger(ecran);
			else if (menu == 7)
				default_quitter(ecran);
			else if (menu == 8)
				default_winner(ecran,qui_commence,i);
                    break;
            }
        }
        if (now-before<interval)
		SDL_Delay(interval-(now-before));
        // refresh screen
        // mettre ici tous les blit utiles s'il y a des changements dans les surfaces, board, nouveaux pions
        SDL_Flip(ecran); //maj des surfaces pour affichage
	before=now;
    }
    
    /* Clean up the SDL library */
    SDL_FreeSurface(pionBleu);
    SDL_FreeSurface(pionRouge);
    SDL_FreeSurface(ecran);
    SDL_FreeSurface(board);
    SDL_FreeSurface(background);
    SDL_FreeSurface(bienvenue);
    SDL_FreeSurface(texte_Charger);
    SDL_FreeSurface(texte_Jouer);
    SDL_FreeSurface(texte_Quitter);
    SDL_FreeSurface(ia);
    SDL_FreeSurface(ia1);
    SDL_FreeSurface(retour);
    SDL_FreeSurface(ia2);
    SDL_FreeSurface(human);
    SDL_FreeSurface(difficulte);
    SDL_FreeSurface(adversaire);
    SDL_FreeSurface(background2);
    SDL_FreeSurface(historique);
    SDL_FreeSurface(sauvegarder);
    SDL_FreeSurface(undo);
    SDL_FreeSurface(valider);
    SDL_FreeSurface(stringHist);
    SDL_FreeSurface(names);
    TTF_CloseFont(fontMenu);
    TTF_CloseFont(fontSousMenu);
    TTF_CloseFont(fontSousMenu2);
    TTF_Quit();
    SDL_Quit();
    fclose(f_in);
    return(0);
}
开发者ID:suchiz,项目名称:SDL_Project,代码行数:101,代码来源:main.c

示例4: switch

void
GlobalEvent::on_button_press(const SDL_KeyboardEvent& event)
{
  switch (event.keysym.sym)
  {
    case SDLK_F10:
      config_manager.set_print_fps(!config_manager.get_print_fps());
      break;

    case SDLK_RETURN:
      if (event.keysym.mod & KMOD_ALT)
      {
        config_manager.set_fullscreen(!config_manager.get_fullscreen());
      }
      break;

    case SDLK_TAB: // unlock mouse grab if Alt-Tab is pressed to allow the user to change windows
      if (config_manager.get_mouse_grab())
      {
        if (event.keysym.mod & KMOD_ALT)
        {
          // FIXME: should suspend the grab till the user clicks the
          // window again, not completely disable it
          config_manager.set_mouse_grab(false);
        }
      }
      break;

    case SDLK_F11:
      config_manager.set_fullscreen(!config_manager.get_fullscreen());
      break;

    case SDLK_F5:
      if (!dynamic_cast<OptionMenu*>(ScreenManager::instance()->get_current_screen().get()))
        ScreenManager::instance()->push_screen(std::make_shared<OptionMenu>());
      break;

    case SDLK_o:
      if (event.keysym.mod & KMOD_CTRL)
      {
        if (!dynamic_cast<OptionMenu*>(ScreenManager::instance()->get_current_screen().get()))
          ScreenManager::instance()->push_screen(std::make_shared<OptionMenu>());
      }
      break;

    case SDLK_F6:
      if (globals::developer_mode)
      {
        if (!dynamic_cast<AddOnMenu*>(ScreenManager::instance()->get_current_screen().get()))
          ScreenManager::instance()->push_screen(std::make_shared<AddOnMenu>());
      }
      break;

    case SDLK_F12:
      {
        Screenshot::make_screenshot();
      }
      break;

    case SDLK_c:
      if (globals::developer_mode)
        globals::draw_collision_map = !globals::draw_collision_map;
      break;

    case SDLK_k:
      if (globals::developer_mode)
      {
#ifdef OLD_SDL1
        log_info("Low level screen clear triggered");
        SDL_Surface* screen = SDL_GetVideoSurface();
        SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 0));
        SDL_Flip(screen);
#endif
      }
      break;

    case SDLK_m:
      if (event.keysym.mod & KMOD_CTRL)
      {
        log_info("Developer Mode: %1%", globals::developer_mode);
        globals::developer_mode = !globals::developer_mode;
      }
      break;

    case SDLK_g:
      if (event.keysym.mod & KMOD_CTRL)
      {
        config_manager.set_mouse_grab(!config_manager.get_mouse_grab());
      }
      break;

    case SDLK_KP_PLUS:
      globals::game_speed -= 5;
      if (globals::game_speed < 5)
        globals::game_speed = 5;
      break;

    case SDLK_KP_MINUS:
      globals::game_speed += 5;
      break;
//.........这里部分代码省略.........
开发者ID:drewbug,项目名称:pingus,代码行数:101,代码来源:global_event.cpp

示例5: main

int main( int argc, char* args[] )
{

    quit = 0;
    Tile *tiles[ TOTAL_TILES ];

    Timer fps;    levelwon = 0;

     //Initialize
        if( init() == false )
        {
            return 1;
        }

        if( TTF_Init() == -1 )
        {
            return false;
        }


        //Initialize SDL_mixer
        if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
        {
            return false;
        }

 //Load the files
        if( load_files() == false )
        {
            return 1;
        }

        //Clip the tile sheeti
        if( Mix_PlayMusic( music, -1 ) == -1 ) { return 1; }

        clip_tiles();

        if(!welcome)return 1;
        SDL_BlitSurface(welcome, NULL, screen, NULL );
        SDL_Flip( screen );
        SDL_Delay(6000);

        robin robinp;

    while(quit ==false)
    {

        if(level!= 1)
        {
            SDL_BlitSurface( prepare, NULL, screen, NULL );
            SDL_Flip(screen);
            SDL_Delay(3000);
        }

        robinp.reset();

        //Set the tiles
        if( set_tiles( tiles ) == false )
        {
            return 1;
        }
       // SDL_Delay(3000);
        first=1;
    /////////////////////////////////////////////////////////////////////////////////////
        while( quit == false && levelwon == 0)///////////////////////////////////
        {

            //Start the frame timer
            fps.start();

            //While there's events to handle
            while( SDL_PollEvent( &event ) )
            {

              robinp.handle_events();


                //If the user has Xed out the window
                if( event.type == SDL_QUIT )
                {
                    //Quit the program
                    quit = true;
                }
            }

            SDL_BlitSurface( background, NULL, screen, NULL );


            robinp.move(tiles);
            robinp.set_camera();

         for( int t = 0; t < TOTAL_TILES; t++ )
            {
                tiles[ t ]->show();
            }


        for(int i=0;i< en_num;i++)
        {
            enemys[en_num]->show();        //robinp.reset();
//.........这里部分代码省略.........
开发者ID:nithinmurali,项目名称:robin,代码行数:101,代码来源:main.cpp

示例6: main

int main( int argc, char* args[] ) 
{
	
	// this is the last time (SDL_Getticks()) that beasts were evaluated
	int beastLastEval=0;
	// this is how many times per second the beasts should be evaluated
	int beastEvalsPerSec = 30;
	
	paused = 0;
	//get a random seed.
	sgenrand(time(NULL));
	
    //mouse variables and cell types
    int x, y, sleepTime = 0, countVar = 0;
	
    //mouse is held variables
    int mouseStatusLeft = 0, mouseStatusRight = 0;
    
    // these keep track of the position of the right mouse button when it was clicked down
    int mouseRDx;
	int mouseRDy;
	
	//make sure the program waits for a quit
	int quit = false;
	
	init_mats();
	init_graphics();
	init_controls();
	
    //Initialize
    if( init() == false ) return 1;
	
    //Load the files
    if( load_files() == false ) return 2;
	
    //Update the screen
    if( SDL_Flip( screen ) == -1 ) return 3;
    
    gen_world();
	
	// these keep track of the WASD keys.
	int keyw=0, keya=0, keys=0, keyd=0;
	int key; // used as a stand-int for the verbose event.key.keysym.sym
	bool keyF3=true;
	
	//these are used to calculating and keeping track of the FPS
	int ticksSinceLastFPSUpdate = 0;
	int cumulativeFrames = 0;
	int currentTicks = 0;
	
	SDL_Rect screenRect;
	screenRect.x = screenRect.y = 0;
	screenRect.w = SCREEN_WIDTH;
	screenRect.h = SCREEN_HEIGHT;
	
	
    //While the user hasn't quit
    while(1){
		
    	//While there's an event to handle
    	while( SDL_PollEvent( &event ) ){
			
    		//If the user has Xed out the window
    		if( event.type == SDL_QUIT || quit == true ){
				//Quit the program
				clean_up();
				return 0;
			}
			
            if( event.type == SDL_MOUSEBUTTONDOWN ){						/// mouse down
				x = event.motion.x;
				y = event.motion.y;
                if( event.button.button == SDL_BUTTON_LEFT ){
                    mouseStatusLeft = 1;
                }
                else if( event.button.button == SDL_BUTTON_RIGHT ){
                    mouseStatusRight = 1;
                    mouseRDx = x;
                    mouseRDy = y;
                }
                
                else if( event.button.button == SDL_BUTTON_WHEELUP )
					;//zoom_in(x,y);
				else if( event.button.button == SDL_BUTTON_WHEELDOWN )
					;//zoom_out(x,y);
				
            }
            else if(event.type == SDL_MOUSEBUTTONUP){						/// mouse up
				x = event.motion.x;
				y = event.motion.y;
                if( event.button.button == SDL_BUTTON_LEFT ){
                    mouseStatusLeft = 0;
                }
                else if( event.button.button == SDL_BUTTON_RIGHT ){
                    mouseStatusRight = 0;
                }
            }
            else if( event.type == SDL_MOUSEMOTION ){						/// mouse motion
				x = event.motion.x;
				y = event.motion.y;
//.........这里部分代码省略.........
开发者ID:jensenr30,项目名称:CoSwarm,代码行数:101,代码来源:main.c

示例7: vultures_refresh

void vultures_refresh(void)
{
	SDL_Flip( vultures_screen );
}
开发者ID:gerberb,项目名称:vultures,代码行数:4,代码来源:vultures_sdl.cpp

示例8: DrawScreen

void DrawScreen(SDL_Surface* screen, Audio *audio, int xx)
{

    if(SDL_MUSTLOCK(screen))
    {
        if(SDL_LockSurface(screen) < 0) return;
    }

    int ii, xs, ys;
    Real value;
    int red, green, blue;

    for (ii=0; ii<(HEIGHT/Y_STRETCH); ii++) {
        value = frequency_component( audio, frequency( FREQ_BASE + (((double)(ii*Y_STRETCH)) * FREQ_MULT) ) );
#ifdef FORMAT_AMP
        value = value * (Real)ii;
#endif
        ((Real *)fourier->data)[ii] = value;
    }

#ifdef NORMALIZE_FOURIER
    normalize( fourier );
    audio_scale( fourier, 20000.0 );
#endif

    for (ii=0; ii<(HEIGHT/Y_STRETCH); ii++) {
        value = ((Real *)fourier->data)[ii];
#ifdef SQUARE_SUPPRESS
        value *= 0.001;
        value *= value;
#endif

        value *= 0.001;

#ifndef SQUARE_SUPPRESS
        if (value < 0) value = -value;
#endif
/*
#ifdef FORMANT_AMP
        value *= (Real)ii;
#endif
*/

          // If capturing, sum the frequencies
        if (capturing) {
            ((Real *)captured->data)[ii] += value;
            captured_slices++;
        }

        red   = (int)value;
        green = 0;
        blue  = 0;
        if (red > 16000) {
            red = 0;
            green = 255;
            blue = 0;
        } else if (red > 255) {
            green = (int)((value-255.0)/20.0);
            if (blue > 512) {
                blue  = (int)((value-512.0)/100.0);
            }
            red   = 255;
        }

          // x stretch
        for (xs=0; xs<X_STRETCH; xs++) {
            for (ys=0; ys<Y_STRETCH; ys++) {
                setpixel(screen, xx+xs, (HEIGHT-1)-(ii*Y_STRETCH)-ys, red, green, blue);
            }
        }

        if (xx+X_STRETCH < WIDTH-X_STRETCH) {
            for (ys=Y_STRETCH; ys<HEIGHT; ys++) {
                if (windowing) {
                    setpixel(screen, xx+X_STRETCH, ys, 0, 0, 255);
                } else {
                    setpixel(screen, xx+X_STRETCH, ys, 0, 255, 0);
                }
            }
        }

    }

    if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);

    SDL_Flip(screen);
}
开发者ID:petersn,项目名称:tsr,代码行数:87,代码来源:spectrogram.c

示例9: SDL_Flip

	SDL_Surface *Movement(SDL_Surface *screen)
	{
		// Movement
		// D -- Mario move LEFT
		// A -- Mario move RIGHT

		SDL_Surface *background = NULL;
		SDL_Surface *mario0 = NULL;
		//SDL_Surface *mario1 = NULL;
		//SDL_Surface *mario2 = NULL;
		SDL_Surface *mario3 = NULL;
		//SDL_Surface *mario4 = NULL;
		//SDL_Surface *mario5 = NULL;
		
		int x,y;
		x = 125;
		y = 520;

		// Image filenames
		const char *background_image = "bin/stage.bmp";
		const char *mario_image0 = "bin/IMG0.bmp";
		//const char *mario_image1 = "bin/IMG1.bmp";
		//const char *mario_image2 = "bin/IMG2.bmp";
		const char *mario_image3 = "bin/IMG3.bmp";
		//const char *mario_image4 = "bin/IMG4.bmp";
		//const char *mario_image5 = "bin/IMG5.bmp";

		background = scrnfunk::load_image(background_image);
		mario0 = scrnfunk::load_image(mario_image0);
		//mario1 = scrnfunk::load_image(mario_image1);
		//mario2 = scrnfunk::load_image(mario_image2);
		mario3 = scrnfunk::load_image(mario_image3);
		//mario4 = scrnfunk::load_image(mario_image4);
		//mario5 = scrnfunk::load_image(mario_image5);
		
		SDL_Rect clip;

		clip.x = x;
		clip.y = y;
		clip.w = 100;
		clip.h = 100;

		scrnfunk::RemoveColor(mario0, 0x00, 0x00, 0xFF); // Blue
		//scrnfunk::RemoveColor(mario1, 0x00, 0x00, 0xFF); // Blue
		//scrnfunk::RemoveColor(mario2, 0x00, 0x00, 0xFF); // Blue
		scrnfunk::RemoveColor(mario3, 0x00, 0x00, 0xFF); // Blue
		scrnfunk::apply_image(x, y, mario0, screen);
					
		if(screen != 0)
			SDL_Flip(screen);

		SDL_Event event;
		
		while(1)
		{
			while(SDL_PollEvent(&event))
			{
				if(event.type == SDL_QUIT)
					return NULL;

				else if(event.type == SDL_KEYDOWN)
				{
					if(event.key.keysym.sym == SDLK_d) // RIGHT
					{	
						scrnfunk::apply_image(x, y, background, screen, &clip); // Cover current Mario
						x=x+10;
						clip.x = x;
						scrnfunk::apply_image(x, y, mario3, screen); // Place new Mario
					}
					else if(event.key.keysym.sym == SDLK_a) // LEFT
					{
						scrnfunk::apply_image(x, y, background, screen, &clip); // Cover current Mario
						x=x-10;
						clip.x = x;
						scrnfunk::apply_image(x, y, mario3, screen); // Place new Mario
					}
				}
			}
			
			if(screen != 0)
				SDL_Flip(screen);
			else
				fprintf(stderr, "Couldn't update screen.\n");
		}
			
		return screen;
	}
开发者ID:Kris619,项目名称:Trololo,代码行数:87,代码来源:core.cpp

示例10: jouer_Pendu

//Fonction principale du jeu du Pendu, elle gérera l'affichage des différentes étapes d'une partie
int jouer_Pendu(SDL_Surface *ecran, char j1[], char j2[]) {
  //Déclaration des variables locales nécassaires pour la fonction
  SDL_Surface *s_mot_cache = NULL, *s_mot_decouvert = NULL, *resultat = NULL, *joueur = NULL;
  SDL_Rect position_mot_decouvert={200,500,0,0}, positionresultat = {50,400,0,0}, positionjoueur = {0,350,0,0};
  SDL_Event event;
  TTF_Font *police = NULL, *police2 = NULL;
  SDL_Color couleurNoire = {0, 0, 0, 0};
  int j=0, i, continuer=1, coups_reussis=0, coups_rates=1, joueuractuel = 1, joueur1, joueur2;
  char c, ch[30], mot_cache[30], mot_decouvert[30];
  Mix_Chunk *son1, *son2; 
  son1 = Mix_LoadWAV("../Music/Mini-jeux/coup_reussi_pendu.ogg");
  son2 = Mix_LoadWAV("../Music/Mini-jeux/coup_rate_pendu.ogg");

  srand(time(NULL));

  //Chargement de la police
  police = TTF_OpenFont("../Police/comicbd.ttf", 30);
  police2 = TTF_OpenFont("../Police/comicbd.ttf", 40);
  SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
  joueur1 = joueur2 = 0;

  //Point de départ d'un tour (On retourne à cette ligne pour alterner les tours entre les joueurs)
 debut:
  /*Initialisation des variables utilisées durant une partie*/
  c = '0';
  //Génération d'un nombre au hasard entre 1 et 100, ce nombre sera l'indice du mot caché qui sera chargé du fichier mots.txt avec la fonction chargement_Mot
  i = rand()%100+1;
  chargement_Mot(mot_cache,i);
  //Initialisation de la chaine qui va contenir le mot saisi par un joueur
  initialiser(mot_cache,mot_decouvert);
  s_mot_decouvert = TTF_RenderText_Blended(police, mot_decouvert, couleurNoire);
  j++;
  continuer = 1;
  //Alternance du tour
  if(joueuractuel == 1) sprintf(ch,"Joueur : %s",j1);
  else sprintf(ch,"Joueur : %s",j2);
  joueur = TTF_RenderText_Blended(police2, ch, couleurNoire);
  //Boucle while qui gérera l'affichage des différentes étapes du jeu
  while(continuer) {
    SDL_WaitEvent(&event);
    switch(event.type) {
      //En cas de fermeture de la fenêtre
      case SDL_QUIT: continuer = 0; return 0; break;
	//En cas d'appuie sur un bouton, stocker le caractère dans la variable c
      case SDL_KEYDOWN : 
        switch(event.key.keysym.sym) {
          default : c = event.key.keysym.sym; break;
	}

	//Si c'est une lettre en majuscule, la convertir en minuscule
	if(c >= 'A' && c <= 'Z') c -= 32;
	//Si c'est une lettre, faire les tests nécessaires pour voir si le mot caché contient la lettre saisie
	if(c >= 'a' && c <= 'z') {
	  //Si la lettre saisie existe dans le mot caché, l'afficher dans sa/ses position(s) dans le mot découvert (le mot qui contient n tirets | n c'est la longueur du mot caché)
	  if (existe(mot_cache,c) > existe(mot_decouvert,c)) {
	    coups_reussis++;
	    Mix_PlayChannel(1,son1,0);
	    for (i = 0; mot_cache[i] != '\0'; i++) {
	      if (mot_cache[i] == c)
		mot_decouvert[i] = c;
	    }
	    s_mot_decouvert = TTF_RenderText_Blended(police, mot_decouvert, couleurNoire);  
	  }
    /*Si la lettre n'existe pas dans mot_cache, on incrémente les coups ratés de 1, puis on appelle la fonction bonhomme 
      avec le nombre coups_rates qui s'occupera d'afficher l'image correspondante du pendu*/ 
	  else if(existe(mot_cache,c) == existe(mot_decouvert,c)){
	    Mix_PlayChannel(1,son2,0);
	    coups_rates++;
	  } 
	}
	break;
	default : break;
    }

    SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
    bonhomme(ecran,coups_rates);
    SDL_BlitSurface(s_mot_decouvert,NULL, ecran, &position_mot_decouvert);
    //Si le joueur atteint le nombre max de coups ratés, on affiche le mot caché et on garde le nombre de coups ratés afin de le comparer avec celui de l'autre joueur.
    if(coups_rates == 10) {
      if(joueuractuel == 1) {joueuractuel = 2; joueur1 = coups_rates;}
      else {joueuractuel = 1; joueur2 = coups_rates;}
      continuer = 0;
      coups_rates = 1;
      sprintf(ch,"Le mot etait '%s'",mot_cache);
      resultat = TTF_RenderText_Blended(police2, ch, couleurNoire);
      SDL_BlitSurface(resultat,NULL, ecran, &positionresultat);
    }
    //Si le joueur trouve le mot caché, on affiche le texte correspondant et on garde le nombre de coups ratés afin de le comparer avec celui de l'autre joueur.
    else if(!strcmp(mot_cache,mot_decouvert)) {
      if(joueuractuel == 1) {joueuractuel = 2; joueur1 = coups_rates;}
      else {joueuractuel = 1; joueur2 = coups_rates;}
      sprintf(ch,"Bravoo !");
      resultat = TTF_RenderText_Blended(police2, ch, couleurNoire);
      SDL_BlitSurface(resultat,NULL, ecran, &positionresultat);
      continuer = 0;
      coups_rates = 1;
    }
    SDL_BlitSurface(joueur,NULL, ecran, &positionjoueur);
    SDL_Flip(ecran);
//.........这里部分代码省略.........
开发者ID:nizarAbak-kali,项目名称:JeuDeLoie,代码行数:101,代码来源:pendu.c

示例11: SDL_Flip

void Graphics::flip(){
	SDL_Flip(screen_);
}
开发者ID:JamesWotm8,项目名称:Game,代码行数:3,代码来源:graphics.cpp

示例12: Accueil_Pendu

/*Cette fonction sert de page d'accueil du jeu du Pendu, elle fait appel à la fonction jouer_Pendu quand l'utilisateur
  appuie sur "Entrer", et à la fin elle récupère l'indice du gagnant et le renvoie à son tour*/
int Accueil_Pendu(SDL_Surface *ecran, char *j1, char *j2) {
  //Déclaration des variables locales nécessaires pour la fonction.
  SDL_Surface *texte1 = NULL, *texte2 = NULL, *pendu = NULL;
  SDL_Rect positiontexte1, positiontexte2, positionpendu;
  SDL_Event event;
  TTF_Font *police1 = NULL, *police2 = NULL;
  SDL_Color couleurNoire = {0, 0, 0, 0}, couleurBlanche = {255, 255, 255, 0};
  int continuer = 1, gagnant;
  Mix_Music *musique; //Création d'un pointeur de type Mix_Music
  Mix_VolumeMusic(MIX_MAX_VOLUME);
  musique = Mix_LoadMUS("../Music/Mini-jeux/pendu.ogg"); //Chargement de la musique
  Mix_PlayMusic(musique, -1); //Jouer infiniment la musique

  //Chargement de l'image du pendu
  pendu = IMG_Load("../images/Mini-jeux/Pendu10.png");

  //Chargement de la police
  police1 = TTF_OpenFont("../Police/chata.ttf", 65);
  police2 = TTF_OpenFont("../Police/chata.ttf", 25);

  //Initialisation du texte
  texte1 = TTF_RenderText_Shaded(police1, "Le Pendu", couleurNoire, couleurBlanche);
  texte2 = TTF_RenderText_Shaded(police2, "Appuyer sur entrer pour commencer", couleurNoire, couleurBlanche);

  SDL_SetColorKey(texte1, SDL_SRCCOLORKEY, SDL_MapRGB(texte1->format, 255, 255, 255));
  SDL_SetColorKey(texte2, SDL_SRCCOLORKEY, SDL_MapRGB(texte2->format, 255, 255, 255));

  //Remplissage de l'écran principal avec la couleur blanche
  SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 200, 100));

  //Initialisation des positions des différentes surfaces et textes
  positiontexte1.x = (ecran->w - texte1->w) / 2;
  positiontexte1.y = 0;
  positiontexte2.x = (ecran->w - texte2->w) / 2;
  positiontexte2.y = 250 + (ecran->h - texte2->h) / 2;
  positionpendu.x = (ecran->w / 2) - (pendu->w / 2);
  positionpendu.y = (ecran->h / 2) - (pendu->h / 2);

  //Remplissage de l'écran principal avec la couleur blanche
  SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 200, 100));

  //Blit du texte de la page d'accueil
  SDL_BlitSurface(texte1, NULL, ecran, &positiontexte1);
  SDL_BlitSurface(texte2, NULL, ecran, &positiontexte2);

  //Blit de l'image du pendu
  SDL_BlitSurface(pendu, NULL, ecran, &positionpendu);

  //Mise à jour de l'écran
  SDL_Flip(ecran);

  /*Une boucle infine afin de maintenir l'affichage et quitter le programme quand l'utilisateur ferme la fenêtre*/
  while (continuer) {
    SDL_PollEvent(&event);
    switch(event.type) {
    case SDL_QUIT:
      continuer = 0;
      break;
    //En cas d'apuui sur un bouton
    case SDL_KEYDOWN :
      //S'il s'agit du bouton "Entrer", appeler la fonction joueur_Pendu
      if(event.key.keysym.sym == SDLK_RETURN) gagnant = jouer_Pendu(ecran,j1,j2);
      continuer = 0;
      break;
    default: break;
    }
  }

  //Libération de la mémoire occupée par les surfaces et les polices et arrêt de la SDL
  TTF_CloseFont(police1);
  TTF_CloseFont(police2);
  SDL_FreeSurface(pendu);
  SDL_FreeSurface(texte1);
  SDL_FreeSurface(texte2);
  Mix_FreeMusic(musique); //Libération de la musique

  return gagnant;
}
开发者ID:nizarAbak-kali,项目名称:JeuDeLoie,代码行数:80,代码来源:pendu.c

示例13: main

int main(int argc, char **argv) {
    if (argc < 2) {
        fprintf(stderr, "Usage: %s <bbbout-file>\n", argv[0]);
        return 1;
    }

    int err;
    bbbout_stream *bbbout = bbbout_open_read(argv[1], &err);

    if (err != BBBOUT_SUCCESS) {
        fprintf(stderr, "%s: while reading '%s': %s", argv[0], argv[1], bbbout_strerror(err));
        return 1;
    }

    const int width = bbbout->width, height = bbbout->height;

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
        fprintf(stderr, "Error initializing SDL: %s\n", SDL_GetError());
        return 1;
    }

    screen = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    if (screen == NULL) {
        fprintf(stderr, "Unable to set %ix%i at 32 bpp: %s\n", width, height, SDL_GetError());
    }

    uint32_t gen_id;

    char *alive = malloc(width * height * sizeof(char));
    char *dying = malloc(width * height * sizeof(char));

    err = bbbout_read_generation(bbbout, &gen_id, alive, dying);

    while (err == BBBOUT_SUCCESS) {
        unsigned int ticks1 = SDL_GetTicks();

        handle_events();

        int i;

        for (i = 0; i < width * height; i++) {
            if (dying[i]) {
                struct rgb24 team_color = bbbout->team_colors[(unsigned char) dying[i]];

                *((uint32_t *) screen->pixels + i) = SDL_MapRGB(screen->format, team_color.red/2, team_color.green/2, team_color.blue/2);
            } else {
                *((uint32_t *) screen->pixels + i) = 0;
            }
        }

        for (i = 0; i < width * height; i++) {
            if (alive[i]) {
                struct rgb24 team_color = bbbout->team_colors[(unsigned char) alive[i]];

                *((uint32_t *) screen->pixels + i) = SDL_MapRGB(screen->format, team_color.red, team_color.green, team_color.blue);
            }
        }

        SDL_Flip(screen);

        char *temp = dying;
        dying = alive;
        alive = temp;

        err = bbbout_read_generation(bbbout, &gen_id, alive, NULL);

        unsigned int ticks2 = SDL_GetTicks();

        if (ticks2 - ticks1 >= 33) {
            SDL_Delay(1);
        } else {
            SDL_Delay(33 - (ticks2 - ticks1));
        }
    }

    if (err < BBBOUT_SUCCESS) {
        puts(bbbout_strerror(err));
    }

    free(alive);
    free(dying);

    SDL_Quit();

    return 0;
}
开发者ID:devyn,项目名称:bbbattle,代码行数:86,代码来源:bbbout_sdl.c

示例14: getchar_raw

/*-----------------------------------------------------------------
 * Desc: should do roughly what getchar() does, but in raw 
 * 	 (SLD) keyboard mode. 
 * 
 * Return: the (SDLKey) of the next key-pressed event cast to (int)
 *
 *-----------------------------------------------------------------*/
int
getchar_raw (void)
{
  SDL_Event event;
  int Returnkey = 0;
  
  //  keyboard_update ();   /* treat all pending keyboard-events */

  while ( !Returnkey )
    {
      while (!SDL_WaitEventTimeout (&event, 10))    /* wait for next event */
	SDL_Flip (ne_screen);
      
      switch (event.type)
	{
	case SDL_KEYDOWN:
	  /* 
	   * here we use the fact that, I cite from SDL_keyboard.h:
	   * "The keyboard syms have been cleverly chosen to map to ASCII"
	   * ... I hope that this design feature is portable, and durable ;)  
	   */
	  Returnkey = (int) event.key.keysym.sym;
	  if ( event.key.keysym.mod & KMOD_SHIFT ) 
	    Returnkey = toupper( (int)event.key.keysym.sym );
	  break;

	case SDL_JOYBUTTONDOWN: 
#ifdef JOY_BUTTON_COUNT
	  if (event.jbutton.button < JOY_BUTTON_COUNT)
	    Returnkey = joy_button_map[event.jbutton.button];
#else
	  if (event.jbutton.button == 0)
	    Returnkey = JOY_BUTTON1;
	  else if (event.jbutton.button == 1) 
	    Returnkey = JOY_BUTTON2;
	  else if (event.jbutton.button == 2) 
	    Returnkey = JOY_BUTTON3;
#endif
	  break;

	case SDL_MOUSEBUTTONDOWN:
	  if (event.button.button == SDL_BUTTON_LEFT)
	    Returnkey = MOUSE_BUTTON1;
	  else if (event.button.button == SDL_BUTTON_RIGHT)
	    Returnkey = MOUSE_BUTTON2;
	  else if (event.button.button == SDL_BUTTON_MIDDLE)  
	    Returnkey = MOUSE_BUTTON3;
	  else if (event.button.button == SDL_BUTTON_WHEELUP)
	    Returnkey = MOUSE_WHEELUP;
	  else if (event.button.button == SDL_BUTTON_WHEELDOWN)
	    Returnkey = MOUSE_WHEELDOWN;
	  break;

	default:
	  SDL_PushEvent (&event);  /* put this event back into the queue */
	  update_input ();  /* and treat it the usual way */
	  continue;
	}

    } /* while(1) */

  return ( Returnkey );

} /* getchar_raw() */
开发者ID:zeldin,项目名称:freedroidClassic-PS3,代码行数:71,代码来源:input.c

示例15: your_test

int your_test(int argc, char **argv)
{
    int done=0;

    /* check args */
    if(argc!=2)
    {
        fprintf(stderr,"%s file.ttf\n",argv[0]);
        return 1;
    }

    /* initialize the cache to NULL */
    memset(text,0,sizeof(text));

    /* start SDL video */
    if(SDL_Init(SDL_INIT_VIDEO)==-1)
    {
        printf("SDL_Init: %s\n",SDL_GetError());
        return 1;
    }
    atexit(SDL_Quit); /* remember to quit SDL */

    /* open the screen */
    if(!(screen=SDL_SetVideoMode(1200,1000,0,0)))
    {
        printf("SDL_SetVideoMode: %s\n",SDL_GetError());
        return 1;
    }

    /* allow for key repeat (so the user can hold down a key...) */
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

    /* start SDL_ttf */
    if(TTF_Init()==-1)
    {
        printf("TTF_Init: %s\n", TTF_GetError());
        return 2;
    }
    atexit(TTF_Quit); /* remember to quit SDL_ttf */
    atexit(free_font); /* remember to free any loaded font and glyph cache */

    while(!done)
    {
        SDL_Event event;
        static int x=0, y=0, need_draw=1,last_size=0, last_start_glyph=-1;

        /* smartly load font and generate new glyph cache (font_size change) */
        if(last_size!=font_size)
        {
            if(font_size<1)
                font_size=1;
            load_font(argv[1], font_size);
            need_draw=1;
            last_size=font_size;
        }
        /* smartly generate new glyph cache (page change) */
        if(last_start_glyph!=start_glyph)
        {
            cache_glyphs();
            need_draw=1;
            last_start_glyph=start_glyph;
        }
        /* smartly redraw as needed */
        if(need_draw)
        {
            SDL_FillRect(screen,0,~0);
            draw_table(x,y);
            SDL_Flip(screen);
            need_draw=0;
        }
        /* wait for events and handle them */
        /* this waits for one, then handles all that are queued before finishing */
        if(SDL_WaitEvent(&event))
            do {
                switch(event.type)
                {
                case SDL_QUIT:
                    done=1;
                    break;
                case SDL_KEYDOWN:
                    switch(event.key.keysym.sym)
                    {
                    case '0':
                        start_glyph=0;
                        break;
                    case SDLK_LEFT:
                        start_glyph=(start_glyph+0x10000-0x80)&0xffff;
                        break;
                    case SDLK_RIGHT:
                        start_glyph=(start_glyph+0x80)&0xffff;
                        break;
                    case SDLK_UP:
                        font_size++;
                        break;
                    case SDLK_DOWN:
                        font_size--;
                        break;
                    case 'n':
                        style=TTF_STYLE_NORMAL;
                        last_start_glyph=-1;
//.........这里部分代码省略.........
开发者ID:latelee,项目名称:SDLProject,代码行数:101,代码来源:SDL_latin.cpp


注:本文中的SDL_Flip函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。