Ejemplo n.º 1
0
void BattleLayer::_initTower(){
    TMXTiledMap *tiledMap = TMXTiledMap::create("res/map/battle_map.tmx");
    TMXObjectGroup *towerObjectData = tiledMap->getObjectGroup("tower");
    auto &towersData = towerObjectData->getObjects();
    for (auto &towerDataItem : towersData){
        ValueMap &towerData = towerDataItem.asValueMap();
        
//        CCLOG("%s, %s", towerData["side"].asString().c_str(), towerData["type"].asString().c_str());
        
        if (towerData["side"].asString() == "player"){
            if (towerData["type"].asString() == "king"){
//                _playerKingTower = Tower::createTower(TowerType::King, Side::Player, this);
                playerKingTower = createTower(TowerType::King, Side::Player, this);
                playerKingTower->setPosition(_battleMapSize.width / 2, 0);
                _battleMap->addChild(playerKingTower, getBattleElementZOrderOnBattleMap(playerKingTower));
                playerTowers.push_back(playerKingTower);
            }else {
                if (towerData["road"].asString() == "left"){
//                    _playerDefendLeftTower = Tower::createTower(TowerType::Defend, Side::Player, this);
                    playerDefendLeftTower = createTower(TowerType::Defend, Side::Player, this);
                    playerDefendLeftTower->setPosition(_battleTileSize.width * 3.5, _battleTileSize.height * 5);
                    _battleMap->addChild(playerDefendLeftTower, getBattleElementZOrderOnBattleMap(playerDefendLeftTower));
                    playerTowers.push_back(playerDefendLeftTower);
                }
                if (towerData["road"].asString() == "right"){
//                    _playerDefendRightTower = Tower::createTower(TowerType::Defend, Side::Player, this);
                    playerDefendRightTower = createTower(TowerType::Defend, Side::Player, this);
                    playerDefendRightTower->setPosition(_battleTileSize.width * 16.5, _battleTileSize.height * 5);
                    _battleMap->addChild(playerDefendRightTower, getBattleElementZOrderOnBattleMap(playerDefendRightTower));
                    playerTowers.push_back(playerDefendRightTower);
                }
            }
        }else {
            if (towerData["type"].asString() == "king"){
//                _npcKingTower = Tower::createTower(TowerType::King, Side::NPC, this);
                npcKingTower = createTower(TowerType::King, Side::NPC, this);
                npcKingTower->setPosition(_battleMapSize.width / 2, _battleTileSize.height * 26);
                _battleMap->addChild(npcKingTower, getBattleElementZOrderOnBattleMap(npcKingTower));
                npcTowers.push_back(npcKingTower);
            }else {
                if (towerData["road"].asString() == "left"){
//                    _npcDefendLeftTower = Tower::createTower(TowerType::Defend, Side::NPC, this);
                    npcDefendLeftTower = createTower(TowerType::Defend, Side::NPC, this);
                    npcDefendLeftTower->setPosition(_battleTileSize.width * 3.5, _battleTileSize.height * 23);
                    _battleMap->addChild(npcDefendLeftTower, getBattleElementZOrderOnBattleMap(npcDefendLeftTower));
                    npcTowers.push_back(npcDefendLeftTower);
                }
                if (towerData["road"].asString() == "right"){
//                    _npcDefendRightTower = Tower::createTower(TowerType::Defend, Side::NPC, this);
                    npcDefendRightTower = createTower(TowerType::Defend, Side::NPC, this);
                    npcDefendRightTower->setPosition(_battleTileSize.width * 16.5, _battleTileSize.height * 23);
                    _battleMap->addChild(npcDefendRightTower, getBattleElementZOrderOnBattleMap(npcDefendRightTower));
                    npcTowers.push_back(npcDefendRightTower);
                }
            }
        }
        
    }
}
Ejemplo n.º 2
0
void AttackMapLayer::addMapMenu(){
	//以下全部为设置地图的窗口
	TMXTiledMap * changeMap = TMXTiledMap::create("bakground(1).tmx");
	this->addChild(changeMap);
	float cmX = (vSize.width - changeMap->getContentSize().width) / 2;
	changeMap->setPosition(Vec2(cmX, 0));
	TMXObjectGroup * objectgroup = changeMap->getObjectGroup("object");
	ValueMap valuemap = objectgroup->getObject("object1");
	float x = valuemap.at("x").asFloat();
	float y = valuemap.at("y").asFloat();
	auto menuitem = MenuItemImage::create("stage-9.png", "stage-9.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_1, this));
	menuitem->setPosition(Vec2(x, y));
	auto menu = Menu::create(menuitem, NULL);
	menu->setPosition(Vec2(cmX, 0));
	//房后闪光
	auto flashBG = Sprite::create("crusade_stage_7_curren.png");
	flashBG->setPosition(Vec2(x , y));
	//动画渐入渐出
	auto flashAnimationOut = FadeOut::create(0.5);
	auto flashAnimationIn = FadeIn::create(0.5);
	auto seqAction = Sequence::create(flashAnimationOut, flashAnimationIn, NULL);
	flashBG->runAction(RepeatForever::create(seqAction));
	addChild(flashBG);


	valuemap = objectgroup->getObject("object2");
	x = valuemap.at("x").asFloat();
	y = valuemap.at("y").asFloat();
	auto  menuitem1 = MenuItemImage::create("stage-19.png", "stage-19.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_2, this));
	menuitem1->setPosition(Vec2(x, y));
	menu->addChild(menuitem1);

	valuemap = objectgroup->getObject("object3");
	x = valuemap.at("x").asFloat();
	y = valuemap.at("y").asFloat();
	auto  menuitem2 = MenuItemImage::create("stage-23.png", "stage-23.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_3, this));
	menuitem2->setPosition(Vec2(x, y));
	menu->addChild(menuitem2);

	valuemap = objectgroup->getObject("object4");
	x = valuemap.at("x").asFloat();
	y = valuemap.at("y").asFloat();
	auto  menuitem3 = MenuItemImage::create("stage-25.png", "stage-25.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_4, this));
	menuitem3->setPosition(Vec2(x, y));
	menu->addChild(menuitem3);


	this->addChild(menu);
}
Ejemplo n.º 3
0
//鍔犺浇鏁屼汉琛岃蛋璺緞鐐?
void GameScene::initAllPoints()
{
	//寰楀埌tmx鍦板浘
	TMXTiledMap* ourMap = (TMXTiledMap*)this->getChildByTag(0);
	auto Group = ourMap->getObjectGroup("Obj1");//鑾峰彇瀵硅薄灞傛暟鎹?
	auto Objs = Group->getObjects();

	for (auto &eachObj : Objs)
	{
		ValueMap& dict = eachObj.asValueMap();
		float x = dict["x"].asFloat();
		float y = dict["y"].asFloat();
		//灏嗗悇涓偣鏁版嵁鎻愬彇骞剁敓鎴怲DPoint
		TDPoint * newPoint = TDPoint::createPoint(x, y);
		//灏嗘柊鐢熸垚鐨凾DPoint鍔犲叆鏍?
		allPoint.pushBack(newPoint);
	}
}
Ejemplo n.º 4
0
void MapAnalysis::initMap(char* levelName)
{
	GameManager* gameManager = GameManager::getInstance();
	//¶ÁÈ¡TiledµØͼ×ÊÔ´
	TMXTiledMap* tiledMap = TMXTiledMap::create(levelName);
	gameManager->gameLayer->addChild(tiledMap, -1);

	//todo--ÊӲ¾°£¬´Ë´¦ÐÞ¸Ä!TODO!ÔƲÊ
	Sprite* could1 = Sprite::create("Items/cloud1.png");
	could1->setPosition(500, 500);
	gameManager->bkLayer->addChild(could1);
	Sprite* could2 = Sprite::create("Items/cloud2.png");
	could2->setPosition(900, 700);
	gameManager->bkLayer->addChild(could2);
	Sprite* could3 = Sprite::create("Items/cloud3.png");
	could3->setPosition(1400, 450);
	gameManager->bkLayer->addChild(could3);
	Sprite* could4 = Sprite::create("Items/cloud1.png");
	could4->setPosition(1400 + 500, 500);
	gameManager->bkLayer->addChild(could4);
	Sprite* could5 = Sprite::create("Items/cloud2.png");
	could5->setPosition(1400 + 700, 700);
	gameManager->bkLayer->addChild(could5);
	Sprite* could6 = Sprite::create("Items/cloud3.png");
	could6->setPosition(1400 + 1400, 450);
	gameManager->bkLayer->addChild(could6);

	//BrickLayer µØ°å   Spikes ·æ´Ì
	TMXObjectGroup* brickLayer = tiledMap->getObjectGroup("BrickLayer");
	ValueVector bricks = brickLayer->getObjects();
	for (int i = 0; i < bricks.size(); i++)
	{
		ValueMap brick = bricks.at(i).asValueMap();
		float w = brick.at("width").asFloat();
		float h = brick.at("height").asFloat();
		float x = brick.at("x").asFloat() + w/2.0f;
		float y = brick.at("y").asFloat() + h/2.0f;

		if (brick.at("name").asString() == "Brick")//̨½×
		{
			Brick* b = Brick::create(x, y, w, h);
			gameManager->gameLayer->addChild(b);
		}
		else if (brick.at("name").asString() == "Wall")//ǽ
		{
			Wall* wa = Wall::create(x, y, w, h);
			gameManager->gameLayer->addChild(wa);
		}
		else if (brick.at("name").asString() == "Spikes")//·æ´Ì
		{
			Spikes* sk = Spikes::create(x, y, w, h);
			gameManager->gameLayer->addChild(sk);
		}
		else if (brick.at("name").asString() == "DeadRoof")//ËÀÍǫ̈½×
		{
			DeadRoof* dr = DeadRoof::create(x, y, w, h);
			gameManager->gameLayer->addChild(dr);
		}
	}
	//CoinLayer ½ð±Ò
	TMXObjectGroup* coinLayer = tiledMap->getObjectGroup("CoinLayer");
	ValueVector coins = coinLayer->getObjects();
	for (int i = 0; i < coins.size(); i++)
	{
		ValueMap coin = coins.at(i).asValueMap();
		float w = SD_FLOAT("coin_float_width");
		float h = SD_FLOAT("coin_float_height");
		float x = coin.at("x").asFloat() + w / 2.0f;
		float y = coin.at("y").asFloat() + h / 2.0f;

		Coin* c = Coin::create(x, y, w, h);
		gameManager->thingLayer->addChild(c);
	}
	//MonsterLayer ¹ÖÎï
	TMXObjectGroup* monsterLayer = tiledMap->getObjectGroup("MonsterLayer");
	ValueVector monsters = monsterLayer->getObjects();
	for (int i = 0; i < monsters.size(); i++)
	{
		ValueMap monster = monsters.at(i).asValueMap();
		//MonsterEx ÈËÐ͹ÖÎï
		if (monster.at("name").asString() == "MonsterEx")
		{
			float w = SD_FLOAT("monster_float_width");
			float h = SD_FLOAT("monster_float_height");
			float x = monster.at("x").asFloat() + w / 2.0f;
			float y = monster.at("y").asFloat() + h / 2.0f;

			MonsterEx* m = MonsterEx::create(x, y, w, h);
			gameManager->monsterLayer->addChild(m);
		}
		//FlyingSlime ·ÉÐÐÊ·À³Ä·
		if (monster.at("name").asString() == "FlyingSlime")
		{
			float w = SD_FLOAT("flyingslime_float_width");
			float h = SD_FLOAT("flyingslime_float_height");
			float x = monster.at("x").asFloat() + w / 2.0f;
			float y = monster.at("y").asFloat() + h / 2.0f;

			FlyingSlime* f = FlyingSlime::create(x, y, w, h);
			gameManager->monsterLayer->addChild(f);
		}
		//Slime Ê·À³Ä·
		if (monster.at("name").asString() == "Slime")
		{
			float w = SD_FLOAT("slime_float_width");
			float h = SD_FLOAT("slime_float_height");
			float x = monster.at("x").asFloat() + w / 2.0f;
			float y = monster.at("y").asFloat() + h / 2.0f;

			Slime* s = Slime::create(x, y, w, h);
			gameManager->monsterLayer->addChild(s);
		}
		//£¡£¡£¡Bird Äñ  ÖÐÁ¢µÄ--------£¡£¡£¡£¡£¡
		if (monster.at("name").asString() == "Bird")
		{
			float w = SD_FLOAT("bird_float_width");
			float h = SD_FLOAT("bird_float_height");
			float x = monster.at("x").asFloat() + w / 2.0f;
			float y = monster.at("y").asFloat() + h / 2.0f;

			Bird* b = Bird::create(x, y, w, h);
			gameManager->monsterLayer->addChild(b);
		}
	}
	//ArticleLayer ½»»¥ÎïÌå
	TMXObjectGroup* articleLayer = tiledMap->getObjectGroup("ArticleLayer");
	ValueVector articles = articleLayer->getObjects();
	for (int i = 0; i < articles.size(); i++)
	{
		ValueMap article = articles.at(i).asValueMap();
		//Article ½»»¥ÎïÌå-Ïä×Ó
		if (article.at("name").asString() == "Article")
		{
			float w = SD_FLOAT("article_float_width");
			float h = SD_FLOAT("article_float_height");
			float x = article.at("x").asFloat() + w / 2.0f;
			float y = article.at("y").asFloat() + h / 2.0f;

			Article* a = Article::create(x, y, w, h);
			gameManager->thingLayer->addChild(a);
		}
		//Door ÃÅ
		if (article.at("name").asString() == "Door")
		{
			float w = SD_FLOAT("door_float_width");
			float h = SD_FLOAT("door_float_height");
			float x = article.at("x").asFloat() + w / 2.0f;
			float y = article.at("y").asFloat() + h / 2.0f;

			Door* a = Door::create(x, y, w, h);
			gameManager->thingLayer->addChild(a);
		}
		//JumpBoard Ìø°å
		if (article.at("name").asString() == "JumpBoard")
		{
			float w = SD_FLOAT("jump_float_width");
			float h = SD_FLOAT("jump_float_height");
			float x = article.at("x").asFloat() + w / 2.0f;
			float y = article.at("y").asFloat() + h / 2.0f;

			JumpBoard* jb = JumpBoard::create(x, y, w, h);
			gameManager->gameLayer->addChild(jb);
		}
	}
	//HeroLayer Ó¢ÐÛ
	TMXObjectGroup* heroLayer = tiledMap->getObjectGroup("HeroLayer");
	ValueVector heros = heroLayer->getObjects();
	for (int i = 0; i < heros.size(); i++)
	{
		ValueMap hero = heros.at(i).asValueMap();
		//Article ½»»¥ÎïÌå-Ïä×Ó
		if (hero.at("name").asString() == "Hero")
		{
			float w = SD_FLOAT("hero_float_width");
			float h = SD_FLOAT("hero_float_height");
			float x = hero.at("x").asFloat() + w / 2.0f;
			float y = hero.at("y").asFloat() + h / 2.0f;

			Hero* e = Hero::create(x, y, w, h);
			gameManager->heroLayer->addChild(e);
			//ÎÞµÐ1Ãë
			e->setUnbeatable(1);
			GameManager::getInstance()->hero = e;
		}
	}

}
// on "init" you need to initialize your instance
bool GamePlaying::init()
{
	_trans=false;
	_tag=0;
	//////////////////////////////
	// 1. super init first
	if ( !Layer::init() )
	{
	return false;
	}
    
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();
	
	/////////////////////////////
	// 2. add a menu item with "X" image, which is clicked to quit the program
	//    you may modify it.

	// add a "close" icon to exit the progress. it's an autorelease object
	
	auto closeItem = MenuItemImage::create(
						"CloseNormal.png",
						"CloseSelected.png",
						CC_CALLBACK_1(GamePlaying::menuCloseCallback, this));
	Vec2 menupos = Vec2(origin.x + visibleSize.width,
				origin.y + closeItem->getContentSize().height/2);
	menupos.x -=closeItem->getContentSize().width/2;
	closeItem->setPosition(menupos);

	
	//リロード
	auto reloadItem = MenuItemImage::create(
		"reload.png",
		"reload.png",
		CC_CALLBACK_1(GamePlaying::menuReloadCallback, this));
	menupos.x =visibleSize.width/2;
	reloadItem->setPosition(menupos);

	//次へ
	auto nextItem = MenuItemImage::create(
		"next.png",
		"next.png",
		CC_CALLBACK_1(GamePlaying::menuNextCallback, this));
	
	menupos.x =visibleSize.width/2 + nextItem->getContentSize().width*2;
	nextItem->setPosition(menupos);


	// create menu, it's an autorelease object
	auto menu = Menu::create(closeItem, reloadItem ,nextItem, nullptr);
	menu->setPosition(Vec2::ZERO);
	this->addChild(menu, 100);

	int priority=0;


	_pm = PHYSICSSHAPE_MATERIAL_DEFAULT;
	_pm.friction = 0.5f;
	_pm.density = 0.5f;
	/////////////////////////////
	// 3. add your codes below...

	//背景
	auto bg = SpriteBatchNode::create("bg.png");
	auto bg2 = SpriteBatchNode::create("bg2.png");
	int i=0,j=0;
	for(int j=0;j<4;++j){
		for(int i=0;i<2;++i){
			auto sp=Sprite::createWithTexture(bg->getTexture());
			sp->setPosition(128+i*256,128+j*256);
			bg->addChild(sp);
			auto sp2=Sprite::createWithTexture(bg2->getTexture());
			sp2->setPosition(128+i*256,128+j*256);
			bg2->addChild(sp2);
			sp2->runAction(RepeatForever::create(Sequence::createWithTwoActions( FadeIn::create(2.5f),FadeOut::create(2.5f) )));
		}
	}
	addChild(bg);
	addChild(bg2);

	

	TMXTiledMap* tiledmap;
	TMXMapInfo* mapinfo;
	if(stage_no==0){
		_slushLimit=10;
		auto label = LabelTTF::create(GetUTF8FromSJIS("チャンスは1度きり…"), "Arial", 24);
		// position the label on the center of the screen
		label->setPosition(Vec2(origin.x + visibleSize.width/2,
					origin.y + visibleSize.height - label->getContentSize().height));
		// add the label as a child to this layer
		this->addChild(label, priority++);
		tiledmap = TMXTiledMap::create("stage1.tmx");
		mapinfo = TMXMapInfo::create("stage1.tmx");
	}else if(stage_no==2){
		_slushLimit=2;
		auto label = LabelTTF::create(GetUTF8FromSJIS("チャンスは2回のみだ"), "Arial", 24);
		// position the label on the center of the screen
		label->setPosition(Vec2(origin.x + visibleSize.width/2,
					origin.y + visibleSize.height - label->getContentSize().height));

		// add the label as a child to this layer
		this->addChild(label, priority++);

		tiledmap = TMXTiledMap::create("stage2.tmx");
		mapinfo = TMXMapInfo::create("stage2.tmx");
	}else if(stage_no==2){
		_slushLimit=3;
#ifdef _WINDOWS
		auto label = LabelTTF::create(GetUTF8FromSJIS("3回切ってくれたまえ"), "Arial", 24);
#else
		auto label = LabelTTF::create(GetUTF8FromSJIS("3回切ってくれたまえ"),"Arial",24);
#endif
		// position the label on the center of the screen
		label->setPosition(Vec2(origin.x + visibleSize.width/2,
					origin.y + visibleSize.height - label->getContentSize().height));

		// add the label as a child to this layer
		this->addChild(label, priority++);

		tiledmap = TMXTiledMap::create("stage3.tmx");
		mapinfo = TMXMapInfo::create("stage3.tmx");
	}else{
		_slushLimit=3;
		auto data = cocos2d::FileUtils::sharedFileUtils()->getStringFromFile("String.txt");
		
		auto label = LabelTTF::create(data.c_str()/*("3回ぶった斬れ!!")*/, "MS Pゴシック", 24);
    
		// position the label on the center of the screen
		label->setPosition(Vec2(origin.x + visibleSize.width/2,
					origin.y + visibleSize.height - label->getContentSize().height));

		// add the label as a child to this layer
		this->addChild(label, priority++);

		tiledmap = TMXTiledMap::create("stage4.tmx");
		mapinfo = TMXMapInfo::create("stage4.tmx");
	}
	
	auto soni=Sprite::create("soniko_t.png");
	soni->setScale(0.5);
	soni->setPosition(250,400);
	addChild(soni);


	Vector<TMXTilesetInfo*>& tileset = mapinfo->getTilesets();
	TMXTilesetInfo* ts= tileset.at(0);
	
	ObjectLayerParse(tiledmap->getObjectGroup("cuttable"),priority);
	ObjectLayerParse(tiledmap->getObjectGroup("scaffold"),priority);
  
	auto director = Director::getInstance();
	
	auto listener=EventListenerTouchOneByOne::create();
	listener->onTouchBegan=CC_CALLBACK_2(GamePlaying::onTouchBegan,this);
	listener->onTouchMoved=CC_CALLBACK_2(GamePlaying::onTouchMoved,this);
	listener->onTouchEnded=CC_CALLBACK_2(GamePlaying::onTouchEnded,this);

	getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener,this);

	Director::getInstance()->getTextureCache()->addImage("blade.png");

	auto qp=ParticleSystemQuad::create("hellfire.plist");
	qp->setPosition(300,0);
	addChild(qp,10);

	//auto streak = MotionStreak::create(0.3f,0.01f,30.f,Color3B::WHITE,"trail.png");
	//streak->setName("streak");
	//streak->setBlendFunc(BlendFunc::ALPHA_PREMULTIPLIED);
	//addChild(streak);

	//streak->setBlendFunc(b);
	//cocos2d::BlendFunc b;
	//b.dst=GL_ZERO;
	//b.src=GL_ONE_MINUS_DST_COLOR;
	//
	//auto s=Sprite::create();
	//s->setTextureRect(Rect(0,0,480,800));
	//s->setPosition(240,400);
	//s->setColor(Color3B::WHITE);
	//s->setBlendFunc(b);
	//s->setName("reverse");
	//s->setVisible(false);
	//addChild(s,65535);

	scheduleUpdate();

    return true;
}
bool GameMap::loadMap(const int& level)
{
	string fileName = StringUtils::format("map/map_%03d.tmx", level);
	TMXTiledMap* map = TMXTiledMap::create(fileName);
	m_map = map;
	float scale = 1 / Director::getInstance()->getContentScaleFactor();

	//GridPos
	TMXObjectGroup* group = map->getObjectGroup("TowerPos");
	ValueVector vec = group->getObjects();
	m_gridPos.clear();
	m_gridPos.resize(vec.size());
	if (!vec.empty())
	{
		int i = 0;
		for (const auto& v : vec)
		{
			const ValueMap& dict = v.asValueMap();

			m_gridPos[i] = new GridPos( 
				i,
				Rect(dict.at("x").asFloat(),
				dict.at("y").asFloat(),
				dict.at("width").asFloat(),
				dict.at("height").asFloat()));
			i++;
		}
	}
	//计算临近的塔的ID
	float h = group->getProperty("TowerPosHeight").asFloat() *scale;
	float w = group->getProperty("TowerPosWidth").asFloat() *scale;
	float dis = (h + 2)*(h + 2) + (w + 2)*(w + 2);
	vector<int> GridPosID;
	for (auto t1 : m_gridPos)
	{
		GridPosID.clear();
		Point pos = t1->getPos();
		for (auto t2 : m_gridPos)
		{
			if (t1 != t2 && pos.distanceSquared(t2->getPos())<=dis)
			{
				GridPosID.push_back(t2->ID);
			}
		}

		int around[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
		for (auto tid : GridPosID)
		{
			Rect rect = m_gridPos[tid]->getRect();
			if		(rect.containsPoint( Point(pos.x	, pos.y + h	)))around[North] = tid;
			else if (rect.containsPoint( Point(pos.x - w, pos.y + h	)))around[NorthWest] = tid;
			else if (rect.containsPoint( Point(pos.x - w, pos.y		)))around[West] = tid;
			else if (rect.containsPoint( Point(pos.x - w, pos.y - h	)))around[SouthWest] = tid;
			else if (rect.containsPoint( Point(pos.x	, pos.y - h	)))around[South] = tid;
			else if (rect.containsPoint( Point(pos.x + w, pos.y - h	)))around[SouthEast] = tid;
			else if (rect.containsPoint( Point(pos.x + w, pos.y		)))around[East] = tid;
			else if (rect.containsPoint( Point(pos.x + w, pos.y + h	)))around[NorthEast] = tid;
		}
		t1->setAroundGridPosID(around);
	}


	//MonsterPath
	group = map->getObjectGroup("Path");
	vec = group->getObjects();
	MonsterPath.clear();
	if (!vec.empty())
	{
		vector<Point> posvec;
		for (const auto& var : vec)
		{
			posvec.clear();
			const ValueMap& dict = var.asValueMap();
			const ValueVector& vec2 = dict.at("polylinePoints").asValueVector();
			Point pos = Point(dict.at("x").asFloat(), dict.at("y").asFloat());

			for (const auto& v : vec2)
			{
				const ValueMap& dict = v.asValueMap();
				posvec.push_back(Point(pos.x + dict.at("x").asFloat()*scale, pos.y - dict.at("y").asFloat()*scale));
				//posvec.push_back(Point(pos.x + dict.at("x").asFloat(), pos.y - dict.at("y").asFloat()));
			}
			MonsterPath.push_back(MapPath(dict.at("LoopTo").asInt(), posvec));
		}
	}

	//WaveData
	int waveCount= map->getProperty("WaveCount").asInt();
	std::stringstream ss;
	string propertyName;
	WaveList.clear();
	for (int i = 1; i <= waveCount; i++)
	{
		propertyName = StringUtils::format("Wave%03d", i);
		group = map->getObjectGroup(propertyName);
		CCASSERT(group != nullptr, string("propertyName :" + propertyName +" NOT found").c_str());

		Wave wave;
		wave.WaveTime = group->getProperty("waveTime").asInt();
		
		int momsterCount = group->getProperty("momsterCount").asInt();
		for (int j = 1; j <=momsterCount; j++)
		{
			propertyName = StringUtils::format("m%03d", j);
			ss.clear();
			ss << group->getProperty(propertyName).asString();

			WaveData data;
			ss >> data.MonsterID;
			ss >> data.PathID;
			ss >> data.NextDalay;

			wave.wavedata.push_back(data);
		}
		WaveList.push_back(wave);
	}

	return true;
}
Ejemplo n.º 7
0
PushBoxScene::PushBoxScene()
{
    TMXTiledMap* mytmx = TMXTiledMap::create("Pushbox/map.tmx");
    mytmx->setPosition(visibleSize.width / 2, visibleSize.height / 2);
    mytmx->setAnchorPoint(Vec2(0,0));
    myx = (visibleSize.width - mytmx->getContentSize().width) / 2;
    myy = (visibleSize.height - mytmx->getContentSize().height) / 2;
    this->addChild(mytmx, 0);

    count = 0;
    success = 0;
    /*mon = Sprite::create("Pushbox/player.png");
    mon->setAnchorPoint(Vec2(0, 0));
    mon->setPosition(Vec2(SIZE_BLOCK*1+myx, SIZE_BLOCK*8+myy));
    mon->setTag(TAG_PLAYER);
    this->addChild(mon, 1);*/



    TMXObjectGroup* objects = mytmx->getObjectGroup("wall");
    //从对象层中获取对象数组
    ValueVector container = objects->getObjects();
    //遍历对象
    for (auto obj : container) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        Sprite* temp = Sprite::create("Pushbox/wall.png");
        temp->setAnchorPoint(Point(0, 0));
        temp->setPosition(Point(x,y+64));
        mywall.pushBack(temp);
        this->addChild(temp, 1);
    }

    TMXObjectGroup* objects1 = mytmx->getObjectGroup("box");
    //从对象层中获取对象数组
    ValueVector container1 = objects1->getObjects();
    //遍历对象
    for (auto obj : container1) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        Sprite* temp = Sprite::create("Pushbox/box.png");
        temp->setAnchorPoint(Point(0, 0));
        temp->setPosition(Point(x, y+64));
        mybox.pushBack(temp);
        this->addChild(temp, 3);
    }

    TMXObjectGroup* objects2 = mytmx->getObjectGroup("player");
    //从对象层中获取对象数组
    ValueVector container2 = objects2->getObjects();
    //遍历对象
    for (auto obj : container2) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        Sprite* temp = Sprite::create("Pushbox/player.png");
        temp->setAnchorPoint(Point(0, 0));
        temp->setPosition(Point(x, y+64));
        mon = temp;
        this->addChild(temp, 2);
    }

    TMXObjectGroup* objects3 = mytmx->getObjectGroup("goal");
    //从对象层中获取对象数组
    ValueVector container3 = objects3->getObjects();
    //遍历对象
    for (auto obj : container3) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        Sprite* temp = Sprite::create("Pushbox/goal.png");
        temp->setAnchorPoint(Point(0, 0));
        temp->setPosition(Point(x, y+64));
        mygoal.pushBack(temp);
        this->addChild(temp, 1);
    }
}
Ejemplo n.º 8
0
void prep::testTMX()
{
    Size visibleSize = Director::getInstance()->getVisibleSize();

    //创建游戏
    TMXTiledMap* tmx = TMXTiledMap::create("map.tmx");
    tmx->setPosition(visibleSize.width / 2, visibleSize.height / 2);
    tmx->setAnchorPoint(Vec2(0.5, 0.5));
    tmx->setName("paopaot");
    this->addChild(tmx);

    //获取对象层
    TMXObjectGroup* objects = tmx->getObjectGroup("bubble");
    //对应对象层的对象数组
    ValueVector container = objects->getObjects();

    //遍历
    for (auto obj : container) {
        ValueMap values = obj.asValueMap();
        //获取坐标(cocos2dx坐标)
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        auto buble = Sprite::create("bubble.png");
        buble->setPosition(Vec2(x, y + 64));
        buble->ignoreAnchorPointForPosition(true);
        tmx->addChild(buble, 2);
        prep::bubbles.pushBack(buble);
    }

    objects = tmx->getObjectGroup("wall");
    container = objects->getObjects();
    for (auto obj : container) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        auto wall = Sprite::create("wall.png");
        wall->setPosition(Vec2(x, y + 64));
        wall->ignoreAnchorPointForPosition(true);
        tmx->addChild(wall, 1);
        prep::walls.pushBack(wall);
    }

    objects = tmx->getObjectGroup("money");
    container = objects->getObjects();
    for (auto obj : container) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        auto goal = Sprite::create("money.png");
        goal->setPosition(Vec2(x, y + 64));
        goal->ignoreAnchorPointForPosition(true);
        tmx->addChild(goal, 1);
        prep::money.pushBack(goal);
    }

    objects = tmx->getObjectGroup("player");
    container = objects->getObjects();
    for (auto obj : container) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        auto player = Sprite::create("player.png");
        player->setPosition(Vec2(x, y + 64));
        player->ignoreAnchorPointForPosition(true);
        player->setName("player");
        tmx->addChild(player, 1);
    }

}