예제 #1
0
파일: skin.cpp 프로젝트: bambams/ma5king
////////////////////////////////////////////////////////////////////////////////
// A helper function for loading an Allegro dat file where bitmaps are
// supposed to be stored.
MAS::Error MAS::Skin::LoadData(ALLEGRO_PATH *dir, ALLEGRO_CONFIG *config) {
   if (!dir || !al_is_path_present(dir) || !al_get_path_filename(dir)) {
      return Error(Error::SKIN_DAT);
   }

   // load the datafile
   int i;
   char tmp[256];
   const char *str;

   // Look for each bitmap inside and load it if it exists
   for (i=0; i<nBitmaps; i++) {
      al_set_path_filename(dir, bitmapName[i]);
	  al_set_path_extension(dir, ".png");
      const char *fullPath = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP);
      Bitmap bmp;
      if (bmp.Load(fullPath, Bitmap::MEMORY) == Error::NONE) {
         bmpList[i]->Set(bmp, true, MAS::Settings::useVideoMemory ? Bitmap::VIDEO : Bitmap::MEMORY);

         snprintf(tmp, 256, "%s_TCKX", bitmapName[i]);
         bmpList[i]->ThickX((str = al_get_config_value(config, "TILING", tmp)) ? strtol(str, NULL, 10) : -1);
         snprintf(tmp, 256, "%s_TCKY", bitmapName[i]);
         bmpList[i]->ThickY((str = al_get_config_value(config, "TILING", tmp)) ? strtol(str, NULL, 10) : -1);
      }
   }

   al_set_path_filename(dir, "");

   return Error(Error::NONE);
}
예제 #2
0
파일: skin.cpp 프로젝트: bambams/ma5king
////////////////////////////////////////////////////////////////////////////////
// A helper function for loading an Allegro dat file where samples are
// supposed to be stored.
MAS::Error MAS::Skin::LoadSamples(ALLEGRO_PATH *dir) {
   if (!dir || !al_is_path_present(dir))
      return Error(Error::NO_FILE);

   int i;

   const char *sampleName[] = {
      "SAMPLE_ACTIVATE",
      "SAMPLE_CLOSE",
      "SAMPLE_GOTFOCUS",
      "SAMPLE_KEY",
      "SAMPLE_LOSTFOCUS",
      "SAMPLE_OPEN",
      "SAMPLE_SCROLL"
   };

   // Look for each sample inside the dat file and load it if it exists
   for (i=0; i<nSamples; i++) {
      al_set_path_filename(dir, sampleName[i]);
	  al_set_path_extension(dir, ".wav");
      const char *fullPath = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP);
      Sample spl;
      if (spl.Load(fullPath) == Error::NONE) {
         smpList[i]->Set(spl, true);
      }
   }

   al_set_path_filename(dir, "");

   return Error(Error::NONE);
}
예제 #3
0
파일: skin.cpp 프로젝트: bambams/ma5king
////////////////////////////////////////////////////////////////////////////////
// A helper function for loading an Allegro dat file where cursors are
// supposed to be stored.
MAS::Error MAS::Skin::LoadCursors(ALLEGRO_PATH *dir, ALLEGRO_CONFIG *config) {
   if (!dir || !al_is_path_present(dir)) {
      return Error(Error::NO_FILE);
   }

   MAS::Cursor::ReadSkinData(config);

   al_set_path_filename(dir, al_get_path_component(dir, -1));
   al_set_path_extension(dir, ".ini");
   const char *config_path_t = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP);
   ALLEGRO_CONFIG *mouse_config = al_load_config_file(config_path_t);

   int i;
   char tmp[256];
   char *config_path = strdup(config_path_t);
   int x, y, frames, interval;
   const char *str;

   // Look for each bitmap inside the dat file and load it if it exists
   for (i=0; i<nCursors; i++) {
      al_set_path_filename(dir, cursorName[i]);
      al_set_path_extension(dir, ".png");
      const char *fullPath = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP);
      Bitmap bmp;
      if (bmp.Load(fullPath, Bitmap::MEMORY) == Error::NONE) {
         snprintf(tmp, 256, "%s_FCSX", cursorName[i]);
         x = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 0;

         snprintf(tmp, 256, "%s_FCSY", cursorName[i]);
         y = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 0;

         snprintf(tmp, 256, "%s_FRMS", cursorName[i]);
         frames = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 1;

         snprintf(tmp, 256, "%s_FDUR", cursorName[i]);
         interval = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 20;

         curList[i]->Create(bmp, frames);
         curList[i]->SetFocus(x, y);
         curList[i]->SetAnimationInterval(interval);
      }
   }

   al_set_path_filename(dir, "");
   free(config_path);
   al_destroy_config(mouse_config);

   return Error(Error::NONE);
}
예제 #4
0
파일: system.c 프로젝트: liballeg/allegro5
static void read_allegro_cfg(void)
{
   /* We assume that the stdio file interface is in effect. */

   ALLEGRO_PATH *path;
   ALLEGRO_CONFIG *temp;

   if (!sys_config)
      sys_config = al_create_config();

#if defined(ALLEGRO_UNIX) && !defined(ALLEGRO_IPHONE)
   temp = al_load_config_file("/etc/allegro5rc");
   if (temp) {
      al_merge_config_into(sys_config, temp);
      al_destroy_config(temp);
   }

   path = _al_unix_get_path(ALLEGRO_USER_HOME_PATH);
   if (path) {
      al_set_path_filename(path, "allegro5rc");
      temp = al_load_config_file(al_path_cstr(path, '/'));
      if (temp) {
         al_merge_config_into(sys_config, temp);
         al_destroy_config(temp);
      }
      al_set_path_filename(path, ".allegro5rc");
      temp = al_load_config_file(al_path_cstr(path, '/'));
      if (temp) {
         al_merge_config_into(sys_config, temp);
         al_destroy_config(temp);
      }
      al_destroy_path(path);
   }
#endif

   path = early_get_exename_path();
   if (path) {
      al_set_path_filename(path, "allegro5.cfg");
      temp = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
      if (temp) {
         al_merge_config_into(sys_config, temp);
         al_destroy_config(temp);
      }
      al_destroy_path(path);
   }
   /* Reconfigure logging in case something changed. */
   _al_configure_logging();
}
예제 #5
0
bool Message::Init()
{
	ALLEGRO_PATH * pPath = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
	al_append_path_component(pPath, "graphics");
    al_append_path_component(pPath, "Avatar");

    for (int i=0;i<7;i++)
	{
		char szFileName[255];
		sprintf(szFileName,"av%03d.png",i);
		al_set_path_filename(pPath,szFileName);
        ALLEGRO_BITMAP * pBitmap = al_load_bitmap(al_path_cstr(pPath,ALLEGRO_NATIVE_PATH_SEP));
	    if (pBitmap!=NULL)
	    {
	        g_lstAvatar.push_back(pBitmap);
	    }
	    else
	    {
            al_destroy_path(pPath);
            return false;
	    }
	}

	al_destroy_path(pPath);
	return true;
}
예제 #6
0
static void read_scores(void)
{
   ALLEGRO_PATH *fn = userResourcePath();

   if (al_make_directory(al_path_cstr(fn, ALLEGRO_NATIVE_PATH_SEP))) {
      al_set_path_filename(fn, "scores.cfg");
      ALLEGRO_CONFIG *cfg = al_load_config_file(al_path_cstr(fn, ALLEGRO_NATIVE_PATH_SEP));
      if (cfg) {
         for (int i = 0; i < NUM_SCORES; i++) {
            char name[]  = {'n', (char)('0'+i), '\0'};
            char score[] = {'s', (char)('0'+i), '\0'};
            const char *v;

            v = al_get_config_value(cfg, "scores", name);
            if (v && strlen(v) <= 3) {
               strcpy(highScores[i].name, v);
            }
            v = al_get_config_value(cfg, "scores", score);
            if (v) {
               highScores[i].score = atoi(v);
            }
         }

         al_destroy_config(cfg);
      }
   }

   al_destroy_path(fn);
}
예제 #7
0
파일: path.c 프로젝트: trezker/allua
static int allua_Path_set_filename(lua_State * L)
{
   ALLUA_path path = allua_check_path(L, 1);
   const char *s = luaL_checkstring(L, 2);

   al_set_path_filename(path, s);

   return 0;
}
예제 #8
0
파일: map.cpp 프로젝트: faod/ld33
Tileset::Tileset(const char* filename)
{
    ALLEGRO_PATH *path;

    path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(path, RESOURCES_DIR);
    al_set_path_filename(path, filename);
    spritesheet_ = al_load_bitmap(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));

    al_destroy_path(path);
}
예제 #9
0
static char* test_level_write_to_file()
{
    char* level_name = "test-write.world";

    ALLEGRO_PATH* path = al_create_path(FILES_ASSETS_PATH);
    al_append_path_component(path, FILES_LEVELS_SUBDIRNAME);
    al_set_path_filename(path, level_name);
    const char* filename = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);

    // create new test level
    Level* level_new = level_alloc_empty(LEVEL_TEST_WIDTH, LEVEL_TEST_HEIGHT);
    level_new->cells[3][4] = cell_init(UNIT_1, OWNER_HUMAN, 3, 4);

    // write level to file
    level_write_to_file(level_new, filename);
    level_free(level_new);

    // read level from file 
    // (this function is assumed to work correctly
    // because it has been tested earlier)
    Level* level = level_alloc_read_from_file(filename);

    // test if level was correctly written
    mu_assert(level != NULL);
    mu_assert(level->width == LEVEL_TEST_WIDTH);
    mu_assert(level->height == LEVEL_TEST_HEIGHT);

    // test if cells were correctly written
    int i;
    int j;
    for (i = 0; i < level->height; i++) // rows
    {
        for (j = 0; j < level->width; j++) // cols
        {
            mu_assert(level->cells[i][j].row == i);
            mu_assert(level->cells[i][j].col == j);
        }
    }

    mu_assert(level->cells[0][0].type == GROUND);
    mu_assert(level->cells[0][0].owner == OWNER_NONE);
    mu_assert(level->cells[3][4].type == UNIT_1);
    mu_assert(level->cells[3][4].owner == OWNER_HUMAN);

    al_destroy_path(path);
    level_free(level);

    return NULL;
}
예제 #10
0
BolsaDinero * BolsaDinero::crear_bolsa_dinero(ActorManager *actmgr,int mov_to_dead)
{
	  ALLEGRO_BITMAP *bmp;
	  MapaDeBits 	 *bitm;
	  BolsaDinero	 *bolsa_dinero_tmp;
	  ALLEGRO_PATH   *path;

	 /*
	 * para crear path relativos y poder distribuir el programa y ejecutarlo
	 * fuera del IDE
	 */

	 path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
	 al_remove_path_component(path,-1);
	 al_append_path_component(path, "resources");

	 al_set_path_filename(path, "bolsa-dinero.png");

	 bolsa_dinero_tmp = new BolsaDinero(actmgr,mov_to_dead);
	 bmp = al_load_bitmap(al_path_cstr(path, '/'));
	 if(bmp == NULL)
	 {
		al_show_native_message_box(al_get_current_display(), "Ventana de error",
								   "error fatal", "Error al cargar resource bitmap",
								   NULL, ALLEGRO_MESSAGEBOX_ERROR);
		exit(-1);
	 }
	 // Hacemos que no se vea el color negro en el bitmap de rana
	 al_convert_mask_to_alpha(bmp, al_map_rgb(0,0,0));


	 bitm=new MapaDeBits(bolsa_dinero_tmp, bmp);
	 bolsa_dinero_tmp->set_actor_graphic(bitm);

	 bolsa_dinero_tmp->set_x(Game::rnd(0,Game::gfx_w-bolsa_dinero_tmp->get_w()));
	 bolsa_dinero_tmp->set_y(Game::rnd(50,Game::gfx_h-bolsa_dinero_tmp->get_h()));
	 bolsa_dinero_tmp->set_is_detected(true);
	 bolsa_dinero_tmp->set_team(TEAM_BOLSA_DINERO);
	 bolsa_dinero_tmp->set_collision_method(CollisionManager::PP_COLLISION);

	 actmgr->add(bolsa_dinero_tmp);

	 al_destroy_path(path);

	 return bolsa_dinero_tmp;

}
예제 #11
0
static char* test_level_alloc_read_from_file_read_invalid_level_size_for_dimensions()
{
    char* level_name = "test-invalid-level-size-for-dimensions.world";

    ALLEGRO_PATH* path = al_create_path(FILES_ASSETS_PATH);
    al_append_path_component(path, FILES_LEVELS_SUBDIRNAME);
    al_set_path_filename(path, level_name);
    const char* filename = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);

    Level* level = level_alloc_read_from_file(filename);

    mu_assert(level == NULL);

    al_destroy_path(path);
    level_free(level);

    return NULL;
}
예제 #12
0
bool TKlingonBC::Init()
{
	ALLEGRO_PATH * pPath = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(pPath, "graphics");
    al_append_path_component(pPath, "Ships");
    al_set_path_filename(pPath,"KlingonCruiser.png");
    g_pKlingonBCBitmap = al_load_bitmap(al_path_cstr(pPath,ALLEGRO_NATIVE_PATH_SEP));
    al_destroy_path(pPath);

	if (g_pKlingonBCBitmap==NULL)
	{
		return false;
	}
	else
	{
		return true;
	}
}
예제 #13
0
static ALLEGRO_PATH *maybe_parent_dir(const ALLEGRO_PATH *path)
{
    ALLEGRO_PATH *path2;

    if (!path)
        return NULL;

    if (!is_build_config_name(al_get_path_tail(path)))
        return NULL;

    path2 = al_clone_path(path);
    if (path2) {
        al_drop_path_tail(path2);
        al_set_path_filename(path2, NULL);
        ALLEGRO_DEBUG("Also searching %s\n", al_path_cstr(path2, '\\'));
    }

    return path2;
}
예제 #14
0
파일: map.cpp 프로젝트: faod/ld33
std::shared_ptr<ALLEGRO_BITMAP> Tile::getFlameFrame(size_t num)
{
    if(flames == NULL)
    {
        ALLEGRO_PATH *path;

        path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
        al_append_path_component(path, RESOURCES_DIR);
        al_set_path_filename(path, "flames.png");
        flames = al_load_bitmap(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));

        al_destroy_path(path);
    }
    if(num < 3)
    {
        return std::shared_ptr<ALLEGRO_BITMAP>(al_create_sub_bitmap(flames, num * 32, 0, 32, 32), al_destroy_bitmap);
    }
    return NULL;
}
예제 #15
0
static void write_scores(void)
{
   ALLEGRO_CONFIG *cfg = al_create_config();
   for (int i = 0; i < NUM_SCORES; i++) {
      char name[]  = {'n', (char)('0'+i), '\0'};
      char score[] = {'s', (char)('0'+i), '\0'};
      char sc[32];

      al_set_config_value(cfg, "scores", name, highScores[i].name);
      snprintf(sc, sizeof(sc), "%d", highScores[i].score);
      al_set_config_value(cfg, "scores", score, sc);
   }

   ALLEGRO_PATH *fn = userResourcePath();
   al_set_path_filename(fn, "scores.cfg");
   al_save_config_file(al_path_cstr(fn, ALLEGRO_NATIVE_PATH_SEP), cfg);
   al_destroy_path(fn);

   al_destroy_config(cfg);
}
예제 #16
0
/* Function: al_get_standard_path
 */
