Esempio n. 1
0
void Bullet::bulletBoom()
{
    Rect rect = getBoundingBox();
    Size mapSize = mTileMapInfo->getTileMap()->getContentSize();

    if (rect.getMinX() < 0 || rect.getMaxX() >= mapSize.width || rect.getMinY() < 0
            || rect.getMaxY() >= mapSize.height)
        return;

    TMXLayer* tmxLayer = mTileMapInfo->getTileMap()->getLayer("layer_0");
    Size tileSize = tmxLayer->getMapTileSize();


    float MinY = mapSize.height - rect.getMinY();
    float MaxY = mapSize.height - rect.getMaxY();


    Point pt = Point((int) rect.getMinX() / tileSize.width, (int) (MinY / tileSize.height));
    if (gidToTileType[tmxLayer->getTileGIDAt(pt)] == tileWall)
        tmxLayer->setTileGID(gidToTileType[tileNone], pt);

    pt = Point((int) rect.getMinX() / tileSize.width, (int) (MaxY / tileSize.height));
    if (gidToTileType[tmxLayer->getTileGIDAt(pt)] == tileWall)
        tmxLayer->setTileGID(gidToTileType[tileNone], pt);

    pt = Point((int) rect.getMaxX() / tileSize.width, (int) (MinY / tileSize.height));
    if (gidToTileType[tmxLayer->getTileGIDAt(pt)] == tileWall)
        tmxLayer->setTileGID(gidToTileType[tileNone], pt);

    pt = Point((int) rect.getMaxX() / tileSize.width, (int) (MaxY / tileSize.height));
    if (gidToTileType[tmxLayer->getTileGIDAt(pt)] == tileWall)
        tmxLayer->setTileGID(gidToTileType[tileNone], pt);
}
void SimplePlatformerScene::drawCollisionTiles()
{
    TMXLayer* collisionLayer = _tileMapNode->getLayer("edgeLayer");
    auto mapSize = _tileMapNode->getMapSize();
    auto tileSize = _tileMapNode->getTileSize();
    Sprite* tile = nullptr;
    Point pos;
    for(int i = 0; i < mapSize.width; i++)
    {
        for(int j = 0; j < mapSize.height; j++)
        {
            tile = collisionLayer->getTileAt(Point(i, j));
            if(tile != nullptr)
            {
                const ValueMap property = _tileMapNode->getPropertiesForGID(collisionLayer->getTileGIDAt(Point(i, j))).asValueMap();
                bool collidable = property.at("collidable").asBool();
                if(collidable)
                {
                    pos = collisionLayer->getPositionAt(Point(i, j));
                    makeBoxObjAt(tile, tileSize, false, PhysicsMaterial(0.2f, 0.5f, 0.5f));
                }
            }
        }
    }
}
Esempio n. 3
0
bool MapLayer::onTouchBegan(Touch *touch, Event *unused_event)
{
    Point beginPos = touch->getLocationInView();
    beginPos = Director::getInstance()->convertToGL(beginPos);

    TMXTiledMap* map = (TMXTiledMap*)this->getChildByTag(kTagTileMap);

    // 获取触摸点在地图位置上的索引
    Point mapPos = map->getPosition();
    Point aimMapIndex = convertTo2d(Point(beginPos.x - mapPos.x, beginPos.y - mapPos.y));
    if(aimMapIndex.x < 0 || aimMapIndex.y < 0 || aimMapIndex.x >= map->getMapSize().width || aimMapIndex.y >= map->getMapSize().height) {
        // 超出地图边界
        return false;
    }

    Point herop = _tamara->getPosition();
    Point mapIndex = convertTo2d(herop);
    TMXLayer* layer = map->getLayer("grass");
    int tilegid = layer->getTileGIDAt(aimMapIndex);
    Value tileValue = map->getPropertiesForGID(tilegid);
    int touchValue = tileValue.asValueMap().at("conflict").asInt();
    if(touchValue == 1) {
        return false;
    }

    _path = _myAstar->findPath(mapIndex.x, mapIndex.y, aimMapIndex.x, aimMapIndex.y, map);
    if(nullptr != _path && _path->count() >= 2) {
        _stepIndex = 1;
    } else {
        _stepIndex = -1;
    }
    _smallStepIndex = 0;

    return true;
}
Esempio n. 4
0
void HelloWorld::initTileDatas()
{
    Size mapsize = m_gamemap->getMapSize();
    TMXLayer* layer = m_gamemap->layerNamed("block");
    assert(layer != NULL);

    for (int m = 0; m < mapsize.width; ++m)
    {
        for (int n = 0; n < mapsize.height; ++n)
        {
            uint32_t gid = layer->getTileGIDAt(Vec2(m, n));
            TileData* data = new TileData(std::make_pair(m, n));
            if (gid)
            {
                ValueMap property = m_gamemap->getPropertiesForGID(gid).asValueMap();

                if (property["block"].asString() == "true")
                    data->setWalkAble(false);
                data->setPriority(property["Priority"].asInt());
                data->setExtraHScore(property["extra"].asInt());
            }
            m_tileDatas.push_back(data);
        }
    }
}
Esempio n. 5
0
void BattleLayer::_makeAStarData(){
    TMXTiledMap *tiledMap = TMXTiledMap::create("res/map/battle_map.tmx");
    TMXLayer *walkableLayer = tiledMap->getLayer("walkable");
    Size mapSize = walkableLayer->getLayerSize();
//    CCLOG("MapSize: (%f, %f)", mapSize.width, mapSize.height);
    
    AStarDataNode astarDataVec[20][30];
    
    for (int column = 0; column < _battleMapTileSize.width; ++column){
        for (int row = 0; row < _battleMapTileSize.height; ++row){
            Vec2 tileCoord = Vec2(column + 5, mapSize.height - (row + 5) - 1);
            int tileGID = walkableLayer->getTileGIDAt(tileCoord);
            
            if (tileGID > 0){
                Value value = tiledMap->getPropertiesForGID(tileGID);
                ValueMap valueMap = value.asValueMap();
                int walkable = valueMap["walkable"].asInt();
//                CCLOG("Column: %d, Row: %d, Walkable: %d", column, row, walkable);
                
                astarDataVec[column][row].column = column;
                astarDataVec[column][row].row = row;
                astarDataVec[column][row].walkable = (walkable == 0) ? false : true;
                
            }
        }
    }
    
    for (int column = 0; column < _battleMapTileSize.width; ++column){
        std::vector<AStarDataNode> oneList;
        std::vector<BattleElement *> oneBattleElementList;
        for (int row = 0; row < _battleMapTileSize.height; ++row){
            AStarDataNode astarDataNode = AStarDataNode(column, row, astarDataVec[column][row].walkable);
            oneList.push_back(astarDataNode);
            oneBattleElementList.push_back(nullptr);
        }
        astarData.push_back(oneList);
        battleElements.push_back(oneBattleElementList);
    }
    
//    for (int row = 0; row < _battleMapTileSize.height; ++row){
//        for (int column = 0; column < _battleMapTileSize.width; ++column){
//            printf("%d", astarData[column][row].walkable);
//        }
//        printf("\n");
//    }
}
Esempio n. 6
0
// 检测地图上该点是否能通过
bool Astar::checkMap(int col, int row)
{
    // 检查地图中是否有碰撞
    if(abs(_aimCol - col) > 0 || abs(_aimRow - row) > 0) {
        TMXLayer* layer = _map->getLayer("grass");
        int tilegid = layer->getTileGIDAt(Point(col, row));

        //Dictionary* tiledic = _map->propertiesForGID(tilegid);
        //String* mvalue = (String*)tiledic->objectForKey("conflict");
        //int mv = mvalue->intValue();
        Value tileValue = _map->getPropertiesForGID(tilegid);
        int touchValue = tileValue.asValueMap().at("conflict").asInt();
        if(touchValue == 1) {
            // 检测到有碰撞
            return false;
        }
    }

    return true;
}
Esempio n. 7
0
bool Global::tileAllowMove(Point MovePoint)
{
	TMXLayer *metaLayer = global->tileMap->getLayer("Meta");
	Point tileCoord = tilePosFromLocation(MovePoint, global->tileMap);
	int tileGid = metaLayer->getTileGIDAt(tileCoord);

	if (tileGid)
	{
		auto properties = tileMap->getPropertiesForGID(tileGid).asValueMap();
		if (!properties.empty())
		{
			auto collision = properties["Collidable"].asString();
			if ("True" == collision)
				return false;
			else
				return true;
		}
		else
			return true;
	}
	return true;
}
Esempio n. 8
0
void PlayMapSix::onEnter() {
	Layer::onEnter();

	bisover = false;
	//visibleSize,屏幕尺寸
	visibleSize = Director::getInstance()->getVisibleSize();

	//添加碰撞监听器
	contactListener = EventListenerPhysicsContact::create();
	contactListener->onContactBegin = CC_CALLBACK_1(PlayMapSix::onContactBegin, this);
	contactListener->onContactPostSolve = CC_CALLBACK_2(PlayMapSix::onContactPostSolve, this);
	contactListener->onContactPreSolve = CC_CALLBACK_2(PlayMapSix::onContactPreSolve, this);
	contactListener->onContactSeparate = CC_CALLBACK_1(PlayMapSix::onContactSeparate, this);
	//事件分发器
	auto eventDispatcher = Director::getInstance()->getEventDispatcher();
	eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);

	//网格地图
	auto winSize = Director::getInstance()->getWinSize();
	//map00瓦片地图地图
	tilemap = TMXTiledMap::create("map/map6.tmx");
	tilemap->setAnchorPoint(Vec2(0,0));
	tilemap->setPosition(Vec2(0,0));
	//auto group = tilemap->getObjectGroup("objects");
	this->addChild(tilemap,-1);

	TMXObjectGroup *objects = tilemap->getObjectGroup("objLayer");
	CCASSERT(NULL != objects, "'Objects' object group not found");
	auto spawnPoint = objects->getObject("hero");
	CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
	print_x = spawnPoint["x"].asInt();
	print_y = spawnPoint["y"].asInt();


	TMXLayer* layer = tilemap->getLayer("collideLayer");//从map中取出“bricks”图层
	//这个循环嵌套是为了给每个砖块精灵设置一个刚体
	int count = 0; 
	for (int y = 0; y<TMX_HEIGHT; y++)
	{
		log("xxxxxxxxxxxxxxxxxxxx:%d", y); int groundcounter = 0; int deadlinecounter = 0; int dispearcounter = 0; int bodycounter = 0;
		Point groundpoint, deadlinepoint, dispearpoint, bodypoint; Size groundsize, deadlinesize, dispearsize, bodysize;
		for (int x = 0; x<TMX_WIDTH; x++)
		{

			int gid = layer->getTileGIDAt(Vec2(x, y));
			Sprite* sprite = layer->getTileAt(Vec2(x, y));//从tile的坐标取出对应的精灵

			if (gid == GROUND_GID) {

				log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
				if (groundcounter == 0) {
					groundpoint = Point(sprite->getPosition().x, sprite->getPosition().y);
					groundsize = sprite->getContentSize();
					log("groundcounter==0");
				}
				groundcounter++; log("groundcounter=%d", groundcounter);

			}
			else {
				if (groundcounter != 0) {
					log("make execute!");
					groundsize = Size(groundsize.width*groundcounter, groundsize.height);
					log("point=%f  %f,size=%f  %f", groundpoint.x, groundpoint.y, groundsize.width, groundsize.height);
					this->makePhysicsObjAt(groundpoint, groundsize, false, 0, 0.0f, 0.0f, 0, GROUND_GID, -1);
				}
				groundcounter = 0;
			}/////////////////
			if (gid == DEAD_LINE_GID) {

				log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
				if (deadlinecounter == 0) {
					deadlinepoint = Point(sprite->getPosition().x, sprite->getPosition().y);
					deadlinesize = sprite->getContentSize();
					log("groundcounter==0");
				}
				deadlinecounter++; log("groundcounter=%d", deadlinecounter);

			}
			else {
				if (deadlinecounter != 0) {
					log("make execute!");
					deadlinesize = Size(deadlinesize.width*deadlinecounter, deadlinesize.height);
					log("point=%f  %f,size=%f  %f", deadlinepoint.x, deadlinepoint.y, deadlinesize.width, deadlinesize.height);
					this->makePhysicsObjAt(deadlinepoint, deadlinesize, false, 0, 0.0f, 0.0f, 0, DEAD_LINE_GID, -1);
				}
				deadlinecounter = 0;
			}
			if (gid == CAN_DISPEAR_GID) {
				sprite->setTag(count);
				log("sprite->setTag(%d);", count);
				log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
				if (dispearcounter == 0) {
					dispearpoint = Point(sprite->getPosition().x, sprite->getPosition().y);
					dispearsize = sprite->getContentSize();
					log("groundcounter==0");
				}
				dispearcounter++; log("groundcounter=%d", dispearcounter);

			}
			else {
				if (dispearcounter != 0) {
					log("make execute!");
					dispearsize = Size(dispearsize.width*dispearcounter, dispearsize.height);
					log("point=%f  %f,size=%f  %f", dispearpoint.x, dispearpoint.y, dispearsize.width, dispearsize.height);
					this->makePhysicsObjAt(dispearpoint, dispearsize, false, 0, 0.0f, 0.0f, 0, CAN_DISPEAR_GID, count);
					count++;
				}
				dispearcounter = 0;
			}
			if (gid == BODY_GID) {

				log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
				if (bodycounter == 0) {
					bodypoint = Point(sprite->getPosition().x, sprite->getPosition().y);
					bodysize = sprite->getContentSize();
					log("groundcounter==0");
				}
				bodycounter++; log("groundcounter=%d", bodycounter);

			}
			else {
				if (bodycounter != 0) {
					log("make execute!");
					bodysize = Size(bodysize.width*bodycounter, bodysize.height);
					log("point=%f  %f,size=%f  %f", bodypoint.x, bodypoint.y, bodysize.width, bodysize.height);
					this->makePhysicsObjAt(bodypoint, bodysize, false, 0, 0.0f, 0.0f, 0, BODY_GID, -1);
				}
				bodycounter = 0;
			}
			if (count == 10000)count = 0;
		}
	}

