示例#1
0
void
SoundManager::play_music(const std::string& filename, bool fade)
{
  if(filename == current_music && music_source != NULL)
    return;
  current_music = filename;
  if(!music_enabled)
    return;

  if(filename == "") {
    music_source.reset();
    return;
  }

  try {
    std::unique_ptr<StreamSoundSource> newmusic (new StreamSoundSource());
    newmusic->set_sound_file(load_sound_file(filename));
    newmusic->set_looping(true);
    newmusic->set_relative(true);
    if(fade)
      newmusic->set_fading(StreamSoundSource::FadingOn, .5f);
    newmusic->play();

    music_source = std::move(newmusic);
  } catch(std::exception& e) {
    log_warning << "Couldn't play music file '" << filename << "': " << e.what() << std::endl;
    // When this happens, previous music continued playing, stop it, just in case.
    stop_music(0);
  }
}
示例#2
0
void close_sound() 
{
	int numtimesopened, frequency, channels;
	Uint16 format;

	if (mix_ok) {
		stop_bell();
		stop_UI_sound();
		stop_sound();
		sound_cache.clear();
		stop_music();
		mix_ok = false;

		numtimesopened = Mix_QuerySpec(&frequency, &format, &channels);
		if(numtimesopened == 0) {
			ERR_AUDIO << "Error closing audio device: " << Mix_GetError() << "\n";
		}
		while (numtimesopened) {
			Mix_CloseAudio();
			--numtimesopened;
		}
	}
	if (SDL_WasInit(SDL_INIT_AUDIO) != 0) {
		SDL_QuitSubSystem(SDL_INIT_AUDIO);
	}

	LOG_AUDIO << "Audio device released.\n";
}
示例#3
0
static void hall_of_fame_phase_exit(struct phase *up)
{
	struct hall_of_fame_phase *self =
		b6_cast_of(up, struct hall_of_fame_phase, up);
	int i;
	finalize_fade_io(&self->fade_io);
	if (self->entry) {
		save_hall_of_fame(&up->engine->hall_of_fame);
		self->entry = NULL;
	}
	if (self->music) {
		stop_music(up->engine->mixer);
		unload_music(up->engine->mixer);
	}
	del_controller_observer(&self->controller_observer);
	del_renderer_observer(&self->renderer_observer);
	if (self->cursor_base) {
		finalize_toolkit_label(&self->cursor_label);
		destroy_renderer_base(self->cursor_base);
	}
	for (i = 0; i < b6_card_of(self->label); i += 1)
		finalize_toolkit_label(&self->label[i]);
	if (self->panel) {
		destroy_renderer_texture(self->panel->texture);
		destroy_renderer_tile(self->panel);
	}
	if (self->background) {
		destroy_renderer_texture(self->background->texture);
		destroy_renderer_tile(self->background);
	}
	finalize_fixed_font(&self->font);
	close_hall_of_fame(self->array);
}
示例#4
0
void finalize_menu_mixer(struct menu_mixer *self)
{
	del_menu_observer(&self->menu_observer);
	if (self->music) {
		stop_music(self->mixer);
		unload_music(self->mixer);
	}
}
示例#5
0
// --------------------------------------------------------------
// object which gives a temporary boost to luck
// --------------------------------------------------------------
void t_luck_object::activate_trigger( t_army* army, t_adv_map_point const& point, 
		                              t_direction direction, t_adventure_frame* frame )
{
	int  i;
	bool any_award = false;

	// loop through all heroes/creatures in the army and award temporary statistic based on subtype

	t_creature_array& creatures = army->get_creatures();


	for (i = 0; i < t_creature_array::k_size; i++)
	{
		if (creatures[i].get_number() == 0)
			continue;
		if (creatures[i].has_temporary_bonus( get_type() ))
			continue;
		add_bonus( creatures[i] );
		any_award = true;
	}

	// determine what response to print
	if (army->get_owner()->is_computer())
		return;

	t_basic_dialog*          dialog;
	std::string              text;

	dialog = new t_basic_dialog;
	if (any_award)
	{
		text = get_text( "initial" );
		add_icons( dialog );
	}
	else
	{
		text = get_text( "empty" );
	}

	dialog->set_text( text );
	dialog->add_ok_button();
	dialog->set_title( get_name() );
	dialog->open( get_dialog_bottom( point ), true, k_align_bottom );
	t_sound_cache music = get_music_playing();
	stop_music();
	get_dialog_sound( k_dialog_sound_luck )->play( get_sound_volume() );
	dialog->run_modal();
    // Update stats.
    frame->update_army();
	play_music( music );
}
示例#6
0
AudioController::~AudioController() {
    //Unload all the audio files. This is called on exit.
    stop_music();
    for (int i=0;i<NUM_SFX;i++) {
        Mix_FreeChunk(SFX[i]);
    }
    for (int i=0;i<NUM_TRACKS;i++) {
        Mix_FreeMusic(music[i]);
    }
    delete[] SFX;
    delete[] music;
    Mix_CloseAudio();

}
示例#7
0
// stop or start sounds when minimized
void handle_adventure_sound_minimization(bool minimized)
{
	static bool was_minimized = false;
	static bool music_is_saved = false;
	static int former_music_volume;
	static t_sound_cache saved_music;

	if (minimized == false && !was_minimized) // never have minimized yet
		return;

	// go through the current managed sound list and make sure a sound
	t_active_sounds::iterator iter;

	if (minimized)
		was_minimized = true;

	// handle music
	if (music_is_saved && !minimized) 
		play_music( saved_music );
	else if (minimized)
	{
		music_is_saved = true;
		saved_music = get_music_playing();
	//	if (saved_music)
	//		former_music_volume = saved_music->get_volume();
		stop_music();
	}

	// traverse the list of active sounds and process each
	for( iter = active_sounds.begin(); iter != active_sounds.end(); ++iter )
	{
		t_managed_sound * playing_sound = (*iter).get();
		if (minimized) // fade out the sound
		{
			playing_sound->set_former_volume(playing_sound->get_sound_ptr()->get_volume());
			playing_sound->get_sound_ptr()->set_volume(k_almost_min_volume);
		}
		else // restore prior volume level
		{
			if (playing_sound->get_sound_ptr())
			{
				playing_sound->get_sound_ptr()->set_volume(playing_sound->get_former_volume() );
			}
			else
			{
				minimized = minimized; // debug hook for a bug??
			}
		}
	}
}
示例#8
0
void t_sanctuary::activate_trigger( t_army* army, t_adv_map_point const& point, 
									t_direction direction, 
									t_adventure_frame* frame )
{
	t_dialog_sanctuary*				dialog;
	t_player*						player = army->get_owner();
	std::string						text;
	t_screen_point					zero(0,0);

	resurrect_heroes( *army, k_text_sanctuary_resurrects_heroes, frame );
	dialog = new t_dialog_sanctuary( frame );

	if (!empty())
	{
		dialog->set_text( get_text( "denied" ) );
		dialog->enable_entry( false );
	}
	else if (m_paid[army->get_owner_number()])
	{
		dialog->set_text( get_text( "paid" ) );
		dialog->enable_entry( true );
	}
	else
	{
		dialog->set_text( get_text( "initial" ));
		dialog->enable_entry( player->get_funds()[k_gold] >= k_rental_fee);
	}
	dialog->set_title( get_name() );

	t_sound_cache music = get_music_playing();
	stop_music();
	get_dialog_sound( k_dialog_sound_sanctuary )->play( get_sound_volume() );
	switch (dialog->run_modal())
	{
		case k_choice_cancel:
			return;

		case k_choice_enter:
			if (!m_paid[army->get_owner_number()])
			{
				player->spend( k_gold, k_rental_fee );
				m_paid[army->get_owner_number()] = true;
			}
			set_owner( army->get_owner_number() );
			swap( army->get_creatures() );
			frame->destroy_army( army );
			break;
	}
	play_music( music );
}
示例#9
0
void MainWindow::game_finished()
{
    timer->stop();
    stop_music();

    // score
    cur_scene = score;
    ui->scoreLabel->setText(QString("Score: %1").arg(canvas->getScore()));
    ui->scoreLabel->setVisible(true);
    ui->nameEdit->setVisible(true);

    delete canvas;
    setFocus();
    ui->nameEdit->setFocus();
}
示例#10
0
文件: sound.c 项目: pepone42/hexgem
void play_music(SOUNDID id) {
	stop_music();
	switch(id) {
	case SID_MUSIC1:
		Mix_PlayMusic(music1, -1);
		break;
	case SID_MUSIC2:
		Mix_PlayMusic(music2, -1);
		break;
	case SID_MUSIC3:
		Mix_PlayMusic(music3, -1);
		break;
		default:
		break;
	}
}
示例#11
0
static void following_song_hook(void) {

  /** Play next song hook function **/

  if ( music_song_counter < (total_song_counter-1) && ! play_order) {
    music_song_counter++ ;
  }
  else if ( music_song_counter > 0                 &&   play_order) {
    music_song_counter-- ;
  }
  else if (music_song_counter == (total_song_counter-1) ) {

    /** End of playlist reached. **/

    if (is_repeat_all) { // Repeat all feature enabled.

      music_song_counter = 0 ;

    }
    else {  // Repeat all feature disabled.

      if (! is_shuffle) { // Shuffle feature disabled.



        // We stop playing song as set from the user.
        stop_music(NULL, NULL) ;

        // Update the displayed playlist window if currently displayed.
        update_playlist() ;

        return ;
      }

    }

  }

  if (is_shuffle) { music_song_counter = shuffle_get_song_index() ; if (is_end_of_shuffle_playlist()) { stop_music(NULL, NULL) ; return ; } ;  }

  // Update the displayed playlist window if currently displayed.
  update_playlist() ;

  timeout_action = true ;

}
示例#12
0
void AudioController::play_music(int track,int loopnum) {
     stop_music(); //Stop music first.
     if (track<=0) track=1;
     if (track>NUM_TRACKS) track=NUM_TRACKS;
     if( Mix_PlayingMusic() == 0 ) {
         if (Mix_PlayMusic( music[track-1], loopnum ) == -1) {
            //Fail somehow
         };
     }
     
    //Play one of the MIDI tracks.
    //Specify which one in the documentation.
    //Only one music should be playable at a time.
    //Also it should automatically loop to a starting point.
    //All the songs that need to loop to a specific point will have
    // a midi cue at that point named "loopStart" when they're done.
}
示例#13
0
文件: loading.c 项目: wosigh/tuxracer
void loading_init(void) 
{
    winsys_set_display_func( main_loop );
    winsys_set_idle_func( main_loop );
    winsys_set_reshape_func( reshape );
    winsys_set_mouse_func( ui_event_mouse_func );
    winsys_set_motion_func( ui_event_motion_func );
    winsys_set_passive_motion_func( NULL );
    
    passInLoop = 0;
    
    draw_loading_text();
	
	choose_sponsor();
    
    reshape( getparam_x_resolution(), getparam_y_resolution() );
    
    stop_music();
}
示例#14
0
/*
	Purpose: test the music functions
	Input  : the array of music notes
	Returns: ouputs music 
	Assume : nothing
*/
int main()
{
	int j = 0;
	int i = 0;
	int music[104];
	
	music = get_music();
	
	start_music();
	
	for (i = 0; i < 104; i++){
		play_music(music[i]);
		while (j < 32000)
			j++
	}
	stop_music();
	
	
	return 0;
}
示例#15
0
文件: setup.c 项目: rj76/kq
/*! \brief Initialize sound system
 * \author JB
 * \date ????????
 * \remark On entry is_sound=1 to initialise,
 *         on exit is_sound=0 (failure) or 2 (success),
 *         is_sound=2 to shutdown,
 *         on exit is_sound=0
 * \remark 20020914 - 05:28 RB : Updated
 *  20020922 - ML : updated to use DUMB
 *  20020922 - ML : Changed to only reserving 8 voices. (32 seemed over-kill?)
 */