ALLEGRO_PATH *al_get_standard_path(int id)
{
   ASSERT(active_sysdrv);
   ASSERT(active_sysdrv->vt);
   ASSERT(active_sysdrv->vt->get_path);
   
   if (id == ALLEGRO_EXENAME_PATH && active_sysdrv->user_exe_path)
      return al_clone_path(active_sysdrv->user_exe_path);
   
   if (id == ALLEGRO_RESOURCES_PATH && active_sysdrv->user_exe_path) {
      ALLEGRO_PATH *exe_dir = al_clone_path(active_sysdrv->user_exe_path);
      al_set_path_filename(exe_dir, NULL);
      return exe_dir;
   }

   if (active_sysdrv->vt->get_path)
      return active_sysdrv->vt->get_path(id);

   return NULL;
}
static char* test_find_path_non_empty_level_around_obstacles()
{
    char* level_name = "test-around-obstacles.world";

    ALLEGRO_PATH* file_path = al_create_path(FILES_ASSETS_PATH);
    al_append_path_component(file_path, FILES_LEVELS_SUBDIRNAME);
    al_set_path_filename(file_path, level_name);
    const char* filename = al_path_cstr(file_path, ALLEGRO_NATIVE_PATH_SEP);

    Level* level = level_alloc_read_from_file(filename);

    mu_assert(level != NULL);
    Cell* start_cell = &level->cells[0][0];
    Cell* target_cell = &level->cells[11][24];

    Path* path = find_path(level, start_cell, target_cell);

    mu_assert(path != NULL);
    mu_assert(path->distance == 12 * 95 + 17 * 26);
    mu_assert(path->step_count == 122);

    mu_assert(path->steps != NULL);
    mu_assert(test_is_path_start_and_end_step_correct(path, start_cell, target_cell));
    mu_assert(test_is_path_walkable(path, level) == 1);

    // test a few steps
    mu_assert(path->steps[5].row == 5);
    mu_assert(path->steps[5].col == 1);
    mu_assert(path->steps[11].row == 11);
    mu_assert(path->steps[11].col == 2);
    mu_assert(path->steps[65].row == 1);
    mu_assert(path->steps[65].col == 12);
    mu_assert(path->steps[119].row == 11);
    mu_assert(path->steps[119].col == 22);

    path_free(path);
    al_destroy_path(file_path);
    level_free(level);

    return NULL;
}
예제 #18
0
bool TEnterprise::Init()
{
	ALLEGRO_PATH * pPath = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(pPath, "graphics");
    al_append_path_component(pPath, "Ships");
    al_set_path_filename(pPath,"ent01.png");
    g_pEnterpriseBitmap = al_load_bitmap(al_path_cstr(pPath,ALLEGRO_NATIVE_PATH_SEP));
	if (g_pEnterpriseBitmap == NULL)  return false;

	pPath = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(pPath, "graphics");
    al_append_path_component(pPath, "Interface");
    al_set_path_filename(pPath,"eng01.png");
    g_pEngineeringBitmap = al_load_bitmap(al_path_cstr(pPath,ALLEGRO_NATIVE_PATH_SEP));
	if (g_pEngineeringBitmap == NULL)  return false;

	pPath = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(pPath, "graphics");
    al_append_path_component(pPath, "Interface");
    al_set_path_filename(pPath,"Com_Trans.png");
    g_pCommunicationBitmap = al_load_bitmap(al_path_cstr(pPath,ALLEGRO_NATIVE_PATH_SEP));
	if (g_pCommunicationBitmap == NULL)  return false;

	pPath = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(pPath, "graphics");
    al_append_path_component(pPath, "Interface");
    al_set_path_filename(pPath,"Switch.png");
    g_pSwitchBitmap = al_load_bitmap(al_path_cstr(pPath,ALLEGRO_NATIVE_PATH_SEP));
	if (g_pSwitchBitmap == NULL)  return false;

    pPath = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(pPath, "graphics");
    al_append_path_component(pPath, "Photon");
    al_set_path_filename(pPath,"casing.png");
    g_pPhotonCasing = al_load_bitmap(al_path_cstr(pPath,ALLEGRO_NATIVE_PATH_SEP));
	if (g_pPhotonCasing == NULL)  return false;

	pPath = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_append_path_component(pPath, "graphics");
    al_append_path_component(pPath, "probe");
    al_set_path_filename(pPath,"casing.png");
    g_pProbeCasing = al_load_bitmap(al_path_cstr(pPath,ALLEGRO_NATIVE_PATH_SEP));
	if (g_pProbeCasing == NULL)  return false;


	al_destroy_path(pPath);
	return true;
}
static char* test_find_path_non_empty_level_end_in_unwalkable_cell()
{
    char* level_name = "test-unreachable-cell.world";

    ALLEGRO_PATH* file_path = al_create_path(FILES_ASSETS_PATH);
    al_append_path_component(file_path, FILES_LEVELS_SUBDIRNAME);
    al_set_path_filename(file_path, level_name);
    const char* filename = al_path_cstr(file_path, ALLEGRO_NATIVE_PATH_SEP);

    Level* level = level_alloc_read_from_file(filename);

    mu_assert(level != NULL);
    Cell* start_cell = &level->cells[0][0];
    Cell* target_cell = &level->cells[1][22];

    Path* path = find_path(level, start_cell, target_cell);

    mu_assert(path == NULL);

    al_destroy_path(file_path);
    level_free(level);

    return NULL;
}
예제 #20
0
파일: game.c 프로젝트: hiltonm/nostos
GAME * game_init ()
{
    if (!al_init ()) {
        fprintf (stderr, "Failed to initialize Allegro.\n");
        return NULL;
    }

    if (!al_init_image_addon ()) {
        fprintf (stderr, "Failed to initialize image addon.\n");
        return NULL;
    }

    if (!al_install_keyboard ()) {
        fprintf (stderr, "Failed to install keyboard.\n");
        return NULL;
    }

    al_init_font_addon ();

    if (!al_init_ttf_addon ()) {
        fprintf (stderr, "Failed to initialize ttf addon.\n");
        return NULL;
    }

    if (!al_init_primitives_addon ()) {
        fprintf (stderr, "Failed to initialize primitives addon.\n");
        return NULL;
    }

    GAME *game = al_malloc (sizeof (GAME));
    if (!game)
        return NULL;

    srand (time (NULL));

    game->running = true;
    game->paused = false;

    game->fullscreen = 1;
    game->windowed = 1;
    game->rrate = 60;
    game->suggest_vsync = 1;
    game->force_vsync = 0;

    game->current_npc = NULL;

    game->screen = screen_new ();

    char *filename;
    const char *str;

    filename = get_resource_path_str ("data/game.ini");
    ALLEGRO_CONFIG *game_config = al_load_config_file (filename);
    al_free (filename);

    str = al_get_config_value (game_config, "", "org");
    al_set_org_name (str);
    str = al_get_config_value (game_config, "", "app");
    al_set_app_name (str);

    ALLEGRO_PATH *settpath = al_get_standard_path (ALLEGRO_USER_SETTINGS_PATH);
    ALLEGRO_PATH *gcpath = al_clone_path (settpath);

    al_set_path_filename (gcpath, "general.ini");
    const char * gcpath_str = al_path_cstr (gcpath, ALLEGRO_NATIVE_PATH_SEP);

    ALLEGRO_CONFIG *gconfig = al_load_config_file (gcpath_str);

    if (!gconfig) {
        gconfig = al_create_config ();
        al_make_directory (al_path_cstr (settpath, ALLEGRO_NATIVE_PATH_SEP));

        set_config_i (gconfig, "display", "width", game->screen.width);
        set_config_i (gconfig, "display", "height", game->screen.height);
        set_config_i (gconfig, "display", "fullscreen", game->fullscreen);
        set_config_i (gconfig, "display", "windowed", game->windowed);
        set_config_i (gconfig, "display", "refreshrate", game->rrate);
        set_config_i (gconfig, "display", "suggest_vsync", game->suggest_vsync);
        set_config_i (gconfig, "display", "force_vsync", game->force_vsync);
    } else {
        get_config_i (gconfig, "display", "width", &game->screen.width);
        get_config_i (gconfig, "display", "height", &game->screen.height);
        get_config_i (gconfig, "display", "fullscreen", &game->fullscreen);
        get_config_i (gconfig, "display", "windowed", &game->windowed);
        get_config_i (gconfig, "display", "refreshrate", &game->rrate);
        get_config_i (gconfig, "display", "suggest_vsync", &game->suggest_vsync);
        get_config_i (gconfig, "display", "force_vsync", &game->force_vsync);
    }

    al_save_config_file (gcpath_str, gconfig);

    al_destroy_path (settpath);
    al_destroy_path (gcpath);
    al_destroy_config (gconfig);

    int flags = 0;

    if (game->fullscreen == game->windowed)
        flags |= ALLEGRO_FULLSCREEN_WINDOW;
    else if (game->fullscreen)
        flags |= ALLEGRO_FULLSCREEN;
    else
        flags |= ALLEGRO_WINDOWED;

    al_set_new_display_option (ALLEGRO_VSYNC, game->suggest_vsync, ALLEGRO_SUGGEST);
    al_set_new_display_option (ALLEGRO_DEPTH_SIZE, 8, ALLEGRO_SUGGEST);

    al_set_new_display_flags (flags);
    al_set_new_display_refresh_rate (game->rrate);
    game->display = al_create_display (game->screen.width, game->screen.height);
    if (!game->display) {
        fprintf (stderr, "Failed to create display.\n");
        al_free (game);
        return NULL;
    }

    al_set_new_bitmap_flags (ALLEGRO_VIDEO_BITMAP);

    game->timer = al_create_timer (1.0 / FPS);
    if (!game->timer) {
        fprintf (stderr, "Failed to create timer.\n");
        al_free (game);
        return NULL;
    }

    game->screen.width = al_get_display_width (game->display);
    game->screen.height = al_get_display_height (game->display);
    screen_update_size (&game->screen, game->screen.width, game->screen.height);

    game->rrate = al_get_display_refresh_rate (game->display);

    game->event_queue = al_create_event_queue ();
    if (!game->event_queue) {
        fprintf (stderr, "Failed to create event queue.\n");
        al_free (game);
        return NULL;
    }

    al_register_event_source (game->event_queue, al_get_display_event_source (game->display));
    al_register_event_source (game->event_queue, al_get_timer_event_source (game->timer));

    al_set_render_state (ALLEGRO_ALPHA_FUNCTION, ALLEGRO_RENDER_EQUAL);
    al_set_render_state (ALLEGRO_ALPHA_TEST_VALUE, 1);

    filename = get_resource_path_str ("data/sprites.ini");
    game->sprites = sprite_load_sprites (filename);
    al_free (filename);

    filename = get_resource_path_str ("data/scenes.ini");
    game->scenes = scene_load_file (filename);
    scene_load_scenes (game->scenes, game->sprites);
    al_free (filename);

    str = al_get_config_value (game_config, "", "scene");
    game->current_scene = scene_get (game->scenes, str);

    str = al_get_config_value (game_config, "", "actor");
    game->current_actor = sprite_new_actor (game->sprites, str);
    str = al_get_config_value (game_config, "", "portal");
    SCENE_PORTAL *portal = scene_get_portal (game->scenes, str);

    al_destroy_config (game_config);

    filename = get_resource_path_str ("data/ui.ini");
    game->ui = ui_load_file (filename);
    al_free (filename);

    sprite_center (game->current_actor, &portal->position);
    screen_center (&game->screen, portal->position, game->current_scene->map);

    return game;
}
예제 #21
0
파일: game.cpp 프로젝트: kotori/alMonopoly
int MonopolyGame::loadResources() {

	reset();

    // Normalize the paths.
    ALLEGRO_PATH *path = al_get_standard_path( ALLEGRO_RESOURCES_PATH );
    al_append_path_component( path, "etc" );
    al_change_directory( al_path_cstr( path, '/' ) );  // change the working directory

    //
    // Load the board's bitmap
    //
    al_set_path_filename(path, "board.png");
    if( !fileExists( al_path_cstr(path, '/') ) ) {
       	fprintf( stderr, "[ERROR] Cannot find bitmap: %s\n", al_path_cstr(path, '/') );
       	return -1;
    }
    else {
    	m_alBoardImage = al_load_bitmap( al_path_cstr(path, '/') );
    	if( !m_alBoardImage ) {
    		fprintf( stderr, "[ERROR] Failed loading board bitmap: %s\n", al_path_cstr(path, '/') );
    		return -1;
    	}
    }

    //
    // Load the font set.
    //
    al_set_path_filename(path, "Emblem.ttf");
    // Start building the fonts from 24pt.
    int initialSize = 24;
    if( !fileExists( al_path_cstr(path, '/') ) ) {
    	fprintf( stderr, "[ERROR] Cannot find font file: %s\n", al_path_cstr(path, '/') );
    	return -1;
    }
    else
    {
    	for( int fontCounter = 0; fontCounter < MAX_FONTS; fontCounter++ ) {
    		m_fontCollection[fontCounter] = al_load_font( al_path_cstr(path, '/'), initialSize, 0 );
    		initialSize += 10;
    		if( !m_fontCollection[fontCounter] ) {
    			fprintf( stderr, "[ERROR] Failed loading font: %s size: %i\n", al_path_cstr(path, '/'), initialSize );
    			return -1;
    		}
    	}
    }

    // Now load the possible player pieces into memory.
    //  The piece file locations are stored in the database.
    for( int pieceCounter = 0; pieceCounter < PLAYER_PIECES_COUNT; pieceCounter++ ) {
    	std::string tempQuery = "";
    	std::string sFileName = "";
    	tempQuery = m_sqlConn.Format( "SELECT %s FROM %s WHERE %s = %i", "path", DB_PIECES_TABLE, "id", pieceCounter );

    	if( !m_sqlConn.SelectStr( sFileName, tempQuery.c_str() ) ) {
    		// Append the filename to the resource path.
    		al_set_path_filename( path, sFileName.c_str() );
        	if( !fileExists( al_path_cstr(path, '/') ) ) {
        		fprintf( stderr, "[ERROR] Cannot find bitmap: %s\n", al_path_cstr(path, '/') );
        		return -1;
        	}
        	else {
        		// Load the bitmap from the filename from above.
        		m_alpieceImages[pieceCounter] = al_load_bitmap( al_path_cstr(path, '/') );
        	}
    		if( !m_alpieceImages[pieceCounter] ) {
    			// TODO: CURRENTLY I HAVE NO PLACE HOLDER IMAGES, SO THE APPLICATION WILL FAIL HERE!
    			fprintf( stderr, "[ERROR] Failed loading bitmap: %s\n", al_path_cstr(path, '/') );
    			return -1;
    		}
    	}
    	else {
    		fprintf( stderr, "[ERROR] Error processing SQL statement: %s\n", tempQuery.c_str() );
    		return -1;
    	}
    }

    // Assign random pieces to each player.
    for( int plCount = 0; plCount < NUM_PLAYERS; plCount++ ) {
    	int* randomPlayerSel = rollDice( 1, PLAYER_PIECES_COUNT );
    	m_playerList[plCount].set_image( m_alpieceImages[randomPlayerSel[0]] );

    }

    al_destroy_path( path );

    //
    // Finally we will pull the property list from the database.
    //
    if( buildPropertyList() )
    {
        fprintf( stderr, "Failure building Property List, Please ensure the database is available!\n" );
        return -1;
    }

    return 0;
}
/* _find_executable_file:
 *  Helper function: searches path and current directory for executable.
 *  Returns 1 on succes, 0 on failure.
 */