/*******    原始添加刚体算法,当刚体太多容易造成屏幕反应迟钝,故优化为以上算法    **************
	for (int y = 0; y<TMX_HEIGHT; y++)
	{
		log("xxxxxxxxxxxxxxxxxxxx:%d",y);
		for (int x = 0; x<TMX_WIDTH; x++)
		{
			log("yyyyyyyyyyyyyyyyy:%d",x);
			int gid = layer->getTileGIDAt(Vec2(x, y));//为了提高点效率,我们没必要给每个tile加上刚体,在创建地图时我们设定了空白处的gid值为12,因此我们只对非12的tile加上刚体
			log("GGIIDD %d",gid);
			switch (gid)
			{
			case GROUND_GID:
				{
					log("GGGGGGGGGGGGIIIIIIIIIIIIIDDDDDDDDDDDDD");
					Sprite* sprite = layer->getTileAt(Vec2(x, y));//从tile的坐标取出对应的精灵
					log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
					auto point = Point(sprite->getPosition().x, sprite->getPosition().y);
					auto size = Size(sprite->getContentSize().width, sprite->getContentSize().height);
					log("xxxxxxxxxxx  %f,llllllllllll %f", sprite->getContentSize().width, sprite->getContentSize().height);
					this->makePhysicsObjAt(point, size, false, 0, 0.0f, 0.0f, 0, GROUND_GID,-1);
				}break;
			case DEAD_LINE_GID:
			{
				Sprite* sprite = layer->getTileAt(Vec2(x, y));//从tile的坐标取出对应的精灵
				log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
				auto point = Point(sprite->getPosition().x, sprite->getPosition().y);
				auto size = Size(sprite->getContentSize().width, sprite->getContentSize().height);
				log("xxxxxxxxxxx  %f,llllllllllll %f", sprite->getContentSize().width, sprite->getContentSize().height);
				this->makePhysicsObjAt(point, size, false, 0, 0.0f, 0.0f, 0, DEAD_LINE_GID,-1);
			}break;
			case CAN_DISPEAR_GID:
			{
				Sprite* sprite = layer->getTileAt(Vec2(x, y));//从tile的坐标取出对应的精灵
				sprite->setTag(count);
				log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
				auto point = Point(sprite->getPosition().x, sprite->getPosition().y);
				auto size = Size(sprite->getContentSize().width, sprite->getContentSize().height);
				log("xxxxxxxxxxx  %f,llllllllllll %f", sprite->getContentSize().width, sprite->getContentSize().height);
				this->makePhysicsObjAt(point, size, false, 0, 0.0f, 0.0f, 0, CAN_DISPEAR_GID,count);
				count++;
			}break;
			case  BODY_GID:
			{
				log("GGGGGGGGGGGGIIIIIIIIIIIIIDDDDDDDDDDDDD");
				Sprite* sprite = layer->getTileAt(Vec2(x, y));//从tile的坐标取出对应的精灵
				log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
				auto point = Point(sprite->getPosition().x, sprite->getPosition().y);
				auto size = Size(sprite->getContentSize().width, sprite->getContentSize().height);
				log("xxxxxxxxxxx  %f,llllllllllll %f", sprite->getContentSize().width, sprite->getContentSize().height);
				this->makePhysicsObjAt(point, size, false, 0, 0.0f, 0.0f, 0, GROUND_GID, -1);
			}break;
			default:
				break;
			}
			if (count == 10000)count = 0;
		}
	}
*/
	/*
	//带物理的会动的
	dead = DeadStar::create();
	dead->initWithFile("dead.png");			
	dead->setAnchorPoint(Point(0, 0);
	dead->setPosition(visibleSize.width / 2 + 20, visibleSize.height / 3 + 400);
	dead->getPhysicsBody()->setContactTestBitmask(DEAD_LINE);
	this->addChild(dead);
	*/

	//加入障碍物
