void soundManager::update(int state)
{
	if ( currentState == -1 )
	{
		loopTitleMusic();
		currentState = TITLE;
	}
	else if ( state != currentState && state != HELP )
	{
		al_stop_samples();
		currentState = state;
		if ( state == TITLE )
		{
			loopTitleMusic();
		}
		else if ( state == PLAYING )
		{
			loopBGMusic();
		}
		else if ( state == ENDGAME )
		{
			//play endgame music
			loopTitleMusic();
		}
	}
}
// odtwarzanie glosu postaci
void glos (Pion_s *pion, int c, stan_tury stan)
{
	
	int x = rand()% 3;
	int y = rand()% 3 + 3;
	al_stop_samples();
	switch (stan)
	{
	case pods_bicie:
		al_play_sample(pion[c].dzwiek[x], 1.0,0.0,1.0,ALLEGRO_PLAYMODE_ONCE,NULL);
		break;
	case pods_ruch:
		al_play_sample(pion[c].dzwiek[x], 1.0,0.0,1.0,ALLEGRO_PLAYMODE_ONCE,NULL);
		break;
	case czyn_bicie:
		al_play_sample(pion[c].dzwiek[y], 1.0,0.0,1.0,ALLEGRO_PLAYMODE_ONCE,NULL);
		break;
	case czyn_ruch:
		al_play_sample(pion[c].dzwiek[y], 1.0,0.0,1.0,ALLEGRO_PLAYMODE_ONCE,NULL);
		break;
	default:
		break;
	}
	x=0;
	y=0;
}
Exemple #3
0
/* closes down the sound system */
void shutdown_sound()
{
   if (!al_is_audio_installed())
      return;

   al_destroy_thread(sound_update_thread);
   al_uninstall_timer(ping_timer);

   al_stop_samples();

   al_destroy_sample(zap);
   al_destroy_sample(bang);
   al_destroy_sample(bigbang);
   al_destroy_sample(ping);

   if (!no_music) {
      al_uninstall_timer(music_timer);

      al_destroy_sample_instance(part_voice[0]);
      al_destroy_sample_instance(part_voice[1]);
      al_destroy_sample_instance(part_voice[2]);
      al_destroy_sample_instance(part_voice[3]);

      al_destroy_sample(sine);
      al_destroy_sample(square);
      al_destroy_sample(saw);
      al_destroy_sample(bd);
      al_destroy_sample(snare);
      al_destroy_sample(hihat);
   }
}
Exemple #4
0
void killSound(void)
{

    /* terminate all sound and music playing in background */
    al_stop_samples();
    if (music != NULL)
    {
      al_drain_audio_stream(music);
      al_destroy_audio_stream(music);
      music = NULL;
    }

}
Exemple #5
0
void done(void)
{
   // Free resources
   al_stop_samples();
   ResourceManager& rm = ResourceManager::getInstance();
   for (int i = RES_STREAM_START; i < RES_STREAM_END; i++) {
      ALLEGRO_AUDIO_STREAM *s = (ALLEGRO_AUDIO_STREAM *)rm.getData(i);
      if (s)
         al_set_audio_stream_playing(s, false);
   }

   ResourceManager::getInstance().destroy();
}
Exemple #6
0
void shutdownSound(void)
{

    /* shutdown sound system when done */
    al_stop_samples();
    if (music != NULL)
    {
        al_destroy_audio_stream(music);
    }
    al_destroy_mixer(mixer);
    al_destroy_voice(voice);
    al_uninstall_audio();

}
Exemple #7
0
void playMusicOnce(const char *filename)
{

    /* play music only once in background, terminating old music */

    ALLEGRO_PLAYMODE loop = ALLEGRO_PLAYMODE_ONCE;
    al_stop_samples();
    if (music != NULL)
    {
      al_drain_audio_stream(music);
      al_destroy_audio_stream(music);
    }
    music = al_load_audio_stream(filename, 4, 2048);
    al_set_audio_stream_playmode(music, loop);
    al_attach_audio_stream_to_mixer(music, mixer);

}
Exemple #8
0
void loadLevel(std::string lvl) {
	clearMenu();
	clearPause();
	buildPause();
	danmakux.framesPast = 0;
	if (danmakux.menu.running) closeScript(&danmakux.menu);
	if (danmakux.level.running) closeScript(&danmakux.level);
	std::string filename = "lvl_" + lvl + ".lua";
	loadScript(&danmakux.level, filename);
	regFunction(&danmakux.level, "setBGM", setBGM);
	regFunction(&danmakux.level, "setBG", setBG);
	regFunction(&danmakux.level, "addEnemy", addEnemy);
	regFunction(&danmakux.level, "elapsedTime", timePassed);
	regFunction(&danmakux.level, "win", winLevel);
	runFunction(&danmakux.level, "start");
	al_stop_samples();
	al_play_sample(danmakux.bgm, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
}
Exemple #9
0
void game_next_map_test(Game* game){
	if(jeu_fin_jeu(game->jeu) == 1){
		int i = 1;
		Elem* map_i = game->maps->tete;
		while(i <= game->current_map_i){
			map_i = liste_suivant(game->maps,map_i);
			i++;
		}

		if(i == game->size +1){
			game->jeu->boucle_jeu = false;
			game->success = true;
		}else{
			ALLEGRO_SAMPLE* current_musique = game->jeu->map->musique;
			game->jeu = jeu_init((char*)(map_i->object));
			ALLEGRO_SAMPLE* next_musique = game->jeu->map->musique;
			if(current_musique!=next_musique){
				al_stop_samples();
				map_play_musique(game->jeu->map);
			}
			game->current_map_i += 1;
			char num_niveau[4];
			al_clear_to_color(al_map_rgb(0,0,0));
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),300,150,ALLEGRO_ALIGN_LEFT,"STAGE CLEAR !");
			if(game->size == game->current_map_i){
				al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),280,190,ALLEGRO_ALIGN_LEFT,"Loading final stage");
			}else{
				al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),300,190,ALLEGRO_ALIGN_LEFT,"Loading level ");
				al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),440,190,ALLEGRO_ALIGN_LEFT,num_niveau);
			}
			al_flip_display();
			sleep(2);
			al_clear_to_color(al_map_rgb(0,0,0));
			al_flip_display();
			map_set_frame(game->jeu->map,DISPLAY_W/2-200,100,200,DISPLAY_H-300);	
		}
	}
}
Exemple #10
0
void playMusic(const char *filename)
{

    /* play music in background, on loop - unpause if music is already playing */
    if (isMusicPaused())
    {
        unPauseMusic();
        return;
    }

    /* music not playing, start over from beginning */
    ALLEGRO_PLAYMODE loop = ALLEGRO_PLAYMODE_LOOP;
    al_stop_samples();
    if (music != NULL)
    {
      al_drain_audio_stream(music);
      al_destroy_audio_stream(music);
    }
    music = al_load_audio_stream(filename, 4, 2048);
    al_set_audio_stream_playmode(music, loop);
    al_attach_audio_stream_to_mixer(music, mixer);

}
Exemple #11
0
int main(int argc, const char *argv[])
{
    ALLEGRO_SAMPLE *sample_data[MAX_SAMPLE_DATA] = {NULL};
    ALLEGRO_DISPLAY *display;
    ALLEGRO_EVENT_QUEUE *event_queue;
    ALLEGRO_EVENT event;
    int i;

    if (argc < 2) {
        fprintf(stderr, "Usage: %s {audio_files}\n", argv[0]);
        return 1;
    }
    argc--;
    argv++;

    if (!al_init()) {
        abort_example("Could not init Allegro.\n");
    }

    al_install_keyboard();

    display = al_create_display(640, 480);
    if (!display) {
        abort_example("Could not create display\n");
    }

    event_queue = al_create_event_queue();
    al_register_event_source(event_queue, al_get_keyboard_event_source());

    al_init_acodec_addon();

Restart:

    if (!al_install_audio()) {
        fprintf(stderr, "Could not init sound!\n");
        return 1;
    }

    if (!al_reserve_samples(RESERVED_SAMPLES)) {
        fprintf(stderr, "Could not set up voice and mixer.\n");
        return 1;
    }

    memset(sample_data, 0, sizeof(sample_data));
    for (i = 0; i < argc && i < MAX_SAMPLE_DATA; i++) {
        const char *filename = argv[i];

        /* Load the entire sound file from disk. */
        sample_data[i] = al_load_sample(argv[i]);
        if (!sample_data[i]) {
            fprintf(stderr, "Could not load sample from '%s'!\n", filename);
            continue;
        }
    }

    printf("Press digits to play sounds, space to stop sounds, "
           "Escape to quit.\n");

    while (true) {
        al_wait_for_event(event_queue, &event);
        if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
            if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
                break;
            }
            if (event.keyboard.unichar == ' ') {
                al_stop_samples();
            }

            if (event.keyboard.unichar >= '0' && event.keyboard.unichar <= '9') {
                i = (event.keyboard.unichar - '0' + 9) % 10;
                if (sample_data[i]) {
                    printf("Playing %d\n",i);
                    if (!al_play_sample(sample_data[i], 1.0, 0.5, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL)) {
                        fprintf(stderr,
                                "al_play_sample_data failed, perhaps too many sounds\n");
                    }
                }
            }

            /* Hidden feature: restart audio subsystem.
             * For debugging race conditions on shutting down the audio.
             */
            if (event.keyboard.unichar == 'r') {
                al_uninstall_audio();
                goto Restart;
            }
        }
    }

    /* Sample data and other objects will be automatically freed. */
    al_uninstall_audio();

    return 0;
}
Exemple #12
0
void SoundManager::muteSFX()
{
	v_mute_sfx = true;

	al_stop_samples();
}
Exemple #13
0
int main(int argc, char **argv){

	if(argc==3){
		if(strcmp(argv[1],"rand")==0 && strcmp(argv[1],"map/maps.txt")!=0){
			map_aleatoire(argv[2], 1000,100);
			printf("map cree\n");
			return 0;
		}
	}

	/* Creation de l ecran */
	ALLEGRO_DISPLAY *display = NULL;
	/* Creation du timer */
	ALLEGRO_TIMER *timer;
	/* Creation de la liste d'evenement */
	ALLEGRO_EVENT_QUEUE *queue;
	bool redraw = true;
	/*bool boucle_jeu=true;*/


	/* Initialisation d allegro */
	if(!al_init()) {
		fprintf(stderr, "failed to initialize allegro!\n");
		return -1;
	}
	if(!al_init_image_addon()) {
		fprintf(stderr, "failed to initialize allegro image addon!\n");
		return -1;
	}
	if(!al_init_primitives_addon()) {
		fprintf(stderr, "failed to initialize allegro primitive addon!\n");
		return -1;
	}
	if(!al_install_mouse()) {
		fprintf(stderr, "failed to initialize allegro mouse !\n");
		return -1;
	}
	if(!al_install_keyboard()) {
		fprintf(stderr, "failed to initialize allegro keyboard!\n");
		return -1;
	}
	if(!al_install_joystick()){
		fprintf(stderr, "failed to initialize allegro joystick!\n");
		return -1;
	}
	if(!al_install_audio()) {
		fprintf(stderr, "failed to initialize allegro audio!\n");
		/*return -1;*/
	}
	if(!al_init_acodec_addon()){
		fprintf(stderr, "failed to initialize allegro audio codec!\n");
		/*return -1;*/
	}
	if (!al_reserve_samples(2)){
		fprintf(stderr, "failed to initialize allegro reserve sample 1!\n");
		/*return -1;*/
	}

	al_init_font_addon();

	if(!al_init_ttf_addon()){
		fprintf(stderr, "failed to initialize allegro ttf addon!\n");
		return -1;
	}

	Game* game;
	/* Instantiation de l ecran */
	display = al_create_display(DISPLAY_W,DISPLAY_H);
	if(!display) {
		fprintf(stderr, "failed to create display!\n");
		return -1;
	}

	bool recommencer = true;
	while(recommencer){

		recommencer = false;
		game = game_init();

		al_hide_mouse_cursor(display);

		/* Instantiation de la liste d evenement */
		queue = al_create_event_queue();

		/* Instantiation du timer de jeu */
		timer = al_create_timer(1.0/FPS);
		al_start_timer(timer);

		/* Enregistrement des evenement */
		al_register_event_source(queue, al_get_keyboard_event_source());
		al_register_event_source(queue, al_get_mouse_event_source());
		al_register_event_source(queue, al_get_joystick_event_source());
		al_register_event_source(queue, al_get_display_event_source(display));
		al_register_event_source(queue, al_get_timer_event_source(timer));


		/* ECRAN TITRE */

		al_clear_to_color(al_map_rgb(0,0,0));
		al_draw_bitmap_region(game->jeu->map->background,250,200,game->jeu->map->w*LENGTH_SPRITE,game->jeu->map->h*LENGTH_SPRITE,0,0,0);
		al_draw_text(game->jeu->font_jeu,al_map_rgb(0,0,0),280,150,ALLEGRO_ALIGN_LEFT,"Titre du jeu");
		al_draw_text(game->jeu->font_jeu,al_map_rgb(0,0,0),280,190,ALLEGRO_ALIGN_LEFT,"Press enter");
		if(al_is_audio_installed()){
			ALLEGRO_SAMPLE* main_musique;
			main_musique = al_load_sample("musique/musique_titre.ogg");
			if (!main_musique){
				fprintf(stderr, "Erreur lors du chargement musique d'intro\n");
			}

			al_play_sample(main_musique, 0.1, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,NULL);
		}
		al_flip_display();
		bool debut = false;
		Event* event_titre;
		ALLEGRO_EVENT event_titre_event;
		event_titre = event_init(EVENT_PERIPH_XBOX);
		while(debut != true){
			al_wait_for_event(queue, &event_titre_event);
			if(event_get_ok_court(event_titre)){
				debut = true;
			}
			event_update(event_titre,&event_titre_event);
		}

		if(al_is_audio_installed()){
			al_stop_samples();
		}
		/* Ecran de chargement du premier niveau */

		char num_niveau[4];
		sprintf(num_niveau,"%d",game->current_map_i);
		al_clear_to_color(al_map_rgb(0,0,0));
		if(game->size == game->current_map_i){
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),280,190,ALLEGRO_ALIGN_LEFT,"Loading final stage");
		}else{
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),300,190,ALLEGRO_ALIGN_LEFT,"Loading level ");
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),440,190,ALLEGRO_ALIGN_LEFT,num_niveau);
		}
		al_flip_display();
		sleep(2);
		al_clear_to_color(al_map_rgb(0,0,0));
		al_flip_display();

		/* Début de la boucle de jeu */
		game->jeu->ev->son = true;
		map_set_frame(game->jeu->map,DISPLAY_W/2-200,100,200,DISPLAY_H-300);	

		while(game->jeu->boucle_jeu){

			

			game_next_map_test(game);
			
			ALLEGRO_EVENT event;
			al_wait_for_event(queue, &event);

				/* On demande a quitter le jeu */
			if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE ){
				game->jeu->boucle_jeu=false;
			}
			event_update(game->jeu->ev,&event);

			/* Evenement timer */
			if(event.type == ALLEGRO_EVENT_TIMER){
				redraw=true;
			}

			/*
			if(event.type == ALLEGRO_EVENT_DISPLAY_RESIZE){
				al_acknowledge_resize(display);
				redraw = true;
			}
			*/
				/* affichage */

			if(redraw && al_is_event_queue_empty(queue)){
				redraw=false; 
				game->jeu->boucle_jeu = jeu_update_event(game->jeu);
				jeu_draw(game->jeu);
			}

		}



		/* Ecran de fin du jeu */
		if(game->success == true){
			al_clear_to_color(al_map_rgb(0,0,0));
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,100,ALLEGRO_ALIGN_CENTER,"Félicitation, vous avez terminés les premiers niveaux du jeu !");
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,120,ALLEGRO_ALIGN_CENTER,"Ce jeu à été créé à l'occasion du premier projet de C de");
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,140,ALLEGRO_ALIGN_CENTER,"la promotion 2016 de Télécom Nancy");
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,160,ALLEGRO_ALIGN_CENTER,"par");
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,180,ALLEGRO_ALIGN_CENTER,"Giannini Valentin et Eric Perlinski");
			al_flip_display();
			sleep(5);
			al_clear_to_color(al_map_rgb(0,0,0));
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,150,ALLEGRO_ALIGN_CENTER,"Appuyez sur [ESC] pour quitter, ou sur [Entrer] pour recommencer");
			al_flip_display();
		}else{
			al_clear_to_color(al_map_rgb(0,0,0));
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,100,ALLEGRO_ALIGN_CENTER,"Vous avez épuisés toutes les vies de votre personnage !");
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,120,ALLEGRO_ALIGN_CENTER,"Ce jeu à été créé à l'occasion du premier projet de C de");
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,140,ALLEGRO_ALIGN_CENTER,"la promotion 2016 de Télécom Nancy");
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,160,ALLEGRO_ALIGN_CENTER,"par");
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,180,ALLEGRO_ALIGN_CENTER,"Gianini Valentin et Eric Perlinski");
			al_flip_display();
			sleep(5);
			al_clear_to_color(al_map_rgb(0,0,0));
			al_draw_text(game->jeu->font_jeu,al_map_rgb(255,255,255),400,150,ALLEGRO_ALIGN_CENTER,"Appuyez sur [ESC] pour quitter, ou sur [Entrer] pour recommencer");
			al_flip_display();
		}
		/* TODO Chargement écran de fin */
		bool action = false;
		Event* event_credits;
		ALLEGRO_EVENT event_credits_event;
		
		event_credits = event_init(EVENT_PERIPH_XBOX);
		while(action != true){
			al_wait_for_event(queue, &event_credits_event);
			if(event_get_ok_court(event_credits)){
				action = true;
				recommencer = true;
			}else if (event_get_menu(event_credits)){
				action = true;
				recommencer = false;
			}
			event_update(event_credits,&event_credits_event);
		}

	}

	jeu_dest(game->jeu);
	al_destroy_display(display);

	return 0;
}
Exemple #14
0
int main()
{
  if(!ALLEGRO5_INIT) allegro5_init();
  
  short int      option;
  char           options_list[][50] =
                 {
                   "Start",
                   "Exit",
                   "Help",
                   "-"
                 };
  
  volatile int       i = 0;
  long int           life = 100;
  char               key_char[50];
  bool               terminou = false,
                     redraw   = true;
  LifeBar            lifeBar;
  Font               global_font;
  ALLEGRO_EVENT      ev;
  
  lifeBar.open(200, 0, 0, SCREEN_W/2, 50, "resource\\LifeBars\\001.bmp", INVISIBLE);
  
  global_font.open("resource\\Font\\impressedMetal.ttf", 32, 0, WHITE);
  log.append("Font...OK");
  
  Loading(global_font);
  
  option = StartGame(
    "resource\\StartGame\\Sprites\\intro.bmp", 
    "resource\\StartGame\\Snd\\background.wav", 
    "resource\\StartGame\\Sprites\\csr.bmp", 
    "resource\\StartGame\\Snd\\csr.wav", 
    "resource\\Font\\impressedMetal.ttf", 
    options_list);
  
  log.append("\t\tLoop principal");
    
  al_start_timer(global_timer);
  
  al_clear_to_color(BLACK);
  al_flip_display();
  
  while(!terminou)
  {
    al_wait_for_event(eventos_globais, &ev);
    
    switch(ev.type)
    {
      case ALLEGRO_EVENT_DISPLAY_CLOSE:
        terminou = true;
        break;
        
      case ALLEGRO_EVENT_TIMER:
        if(ev.timer.source == global_timer)
          redraw = true;
        break;
        
      case KEY_DOWN:
        strcpy(key_char, al_keycode_to_name(ev.keyboard.keycode));
        
        if( StringCompareNoCase(key_char, "escape") ) terminou = true;
        
        else if( StringCompareNoCase(key_char, "down") ){ }
          
        else if( StringCompareNoCase(key_char, "up") ){ }
        
        else if( StringCompareNoCase(key_char, "right") ){ }
          
        else if( StringCompareNoCase(key_char, "left") ){ }
        
      break;
      
      /**************************
          Soltou uma tecla
      ***************************/
      case KEY_UP:
        strcpy(key_char, al_keycode_to_name(ev.keyboard.keycode));
        break;
    }
    
    if(redraw && al_is_event_queue_empty(eventos_globais) && !terminou)
    {
      redraw = false;

      al_set_target_bitmap(al_get_backbuffer(display));
      
      lifeBar.print(life);
      if(life > 0)life--;
      else
        life = 200;
      global_font.print(0, SCREEN_H/2, "Teste");

      al_flip_display();
      al_clear_to_color(BLACK);
    }
  }
  
  al_stop_samples();
  
  Fim("resource\\Font\\Resident_Evil_Large.ttf");
  
  al_destroy_display(display);
  al_destroy_event_queue(eventos_globais);
  al_destroy_timer(global_timer);
  
  log.append("\t\tLoop principal...OK");
  log.append("[FIM]");
  log.close();
}