static ALLEGRO_PATH *_find_executable_file(const char *filename)
{
   char *env;

   /* If filename has an explicit path, search current directory */
   if (strchr(filename, '/')) {
      if (filename[0] == '/') {
         /* Full path; done */
         return al_create_path(filename);
      }
      else {
         struct stat finfo;
         char *cwd;

         /* Prepend current directory */
         cwd = al_get_current_directory();
         if (cwd) {
            ALLEGRO_PATH *path = al_create_path_for_directory(cwd);
            al_free(cwd);
            al_set_path_filename(path, filename);

            if (stat(al_path_cstr(path, '/'), &finfo) == 0
                  && !S_ISDIR(finfo.st_mode)) {
               return path;
            }

            al_destroy_path(path);
         }
      }
   }
   /* If filename has no explicit path, but we do have $PATH, search
    * there
    */
   else if ((env = getenv("PATH"))) {
      struct stat finfo;
      ALLEGRO_USTR *us = al_ustr_new(env);
      int start_pos = 0;
      while (start_pos >= 0) {
         int next_start_pos = al_ustr_find_chr(us, start_pos + 1, ':');
         int end_pos = next_start_pos;
         if (next_start_pos < 0)
            end_pos = al_ustr_size(us);
         ALLEGRO_USTR_INFO info;
         const ALLEGRO_USTR *sub = al_ref_ustr(&info, us, start_pos, end_pos);

         ALLEGRO_PATH *path = al_create_path_for_directory(al_cstr(sub));
         al_set_path_filename(path, filename);

         if (stat(al_path_cstr(path, '/'), &finfo) == 0 &&
            !S_ISDIR (finfo.st_mode)) {
            return path;
         }

         al_destroy_path(path);

         start_pos = next_start_pos;
      }
   }

   return NULL;
}
예제 #23
0
파일: main.c 프로젝트: dradtke/battlechess
/* 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;
}
예제 #24
0
파일: tiled.c 프로젝트: hiltonm/nostos
TILED_MAP* tiled_load_tmx_file (const char *filename)
{
    TILED_MAP *map;
    xmlDoc *doc;
    xmlNode *root;
    char *str;

    if (!filename)
        return NULL;

    LIBXML_TEST_VERSION

    doc = xmlReadFile (filename, NULL, 0);
    if (!doc)
        return NULL;

    ALLEGRO_PATH *mapdir = al_create_path (filename);
    al_set_path_filename (mapdir, NULL);

    if (!al_change_directory (al_path_cstr (mapdir, ALLEGRO_NATIVE_PATH_SEP))) {
        printf ("Failed to change directory.");
    }

    al_destroy_path (mapdir);

    root = xmlDocGetRootElement (doc);

    map = al_malloc (sizeof (TILED_MAP));
    map->width = get_int (root, "width", 0);
    map->height = get_int (root, "height", 0);
    map->tile_width = get_int (root, "tilewidth", 0);
    map->tile_height = get_int (root, "tileheight", 0);
    map->strings = _al_list_create ();
    map->properties = get_properties (root, map);
    map->tiles = NULL;

    str = get_xml_attribute (root, "orientation");
    if (!strcmp (str, "orthogonal"))
        map->orientation = ORIENTATION_ORTHOGONAL;
    else if (!strcmp (str, "isometric"))
        map->orientation = ORIENTATION_ISOMETRIC;
    else if (!strcmp (str, "staggered"))
        map->orientation = ORIENTATION_STAGGERED;
    else
        map->orientation = ORIENTATION_UNKNOWN;

    // Tilesets
    LIST *tileset_nodes = get_children_for_name (root, 1, "tileset");
    map->tilesets = create_list (_al_list_size (tileset_nodes));

    LIST_ITEM *tileset_item = _al_list_front (tileset_nodes);
    while (tileset_item) {
        xmlNode *tileset_node = _al_list_item_data (tileset_item);
        TILED_TILESET *tileset = al_malloc (sizeof (TILED_TILESET));
        tileset->first_gid = get_int (tileset_node, "firstgid", 1);
        tileset->tile_width = get_int (tileset_node, "tilewidth", 0);
        tileset->tile_height = get_int (tileset_node, "tileheight", 0);
        tileset->name = get_str (tileset_node, "name");
        tileset->properties = get_properties (tileset_node, map);

        xmlNode *image_node = get_first_child_for_name (tileset_node, "image");
        tileset->image_width = get_int (image_node, "width", 0);
        tileset->image_height = get_int (image_node, "height", 0);
        tileset->image_source = get_str (image_node, "source");
        tileset->bitmap = al_load_bitmap (tileset->image_source);

        LIST *tile_nodes = get_children_for_name (tileset_node, 1, "tile");

        int tiles_per_row = tileset->image_width / tileset->tile_width;
        tileset->num_tiles = (tileset->image_width * tileset->image_height) /
                             (tileset->tile_width * tileset->tile_height);

        TILED_TILE *tile;
        tileset->tiles = al_malloc (tileset->num_tiles * sizeof (TILED_TILE));
        for (int i = 0; i < tileset->num_tiles; i++) {
            tile = &tileset->tiles[i];
            tile->id = i;
            tile->gid = i + tileset->first_gid;
            tile->tileset = tileset;
            tile->properties = NULL;

            int x = (i % tiles_per_row) * tileset->tile_width;
            int y = (i / tiles_per_row) * tileset->tile_height;
            tile->bitmap = al_create_sub_bitmap(tileset->bitmap, x, y,
                                                tileset->tile_width,
                                                tileset->tile_height);

            map->tiles = aa_insert (map->tiles, &tile->gid, tile, intcmp);
        }

		LIST_ITEM *tile_item = _al_list_front (tile_nodes);
		while (tile_item) {
			xmlNode *tile_node = (xmlNode*)_al_list_item_data (tile_item);
            int id = get_int (tile_node, "id", 0);

            tile = &tileset->tiles[id];
            tile->properties = get_properties (tile_node, map);

			tile_item = _al_list_next (tile_nodes, tile_item);
		}

		_al_list_destroy (tile_nodes);
		_al_list_push_back_ex (map->tilesets, tileset, dtor_tileset);
		tileset_item = _al_list_next (tileset_nodes, tileset_item);
    }

    _al_list_destroy (tileset_nodes);

    // Layers
    LIST *layer_nodes = get_children_for_name (root, 2, "layer", "objectgroup");
    map->layers = create_list (_al_list_size (layer_nodes));
    map->layers_fore = _al_list_create ();
    map->layers_back = _al_list_create ();

    LIST_ITEM *layer_item = _al_list_front (layer_nodes);
    while (layer_item) {
        xmlNode *layer_node = _al_list_item_data (layer_item);
        TILED_LAYER *layer = NULL;

        const char* type_str = (const char *)layer_node->name;
        if (!strcmp (type_str, "layer")) {
            layer = al_malloc (sizeof (TILED_LAYER_TILE));
            layer->type = LAYER_TYPE_TILE;
        }
        else if (!strcmp (type_str, "objectgroup")) {
            layer = al_malloc (sizeof (TILED_LAYER_OBJECT));
            layer->type = LAYER_TYPE_OBJECT;
        }

        layer->name = get_str (layer_node, "name");
        layer->width = get_int (layer_node, "width", 0);
        layer->height = get_int (layer_node, "height", 0);
        layer->opacity = get_float (layer_node, "opacity", 1.0);
        layer->map = map;
        layer->properties = get_properties (layer_node, map);

        char *order = aa_search (layer->properties, "order", charcmp);

        if (layer->type == LAYER_TYPE_TILE) {
            TILED_LAYER_TILE *tile_layer = (TILED_LAYER_TILE *)layer;
            tile_layer->tiles = al_malloc (layer->height * sizeof (TILED_TILE*));

            xmlNode *data_node = get_first_child_for_name (layer_node, "data");
            LIST *tile_nodes = get_children_for_name (data_node, 1, "tile");

            LIST_ITEM *tile_item = _al_list_front (tile_nodes);
            for (int j = 0; j < layer->height; j++) {
                tile_layer->tiles[j] = al_malloc (layer->width * sizeof (TILED_TILE*));
                for (int k = 0; k < layer->width; k++) {
                    xmlNode *tile_node = (xmlNode*)_al_list_item_data (tile_item);
                    int id = get_int (tile_node, "gid", 0);

                    if (id == 0) {
                        tile_layer->tiles[j][k] = NULL;
                    } else {
                        TILED_TILE *tile = aa_search (map->tiles, &id, intcmp);
                        tile_layer->tiles[j][k] = tile;
                    }

                    tile_item = _al_list_next (tile_nodes, tile_item);
                }
            }
            _al_list_destroy (tile_nodes);
        } else if (layer->type == LAYER_TYPE_OBJECT) {
            TILED_LAYER_OBJECT *object_layer = (TILED_LAYER_OBJECT *)layer;

            object_layer->objects = _al_list_create ();
            LIST *object_nodes = get_children_for_name (layer_node, 1, "object");

            LIST_ITEM *object_item = _al_list_front (object_nodes);
            while (object_item) {
                xmlNode *object_node = (xmlNode*)_al_list_item_data (object_item);
                TILED_OBJECT *cobj = NULL;

                int width = get_int (object_node, "width", 0);
                int gid = get_int (object_node, "gid", 0);
                int px = get_int (object_node, "x", 0);
                int py = get_int (object_node, "y", 0);

                if (width > 0) {
                    TILED_OBJECT_RECT *obj = al_malloc (sizeof (TILED_OBJECT_RECT));
                    obj->object.type = OBJECT_TYPE_RECT;
                    obj->width = width;
                    obj->height = get_int (object_node, "height", 0);

                    cobj = (TILED_OBJECT *) obj;
                } else if (gid > 0) {
                    TILED_OBJECT_TILE *obj = al_malloc (sizeof (TILED_OBJECT_TILE));
                    obj->object.type = OBJECT_TYPE_TILE;
                    obj->tile = aa_search (map->tiles, &gid, intcmp);

                    cobj = (TILED_OBJECT *) obj;
                } else {
                    TILED_OBJECT_GEOM *obj = al_malloc (sizeof (TILED_OBJECT_GEOM));
                    obj->object.type = OBJECT_TYPE_GEOM;

                    xmlNode *poly_node = get_first_child_for_name (object_node, "polyline");
                    if (poly_node) {
                        obj->points = get_float_points (poly_node, "points", &obj->num_points);
                        offset_points (px, py, obj->points, obj->num_points);
                    } else {
                        poly_node = get_first_child_for_name (object_node, "polygon");
                        if (poly_node)
                            obj->points = get_float_points (poly_node, "points", &obj->num_points);
                            offset_points (px, py, obj->points, obj->num_points);
                    }
                    cobj = (TILED_OBJECT *) obj;
                }

                cobj->x = px;
                cobj->y = py;
                cobj->name = get_str (object_node, "name");
                cobj->type_str = get_str (object_node, "type");
                cobj->properties = get_properties (object_node, map);

                _al_list_push_back_ex (object_layer->objects, cobj, dtor_object);
                object_item = _al_list_next (object_nodes, object_item);
            }
            _al_list_destroy (object_nodes);
        }

		layer_item = _al_list_next (layer_nodes, layer_item);
        _al_list_push_back_ex (map->layers, layer, dtor_layer);
        if (order && !strcmp (order, "fore"))
            _al_list_push_back (map->layers_fore, layer);
        else
            _al_list_push_back (map->layers_back, layer);
    }
    _al_list_destroy (layer_nodes);

    xmlFreeDoc (doc);
    xmlCleanupParser ();

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

    return map;
}
예제 #25
0
파일: upath.c 프로젝트: sesc4mt/mvcdecoder
ALLEGRO_PATH *_al_unix_get_path(int id)
{
   switch (id) {
      case ALLEGRO_TEMP_PATH: {
         /* Check: TMP, TMPDIR, TEMP or TEMPDIR */
         char *envs[] = { "TMP", "TMPDIR", "TEMP", "TEMPDIR", NULL};
         uint32_t i = 0;
         for (; envs[i] != NULL; ++i) {
            char *tmp = getenv(envs[i]);
            if (tmp) {
               return al_create_path(tmp);
            }
         }

         /* next try: /tmp /var/tmp /usr/tmp */
         char *paths[] = { "/tmp/", "/var/tmp/", "/usr/tmp/", NULL };
         for (i=0; paths[i] != NULL; ++i) {
            ALLEGRO_FS_ENTRY *fse = al_create_fs_entry(paths[i]);
            bool found = al_fs_entry_is_directory(fse);
            al_destroy_fs_entry(fse);
            if (found) {
               return al_create_path(paths[i]);
            }
         }

         /* Give up? */
         return NULL;
      } break;

      case ALLEGRO_PROGRAM_PATH: {

         ALLEGRO_PATH *exe = get_executable_name();
         al_set_path_filename(exe, NULL);
         return exe;

      } break;

      case ALLEGRO_SYSTEM_DATA_PATH: {
         ALLEGRO_PATH *sys_data_path = NULL;

         /* FIXME: make this a compile time define, or a allegro cfg option? or both */
         sys_data_path = al_create_path("/usr/share/");
         al_append_path_component(sys_data_path, al_get_orgname());
         al_append_path_component(sys_data_path, al_get_appname());

         return sys_data_path;
      } break;