//	auto obstacle1 = Obstacle::create();
//	obstacle1->setAnchorPoint(Point(0, 0));//
//	obstacle1->setPosition(visibleSize.width / 2+300 , visibleSize.height /2);
//	obstacle1->getPhysicsBody()->setContactTestBitmask(OBJECT_BIT_MASK);
//	this->addChild(obstacle1);

	//加入圆形
	/*
	auto circular = Circular::create();
	circular->setPosition(visibleSize.width / 2 + 100, visibleSize.height / 3+50);
	circular->getPhysicsBody()->setContactTestBitmask(OBJECT_BIT_MASK);
	addChild(circular);

	auto circular2 = Circular::create();
	circular2->setPosition(visibleSize.width / 2 + 100, visibleSize.height / 3 + 100);
	circular2->getPhysicsBody()->setContactTestBitmask(OBJECT_BIT_MASK);
	addChild(circular2);*/

	//加入小怪兽
//	MA1 = MonsterA::create();
//	MA1->initWithFile("redcircle.png");
//	MA1->setAnchorPoint(Point(0, 1));////////////////
//	MA1->setPosition(visibleSize.width *2 + 60, visibleSize.height / 3 + 200);
//	MA1->getPhysicsBody()->setContactTestBitmask(MONSTER1_BIT_MASK);
//	log("MA1 - getTag();%d", MA1 - getTag());
//	this->addChild(MA1);