void sound_init (void)
{
   if (!sound_avail) {
      is_sound = 0;
      return;
   }
   switch (is_sound) {
   case 1:
      /* set_volume_per_voice (2); */
      init_music ();
      is_sound = load_samples ()? 0 : 2;        /* load the wav files */
      break;
   case 2:
      /* TT: We forgot to add this line, causing phantom music to loop */
      stop_music ();
      free_samples ();
      is_sound = 0;
      break;
   }
}
示例#16
0
/*
** Player visits this blacksmith.
*/
void t_adv_blacksmith::activate_trigger( t_army* army_ptr, t_adv_map_point const& point, 
		                               t_direction direction, t_adventure_frame* frame_ptr )
{

	t_counted_ptr<t_dialog_blacksmith> dialog_ptr;

    // Set player visited.
	m_visited[army_ptr->get_owner_number()] = true;

    /*
    ** Create and show dialog, and let user buy from this blacksmith.
    */
	dialog_ptr = new t_dialog_blacksmith( frame_ptr );
	dialog_ptr->init_dialog( frame_ptr, army_ptr, m_available_potions, m_available_items, m_available_long_items);
	t_sound_cache music = get_music_playing();
	stop_music();
	get_dialog_sound( k_dialog_sound_marketplace )->play( get_sound_volume() );
	dialog_ptr->run_modal();
	play_music( music );
    
	frame_ptr->update_funds();
}
示例#17
0
// -------------------------------------------------------
// artifact as it appears on the adventure map
// -------------------------------------------------------
void t_adv_artifact::activate_trigger( t_army* army, t_adv_map_point const& point, 
		                               t_direction direction, t_adventure_frame* frame )
{
	destroy(); // we should not be deleted by this, because the caller has a reference.
	if (!army->get_owner()->is_computer())
	{
		army->add( m_artifact );

		std::string text = m_artifact.get_pickup_text();
		std::string name = m_artifact.get_name();
		t_adventure_map*		 map = get_map();
		t_adventure_map_window*  map_window = frame->get_map_window();
		t_level_map_point_2d     location = get_position();
		t_screen_point           screen_point = get_screen_point( *map, *this, location )
												- map_window->get_view_pos();
		t_artifact_type          type = m_artifact.get_icon();
		t_bitmap_layer_ptr       icon = get_icon( type );

		//t_bitmap_layer_cache_window_ptr icon_window;
		t_counted_ptr<t_basic_dialog>	dialog = new t_basic_dialog( frame );

		dialog->add_ok_button();
		//icon_window = new t_bitmap_layer_cache_window( icon, t_screen_point(0,0), dialog, false );
		//icon_window->set_help_balloon_text( m_artifact.get_name() );
		//icon_window->set_right_click_text( m_artifact.get_help_text() );
		dialog->add_artifact( m_artifact, 1, true );
		dialog->set_text( text );
		//dialog->add_display_window( icon_window, name );
		dialog->set_title( get_name() );
		dialog->open( screen_point, true, k_align_bottom );
		t_sound_cache music = get_music_playing();
		stop_music();
		get_dialog_sound( k_dialog_sound_treasure )->play( get_sound_volume() );
		dialog->run_modal();
		play_music( music );
	} 
	else 
		ai_give_artifact_to_army( *army, m_artifact );
}
void SingleClassicMode::trigger_pressed(int id, qreal trigger)
{
	if(have_won)
	{
		emit change_sound_volume(1.0);
	}
	else
	{
		/* Check if the trigger is fully pressed */
		if(trigger/255.)
		{
			if(current_distance < obstacle_hearing_sound)
			{
				emit change_sound_volume(1.5*(obstacle_hearing_sound - current_distance)/obstacle_hearing_sound);

				if(!set_beep)
				{
					set_beep = 1;

					emit play_beep();
				}
			}
		}
		else
		{
			emit change_sound_volume(1.0);

			if(set_beep)
			{
				set_beep = 0;

				stop_music();
			}

			return;	
		}
	}
}
void SingleClassicMode::init()
{
	emit stop_music();

	emit change_sound_volume(1.0);
}
示例#20
0
void press_btnA()
{
  switch(work)
  {
    case MAIN_MENU:into_menu(); break;
    case BOOK_MENU:{
                     strcpy(book_name, "book/");
                     strcat(book_name, file_list[file_list_point]);
                     into_book(book_name, 0);
                     break;
                   }
    case BOOK_CONFIG:if(!in_pallet)
                     {
                       switch(book_config_point)
                       {
                         case 0: case 1:{
                                          draw_book_config_point(book_config_point, 255, 255, 255);
                                          show_pallet(book_config_point);
                                          break;
                                        }
                         case 4:{
                                  txtbr = temp_r[0];
                                  txtbg = temp_g[0];
                                  txtbb = temp_b[0];
                                  txtfr = temp_r[1];
                                  txtfg = temp_g[1];
                                  txtfb = temp_b[1];
                                  txtdot = temp_dot;
                                  if(txt_offset_changed)
                                  {
                                    txt_now_offset = txt_max_offset * temp_offset_rate / 100;
                                    if(txt_now_offset >= txt_max_offset)
                                      txt_now_offset -= 20;
                                    check_txt_offset();
                                  }
                                }
                         case 5:exit_book_config(); break;
                       }
                     }
                     else if(temp_point == 3)
                     {
                       myGLCD.setColor(temp_r[book_config_point], temp_g[book_config_point], temp_b[book_config_point]);
                       myGLCD.fillRect(146, 2 + 66 * book_config_point, 209, 2 + 66 * book_config_point + 63);
                       in_pallet = false;
                       draw_book_config_point(book_config_point, 255, 0, 0);
                     }
                     break;
    case MUSIC_MENU:{
                      strcpy(music_name, file_list[file_list_point]);
                      into_music(music_name);
                      break;
                    }
    case MUSIC_PLAY: stop_music(); break;
    case IMAGE_MENU:{
                      strcpy(image_name, "image/");
                      strcat(image_name, file_list[file_list_point]);
                      into_image(image_name);
                      break;
                    }
    case IMAGE_SHOW:switch(image_point)
                    {
                      case 3: image_update(); break;
                      case 4: image_left_spin(); break;
                      case 5: image_right_spin(); break;
                      case 6: image_next(-1); break;
                      case 7: image_next(1); break;
                    }
                    break;
    case GAME_MENU: {
                      strcpy(game_name, "game/");
                      strcat(game_name, file_list[file_list_point]);
                      into_game(game_name);
                      break;
                    }
    case GAME_START:switch(game_menu_point)
                    {
                      case 0: game_start(); break;
                      case 1: show_game_save(); break;
                      case 2: show_game_help(); break;
                      case 3: exit_game(); break;
                    }
                    break;
    case GAME_CLEAR:if(game_clear_point == 0)
                      clear_cancel();
                    else
                      clear_save();
                    break;
    case FILE_MENU: file_into(); break;
    case FILE_DELETE: if(file_delete_point == 0)
                        file_no_delete();
                      else
                        file_yes_delete();
                      break;
    case ABOUT_MENU:if(about_menu_point == 0)
                      into_help();
                    else
                      into_ap();
                    break;
    case ABOUT_HELP:show_help(about_help_point); break;
  }
}
示例#21
0
// -------------------------------------------------------------------
// Army touched the prison. Release prisoner
// -------------------------------------------------------------------
void t_adv_prison::activate_trigger( t_army* army, t_adv_map_point const& point, 
		                             t_direction direction, t_adventure_frame* frame )
{
	t_counted_ptr< t_adventure_map > map = frame->get_map();

	t_player* owner = army->get_owner();

	if (!owner) return;

	if (!owner->is_computer())
	{
		/*
		** Setup result dialog box.
		*/
		t_counted_ptr<t_basic_dialog> dialog_ptr = new t_basic_dialog ();
		std::string     text;

		text = replace_keywords( get_text("Initial"), m_hero.get() );

		dialog_ptr->set_text( text );
		dialog_ptr->add_ok_button();
		dialog_ptr->add_creature ( *m_hero, false );
		/*
		** Update frame.
		*/
		//frame->update_armies();
		frame->update();

		// Result dialog box.
		dialog_ptr->open();
		t_sound_cache music = get_music_playing();
		stop_music();
		get_dialog_sound( k_dialog_sound_thieves_guild )->play( get_sound_volume() );
		dialog_ptr->run_modal();
		play_music( music );
	}

    /*
    ** Add hero.  Add to creature array if possible.
    */
    if (army->get_creatures().can_add_hero())
    {
        army->get_creatures().add( m_hero ); //, 1 );
    }
    /*
    ** Or else create new army.
    */
    else	// TODO:  Should this be "else if ( player.can_create_army() )"? -- SCR 1/24/02
    {
	    t_army *		    temp_army = new t_army;
	    t_creature_array&   temp_creatures = temp_army->get_creatures();

        /*
        ** Create new army.
        ** Make army same color as player.
        */
	    temp_creatures.add ( m_hero );
	    temp_army->set_owner( army->get_owner_number() );
	    t_army * army = frame->create_army( this, temp_army, temp_army );

		army->trigger_events();
    }

    destroy();
}
示例#22
0
文件: combat.c 项目: rj76/kq
/*! \brief Really do combat once fighters have been inited
 *
 * \param   bg Background image
 * \param   mus Music
 * \param   is_rnd If !=0 then this is a random combat
 * \returns 1 if battle occurred
 */
