Пример #1
0
int t3f_save_animation_f(T3F_ANIMATION * ap, ALLEGRO_FILE * fp)
{
	int i;

	ani_header[11] = T3F_ANIMATION_REVISION; // put the version number in
	al_fwrite(fp, ani_header, 12);
	al_fwrite16le(fp, ap->bitmaps->count);
	for(i = 0; i < ap->bitmaps->count; i++)
	{
		if(!t3f_save_bitmap_f(fp, ap->bitmaps->bitmap[i]))
		{
			printf("failed to save bitmap\n");
			return 0;
		}
	}
	al_fwrite16le(fp, ap->frames);
	for(i = 0; i < ap->frames; i++)
	{
		al_fwrite16le(fp, ap->frame[i]->bitmap);
		t3f_fwrite_float(fp, ap->frame[i]->x);
		t3f_fwrite_float(fp, ap->frame[i]->y);
		t3f_fwrite_float(fp, ap->frame[i]->z);
		t3f_fwrite_float(fp, ap->frame[i]->width);
		t3f_fwrite_float(fp, ap->frame[i]->height);
		t3f_fwrite_float(fp, ap->frame[i]->angle);
		al_fwrite32le(fp, ap->frame[i]->ticks);
		al_fwrite32le(fp, ap->frame[i]->flags);
	}
	al_fwrite32le(fp, ap->flags);
	return 1;
}
Пример #2
0
int t3f_save_tilemap_f(T3F_TILEMAP * tmp, ALLEGRO_FILE * fp)
{
	int i, j, k;
	char header[16] = {0};
	strcpy(header, "T3F_TILEMAP");
	header[15] = 0;

	al_fwrite(fp, header, 16);
	al_fwrite16le(fp, tmp->layers);
	for(i = 0; i < tmp->layers; i++)
	{
		al_fwrite16le(fp, tmp->layer[i]->width);
		al_fwrite16le(fp, tmp->layer[i]->height);
		for(j = 0; j < tmp->layer[i]->height; j++)
		{
			for(k = 0; k < tmp->layer[i]->width; k++)
			{
				al_fwrite16le(fp, tmp->layer[i]->data[j][k]);
			}
		}
		t3f_fwrite_float(fp, tmp->layer[i]->x);
		t3f_fwrite_float(fp, tmp->layer[i]->y);
		t3f_fwrite_float(fp, tmp->layer[i]->z);
		t3f_fwrite_float(fp, tmp->layer[i]->scale);
		t3f_fwrite_float(fp, tmp->layer[i]->speed_x);
		t3f_fwrite_float(fp, tmp->layer[i]->speed_y);
		al_fwrite32le(fp, tmp->layer[i]->flags);
	}
	al_fwrite32le(fp, tmp->flags);
	return 1;
}
Пример #3
0
void WorldStage::SaveMapToFile(RegionalMap *map)
{
	std::stringstream ss;
	const int MAP_WIDTH=80, MAP_HEIGHT=80;

	//Open a file based on map position
	ss << "region." << map->startX/MAP_WIDTH << "." << map->startY/MAP_HEIGHT;
	ALLEGRO_FILE *file = al_fopen(ss.str().c_str(), "w");
	if(file)
	{
		//Write magic number to it and newline
		al_fputs(file, "b272bda9bf0c1cdcba614b5ed99c4d62");
		al_fputs(file, "\n");

		//Write version number and newline
		al_fputs(file, "0\n");

		//Write each tile as a 32le
		for(int y = 0; y < MAP_HEIGHT; y++) for(int x = 0; x < MAP_WIDTH; x++)
		{
			al_fwrite32le(file, map->tile[x][y].materialTypeIndex);
		}

		//Write each actor id as a 32le
		for(auto actorId = map->actorIDs.begin(); actorId != map->actorIDs.end(); actorId++)
		{
			al_fwrite32le(file, (*actorId));
		}


		//Close a file
		al_fclose(file);
	}
}
bool t3f_save_vector_object_f(T3F_VECTOR_OBJECT * vp, ALLEGRO_FILE * fp)
{
	unsigned char r, g, b, a;
	char header[16] = {'T', '3', 'F', 'V'};
	int i;
	
	if(al_fwrite(fp, header, 16) != 16)
	{
		return false;
	}
	al_fwrite32le(fp, vp->segments);
	for(i = 0; i < vp->segments; i++)
	{
		t3f_fwrite_float(fp, vp->segment[i]->point[0].x);
		t3f_fwrite_float(fp, vp->segment[i]->point[0].y);
		t3f_fwrite_float(fp, vp->segment[i]->point[0].z);
		t3f_fwrite_float(fp, vp->segment[i]->point[1].x);
		t3f_fwrite_float(fp, vp->segment[i]->point[1].y);
		t3f_fwrite_float(fp, vp->segment[i]->point[1].z);
		al_unmap_rgba(vp->segment[i]->color, &r, &g, &b, &a);
		al_fputc(fp, r);
		al_fputc(fp, g);
		al_fputc(fp, b);
		al_fputc(fp, a);
		t3f_fwrite_float(fp, vp->segment[i]->thickness);
	}
	return true;
}
static void pack_object(ALLEGRO_FILE *file, const void *object, size_t len)
{
   /* First write the length of the object, so we know how big to make
      the slice when it is opened later. */      
   al_fwrite32le(file, len);
   al_fwrite(file, object, len);
}
Пример #6
0
int t3f_save_tileset_f(T3F_TILESET * tsp, ALLEGRO_FILE * fp)
{
	int i, j;
	char header[16] = {0};
	strcpy(header, "T3F_TILESET");
	header[15] = 0;

	al_fwrite(fp, header, 16);

	/* write tile data */
	al_fwrite16le(fp, tsp->tiles);
	for(i = 0; i < tsp->tiles; i++)
	{
		t3f_save_animation_f(tsp->tile[i]->ap, fp);
		al_fwrite32le(fp, tsp->tile[i]->flags);

		/* write user data */
		if(tsp->tile[i]->flags & T3F_TILE_FLAG_USER_DATA)
		{
			for(j = 0; j < T3F_TILE_MAX_DATA; j++)
			{
				al_fwrite32le(fp, tsp->tile[i]->user_data[j]);
			}
		}

		/* write animation frames */
		al_fwrite32le(fp, tsp->tile[i]->frame_list_total);
		for(j = 0; j < tsp->tile[i]->frame_list_total; j++)
		{
			al_fwrite16le(fp, tsp->tile[i]->frame_list[j]);
		}
	}

	/* write tileset data */
	al_fwrite32le(fp, tsp->width);
	al_fwrite32le(fp, tsp->height);
	al_fwrite32le(fp, tsp->flags);
	return 1;
}