Esempio n. 1
0
bool SelectRoundLayer::init()
{
	if (!Layer::init())
		return false;

	// background
	std::string filePath = FileUtils::getInstance()->fullPathForFilename("selectRound.tmx");
	TiledMapParser* tiledMapParser = TiledMapParser::create(filePath);
	TMXLayer* layer = tiledMapParser->createLayer("backgroundLayer");
	addChild(layer);

	int max_passed_round = GameController::getInstance()->maxPassedRound();
	Point pos;

	// round buttons
	MapGidToGamePos map;
	tiledMapParser->getGidToGamePosMap("roundIconLayer", &map);
	MapGidToGamePos::iterator it = map.begin();
	for (; map.end() != it; ++it) {
		int round = it->first - 1;
		createRoundButton(round, GameController::getInstance()->isUnlock(round), it->second);
		if (max_passed_round == round)
			pos = it->second;
	}

	Size layer_size = layer->getLayerSize();
	Size visibleSize = Director::getInstance()->getVisibleSize();
	int height_offset = layer_size.height - visibleSize.height;
	Vec2 visibleOrigin = Director::getInstance()->getVisibleOrigin();
	setPosition(Vec2(visibleOrigin.x, visibleOrigin.y + height_offset));

	setTouchEnabled(true);

	return true;
}
Esempio n. 2
0
void BattleLayer::_dealMap(){
    Size visibleSize = Director::getInstance()->getVisibleSize();
    
    _battleMapBackground = LayerColor::create(Color4B(0, 0, 0, 255), visibleSize.width, visibleSize.height);
    _battleMapBackground->setPosition(0, 0);
    this->addChild(_battleMapBackground, 0);
    
    TMXTiledMap *tiledMap = TMXTiledMap::create("res/map/battle_map.tmx");
    TMXLayer *backgroundLayer = tiledMap->getLayer("background");
    TMXLayer *walkableLayer = tiledMap->getLayer("walkable");
    
    walkableLayer->setAnchorPoint(Vec2(0.5, 0.5));
    walkableLayer->setPosition(visibleSize.width / 2, visibleSize.height / 2 + 90);
    _battleMapBackground->addChild(walkableLayer, 1);
    
    backgroundLayer->setAnchorPoint(Vec2(0.5, 0.5));
    backgroundLayer->setPosition(visibleSize.width / 2, visibleSize.height / 2 + 90);
    _battleMapBackground->addChild(backgroundLayer, 1);
    
    Size mapSize = walkableLayer->getLayerSize();
    _battleMapTileSize = Size(20, 30);
    _battleTileSize = walkableLayer->getMapTileSize();
    
    _battleMapSize = Size(20 * _battleTileSize.width, 30 * _battleTileSize.height);
    _battleMap = LayerColor::create(Color4B(255, 255, 255, 150), _battleMapSize.width, _battleMapSize.height);
    _battleMap->ignoreAnchorPointForPosition(false);
    _battleMap->setAnchorPoint(Vec2(0.5, 0.5));
    _battleMap->setPosition(visibleSize.width / 2, visibleSize.height / 2 + 90);
    _battleMapBackground->addChild(_battleMap, 5);
    
}
Esempio n. 3
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. 4
0
TMXResizeTest::TMXResizeTest()
{
    auto map = TMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
    addChild(map, 0, kTagTileMap);
    
    Size CC_UNUSED s = map->getContentSize();
    CCLOG("ContentSize: %f, %f", s.width,s.height);

    TMXLayer* layer;
    layer = map->getLayer("Layer 0");

    auto ls = layer->getLayerSize();
    for (unsigned int y = 0; y < ls.height; y++) 
    {
        for (unsigned int x = 0; x < ls.width; x++) 
        {
            layer->setTileGID(1, Vec2( x, y ) );
        }
    }        
}