Esempio n. 1
0
bool System::initSharedSystem()
{
  if (!al_is_system_installed())
    {
      assert(al_init() && "Failed to initialize Allegro.");
      assert(al_inhibit_screensaver(true) && "Failed to inhibit screensaver.");
    
      al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_GENERATE_EXPOSE_EVENTS | ALLEGRO_OPENGL_FORWARD_COMPATIBLE | ALLEGRO_OPENGL);
      al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP | ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
    }
  if (!al_init_image_addon())
    {
      std::cerr << "Failed to initialize image addon" << std::endl;
      return false;
    }
  if (!al_install_keyboard())
    {
      std::cerr << "Failed to install keyboard" << std::endl;
      return false;
    }
  if (!al_install_mouse())
    {
      std::cerr << "Failed to install mouse" << std::endl;
      return false;
    }
  if (!al_install_joystick())
    {
      std::cerr << "Failed to install joystick" << std::endl;
      return false;
    }

  return true;
}
Esempio n. 2
0
bool Framework::initialize(std::string config_filename)
{
   if (initialized) return initialized;

   if (!al_init()) std::cerr << "al_init() failed" << std::endl;

   ALLEGRO_PATH *resource_path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
   al_change_directory(al_path_cstr(resource_path, ALLEGRO_NATIVE_PATH_SEP));
   al_destroy_path(resource_path);

   if (!al_install_mouse()) std::cerr << "al_install_mouse() failed" << std::endl;
   if (!al_install_keyboard()) std::cerr << "al_install_keyboard() failed" << std::endl;
   if (!al_install_joystick()) std::cerr << "al_install_joystick() failed" << std::endl;
   if (!al_install_audio()) std::cerr << "al_install_audio() failed" << std::endl;

   if (!al_init_native_dialog_addon()) std::cerr << "al_init_native_dialog_addon() failed" << std::endl;
   if (!al_init_primitives_addon()) std::cerr << "al_init_primitives_addon() failed" << std::endl;
   if (!al_init_image_addon()) std::cerr << "al_init_image_addon() failed" << std::endl;
   if (!al_init_font_addon()) std::cerr << "al_init_font_addon() failed" << std::endl;
   if (!al_init_ttf_addon()) std::cerr << "al_init_ttf_addon() failed" << std::endl;
   if (!al_init_acodec_addon()) std::cerr << "al_init_acodec_addon() failed" << std::endl;

   if (!al_reserve_samples(32)) std::cerr << "al_reserve_samples() failed" << std::endl;

   srand(time(NULL));

   primary_timer = al_create_timer(ALLEGRO_BPS_TO_SECS(60));

   al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
   //	al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR | ALLEGRO_MIPMAP);

   builtin_font = al_create_builtin_font();

   event_queue = al_create_event_queue();
   al_register_event_source(event_queue, al_get_keyboard_event_source());
   al_register_event_source(event_queue, al_get_mouse_event_source());
   al_register_event_source(event_queue, al_get_joystick_event_source());
   al_register_event_source(event_queue, al_get_timer_event_source(primary_timer));
   al_register_event_source(event_queue, al_get_joystick_event_source());
   al_register_event_source(event_queue, al_get_default_menu_event_source());

   if (al_get_num_joysticks()) joystick = al_get_joystick(0); // make this better eventually
   else std::cerr << "no joystick(s) detected" << std::endl;

   instance = new Framework(config_filename);

   Attributes::create_datatype_definition(
      AllegroColorAttributeDatatype::IDENTIFIER,
      AllegroColorAttributeDatatype::to_val_func,
      AllegroColorAttributeDatatype::to_str_func
   );

   initialized = true;

   return true;
}
Esempio n. 3
0
void init_allegro() {
    al_init();
    al_install_mouse();
    al_install_keyboard();
    al_install_audio();
    al_install_joystick();
    al_init_image_addon();
    al_init_primitives_addon();
    al_init_acodec_addon();
}
Esempio n. 4
0
// Sets up game
void setup(){
  // Init allegro 5
  al_init();

  // Input
  al_install_keyboard();
  al_install_mouse();
  al_install_joystick();

  // Fonts
  al_init_font_addon();
  al_init_ttf_addon();

  // Graphics
  al_init_image_addon();
  al_init_primitives_addon();

  // Audio
  al_install_audio();
  al_init_acodec_addon();
  al_reserve_samples( 20);

  // Initializing
  timer = al_create_timer(1.0 / MAX_FPS);
  display = al_create_display( SCREEN_W, SCREEN_H);

  // Events
  event_queue = al_create_event_queue();
  al_register_event_source( event_queue, al_get_display_event_source(display));
  al_register_event_source( event_queue, al_get_timer_event_source(timer));
  al_register_event_source( event_queue, al_get_keyboard_event_source());
  al_register_event_source( event_queue, al_get_joystick_event_source());

  al_clear_to_color( al_map_rgb(0,0,0));
  al_flip_display();
  al_start_timer(timer);

  // Creates a random number generator (based on time)
  srand( time(nullptr));

  // Game state
  stateID = STATE_NULL;
  nextState = STATE_NULL;

  // Clear settings
  for( int i = 0; i < 11; i++)
    settings[i] = false;

  // Clear frams array
  for( int i = 0; i < 100; i++)
    frames_array[i] = 0;
}
Esempio n. 5
0
void BaseGame::initModules()
{
	al_init_font_addon();
	if(!(al_init_ttf_addon() &&
		al_init_primitives_addon() &&
		al_init_image_addon() &&
		al_init_acodec_addon() &&
		al_install_keyboard() &&
		al_install_mouse() &&
		al_install_audio() &&
		al_install_joystick()))
	{
		al_show_native_message_box(display, "Error!", "ERROR 42 (0x2a)",
			"Error while loading allegro modules. Please contact distributor and inform them of this error.", NULL, 0);
		exit(42);
	}
}
Esempio n. 6
0
int main(int argc __attribute__((unused)), char *argv[])
{

    /* init allegro library */
    ALLEGRO_TIMER *timer = NULL;
    al_init();

    /* prepare random number generator */
    srand(time(NULL));

    /* activate all engine subsystems using the startup macro */
    resetCollisionTable();
    STARTUP(videoInit())
    STARTUP(init_datafile(argv))
    STARTUP(al_install_keyboard())
    STARTUP(al_install_joystick())
    STARTUP(fontInit())
    STARTUP(setupSound())
    timer = al_create_timer(1.0 / 60);
    al_start_timer(timer);
    initMediaLib();
    initBuffers();

    /* prepare game */
    startGame();

    /* begin game loop */
    while(!state.terminate) {
        runState(timer);
    }

    /* finish, return control to os */
    al_destroy_timer(timer);
    shutdownState();
    shutdownGame();
    videoKill();
    shutdownSound();
    al_uninstall_system();
    PHYSFS_deinit();

    /* no problems, exit false */
    return EXIT_SUCCESS;

}
Esempio n. 7
0
int main(void)
{
    ALLEGRO_DISPLAY *display;

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

    display = al_create_display(640, 480);
    if (!display) {
        abort_example("al_create_display failed\n");
        return 1;
    }

    al_install_keyboard();

    black = al_map_rgb(0, 0, 0);
    grey = al_map_rgb(0xe0, 0xe0, 0xe0);
    white = al_map_rgb(255, 255, 255);

    al_install_joystick();

    event_queue = al_create_event_queue();
    if (!event_queue) {
        abort_example("al_create_event_queue failed\n");
        return 1;
    }

    if (al_get_keyboard_event_source()) {
        al_register_event_source(event_queue, al_get_keyboard_event_source());
    }
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_joystick_event_source());

    setup_joystick_values(al_get_joystick(0));

    main_loop();

    return 0;
}
Esempio n. 8
0
void    Inputs_Joystick_Init(void)
{
    int     i;
    int     num_joy;
    bool    found = FALSE;

    for (i = 0; i < Inputs.Sources_Max; i++)
    {
        t_input_src *src = Inputs.Sources[i];
        if (src->type == INPUT_SRC_TYPE_JOYPAD)
        {
            found = TRUE;
            break;
        }
    }
    if (found == FALSE)
        return;

    // There is at least one joypad so we'll launch initialization
    ConsolePrint(Msg_Get(MSG_Inputs_Joy_Init));

    if (!al_install_joystick() || ((num_joy = al_get_num_joysticks()) == 0))
    {
        ConsolePrint(Msg_Get(MSG_Inputs_Joy_Init_None));
		ConsolePrint("\n");
        return;
    }
    ConsolePrintf (Msg_Get(MSG_Inputs_Joy_Init_Found), num_joy);
    ConsolePrint("\n");

    // Flag available devices "connected and ready"
    for (i = 0; i < Inputs.Sources_Max; i++)
    {
        t_input_src *src = Inputs.Sources[i];
        if (src->type == INPUT_SRC_TYPE_JOYPAD)
            if (src->Connection_Port < num_joy)
                src->Connected_and_Ready = TRUE;
    }
}
  bool					init()
  {
    if (!al_install_keyboard())
      return false;
    if (!al_install_mouse())
      return false;
    this->event_queue_ = al_create_event_queue();
    if (!this->event_queue_)
      return false;
    this->timer_ = al_create_timer(1.0f / 120.0f);
    if (!this->timer_)
      return false;
    if (!al_install_joystick())
      return false;
    al_register_event_source(this->event_queue_, al_get_keyboard_event_source());
    // al_register_event_source(this->event_queue_, al_get_joystick_event_source());
    al_register_event_source(this->event_queue_, al_get_mouse_event_source());
    al_register_event_source(this->event_queue_, al_get_display_event_source(al_get_current_display()));
    al_register_event_source(this->event_queue_, al_get_timer_event_source(this->timer_));
    al_start_timer(this->timer_);

    return true;
  }