// 设置准确位置,放置怪兽;
	auto printM1 = objects->getObject("monster1");
	//	CCASSERT(!printM1.empty(), "SpawnPoint object not found");
	int x1 = printM1["x"].asInt();
	int y1 = printM1["y"].asInt();
	//	auto _player = Sprite::create("orangetriangle.png");
	auto player1 = MonsterD::create();
	//player1->initWithFile("orangetriangle.png");
	player1->setAnchorPoint(Point(0, 1));
	player1->setPosition(x1, y1);
	player1->getPhysicsBody()->setContactTestBitmask(MONSTER1_BIT_MASK);
	addChild(player1);
	//setViewPointCenter(_player->getPosition());

	auto printM2 = objects->getObject("monster2");
	//	CCASSERT(!printM2.empty(), "SpawnPoint object not found");
	int x2 = printM2["x"].asInt();
	int y2 = printM2["y"].asInt();
	//	auto _player = Sprite::create("orangetriangle.png");
	auto player2 = MonsterD::create();
	//player2->initWithFile("orangetriangle.png");
	player2->setAnchorPoint(Point(0, 1));
	player2->setPosition(x2, y2);
	player2->getPhysicsBody()->setContactTestBitmask(MONSTER1_BIT_MASK);
	addChild(player2);

	auto printM3 = objects->getObject("monster3");
	//	CCASSERT(!printM3.empty(), "SpawnPoint object not found");
	int x3 = printM3["x"].asInt();
	int y3 = printM3["y"].asInt();
	//	auto _player = Sprite::create("orangetriangle.png");
	auto player3 = MonsterD::create();
	//player2->initWithFile("orangetriangle.png");
	player3->setAnchorPoint(Point(0, 1));
	player3->setPosition(x3, y3);
	player3->getPhysicsBody()->setContactTestBitmask(MONSTER1_BIT_MASK);
	addChild(player3);

	auto printM4 = objects->getObject("monster4");
	//	CCASSERT(!printM4.empty(), "SpawnPoint object not found");
	int x4 = printM4["x"].asInt();
	int y4 = printM4["y"].asInt();
	//	auto _player = Sprite::create("orangetriangle.png");
	auto player4 = MonsterD::create();
	//player1->initWithFile("orangetriangle.png");
	player4->setAnchorPoint(Point(0, 1));
	player4->setPosition(x4, y4);
	player4->getPhysicsBody()->setContactTestBitmask(MONSTER1_BIT_MASK);
	addChild(player4);
	//setViewPointCenter(_player->getPosition());

	auto printM5 = objects->getObject("monster5");
	//	CCASSERT(!printM5.empty(), "SpawnPoint object not found");
	int x5 = printM5["x"].asInt();
	int y5 = printM5["y"].asInt();
	//	auto _player = Sprite::create("orangetriangle.png");
	auto player5 = MonsterD::create();
	//player2->initWithFile("orangetriangle.png");
	player5->setAnchorPoint(Point(0, 1));
	player5->setPosition(x5, y5);
	player5->getPhysicsBody()->setContactTestBitmask(MONSTER1_BIT_MASK);
	addChild(player5);

	auto printM6 = objects->getObject("monster6");
	//	CCASSERT(!printM6.empty(), "SpawnPoint object not found");
	int x6 = printM6["x"].asInt();
	int y6 = printM6["y"].asInt();
	//	auto _player = Sprite::create("orangetriangle.png");
	auto player6 = MonsterD::create();
	//player2->initWithFile("orangetriangle.png");
	player6->setAnchorPoint(Point(0, 1));
	player6->setPosition(x6, y6);
	player6->getPhysicsBody()->setContactTestBitmask(MONSTER1_BIT_MASK);
	addChild(player6);

	auto printM7 = objects->getObject("monster7");
	//	CCASSERT(!printM1.empty(), "SpawnPoint object not found");
	int x7 = printM7["x"].asInt();
	int y7 = printM7["y"].asInt();
	//	auto _player = Sprite::create("orangetriangle.png");
	auto player7 = MonsterD::create();
	//player1->initWithFile("orangetriangle.png");
	player7->setAnchorPoint(Point(0, 1));
	player7->setPosition(x7, y7);
	player7->getPhysicsBody()->setContactTestBitmask(MONSTER1_BIT_MASK);
	addChild(player7);
	//setViewPointCenter(_player->getPosition());

	//加入门
	auto door = Ground::create();
	door->groundSize = Size(visibleSize.width / 6, visibleSize.height/4);
	door->init(door->groundSize);
	door->getPhysicsBody()->setContactTestBitmask(DOOR_BIT_MASK);
	//stage1->setAnchorPoint(Point(0, 1));visibleSize.width / 2, visibleSize.height / 3
	door->setPosition(door->groundSize.width / 2 + visibleSize.width * 5, door->groundSize.height / 2 + visibleSize.height / 3);
	addChild(door);
	auto doorpicture = Sprite::create("road_5.png");	//静态的,为不动的刚体添加图片使用这种方式
	doorpicture->setAnchorPoint(Point(0, 0));
	doorpicture->setPosition(visibleSize.width * 5, visibleSize.height / 3);
	this->addChild(doorpicture);//

	//加入桥
	/*
	bridge = Board::create();
	bridge->setPosition(100, 100);
	bridge->setPosition(visibleSize.width / 2 + 20, visibleSize.height / 3 + 200);
	addChild(bridge);*/

	state = 0;
	scheduleUpdate();
}
std::vector<cocos2d::Vec2> SpriteInMap::findPath(cocos2d::Vec2 src, cocos2d::Vec2 dst)
{
    int iter_sin[]={0,1,0,-1};
    int iter_cos[]={1,0,-1,0};
    struct path_element {
        int x,y;
        float f,g;
        int prev_x,prev_y;
        bool closedset;
        bool openset;
    };
    //    int prev[(int)map_isize.width][(int)map_isize.height][3]; // 0 prev_x 1 prev_y 2 cost
    path_element mapa[(int)map_isize.width][(int)map_isize.height];
    for (int i=0;i<(int)map_isize.width;i++)
        for (int j=0;j<(int)map_isize.height;j++) {
            mapa[i][j].closedset=false;
            mapa[i][j].openset=false;
        }
    
    //vector<path_element> closed;
    priority_queue<path_element*,vector<path_element*>,function<bool(path_element*,path_element*)> > openq( [] (path_element *a, path_element *b) {
        return (a->f > b->f);
    });
    
    TMXLayer *maplayer = themap->getLayer("main");
    
    //themap->getLayer("selection")->setTileGID(13,Vec2(0,0));
    
    int sx=src.x;
    int sy=src.y;
    path_element *start = &mapa[sx][sy];
    start->x=src.x;
    start->y=src.y;
    start->g=0;
    start->f=0+abs(src.x-dst.x)+abs(src.y-dst.y);
    start->openset=true;
    openq.push(start);
    
    vector<Vec2> reverse_path;
    reverse_path.clear();
    
    while ( !openq.empty() ) {
        //cout << "openqueue size: " <<openq.size() <<"\n";
        path_element *current = openq.top(); openq.pop();
        //cout << "selected ("<<current->x<<","<<current->y<<")\n";
        if ( abs(current->x-dst.x)<0.5 && abs(current->y-dst.y)<0.5 ) {
            //cout<<"found\n";
            path_element *e = current;
            do {
                reverse_path.push_back(Vec2(e->x,e->y));
                e=&mapa[e->prev_x][e->prev_y];
            } while (e!=start);
            return reverse_path;
        }
        int cx=(int)current->x;
        int cy=(int)current->y;
        mapa[cx][cy].closedset=true;
        mapa[cx][cy].openset=false;
        for (int i=0;i<4;i++) {
            int nx=cx+iter_cos[i];
            int ny=cy+iter_sin[i];
            if (maplayer->getTileGIDAt(Vec2(nx,ny))!=0) continue;
            path_element *nb = &mapa[nx][ny];
            //cout << "n ("<<nx<<","<<ny<<")\n";
            if (nb->closedset) continue;
            if (nx<0 || ny<0 || nx>map_isize.width-1 || ny>map_isize.height-1) continue;
            if ( (!nb->openset) || (1+current->g<nb->g) ) {
                //cout << "changed\n";
                nb->x=nx;
                nb->y=ny;
                nb->g=1+current->g;
                nb->f=nb->g+abs(nb->x-dst.x)+abs(nb->y-dst.y);
                nb->prev_x=cx;
                nb->prev_y=cy;
                if (!nb->openset) openq.push(nb);
                nb->openset=true;
                // cout<<"f: "<<nb->g<<" g: "<<nb->f<<" \n";
            }
        }
    }
    return reverse_path;
}