static int do_combat (char *bg, char *mus, int is_rnd)
{
   int zoom_step;
   in_combat = 1;
   backart = load_datafile_object (PCX_DATAFILE, bg);
   if (is_rnd) {
      if ((numchrs == 1) && (pidx[0] == AYLA)) {
         hs = rand () % 100 + 1;
         ms = rand () % 3 + 1;
      } else {
         if (numchrs > 1 && (in_party (AYLA) > 0)) {
            hs = rand () % 20 + 1;
            ms = rand () % 5 + 1;
         } else {
            hs = rand () % 10 + 1;
            ms = rand () % 10 + 1;
         }
      }
   } else {
      hs = 10;
      ms = 10;
   }

   /*  RB: do the zoom at the beginning of the combat.  */
   pause_music ();
   set_music_volume ((gmvol / 250.0) * 0.75);
   play_music (mus, 0);
   if (stretch_view == 2) {
      do_transition (TRANS_FADE_OUT, 2);
      clear_bitmap (double_buffer);
      do_transition (TRANS_FADE_IN, 64);
   } else
      /* TT TODO:
       * Change this so when we zoom into the battle, it won't just zoom into the middle
       * of the screen.  Instead, it's going to zoom into the location where the player
       * is, so if he's on the side of the map somewhere...
       */
      for (zoom_step = 0; zoom_step < 9; zoom_step++) {
         poll_music ();

         /*  RB FIXME: stretching when 640x480, stretching when 320x240?  */
         /*            shouldn't one of those be the "common" size, and   */
         /*            therefore not needing to stretch it?               */
         /*            320x240 is the double_buffer size...               */
         if (stretch_view == 1)
            stretch_blit (double_buffer, screen, zoom_step * 16 + xofs,
                          zoom_step * 12 + yofs, 320 - (zoom_step * 32),
                          240 - (zoom_step * 24), 0, 0, 640, 480);

         else
            stretch_blit (double_buffer, screen, zoom_step * 16 + xofs,
                          zoom_step * 12 + yofs, 320 - (zoom_step * 32),
                          240 - (zoom_step * 24), 0, 0, 320, 240);

         /*  RB FIXME: should we vsync here rather than rest?  */
         kq_wait (100);
      }
   snap_togrid ();
   roll_initiative ();
   curx = 0;
   cury = 0;
   vspell = 0;
   combatend = 0;

   /*  RB: execute combat  */
   do_round ();
   unload_datafile_object (backart);
   set_music_volume (gmvol / 250.0);
   resume_music ();
   if (alldead)
      stop_music ();
   steps = 0;
   in_combat = 0;
   timer_count = 0;
   return (1);
}
示例#23
0
void soundLib::disable_sound() const
{
    game_config.sound_enabled = false;
	stop_music();
}
示例#24
0
文件: music.c 项目: DrItanium/moo
void music_idle_proc(
	void)
{
	if(music_state && music_state->initialized && music_state->state != _no_song_playing)
	{
		short ticks_elapsed= TickCount()-music_state->ticks_at_last_update;

		switch(music_state->state)
		{
			case _delaying_for_loop:
				if((music_state->phase-=ticks_elapsed)<=0)
				{
					/* Start playing.. */
					OSErr error;

					music_state->sound_buffer_size= kDefaultSoundBufferSize;
					music_state->sound_buffer= (Ptr)malloc(music_state->sound_buffer_size);
					if (music_state->sound_buffer)
					{
						assert(music_state->channel);					
	
						error= SndStartFilePlay(music_state->channel, // channel
							music_state->song_file_refnum, // Not from an AIFF file.
							0, // our resource id.
							music_state->sound_buffer_size, // Buffer size
							music_state->sound_buffer, // Let it allocate a buffer for us.
							NULL, // Audio selection ptr.
							music_state->completion_proc, // Completion proc
							TRUE); // Async.
						vwarn(error==noErr, csprintf(temporary, "SndStartFilePlay returned %d;g", error));
						if (!error) 
						{
							music_state->state= _playing_introduction;
						}
						else
						{
							music_state->state= _no_song_playing;
						}
					}
				}
				break;

			case _music_fading:
				if (ticks_elapsed>0)
				{
					if((music_state->phase-=ticks_elapsed)<=0 || (music_state->flags & _song_completed))
					{
						/* oops. we are done.. */
						stop_music();
						music_state->state= _no_song_playing;
						if(music_state->song_index != NONE)
						{
							/* Start the new song playing.. */
							queue_song(music_state->song_index);
						}
					} else {
						if(--music_state->fade_interval_ticks<=0)
						{
							short new_volume;
							SndCommand command;
							OSErr error;
							
							/* Only do this a few times.. */
							music_state->fade_interval_ticks= music_state->fade_interval_duration;
	
							/* Set the sound volume */
							new_volume= (0x100*music_state->phase)/music_state->fade_duration;

							/* set the sound volume */
							command.cmd= volumeCmd;
							command.param1= 0;
							command.param2= BUILD_STEREO_VOLUME(new_volume, new_volume);
							error= SndDoImmediate(music_state->channel, &command);
							vwarn(error==noErr, csprintf(temporary, "SndDoImmediate returned %d;g", error));
						}
					}
				}
				break;
			
			default:
				/* Don't change states until song_completed flag is set. */
				if(music_state->flags & _song_completed)
				{
					struct song_definition *song= get_song_definition(music_state->song_index);
					
					if(song->flags & _song_automatically_loops)
					{
						music_state->state= _delaying_for_loop;
						music_state->phase= song->restart_delay;
					} else {
						music_state->state= _no_song_playing;
					}
					music_state->flags &= ~_song_completed;
				}
				break;
		}
		music_state->ticks_at_last_update= TickCount();
	}

	return;
}
示例#25
0
int game(int type){
  int game_over = 0;
  {
    surface *background = new_image("background.png");
    apply_texture(background, window);
    destroy_surface(background);
  }
  initialize_cameras();initialize_star();initialize_ships(2);initialize_dust();
  initialize_shot();initialize_ai();
  play_music("music.ogg");
  draw_tank(0, (window_width / 2 - 421), window_height / 2 - 150);
  draw_tank(1, window_width / 2 + 401, window_height / 2 - 150);
    // Main loop
  for(;;){
    int i;
    get_input();
    if(keyboard[ESC] || game_over){
      break;
    }
    
    for(i = 0; i < 2; i ++)
      if(ship[i].status == DEAD){
	struct timeval now;
	gettimeofday(&now, NULL);
	if((int) (now.tv_sec - ship[i].time.tv_sec) > 2)
	  game_over = 1;
      }



    erase_ships();    
    erase_shot();     
    
    if(type != CPU_X_CPU){ // Rotation: 10 Propulse: 20 Fire: 20 Hyper: 180 
      int my_ship;
      // Player 1 moves
      if(type == CPU_X_PLR){
	ai_play(0);
	my_ship = 1;
      }
      else if(type == PLR_X_CPU){
	my_ship = 0;
	ai_play(1);
      }
      else
	my_ship = 0;
      if(keyboard[LEFT])
	rotate_ship(my_ship, LEFT); 
      if(keyboard[RIGHT])
	rotate_ship(my_ship, RIGHT);
      if(keyboard[UP])
	propulse_ship(my_ship);
      if(keyboard[DOWN])
	ship_fire(my_ship);
      if(keyboard[RIGHT_CTRL])
	goto_hyperspace(my_ship);
    }
    else{
      ai_play(0);
      ai_play(1);
    }

    if(type == PLR_X_PLR){ 
      // Player 2 moves
      if(keyboard[A])
	rotate_ship(1, LEFT);
      if(keyboard[D])
	rotate_ship(1, RIGHT);
      if(keyboard[W])
	propulse_ship(1);
      if(keyboard[L])
	blow_up(1);
      if(keyboard[S])
	ship_fire(1);
      if(keyboard[LEFT_CTRL])
	goto_hyperspace(1);
    }
    
    update_star(); // 6
    update_ships(); // 2
    update_dust(); // 145
    update_shot(); // 16
    film_ships(); // Até 16
    film_dust(); // 20
    film_shot(); // Até 20
    weaver_rest(10000000);
  }
  stop_music();
  destroy_star();
  destroy_ships();
  destroy_cameras();
  destroy_dust();
  destroy_shot();
  clean_keyboard();
  return 0;
}
示例#26
0
void t_game::initialize()
{
	t_window_ptr window;

	load_options();	

	//== writen by sunjun ==//
	// add_resource_file( "data/new.h4r" );
	// add_resource_file( "data/updates.h4r" );
	add_resource_file( "data/text.h4r" );
	add_resource_file( "data/music.h4r" );
	add_resource_file( "data/movies.h4r" );
	add_resource_folder( "data" );
	if (!add_resource_file( "data/heroes4.h4r" ))
	{
		fatal_error( "Unable to open data/heroes4.h4r" );
		exit(0);
	}

	t_pointer_cache< t_string_table > string_table_cache( "text" );
	t_pointer_cache< t_string_table > movie_string_table_cache( "intro voice over text" );
	t_pointer_cache< t_string_table > credits_string_table_cache( "credits" );

	t_external_string::add_table( *string_table_cache.get() );
	t_external_string::add_table( *movie_string_table_cache.get() );
	t_external_string::add_table( *credits_string_table_cache.get() );

	// this is a once-off shutdown for pre-release code
#ifdef k_useless_serialized_version
	fatal_error( k_text_serial_failure );
	exit(0);
#endif

	std::string cheat_text;

	if (get_command_line_argument( k_text_cheat_menu, cheat_text ))
	{		
		set_show_cheat_menus( true );
	}

	t_screen_point screen_size = get_desktop_size();

	m_frame_window = new t_gray_window(t_screen_rect(0, 0, g_window_width, g_window_height));

	t_mouse_window* cursor = new t_mouse_window;
	t_window*       animation = new t_animated_window( g_sample_cursor.get(), 
		                                               t_screen_point(0,0), 100, cursor );
	m_frame_window->set_cursor( cursor );
	
	set_resolution(g_window_width, g_window_height, false);

	initialize_platform();

	// Play the logo cinematics
	t_sound_cache music = get_music_playing();
	stop_music();

	play_music( music );

	t_main_menu* main_menu = new t_main_menu( m_frame_window );	
}
示例#27
0
static void
update_inner_state(void)
{
	static int prev_level_tics;

	inner_state.tics++;

	switch (inner_state.state) {
		case IS_WAVE_TITLE:
			if (inner_state.tics >= WAVE_TITLE_TICS) {
				set_inner_state(IS_IN_GAME);
				/* set_inner_state(IS_PRE_WAVE_CLEARED); */
			} else {
				if (inner_state.tics == WAVE_TITLE_TICS/2) {
					if (!ship.is_alive)
						spawn_new_ship();
					else
						reset_ship();
				}
			}
			break;

		case IS_IN_GAME:
			level_stat_counters.tics++;
			game_stat_counters.tics++;

			if (gc.tics_remaining <= 0) {
				/* boom. */
				hit_ship(&ship.pos, 1.f);
				trigger_game_over();
			} else {
				gc.tics_remaining--;

				if (!ship.is_alive) {
					prev_level_tics = inner_state.tics;
					set_inner_state(IS_RESPAWNING_SHIP);
				} else if (!gc.foes_left) {
					level_stat_counters.waves++;
					game_stat_counters.waves++;
					if (gc.tics_remaining > TIME_BONUS_MIN_TICS)
						gc.score += gc.tics_remaining*TIME_BONUS_PER_TIC;
					set_inner_state(IS_PRE_WAVE_CLEARED);
				} else {
					spawn_new_foes();
				}
			}
			break;

		case IS_PRE_WAVE_CLEARED:
			if (inner_state.tics >= PRE_WAVE_CLEARED_TICS) {
				gen_ship_implosion();
				reset_powerups();
				reset_missiles();
				reset_bombs();
				reset_lasers();
				vec2_set(&ship.pos, 0.f, 0.f); /* HACK */
				play_fx(FX_WAVE_TRANSITION);
				set_inner_state(IS_WAVE_CLEARED);
			}
			break;

		case IS_RESPAWNING_SHIP:
			if (inner_state.tics >= TICS_UNTIL_RESPAWN) {
				if (gc.ships_left) {
					spawn_new_ship();
					set_inner_state(IS_IN_GAME);
					inner_state.tics = prev_level_tics;
				} else {
					trigger_game_over();
				}
			}
			break;

		case IS_GAME_OVER:
			break;

		case IS_RANK:
			if (inner_state.tics >= RANK_TOTAL_TICS) {
				stop_music();

				if (is_highscore(gc.score)) {
					set_inner_state(IS_HIGHSCORE_INPUT);
					SDL_ShowCursor(SDL_ENABLE);
					start_highscore_input();
				} else {
					/* loser. */
					SDL_ShowCursor(SDL_ENABLE);
					start_main_menu();
				}
			}
			break;

		case IS_WAVE_CLEARED:
			if (gc.cur_wave == levels[gc.cur_level]->num_waves - 1 &&
				inner_state.tics >= WAVE_CLEARED_TICS/2) {
				initialize_stats_table(&level_stat_counters);
				set_inner_state(IS_LEVEL_CLEARED);
			} else if (inner_state.tics >= WAVE_CLEARED_TICS) {
				gc.cur_wave++;
				assert(gc.cur_wave < levels[gc.cur_level]->num_waves);
				reset_wave();
				set_inner_state(IS_WAVE_TITLE);
			}
			break;

		case IS_HIGHSCORE_INPUT:
			break;

		case IS_LEVEL_CLEARED:
			break;

		case IS_LEVEL_TRANSITION:
			if (inner_state.tics >= LEVEL_TRANSITION_TOTAL_TICS) {
				gc.cur_level = (gc.cur_level + 1)%NUM_LEVELS;
				set_inner_state(IS_WAVE_TITLE);
				reset_level();
			}
			break;

		default:
			assert(0);
	}
}
示例#28
0
void t_magic_university::activate_trigger( t_army* army, t_adv_map_point const& point,
        t_direction direction, t_adventure_frame* frame )
{
    int                  i;
    t_hero*              hero;
    std::vector<t_hero*> heroes;
    t_creature_array&    creatures = army->get_creatures();
    std::string          text;
    int                  random_skill_index = 0;

    if (army->get_owner_number() >= 0)
        m_visited[army->get_owner_number()] = true;
    else
        return; // A gray army shouldn't be here.

    // AI decider
    if (army->get_owner()->is_computer())
    {
        for (int i = 0; i < t_creature_array::k_size; i++)
        {
            t_hero* hero  = (*army)[i].get_hero();
            if (!hero) continue;

            t_skill_type type = get_best_compatible_skill( hero, army );
            while (type != k_skill_none)
            {
                hero->learn_skill(t_skill(type, k_mastery_basic), false );
                army->get_owner()->spend( k_gold, k_skill_upgrade_cost );
                type = get_best_compatible_skill( hero, army );
            }
        }
        return;
    }

    /*
    ** Check for eligible heroes.
    */
    bool                    dead_heroes = true;
    bool                    any_heroes = false;
    for (i = 0; i < t_creature_array::k_size; i++)
    {
        hero = creatures[i].get_hero();

        // Hero or not?
        if (hero == 0)
            continue;

        any_heroes = true;

        if (hero->is_dead())
            continue;
        dead_heroes = false;

        heroes.push_back( hero );
    }

    t_sound_cache music = get_music_playing();
    stop_music();
    get_dialog_sound( k_dialog_sound_university )->play( get_sound_volume() );
    std::string status_text;
    if (any_heroes && (dead_heroes == true))
    {
        status_text = get_text("heroes_dead");
        if (status_text == "")
            status_text = k_text_dead_heroes_ineligible;
        ok_dialog( status_text, get_dialog_bottom( point ) );
        play_music( music );
        return;
    }
    // No heroes, show app. message...
    else if (!any_heroes)
    {
        status_text = get_text ("help.empty");
        ok_dialog( status_text, get_dialog_bottom( point ) );
        play_music( music );
        return;
    }

    select_heroes_dialog ( heroes, frame, army);
    play_music( music );
}