Esempio n. 10
0
bool AllegroInput5::Init( bool keyboard, bool mouse, bool gamepad, bool touch )
{
	// There is a slight confusion about these flags. For now, they do not GUARANTEE that a given input method is available!
	// They only indicate that al_intall_*() call was successfull, with the exception of m_hadGamepad, that also checks that
	// at least one joystick is available. This is not quite right, but it's mostly relevant for mobile devies, so I'll fix
	// this later :)
	m_hasKeyboard = keyboard;
	m_hasMouse = mouse;
	m_hasGamepad = gamepad;
	m_hasTouch = touch;

	m_queue = al_create_event_queue();

	if ( keyboard )
	{
		if ( !al_install_keyboard() )
		{
			GetLog().Log( CommonLog(), LL_CRITICAL, "AllegroInput: Failed to install keyboard driver" );
			m_hasKeyboard = false;
		}
		else
		{
			GetLog().Log( CommonLog(), LL_INFO, "AllegroInput: Installed keyboard driver" );
			al_register_event_source( m_queue, al_get_keyboard_event_source() );
		}
	}

	if ( mouse )
	{
		if ( !al_install_mouse() )
		{
			GetLog().Log( CommonLog(), LL_CRITICAL, "AllegroInput: Failed to install mouse driver" );
			m_hasMouse = false;
		}
		else
		{
			GetLog().Log( CommonLog(), LL_INFO, "AllegroInput: Installed mouse driver" );		
			al_register_event_source( m_queue, al_get_mouse_event_source() );
		}
	}

	if ( gamepad )
	{
		if ( !al_install_joystick() )
		{
			GetLog().Log( CommonLog(), LL_CRITICAL, "AllegroInput: Failed to install gamepad driver" );
			m_hasGamepad = false;
		}
		else
		{
			 // Note: only the first joystick is supported. This should be fixed. Sometime.
			ALLEGRO_JOYSTICK *pJoystick = al_get_joystick( 0 );
			if ( !pJoystick )
			{
				GetLog().Log( CommonLog(), LL_CRITICAL, "AllegroInput: Joystick #0 not found" );
				m_hasGamepad = false;
			}
			else
			{
				GetLog().Log( CommonLog(), LL_INFO, "AllegroInput: Installed gamepad driver" );
				al_register_event_source( m_queue, al_get_joystick_event_source() );
			}
		}
	}

	if ( touch )
	{
		if ( !al_install_touch_input() )
		{
			GetLog().Log( CommonLog(), LL_CRITICAL, "AllegroInput: Failed to install touch input driver" );
			m_hasTouch = false;
		}
		else
		{
			GetLog().Log( CommonLog(), LL_INFO, "AllegroInput: Installed touch input driver" );
			al_register_event_source( m_queue, al_get_touch_input_event_source() );
		}
	}

	return true;
}
Esempio n. 11
0
/* the main program body */
int main(int argc, char *argv[])
{
   ALLEGRO_PATH *font_path;
   int w = 0, h = 0;
   int www = FALSE;
   int i, n;
   int display_flags = ALLEGRO_GENERATE_EXPOSE_EVENTS;

   srand(time(NULL));
   
   al_set_org_name("liballeg.org");
   al_set_app_name("SPEED");

   if (!al_init()) {
      fprintf(stderr, "Could not initialise Allegro.\n");
      return 1;
   }
   al_init_primitives_addon();

   /* parse the commandline */
   for (i=1; i<argc; i++) {
      if (strcmp(argv[i], "-cheat") == 0) {
         cheat = TRUE;
      }
      else if (strcmp(argv[i], "-simple") == 0) {
         low_detail = TRUE;
      }
      else if (strcmp(argv[i], "-nogrid") == 0) {
         no_grid = TRUE;
      }
      else if (strcmp(argv[i], "-nomusic") == 0) {
         no_music = TRUE;
      }
      else if (strcmp(argv[i], "-www") == 0) {
         www = TRUE;
      }
      else if (strcmp(argv[i], "-fullscreen") == 0) {
         /* if no width is specified, assume fullscreen_window */
         display_flags |= w ? ALLEGRO_FULLSCREEN : ALLEGRO_FULLSCREEN_WINDOW;
      }
      else {
         n = atoi(argv[i]);

         if (!n) {
            usage();
            return 1;
         }

         if (!w) {
            w = n;
            if (display_flags & ALLEGRO_FULLSCREEN_WINDOW) {
               /* toggle from fullscreen_window to fullscreen */
               display_flags &= ~ALLEGRO_FULLSCREEN_WINDOW;
               display_flags |= ALLEGRO_FULLSCREEN;
            }
         }
         else if (!h) {
            h = n;
         }
         else {
            usage();
            return 1;
         }
      }
   }

   /* it's a real shame that I had to take this out! */
   if (www) {
      printf(
	 "\n"
	 "Unfortunately the built-in web browser feature had to be removed.\n"
	 "\n"
	 "I did get it more or less working as of Saturday evening (forms and\n"
	 "Java were unsupported, but tables and images were mostly rendering ok),\n"
	 "but the US Department of Justice felt that this was an unacceptable\n"
	 "monopolistic attempt to tie in web browsing functionality to an\n"
	 "unrelated product, so they threatened me with being sniped at from\n"
	 "the top of tall buildings by guys with high powered rifles unless I\n"
	 "agreed to disable this code.\n"
	 "\n"
	 "We apologise for any inconvenience that this may cause you.\n"
      );

      return 1;
   }
   
   if (!w || !h) {
      if (argc == 1 || (display_flags & ALLEGRO_FULLSCREEN_WINDOW)) {
         w = 640;
         h = 480;
      }
      else {
         usage();
         return 1;
      }
   }

   /* set the screen mode */
   al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
   al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);

   al_set_new_display_flags(display_flags);
   screen = al_create_display(w, h);
   if (!screen) {
      fprintf(stderr, "Error setting %dx%d display mode\n", w, h);
      return 1;
   }

   al_init_image_addon();

   /* The Allegro 5 port introduced an external data dependency, sorry.
    * To avoid performance problems on graphics drivers that don't support
    * drawing to textures, we build up transition screens on memory bitmaps.
    * We need a font loaded into a memory bitmap for those, then a font
    * loaded into a video bitmap for the game view. Blech!
    */
   font_path = get_resources_path();
   al_set_path_filename(font_path, "a4_font.tga");

   al_init_font_addon();
   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   font = al_load_bitmap_font(al_path_cstr(font_path, '/'));
   if (!font) {
      fprintf(stderr, "Error loading %s\n", al_path_cstr(font_path, '/'));
      return 1;
   }

   al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
   font_video = al_load_bitmap_font(al_path_cstr(font_path, '/'));
   if (!font_video) {
      fprintf(stderr, "Error loading %s\n", al_path_cstr(font_path, '/'));
      return 1;
   }
   
   al_destroy_path(font_path);

   /* set up everything else */
   al_install_keyboard();
   al_install_joystick();
   if (al_install_audio()) {
      if (!al_reserve_samples(8))
         al_uninstall_audio();
   }

   init_input();
   init_sound();
   init_hiscore();

   /* the main program body */
   while (title_screen()) {
      if (play_game()) {
	 show_results();
	 score_table();
      }
   }

   /* time to go away now */
   shutdown_hiscore();
   shutdown_sound();

   goodbye();

   shutdown_input();

   al_destroy_font(font);
   al_destroy_font(font_video);

   return 0;
}
Esempio n. 12
0
//install de le controlleur avec la commande allegro
bool xc_install()
{
	return al_install_joystick();
}
Esempio n. 13
0
Framework::Framework()
{
#ifdef WRITE_LOG
  printf( "Framework: Startup\n" );
#endif

  // Init Allegro
	if( !al_init() )
	{
		return;
	}
	al_init_font_addon();
	if( !al_install_keyboard() || !al_install_mouse() || !al_init_primitives_addon() || !al_init_ttf_addon() || !al_init_image_addon() )
	{
		return;
	}
	if( al_install_joystick() )
  {
    al_reconfigure_joysticks();
  }

  audioInitialised = false;
  InitialiseAudioSystem();

  std::string selectedLanguage;
  quitProgram = false;
  ProgramStages = new StageStack();
  framesToProcess = 0;
  Settings = new ConfigFile( "settings.cfg" );

  eventQueue = al_create_event_queue();

  InitialiseDisplay();

	al_register_event_source( eventQueue, al_get_keyboard_event_source() );
	al_register_event_source( eventQueue, al_get_mouse_event_source() );

	fpsTimer = al_create_timer( 1.0 / (float)FRAMES_PER_SECOND );
	al_register_event_source( eventQueue, al_get_timer_event_source( fpsTimer ) );
	al_start_timer( fpsTimer );

	al_hide_mouse_cursor( displaySurface );


  imageMgr = new ImageManager( this );
  fontMgr = new FontManager( this );
  audioMgr = new AudioManager( this );
  int maxDownloads = 4;
  if( Settings->KeyExists( "Downloads.MaxConcurrentDownloads" ) )
  {
    Settings->GetIntegerValue( "Downloads.MaxConcurrentDownloads", &maxDownloads );
  }
  downloadMgr = new DownloadManager( this, maxDownloads );
  networkMgr = new NetworkManager( this );
  languageMgr = new LanguageManager();
  if( Settings->KeyExists( "Application.Language" ) )
  {
    Settings->GetStringValue( "Application.Language", &selectedLanguage );
    languageMgr->SetActiveLanguage( selectedLanguage );
  }

  NativePlatform = new Platform();

  SystemFramework = this;

  extraEventsMutex = al_create_mutex();
}
int main(int argc, char **argv)
{
   int num_joysticks;
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_JOYSTICK *curr_joy;
   ALLEGRO_DISPLAY *display;

   (void)argc;
   (void)argv;

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

   open_log();

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

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_joystick_event_source());
   al_register_event_source(queue, al_get_display_event_source(display));

   num_joysticks = al_get_num_joysticks();
   log_printf("Num joysticks: %d\n", num_joysticks);

   if (num_joysticks > 0) {
      curr_joy = al_get_joystick(0);
      print_joystick_info(curr_joy);
   }
   else {
      curr_joy = NULL;
   }

   draw(curr_joy);

   while (1) {
      ALLEGRO_EVENT event;
      al_wait_for_event(queue, &event);
      if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
            event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
         break;
      }
      else if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
         break;
      }
      else if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
         int n = event.keyboard.unichar - '0';
         if (n >= 0 && n < num_joysticks) {
            curr_joy = al_get_joystick(n);
            log_printf("switching to joystick %d\n", n);
            print_joystick_info(curr_joy);
         }
      }
      else if (event.type == ALLEGRO_EVENT_JOYSTICK_CONFIGURATION) {
         al_reconfigure_joysticks();
         num_joysticks = al_get_num_joysticks();
         log_printf("after reconfiguration num joysticks = %d\n",
            num_joysticks);
         if (curr_joy) {
            log_printf("current joystick is: %s\n",
               al_get_joystick_active(curr_joy) ? "active" : "inactive");
         }
         curr_joy = al_get_joystick(0);
      }
      else if (event.type == ALLEGRO_EVENT_JOYSTICK_AXIS) {
         log_printf("axis event from %p, stick %d, axis %d\n", event.joystick.id, event.joystick.stick, event.joystick.axis);
      }
      else if (event.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN) {
         log_printf("button down event %d from %p\n",
            event.joystick.button, event.joystick.id);
      } 
      else if (event.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_UP) {
         log_printf("button up event %d from %p\n",
            event.joystick.button, event.joystick.id);
      } 

      draw(curr_joy);
   }

   close_log(false);

   return 0;
}
Esempio n. 15
0
Framework::Framework( int Width, int Height, int Framerate, bool DropFrames )
{
	System = this;

#ifdef WRITE_LOG
	LogFile = fopen( "sjkt.txt", "a" );
	
	fprintf( LogFile, "Framework: Startup: Allegro\n" );
#endif

	if( !al_init() )
	{
		fprintf( LogFile, "Framework: Error: Cannot init Allegro\n" );
		quitProgram = true;
		return;
	}
	
	al_init_font_addon();
	if( !al_install_keyboard() || !al_install_mouse() || !al_install_joystick() || !al_init_primitives_addon() || !al_init_ttf_addon() || !al_init_image_addon() )
	{
		fprintf( LogFile, "Framework: Error: Cannot init Allegro plugin\n" );
		quitProgram = true;
		return;
	}

#ifdef NETWORK_SUPPORT
#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Network\n" );
#endif
	if( enet_initialize() != 0 )
	{
		fprintf( LogFile, "Framework: Error: Cannot init enet\n" );
		quitProgram = true;
		return;
	}
#endif

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Default Variables\n" );
#endif
	quitProgram = false;
  ProgramStages = new StageStack();
  framesToProcess = 0;
	framesPerSecond = Framerate;
	enableSlowDown = DropFrames;

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Settings file\n" );
#endif
  Settings = new ConfigFile( "settings.cfg" );


#ifdef DOWNLOAD_SUPPORT
#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Download Manager\n" );
#endif
	DOWNLOADS = new DownloadManager( Settings->GetQuickIntegerValue( "Downloads.Concurrent", 3 ) );
#endif

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Allegro Events\n" );
#endif
	eventAllegro = al_create_event_queue();
	eventMutex = al_create_mutex_recursive();
	frameTimer = al_create_timer( 1.0 / (double)framesPerSecond );

	srand( (unsigned int)al_get_time() );

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Display\n" );
#endif
	DISPLAY = new Display( Width, Height );
	DISPLAY->Initialise( Settings->GetQuickIntegerValue( "Video.Width", Width ), Settings->GetQuickIntegerValue( "Video.Height", Height ), Settings->GetQuickBooleanValue( "Video.Fullscreen", false ), (DisplayScaleMode::ScaleMode)Settings->GetQuickIntegerValue( "Video.ScaleMode", DisplayScaleMode::Letterbox ) );
	AUDIO = new Audio();

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Register event sources\n" );
#endif
	RegisterEventSource( DISPLAY->GetEventSource() );
	RegisterEventSource( al_get_keyboard_event_source() );
	RegisterEventSource( al_get_mouse_event_source() );
	RegisterEventSource( al_get_joystick_event_source() );
	RegisterEventSource( al_get_timer_event_source( frameTimer ) );

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Joystick IDs\n" );
#endif
	GetJoystickIDs();
}
Esempio n. 16
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;
}