コード例 #1
0
void XmlMapHandler::Save(std::ostream& file, const Map& map)
{
    wxXmlNode* root = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, "Map");

    const Tileset& tileset = map.GetTileset();
    const std::vector<AnimatedTile>& animated_tiles = tileset.GetAnimatedTiles();

    if (map.HasCollisionLayer())
        WriteCollision(root, map);
    for (const auto& tile : animated_tiles)
        WriteAnimation(root, map, tile);
    for (const auto& background : map.GetBackgrounds())
        WriteBackground(root, map, background);
    for (const auto& layer : map.GetLayers())
        WriteLayer(root, map, layer);
    WriteProperties(root, map);

    wxXmlDocument* doc = new wxXmlDocument();
    doc->SetRoot(root);

    wxOutputStream* fos = new wxFOutputStream(file);
    if (!doc->Save(*fos))
        throw "Failed to save XML file";
    delete fos;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: nesterenko-d/kw-game
bool CreateNewGame()
{

	HANDLE mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, NAME_MUTEX2);
	if (!mutex)
		mutex = CreateMutex(NULL, FALSE, NAME_MUTEX2);

	Map *map = new Map(0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 64, 64);
	char path[MAX_PATH];

	strcpy(path, PATH_T0_LEVELS);
	strcat(path, "\\");
	strcat(path, level_name.c_str());

	int count_entitys = 0;

	map->Load(path, count_entitys, next_level_name);
	map->UpdateEdges(GENERAL_MAP_LAYER);
	
	world->Create(map, map->GetLayers());

	Ray::tiles = map;

	InitiatePlayer(0);
	//RefreshPlayer(player);

	

		
	srand((unsigned)time(NULL));
	for (int i = 0; i < count_entitys; i++)
	{
		Entity *e = new Entity(hgeVector(128, 128), GENERAL_MAP_LAYER);
		
		int skin_id = rand()%2+1;

		e->Initiate(skin_id);
		e->SetSpeed(3.5f, 4.5f);

		Sleep(40);
		RefreshPlayer(e);

		world->InsertObject(e);
	}

	//wait_clients = CreateThread(NULL, 0, &WaitClients, NULL, 0, NULL);
	//srv_accept = CreateThread(NULL, 0, &Accept, (void *)world->GetWorldEntitys(), 0, NULL);

	return true;
	

}
コード例 #3
0
ファイル: main.cpp プロジェクト: nesterenko-d/kw-game
bool ConnectToGame()
{
	hgeGUIListbox *lb = (hgeGUIListbox *)gui->GetCtrl(1);
	
	if (0 < lb->GetNumItems())
	{
		int n = lb->GetSelectedItem();
		int find = 0;

		std::string str, srv_ip;
		str = lb->GetItemText(n);

		find = str.find_first_of("|");
		srv_ip = str.substr(0, find);
		level_name = str.substr(find+1);

		Map *map = new Map(0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 64, 64);
		char path[MAX_PATH];
		
		strcpy(path, PATH_T0_LEVELS);
		strcat(path, "\\");
		strcat(path, level_name.c_str());

		//map->Load(path);
		//map->UpdateEdges(GENERAL_MAP_LAYER);
		
		world->Create(map, map->GetLayers());

		Ray::tiles = map;

		HANDLE mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, NAME_MUTEX2);
		if (!mutex)
			mutex = CreateMutex(NULL, FALSE, NAME_MUTEX2);

		//SOCKET sock = ConnectToServer((void *)world, srv_ip);
		//if (sock != NULL)
		//{
		//	NET_DATA *nd = new NET_DATA;
		//	nd->sock = sock;
		//	nd->data = (void *)world->GetWorldEntitys();

		//	client_thread = CreateThread(NULL, 0, &Client, (void *)nd, 0, NULL);
		//}

		return true;
	}

	return false;
}
コード例 #4
0
/** MapToImage
  *
  * Converts a map into an ImageMagick Image
  */
int HandlerUtils::MapToImage(const Map& map, Magick::Image& image)
{
    std::vector<Magick::Image> tiles;

    if (HandlerUtils::GetTiles(map, tiles))
        return -1;

    Magick::Color color = Magick::ColorRGB(0, 0, 0);
    color.alpha(0);

    const Tileset& tileset = map.GetTileset();
    uint32_t tile_width, tile_height;
    tileset.GetTileDimensions(tile_width, tile_height);

    int width = map.GetWidth() * tile_width;
    int height = map.GetHeight() * tile_height;

    image.matte(true);
    image.resize(Magick::Geometry(width, height));
    image.backgroundColor(color);
    image.erase();

    try
    {
        for (const auto& layer : map.GetLayers())
        {
            if (HandlerUtils::LayerToImage(map, layer, tiles, image))
                return -1;
        }
    }
    catch (Magick::Exception& error_)
    {
        return -1;
    }

    return 0;
}