#if 0
      case ALLEGRO_USER_DATA_PATH: {
         int32_t ret = 0;
         uint32_t path_len = 0, ptr_len = 0, prog_len = 0;
         char path[PATH_MAX] = "", *ptr = NULL;
         char prog[PATH_MAX] = "";

         if (_unix_find_home(path, PATH_MAX) != 0) {
            return NULL;
         }

         strncat(path, "/.", 2);

         path_len = strlen(path);

         /* get exe name */
         /* FIXME:
            This really aught to get the "Program" name from somewhere, say a config var? Or a function al_set_program_name()?
            making a ~/.test_program dir for a exe named "test_program" might not be what people have in mind.
         */

         get_executable_name(prog, PATH_MAX);

         ptr = strrchr(prog, '/');
         if (!ptr) {
            al_set_errno(EINVAL);
            return NULL;
         }

         *ptr = '\0';
         ptr++;
         ptr_len = strlen(ptr);
         //
         strncat(path, ptr, ptr_len+1);
         //*(ptr-1) = '/';
         do_uconvert(path, U_ASCII, dir, U_UTF8, strlen(path)+1);

      } break;
#endif

      case ALLEGRO_USER_SETTINGS_PATH:
      case ALLEGRO_USER_DATA_PATH: {
         ALLEGRO_PATH *local_path = NULL;

         local_path = _unix_find_home();
         if (!local_path)
            return NULL;

         al_append_path_component(local_path, ".config");
         al_append_path_component(local_path, al_get_orgname());
         al_append_path_component(local_path, al_get_appname());

        return local_path;
      } break;

      case ALLEGRO_USER_HOME_PATH:
         return _unix_find_home();

      case ALLEGRO_SYSTEM_SETTINGS_PATH: {
         ALLEGRO_PATH *sys_path;

         /* FIXME: make this a compile time define, or something */
         sys_path = al_create_path("/etc/");
         al_append_path_component(sys_path, al_get_orgname());
         al_append_path_component(sys_path, al_get_appname());

         return sys_path;
      } break;

      case ALLEGRO_EXENAME_PATH:
         return get_executable_name();
         break;

      default:
         return NULL;
   }

   return NULL;
}
예제 #26
0
void Hormiga::crear_hormiga(ActorManager *actmgr,int tipo,Hormiguero *hormiguero_tmp,
							int pos_x,int pos_y)
{
	  ALLEGRO_BITMAP *bmp;
	  MapaDeBits 	 *bitm;
	  Hormiga		 *hormiga_tmp;
	  ALLEGRO_PATH   *path;

	 /*
	 * para crear path relativos y poder distribuir el programa y ejecutarlo
	 * fuera del IDE
	 */

	 path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
	 al_remove_path_component(path,-1);
	 al_append_path_component(path, "resources");

	 if (tipo == kRedAnt)
	 {
		 al_set_path_filename(path, "HormigaRoja.png");
		 hormiga_tmp = new Hormiga(actmgr,hormiguero_tmp,kRedAnt);
	 }
	 else
	 {
		 al_set_path_filename(path, "HormigaVerde.png");
		 hormiga_tmp = new Hormiga(actmgr,hormiguero_tmp,kGreenAnt);
	 }

	 bmp = al_load_bitmap(al_path_cstr(path, '/'));
	 if(bmp == NULL)
	 {
		al_show_native_message_box(al_get_current_display(), "Ventana de error",
								   "error fatal", "Error al cargar resource bitmap",
								   NULL, ALLEGRO_MESSAGEBOX_ERROR);
		exit(-1);
	 }
	 // Hacemos que no se vea el color negro en el bitmap de hormiga
	 al_convert_mask_to_alpha(bmp, al_map_rgb(0,0,0));

	 bitm=new MapaDeBits(hormiga_tmp, bmp);
	 hormiga_tmp->set_actor_graphic(bitm);
	 if (pos_x == 0) {
		 hormiga_tmp->set_x(Game::rnd(50,Game::gfx_w-hormiga_tmp->get_w()));
	 } else {
		 hormiga_tmp->set_x(pos_x);
	 }
	 if (pos_y == 0) {
		 hormiga_tmp->set_y(Game::rnd(0,Game::gfx_h-hormiga_tmp->get_h()));
	 } else {
		 hormiga_tmp->set_y(pos_y);
	 }
	 hormiga_tmp->set_is_detected(true);

	 if (tipo == kRedAnt)
	 {
		 hormiga_tmp->set_team(TEAM_HORMIGAS_ROJAS);
	 }
	 else
	 {
		 hormiga_tmp->set_team(TEAM_HORMIGAS_VERDES);
	 }

	 hormiga_tmp->set_collision_method(CollisionManager::PP_COLLISION);

	 actmgr->add(hormiga_tmp);

	 al_destroy_path(path);

}
예제 #27
0
파일: skin.cpp 프로젝트: bambams/ma5king
////////////////////////////////////////////////////////////////////////////////
// Loads and processes the skin description file which is in fact a regular
// Allegro configuration file
MAS::Error MAS::Skin::Load(const char *file) {
   int i = 0;
   lastError = MAS::Error(MAS::Error::NONE);
   ALLEGRO_CONFIG *config;
   const char *str;
   ALLEGRO_PATH *sdp;

   if (!file) {
      lastError =  MAS::Error(MAS::Error::SKIN_INI);
      return lastError;
   }

   // Try to open the skin description file
   sdp = al_create_path(file);
   if (!al_is_path_present(sdp)) {
      al_destroy_path(sdp);
      lastError = MAS::Error(MAS::Error::SKIN_INI);
      return lastError;
   }

   config = al_load_config_file(file);

   if (skinFilePath != file) {
      delete [] skinFilePath;
      skinFilePath = new char[1+strlen(file)];
      strcpy(skinFilePath, file);
   }

   Reset();

   // Get the path to the skin configuration file (drop the filename)
   al_set_path_filename(sdp, "");

   ////////////////////////////////////////////////////////////////////////////////
   // Read the name of the dir and load the bitmap data
   bool default_bitmaps = false;

   str = al_get_config_value(config, "Skin", "main_data");
   if (str) {
      al_append_path_component(sdp, str);
      lastError = LoadData(sdp, config);
      al_drop_path_tail(sdp);
      if (lastError) {
         al_destroy_config(config);
         al_destroy_path(sdp);
         delete [] skinFilePath;
         skinFilePath = NULL;
         return lastError;
      }
   }
   else {
      default_bitmaps = true;
   }

   ////////////////////////////////////////////////////////////////////////////////
   // Read the default colors
#define GET_COLOR_STR(val, def) ((str = al_get_config_value(config, "COLORS", val)) ? str : def)
   c_face     = MAS::Color(GET_COLOR_STR("face",     "210,210,210"));
   c_font     = MAS::Color(GET_COLOR_STR("fontface", " 16, 16, 16"));
   c_shad1    = MAS::Color(GET_COLOR_STR("shad1",    "255,255,255"));
   c_shad2    = MAS::Color(GET_COLOR_STR("shad2",    " 80, 80, 80"));
   c_disable  = MAS::Color(GET_COLOR_STR("disable",  "128,128,128"));
   c_select   = MAS::Color(GET_COLOR_STR("select",   "128,192,128"));
   c_deselect = MAS::Color(GET_COLOR_STR("deselect", "224,224,224"));
   c_focus    = MAS::Color(GET_COLOR_STR("focus",    "128,192,128"));
   c_sunken   = MAS::Color(GET_COLOR_STR("sunken",   "232,232,232"));
   c_back     = MAS::Color(GET_COLOR_STR("back",     "180,180,180"));
#undef GET_COLOR_STR

   if (default_bitmaps) {
      GenerateDefaultBitmaps();
   }

   ////////////////////////////////////////////////////////////////////////////////
   // Read the cursors from another datafile
   str = al_get_config_value(config, "Skin", "cursors");
   if (str) {
      al_append_path_component(sdp, str);
      lastError = LoadCursors(sdp, config);
      al_drop_path_tail(sdp);
      if (lastError) {
         al_destroy_config(config);
         al_destroy_path(sdp);
         delete [] skinFilePath;
         skinFilePath = NULL;
         return lastError;
      }
   }

   ////////////////////////////////////////////////////////////////////////////////
   // Read the samples from another datafile
   str = al_get_config_value(config, "Skin", "sounds");
   if (str) {
      al_append_path_component(sdp, str);
      lastError = LoadSamples(sdp);
      al_drop_path_tail(sdp);
      if (lastError) {
         al_destroy_config(config);
         al_destroy_path(sdp);
         delete [] skinFilePath;
         skinFilePath = NULL;
         return lastError;
      }
   }

#define GET_CONFIG_STR(section, key, def) \
   (str = al_get_config_value(config, section, key)) ? strtol(str, NULL, 10) : def

   ////////////////////////////////////////////////////////////////////////////////
   // Now load the fonts
   const char *fonts[] = { "FONT0", "FONT1", "FONT2", "FONT3",
                           "FONT4", "FONT5", "FONT6", "FONT7" };
   const char *ttfont;
   int size;
   for (i=0; i<nFonts; i++)   {
      size = GET_CONFIG_STR(fonts[i], "size", 10);
      ttfont = al_get_config_value(config, fonts[i], "file");   // the filename of the font
      al_set_path_filename(sdp, ttfont);
	  const char *filename = al_path_cstr(sdp, ALLEGRO_NATIVE_PATH_SEP);
      fntList[i]->Load(filename, size, false);
   }

   ////////////////////////////////////////////////////////////////////////////////
   // Read the object specific data:
   //----------------------------------------------
   const char *fnames[] = { "font1", "font2", "font3", "font4" };
   const char *cnames[] = { "f_col1", "f_col2", "f_col3", "f_col4" };
   const char *snames[] = { "s_col1", "s_col2", "s_col3", "s_col4" };
   const char *def_col[] = { "0,0,0", "0,0,0", "128,128,128", "0,0,0" };
   const char *def_shd[] = { "-1", "-1", "-1", "-1" };

   // button, checkbox, radio button, etc.
   const char *info_name[] = {
      "BOX",
      "BUTTON",
      "CHECKBOX",
      "RADIO",
      "LIST",
      "WINDOW",
      "MENU",
      "TEXT",
      "EDITBOX",
      "PROGRESS",
      "HYPER",
      "TAB",
      "TOOLTIP"
   };

   for (int j=0; j<nInfoItems; j++)   {
      for (i=0; i<4; i++)   {
         fnt[j][i] = GET_CONFIG_STR(info_name[i], fnames[i], 10);
         fcol[j][i] = Color((str = al_get_config_value(config, info_name[j], cnames[i])) ? str : def_col[i]);
         scol[j][i] = Color((str = al_get_config_value(config, info_name[j], snames[i])) ? str : def_shd[i]);
      }
   }

   // wallpaper style
   wallpaperStyle = GET_CONFIG_STR("WALLPAPER", "style", 3);

   // buttons animation
   buttonDisplacement    = GET_CONFIG_STR("BUTTON", "displacement", 1);
   buttonAnimationType   = GET_CONFIG_STR("BUTTON", "animationType", 0);
   buttonAnimationLength = GET_CONFIG_STR("BUTTON", "animationLength", 0);

   // group box info
   boxX =      GET_CONFIG_STR("BOX", "offX", 6);
   boxY =      GET_CONFIG_STR("BOX", "offY", 1);
   boxAlign =  GET_CONFIG_STR("BOX", "alignment", 0);
   boxBack =   (str = al_get_config_value(config, "BOX", "backColor")) ? str : "222,222,222";

   // window
   winTextPos.x(  GET_CONFIG_STR("WINDOW", "textX", 10));
   winTextPos.y(  GET_CONFIG_STR("WINDOW", "textY", 18));
   winTextAlign = GET_CONFIG_STR("WINDOW", "alignment", 0);
   winTextBack  = GET_CONFIG_STR("WINDOW", "textBack", 0);
   winExitPos.x(  GET_CONFIG_STR("WINDOW", "exitX", -22));
   winExitPos.y(  GET_CONFIG_STR("WINDOW", "exitY", 6));
   winMaxPos.x(   GET_CONFIG_STR("WINDOW", "manX", -40));
   winMaxPos.y(   GET_CONFIG_STR("WINDOW", "manY", 6));
   winMinPos.x(   GET_CONFIG_STR("WINDOW", "minX", -56));
   winMinPos.y(   GET_CONFIG_STR("WINDOW", "minY", 6));
   winAnimationType = GET_CONFIG_STR("WINDOW", "animationType", 0);
   winAnimationLength = GET_CONFIG_STR("WINDOW", "animationLength", 0);

   // combo box
   comboAnimationType = GET_CONFIG_STR("COMBOBOX", "animationType", 0);
   comboAnimationLength = GET_CONFIG_STR("COMBOBOX", "animationLength", 0);

   // menu
   menuHeight = GET_CONFIG_STR("MENU", "height", 16);
   menuDelay =  GET_CONFIG_STR("MENU", "delay", 300);
   menuAnimationType = GET_CONFIG_STR("MENU", "animationType", 0);
   menuAnimationLength = GET_CONFIG_STR("MENU", "animationLength", 0);

   // tooltip info
   tooltipAnimationType =   GET_CONFIG_STR("TOOLTIP", "animationType", 0);
   tooltipAnimationLength = GET_CONFIG_STR("TOOLTIP", "animationLength", 0);
   tooltipBack = Color((str = al_get_config_value(config, "TOOLTIP", "backColor")) ? str : "255,255,192");
   tooltipBorder = Color((str = al_get_config_value(config, "TOOLTIP", "backColor")) ? str : "0,0,0");

   // dialog popup animation
   // ...

   // should the GUI draw dotted rectangles?
   drawDots = (str = al_get_config_value(config, "Skin", "dottedRect")) ? *str != '0' : false;

   // how the focus follows the mouse
   focus = GET_CONFIG_STR("Skin", "focus", 1);

#undef GET_CONFIG_STR

   al_destroy_path(sdp);

   return MAS::Error(MAS::Error::NONE);
}
예제 #28
0
bool _al_show_native_file_dialog(ALLEGRO_DISPLAY *display,
   ALLEGRO_NATIVE_DIALOG *fd)
{
   OPENFILENAME ofn;
   ALLEGRO_DISPLAY_WIN *win_display;
   int flags = 0;
   bool ret;
   char buf[4096] = "";
   ALLEGRO_USTR *filter_string = NULL;

   win_display = (ALLEGRO_DISPLAY_WIN *)display;

   if (fd->flags & ALLEGRO_FILECHOOSER_FOLDER) {
      return select_folder(win_display, fd);
   }

   /* Selecting a file. */
   memset(&ofn, 0, sizeof(OPENFILENAME));
   ofn.lStructSize = sizeof(OPENFILENAME);
   ofn.hwndOwner = (win_display) ? win_display->window : NULL;

   /* Create filter string. */
   if (fd->fc_patterns) {
      filter_string = create_filter_string(fd->fc_patterns);
      ofn.lpstrFilter = al_cstr(filter_string);
   }
   else {
      /* List all files by default. */
      ofn.lpstrFilter = "All Files\0*.*\0\0";
   }

   ofn.lpstrFile = buf;
   ofn.nMaxFile = sizeof(buf);

   if (fd->fc_initial_path) {
      ofn.lpstrInitialDir =
         al_path_cstr(fd->fc_initial_path, ALLEGRO_NATIVE_PATH_SEP);
   }

   if (fd->title)
      ofn.lpstrTitle = al_cstr(fd->title);

   flags |= OFN_NOCHANGEDIR | OFN_EXPLORER;
   if (fd->flags & ALLEGRO_FILECHOOSER_SAVE) {
      flags |= OFN_OVERWRITEPROMPT;
   }
   else {
      flags |= (fd->flags & ALLEGRO_FILECHOOSER_FILE_MUST_EXIST) ? OFN_FILEMUSTEXIST : 0;
   }
   flags |= (fd->flags & ALLEGRO_FILECHOOSER_MULTIPLE) ? OFN_ALLOWMULTISELECT : 0;
   flags |= (fd->flags & ALLEGRO_FILECHOOSER_SHOW_HIDDEN) ? 0x10000000 : 0; // NOTE: 0x10000000 is FORCESHOWHIDDEN
   ofn.Flags = flags;

   if (flags & OFN_OVERWRITEPROMPT) {
      ret = GetSaveFileName(&ofn);
   }
   else {
      ret = GetOpenFileName(&ofn);
   }

   al_ustr_free(filter_string);

   if (!ret) {
      DWORD err = GetLastError();
      if (err != ERROR_SUCCESS) {
         char buf[1000];
         FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, sizeof(buf), NULL);
         ALLEGRO_ERROR("al_show_native_file_dialog failed: %s\n", buf);
      }
      return false;
   }

   if (flags & OFN_ALLOWMULTISELECT) {
      int i;
      /* Count number of file names in buf. */
      fd->fc_path_count = 0;
      i = skip_nul_terminated_string(buf);
      while (1) {
         if (buf[i] == '\0') {
            fd->fc_path_count++;
            if (buf[i+1] == '\0')
               break;
         }
         i++;
      }
   }
   else {
      fd->fc_path_count = 1;
   }

   if (fd->fc_path_count == 1) {
      fd->fc_paths = al_malloc(sizeof(void *));
      fd->fc_paths[0] = al_create_path(buf);
   }
   else {
      int i, p;
      /* If multiple files were selected, the first string in buf is the
       * directory name, followed by each of the file names terminated by NUL.
       */
      fd->fc_paths = al_malloc(fd->fc_path_count * sizeof(void *));
      i = skip_nul_terminated_string(buf);
      for (p = 0; p < (int)fd->fc_path_count; p++) {
         fd->fc_paths[p] = al_create_path_for_directory(buf);
         al_set_path_filename(fd->fc_paths[p], buf+i);
         i += skip_nul_terminated_string(buf+i);
      }
   }

   return true;
}
예제 #29
0
static char* test_level_alloc_read_from_file()
{
    char* level_name = "test.world";

    ALLEGRO_PATH* path = al_create_path(FILES_ASSETS_PATH);
    al_append_path_component(path, FILES_LEVELS_SUBDIRNAME);
    al_set_path_filename(path, level_name);
    const char* filename = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);

    Level* level = level_alloc_read_from_file(filename);

    // test if level is correctly initialized & read from file
    mu_assert(level != NULL);
    mu_assert(level->width == 11);
    mu_assert(level->height == 10);

    // test if cells are correctly initialized
    int i;
    int j;
    for (i = 0; i < level->height; i++) // rows
    {
        for (j = 0; j < level->width; j++) // cols
        {
            mu_assert(level->cells[i][j].row == i);
            mu_assert(level->cells[i][j].col == j);
        }
    }

    // test if cells are correctly read from file
    // row 1
    mu_assert(level->cells[0][0].owner == OWNER_NONE);
    mu_assert(level->cells[0][0].type == ROCK);
    mu_assert(level->cells[0][1].owner == OWNER_NONE);
    mu_assert(level->cells[0][1].type == WATER);
    mu_assert(level->cells[0][2].owner == OWNER_NONE);
    mu_assert(level->cells[0][2].type == BRIDGE);
    mu_assert(level->cells[0][3].owner == OWNER_NONE);
    mu_assert(level->cells[0][3].type == WATER);
    mu_assert(level->cells[0][4].owner == OWNER_NONE);
    mu_assert(level->cells[0][4].type == GROUND);
    mu_assert(level->cells[0][5].owner == OWNER_NONE);
    mu_assert(level->cells[0][5].type == GROUND);
    mu_assert(level->cells[0][6].owner == OWNER_NONE);
    mu_assert(level->cells[0][6].type == GROUND);
    mu_assert(level->cells[0][7].owner == OWNER_NONE);
    mu_assert(level->cells[0][7].type == GROUND);
    mu_assert(level->cells[0][8].owner == OWNER_NONE);
    mu_assert(level->cells[0][8].type == GROUND);
    mu_assert(level->cells[0][9].owner == OWNER_NONE);
    mu_assert(level->cells[0][9].type == GROUND);
    mu_assert(level->cells[0][10].owner == OWNER_NONE);
    mu_assert(level->cells[0][10].type == GROUND);
    // row 2
    mu_assert(level->cells[1][0].owner == OWNER_HUMAN);
    mu_assert(level->cells[1][0].type == UNIT_1);
    mu_assert(level->cells[1][1].owner == OWNER_HUMAN);
    mu_assert(level->cells[1][1].type == UNIT_2);
    mu_assert(level->cells[1][2].owner == OWNER_HUMAN);
    mu_assert(level->cells[1][2].type == UNIT_3);
    mu_assert(level->cells[1][3].owner == OWNER_HUMAN);
    mu_assert(level->cells[1][3].type == HEADQUARTER);
    mu_assert(level->cells[1][4].owner == OWNER_HUMAN);
    mu_assert(level->cells[1][4].type == HEADQUARTER);
    mu_assert(level->cells[1][5].owner == OWNER_NONE);
    mu_assert(level->cells[1][5].type == GROUND);
    mu_assert(level->cells[1][6].owner == OWNER_NONE);
    mu_assert(level->cells[1][6].type == GROUND);
    mu_assert(level->cells[1][7].owner == OWNER_NONE);
    mu_assert(level->cells[1][7].type == GROUND);
    mu_assert(level->cells[1][8].owner == OWNER_NONE);
    mu_assert(level->cells[1][8].type == GROUND);
    mu_assert(level->cells[1][9].owner == OWNER_NONE);
    mu_assert(level->cells[1][9].type == GROUND);
    mu_assert(level->cells[1][10].owner == OWNER_NONE);
    mu_assert(level->cells[1][10].type == GROUND);
    // row 3
    mu_assert(level->cells[2][0].owner == OWNER_AI);
    mu_assert(level->cells[2][0].type == HEADQUARTER);
    mu_assert(level->cells[2][1].owner == OWNER_AI);
    mu_assert(level->cells[2][1].type == HEADQUARTER);
    mu_assert(level->cells[2][2].owner == OWNER_NONE);
    mu_assert(level->cells[2][2].type == GROUND);
    mu_assert(level->cells[2][3].owner == OWNER_HUMAN);
    mu_assert(level->cells[2][3].type == HEADQUARTER);
    mu_assert(level->cells[2][4].owner == OWNER_HUMAN);
    mu_assert(level->cells[2][4].type == HEADQUARTER);
    mu_assert(level->cells[2][5].owner == OWNER_NONE);
    mu_assert(level->cells[2][5].type == GROUND);
    mu_assert(level->cells[2][6].owner == OWNER_NONE);
    mu_assert(level->cells[2][6].type == GROUND);
    mu_assert(level->cells[2][7].owner == OWNER_NONE);
    mu_assert(level->cells[2][7].type == GROUND);
    mu_assert(level->cells[2][8].owner == OWNER_NONE);
    mu_assert(level->cells[2][8].type == GROUND);
    mu_assert(level->cells[2][9].owner == OWNER_NONE);
    mu_assert(level->cells[2][9].type == GROUND);
    mu_assert(level->cells[2][10].owner == OWNER_NONE);
    mu_assert(level->cells[2][10].type == GROUND);
    // row 4
    mu_assert(level->cells[3][0].owner == OWNER_AI);
    mu_assert(level->cells[3][0].type == HEADQUARTER);
    mu_assert(level->cells[3][1].owner == OWNER_AI);
    mu_assert(level->cells[3][1].type == HEADQUARTER);
    mu_assert(level->cells[3][2].owner == OWNER_AI);
    mu_assert(level->cells[3][2].type == UNIT_1);
    mu_assert(level->cells[3][3].owner == OWNER_AI);
    mu_assert(level->cells[3][3].type == UNIT_2);
    mu_assert(level->cells[3][4].owner == OWNER_AI);
    mu_assert(level->cells[3][4].type == UNIT_3);
    mu_assert(level->cells[3][5].owner == OWNER_NONE);
    mu_assert(level->cells[3][5].type == GROUND);
    mu_assert(level->cells[3][6].owner == OWNER_NONE);
    mu_assert(level->cells[3][6].type == GROUND);
    mu_assert(level->cells[3][7].owner == OWNER_NONE);
    mu_assert(level->cells[3][7].type == GROUND);
    mu_assert(level->cells[3][8].owner == OWNER_NONE);
    mu_assert(level->cells[3][8].type == GROUND);
    mu_assert(level->cells[3][9].owner == OWNER_NONE);
    mu_assert(level->cells[3][9].type == GROUND);
    mu_assert(level->cells[3][10].owner == OWNER_NONE);
    mu_assert(level->cells[3][10].type == GROUND);
    // other rows
    int k;
    int l;
    for (k = 4; k < level->height; k++) // rows
    {
        for (l = 0; l < level->width; l++) // cols
        {
            mu_assert(level->cells[k][l].owner == OWNER_NONE);
            mu_assert(level->cells[k][l].type == GROUND);
        }
    }

    al_destroy_path(path);
    level_free(level);

    return NULL;
}
bool
initialize ()
{
  ALLEGRO_BITMAP *temp_color_bitmap;
  ALLEGRO_BITMAP *temp_mask_bitmap;

  global.quit = false;
  al_set_app_name ("Super Battle Thor II");
  if (!al_init ())
    {
      fputs ("Error: Could not start allegro.\n", stderr);
      return false;
    }

  al_set_new_display_option (ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
  al_set_new_display_flags (ALLEGRO_GENERATE_EXPOSE_EVENTS);
  global.display = al_create_display (256, 192);
  if (!global.display)
    {
      fputs ("Error: Allegro could not create a display of 256x192 pixels.\n",
             stderr);
      return false;
    }

  if (!al_install_keyboard ())
    {
      fputs ("Allegro could not initialize the keyboard system.\n", stderr);
      return false;
    }

  global.timer = al_create_timer (ALLEGRO_BPS_TO_SECS (60));
  if (!global.timer)
    {
      fputs ("Allegro could not create a 60hrz timer.\n", stderr);
      return false;
    }

  global.queue = al_create_event_queue ();
  if (!global.queue)
    {
      fputs ("Allegro could not create an event queue.\n", stderr);
      return false;
    }
  al_register_event_source (global.queue, al_get_keyboard_event_source ());
  al_register_event_source (global.queue,
                            al_get_display_event_source (global.display));
  al_register_event_source (global.queue,
                            al_get_timer_event_source (global.timer));

  if (!al_init_image_addon ())
    {
      fputs ("Allegro could not initialize the image loading system.\n",
             stderr);
      return false;
    }

  if (!al_install_audio ())
    {
      fputs ("Allegro could not initialize the audio system.\n", stderr);
      return false;
    }
  al_reserve_samples (16);

  if (!al_init_acodec_addon ())
    {
      fputs ("Allegro could not initialize the audio file loading system.\n",
             stderr);
      return false;
    }

  al_init_font_addon ();

  /* load files */
  global.path = al_get_standard_path (ALLEGRO_PROGRAM_PATH);
  al_append_path_component (global.path, "media");

  al_set_path_filename (global.path, "proggy_tiny.png");
  global.programing_font =
    al_load_bitmap_font (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.programing_font)
    {
      fputs ("Allegro could not load proggy_tiny.png.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "mjollnir.png");
  global.sprite_bitmap[SPRITE_THOR] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sprite_bitmap[SPRITE_THOR])
    {
      fputs ("Allegro could not load mjollnir.png.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "arrows.png");
  global.arrow_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.arrow_bitmap)
    {
      fputs ("Allegro could not load arrows.png.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "background_1_2_3_4.jpg");
  global.backgrounds[BACKGROUND_1] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_1])
    {
      fputs ("Allegro could not load background_1_2_3_4.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "background_5.jpg");
  global.backgrounds[BACKGROUND_5] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_5])
    {
      fputs ("Allegro could not load background_5.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "background_6.jpg");
  global.backgrounds[BACKGROUND_6] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_6])
    {
      fputs ("Allegro could not load background_6.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "title_screen.jpg");
  global.backgrounds[BACKGROUND_TITLE] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_TITLE])
    {
      fputs ("Allegro could not load title_screen.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "game_over.jpg");
  global.backgrounds[BACKGROUND_GAME_OVER] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_GAME_OVER])
    {
      fputs ("Allegro could not load game_over.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "you_win.jpg");
  global.backgrounds[BACKGROUND_YOU_WIN] =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.backgrounds[BACKGROUND_YOU_WIN])
    {
      fputs ("Allegro could not load you_win.jpg.\n", stderr);
      return false;
    }

  global.backgrounds[BACKGROUND_BLACK] = al_create_bitmap (256, 192);
  if (!global.backgrounds[BACKGROUND_BLACK])
    {
      fputs ("Allegro could not make a 256x192 bitmap :o", stderr);
      return false;
    }
  al_set_target_bitmap (global.backgrounds[BACKGROUND_BLACK]);
  al_clear_to_color (al_map_rgb (0, 0, 0));
  al_set_target_backbuffer (global.display);

/* start copy paste code here becasue I'm lazy */
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "0-thor.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 0-thor.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "0-thor_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 0-thor_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_THOR] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "1-giant.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 1-giant.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "1-giant_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 1-giant_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_GIANT] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "2-nidhogg.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 2-nidhogg.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "2-nidhogg_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 2-nidhogg_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_NIDHOGG] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "3-ran.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 3-ran.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "3-ran_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 3-ran_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_RAN] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "4-grendel.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 4-grendel.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "4-grendel_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 4-grendel_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_GRENDEL] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "5-fafnir.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 5-fafnir.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "5-fafnir_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 5-fafnir_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_FAFNIR] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "6-loki.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 6-loki.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "6-loki_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 6-loki_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_LOKI] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "7-fenrir.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load 7-fenrir.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "7-fenrir_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load 7-fenrir_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_FENRIR] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
  al_set_path_filename (global.path, "fight.jpg");
  temp_color_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_color_bitmap)
    {
      fputs ("Allegro could not load fight.jpg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "fight_mask.jpg");
  temp_mask_bitmap =
    al_load_bitmap (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!temp_mask_bitmap)
    {
      fputs ("Allegro could not load fight_mask.jpg.\n", stderr);
      return false;
    }

  global.sprite_bitmap[SPRITE_FIGHT] =
    make_from_mask (temp_color_bitmap, temp_mask_bitmap);
  al_destroy_bitmap (temp_color_bitmap);
  al_destroy_bitmap (temp_mask_bitmap);
/*------------------------------------------------------------------------*/
/* loading sounds here (still copy paste) */
  al_set_path_filename (global.path, "titlescreen_loop.ogg");
  global.sounds[SOUND_TITLESCREEN_LOOP] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_TITLESCREEN_LOOP])
    {
      fputs ("Allegro could not load titlescreen_loop.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "begin_battle.ogg");
  global.sounds[SOUND_BEGIN_BATTLE] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_BEGIN_BATTLE])
    {
      fputs ("Allegro could not load begin_battle.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "battle_loop.ogg");
  global.sounds[SOUND_BATTLE_LOOP] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_BATTLE_LOOP])
    {
      fputs ("Allegro could not load battle_loop.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "dragon_loop.ogg");
  global.sounds[SOUND_DRAGON_LOOP] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_DRAGON_LOOP])
    {
      fputs ("Allegro could not load dragon_loop.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "hit_1.ogg");
  global.sounds[SOUND_HIT_1] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_HIT_1])
    {
      fputs ("Allegro could not load hit_1.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "hit_2.ogg");
  global.sounds[SOUND_HIT_2] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_HIT_2])
    {
      fputs ("Allegro could not load hit_2.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_1.ogg");
  global.sounds[SOUND_LAUGH_1] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_1])
    {
      fputs ("Allegro could not load laugh_1.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_2.ogg");
  global.sounds[SOUND_LAUGH_2] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_2])
    {
      fputs ("Allegro could not load laugh_2.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_3.ogg");
  global.sounds[SOUND_LAUGH_3] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_3])
    {
      fputs ("Allegro could not load laugh_3.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_4.ogg");
  global.sounds[SOUND_LAUGH_4] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_4])
    {
      fputs ("Allegro could not load laugh_4.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_5.ogg");
  global.sounds[SOUND_LAUGH_5] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_5])
    {
      fputs ("Allegro could not load laugh_5.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "laugh_6.ogg");
  global.sounds[SOUND_LAUGH_6] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_LAUGH_6])
    {
      fputs ("Allegro could not load laugh_6.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "killed_baddie.ogg");
  global.sounds[SOUND_KILLED_BADDIE] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_KILLED_BADDIE])
    {
      fputs ("Allegro could not load killed_baddie.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "got_hit.ogg");
  global.sounds[SOUND_GOT_HIT] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_GOT_HIT])
    {
      fputs ("Allegro could not load got_hit.ogg.\n", stderr);
      return false;
    }

  al_set_path_filename (global.path, "you_are_dead.ogg");
  global.sounds[SOUND_YOU_ARE_DEAD] =
    al_load_sample (al_path_cstr (global.path, ALLEGRO_NATIVE_PATH_SEP));
  if (!global.sounds[SOUND_YOU_ARE_DEAD])
    {
      fputs ("Allegro could not you_are_dead.ogg.\n", stderr);
      return false;
    }

  global.music = NULL;

  al_destroy_path (global.path);

  return true;
}