Esempio n. 1
0
void RoadScene::Event_1(){
    CCTMXLayer * layer = map->layerNamed("entrance_covered");
    layer->setVisible(false);
    CCRPGTalkBox* box1 = CCRPGTalkBox::create(13, "dialog-box.png", "2_3.txt", 13, CCSizeMake(800, 200), 1,callfunc_selector(RoadScene::GoToNextStage),this,screenpos);
    addChild(box1,9999,13);
    box1->NextText();
}
Esempio n. 2
0
void MyScene::addBackground(){
	CCTMXTiledMap* pTmap = CCTMXTiledMap::create("TileMaps/TestDesert.tmx");
	pTmap->setName("Tmap");
	backgroundNode = CCParallaxNode::create();
	backgroundNode->setName("Background");
	backgroundNode->addChild(pTmap, 1, ccp(1.0f, 1.0f), ccp(0, 0));
	this->addChild(backgroundNode, 0);

	CCTMXObjectGroup* objects = pTmap->objectGroupNamed("Objects");
	ValueMap& spawnPoint = objects->getObject("SpawnPoint");
	CCTMXLayer* metaInfo = pTmap->getLayer("MetaInfo");
	metaInfo->setVisible(false);

	//create a dragon on "SpawnPoint"
	int x = spawnPoint["x"].asInt();
	int y = spawnPoint["y"].asInt();

	this->createDragon(CCPoint(ccp(x, y)));
}
Esempio n. 3
0
bool CMGameMap::Init(CMReceiver* pReceiver,enumMarioLevel &eMarioLevel)
{
	do 
	{
		//初始化成员变量
		m_fDropSpeedPlus = 0;
		m_fJumpSpeed = 0;
		m_bIsLeftKeyDown = false;
		m_bIsRightKeyDown = false;
		m_bIsJumpKeyDown = false;
		m_bIsFireKeyDown = false;
		m_bIsHeroDead = false;
		m_pReceiver = pReceiver;
		m_bNeedResetStage = false;

		//初始化游戏对象数组
		m_pArrayItems = CCArray::create();
		m_pArrayItems->retain();
		m_pArrayMonsters = CCArray::create();
		m_pArrayMonsters->retain();
		m_pArrayBlocks = CCArray::create();
		m_pArrayBlocks->retain();
		m_pArrayFireBall = CCArray::create();
		m_pArrayFireBall->retain();

		//初始化Mario
		CMMario* pMario = CMMario::CreateHero(this,eMarioLevel);
		CC_BREAK_IF(pMario==NULL);
		pMario->setPosition(TileMapPosToTileMapLayerPos(ccp(2,11)));
		addChild(pMario,enZOrderFront,enTagMario);
		//pMario->SetStatus(enMarioStatusBig);

		//隐藏原落坑判断层
		CCTMXLayer* pTrapLayer = layerNamed("trap");
		CC_BREAK_IF(pTrapLayer==NULL);
		pTrapLayer->setVisible(false);

		//初始化显示金币
		CCTMXLayer* pCoinLayer = layerNamed("coin");
		CC_BREAK_IF(pCoinLayer==NULL);
		pCoinLayer->setVisible(false);
		//获得地图的瓦片数量
		int nMapHorizontalTileNum = pCoinLayer->boundingBox().size.width/getTileSize().width;
		int nMapVerticalTileNum = pCoinLayer->boundingBox().size.height/getTileSize().height;
		//遍历每片瓦片,寻找金币,建立并加入金币集合
		for (int i = 0;i<nMapHorizontalTileNum;i++)
		{
			for (int j = 0;j<nMapVerticalTileNum;j++)
			{
				if (TileMapPosToTileType(ccp(i,j))==enTileTypeCoin)
				{
					//将瓦片地图坐标转换为瓦片地图层坐标
					CCPoint CoinTileMapLayerPos = TileMapPosToTileMapLayerPos(ccp(i,j));
					CMItemCoin* pCoin = CMItemCoin::CreateItemIcon(CoinTileMapLayerPos,getTileSize(),pMario,this);
					if (pCoin==NULL)
					{
						CCLog("Coin init Error!");
					}
					pCoin->setPosition(CoinTileMapLayerPos);
					pCoin->setAnchorPoint(ccp(0,0));
					m_pArrayItems->addObject(pCoin);
					addChild(pCoin);
				}
			}
		}

		//初始化怪物显示
		CCTMXObjectGroup* pObjectLayer = objectGroupNamed("objects");
		CC_BREAK_IF(pObjectLayer==NULL);
		CCArray *ObjectArray = pObjectLayer->getObjects();
		CCDictionary *pDic = NULL;
		for (unsigned int i = 0; i < ObjectArray->count(); i++)
		{
			pDic = (CCDictionary *)ObjectArray->objectAtIndex(i);
			int PosX = ((CCString*)pDic->objectForKey("x"))->intValue();
			int PosY = ((CCString*)pDic->objectForKey("y"))->intValue();
			PosY -= this->getTileSize().height;
			CCPoint TileXY = ccp(PosX, PosY);

			CCString *strName = (CCString*)pDic->objectForKey("name");
			CCString *strType = (CCString*)pDic->objectForKey("type");

			// 进行怪物的初始化,先根据名字来判断是不是enemy,再细分enemy类型		
			if (strName->m_sString == "enemy")
			{
				if (strType->m_sString == "mushroom")
				{
					CMMonsterMushrooms *pMonster = CMMonsterMushrooms::CreateMonsterMushrooms(TileXY,pMario,this,this);
					if (pMonster==NULL)
					{
						CCLog("pMonster==NULL!");
					}
					pMonster->setPosition(ccp(TileXY.x,TileXY.y));
					pMonster->setAnchorPoint(ccp(0,0));
					m_pArrayMonsters->addObject(pMonster);
					addChild(pMonster,enZOrderFront);
				}
				if (strType->m_sString == "tortoise")
				{
					CMMonsterTortoise *pMonster = CMMonsterTortoise::CreateMonsterTortoise(TileXY,pMario,this,this);
					if (pMonster==NULL)
					{
						CCLog("pMonster==NULL!");
					}
					pMonster->setPosition(ccp(TileXY.x,TileXY.y));
					pMonster->setAnchorPoint(ccp(0,0));
					m_pArrayMonsters->addObject(pMonster);
					addChild(pMonster,enZOrderFront);
				}
				if (strType->m_sString == "flower")
				{
					CMMonsterFlower *pMonster = CMMonsterFlower::CreateMonsterFlower(TileXY,pMario,this,this);
					if (pMonster==NULL)
					{
						CCLog("pMonster==NULL!");
					}
					pMonster->setPosition(ccp(TileXY.x,TileXY.y));
					pMonster->setAnchorPoint(ccp(0,0));
					m_pArrayMonsters->addObject(pMonster);
					addChild(pMonster,enZOrderFront);
				}
			}
		}

		//初始化砖块显示
		CCTMXLayer* pBlockLayer = layerNamed("block");
		CC_BREAK_IF(pBlockLayer==NULL);
		pBlockLayer->setVisible(false);
		//获得地图的瓦片数量
		// 		int nMapHorizontalTileNum = pCoinLayer->boundingBox().size.width/getTileSize().width;
		// 		int nMapVerticalTileNum = pCoinLayer->boundingBox().size.height/getTileSize().height;
		//遍历每片瓦片,寻找瓦片,建立并加入瓦片集合
		for (int i = 0;i<nMapHorizontalTileNum;i++)
		{
			for (int j = 0;j<nMapVerticalTileNum;j++)
			{
				if (TileMapPosToTileType(ccp(i,j))==enTileTypeBlock)
				{
					//解析得到当前砖块的属性
					int GID = pBlockLayer->tileGIDAt(ccp(i,j));
					CCDictionary *pDic = propertiesForGID(GID);
					CC_BREAK_IF(pDic==NULL);
					CCString *strBlockType = (CCString*)pDic->objectForKey("blockType");
					if (strBlockType==NULL)
					{
						continue;
					}
					int nBlockType = strBlockType->intValue();

					//将瓦片地图坐标转换为瓦片地图层坐标
					CCPoint BlockTileMapLayerPos = TileMapPosToTileMapLayerPos(ccp(i,j));
					CMItemBlock* pBlock = CMItemBlock::CreateItemBlock(BlockTileMapLayerPos,getTileSize(),pMario,this,(enumBlockType)nBlockType);
					if (pBlock==NULL)
					{
						CCLog("Block init Error!");
					}
					pBlock->setPosition(BlockTileMapLayerPos);
					pBlock->setAnchorPoint(ccp(0,0));
					m_pArrayBlocks->addObject(pBlock);
					addChild(pBlock);
				}
			}
		}

		return true;
	} while (false);
	CCLog("Fun CMGameMap::Init Error!");
	return false;
}
Esempio n. 4
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    bool bRet = false;
    do 
    {
        //////////////////////////////////////////////////////////////////////////
        // super init first
        //////////////////////////////////////////////////////////////////////////

        CC_BREAK_IF(! CCLayer::init());

        //////////////////////////////////////////////////////////////////////////
        // add your codes below...
        //////////////////////////////////////////////////////////////////////////
		
		CCSize size = CCDirector::sharedDirector()->getWinSize();				

        // 1. Add a menu item with "X" image, which is clicked to quit the program.

        // Create a "close" menu item with close icon, it's an auto release object.
        CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
            "CloseNormal.png",
            "CloseSelected.png",
            this,
            menu_selector(HelloWorld::menuCloseCallback));
        CC_BREAK_IF(! pCloseItem);

        // Place the menu item bottom-right conner.
        pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));

        // Create a menu with the "close" menu item, it's an auto release object.
        CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);

        // Add the menu to HelloWorld layer as a child layer.
        this->addChild(pMenu, 1);

        //// 2. Add a label shows "Hello World".
        //// Create a label and initialize with string "Hello World".
        //CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
        //CC_BREAK_IF(! pLabel);
        //// Get window size and place the label upper.         
        //pLabel->setPosition(ccp(size.width / 2, size.height - 50));
        //// Add the label to HelloWorld layer as a child layer.
        //this->addChild(pLabel, 1);

        // 3. Add add a splash screen, show the cocos2d splash image.
  //      pSprite = CCSprite::create("HelloWorld.png");
  //      CC_BREAK_IF(! pSprite);
  //      pSprite->setPosition(ccp(size.width/3, size.height/3));
		//pSprite->setAnchorPoint(ccp(0, 0));
  //      this->addChild(pSprite, 0);

		CCTMXTiledMap* tileMap = CCTMXTiledMap::tiledMapWithTMXFile("tmx/orthogonal.tmx");
		this->addChild(tileMap, -1, TileMapNode);
		CCTMXLayer* eventLayer = tileMap->layerNamed("GameEventLayer");
		eventLayer->setVisible(false);
		
		//tileMap->layerNamed("WinterLayer")->setVisible(false);
		//tileMap->layerNamed("Background")->setVisible(false);		

		this->setTouchEnabled(true);

        bRet = true;
    } while (0);

    return bRet;
}
Esempio n. 5
0
void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
	CCNode* node = this->getChildByTag(TileMapNode);	
	//NSAssert([node isKindOfClass:[CCTMXTiledMap class]], @"not a CCTMXTiledMap");
	CCTMXTiledMap* tileMap = (CCTMXTiledMap*)node;
	
	// get the position in tile coordinates from the touch location
	CCPoint touchLocation = this->locationFromTouch((cocos2d::CCTouch *)pTouches->anyObject());	
	CCPoint tilePos = this->tilePosFromLocation(touchLocation, tileMap);	

	//// move tilemap so that touched tiles is at center of screen
	this->centerTileMapOnTileCoord(tilePos, tileMap);

	// Check if the touch was on water (eg. tiles with isWater property drawn in GameEventLayer)
	bool isTouchOnWater = false;	
	CCTMXLayer* eventLayer = tileMap->layerNamed("GameEventLayer");
	int tileGID = eventLayer->tileGIDAt(tilePos);	
	//
	if (tileGID != 0) {
		CCDictionary* properties = tileMap->propertiesForGID(tileGID);
		if (properties) {
			//CCLOG(@"NSDictionary 'properties' contains:\n%@", properties);	
			const CCString * isWaterProperty = properties->valueForKey("isWater");
			isTouchOnWater = isWaterProperty->boolValue();			
		}
	}
	
	// Check if the touch was within one of the rectangle objects
	CCTMXObjectGroup* objectLayer = tileMap->objectGroupNamed("ObjectLayer");
	//NSAssert([objectLayer isKindOfClass:[CCTMXObjectGroup class]], 
	//		 @"ObjectLayer not found or not a CCTMXObjectGroup");
	
	bool isTouchInRectangle = false;
	int numObjects = objectLayer->getObjects()->count();
	for (int i = 0; i < numObjects; i++){
		CCDictionary* properties = (CCDictionary*)objectLayer->getObjects()->objectAtIndex(i);
		CCRect rect = this->getRectFromObjectProperties(properties, tileMap);
		//	
		if (CCRect::CCRectContainsPoint(rect, touchLocation)) {
			isTouchInRectangle = true;
			break;
		}
	}
	
	// decide what to do depending on where the touch was ...
	if (isTouchOnWater) {
		//[[SimpleAudioEngine sharedEngine] playEffect:@"alien-sfx.caf"];
		CCLog("touchOnWater");
	}
	else if (isTouchInRectangle) {
		CCLog("touchObject");
		CCParticleSystem* system = CCParticleSystemQuad::particleWithFile("fx-explosion.plist");
		system->setAutoRemoveOnFinish(true);
		system->setPosition(touchLocation);
		this->addChild(system, 1);
	}
	else {

#if 0
		// get the winter layer and toggle its visibility
		CCTMXLayer* winterLayer = tileMap->layerNamed("WinterLayer");
		winterLayer->setVisible(!winterLayer->isVisible());
		
		// other options you might be interested in are:	

		// remove the touched tile		
		winterLayer->removeTileAt(tilePos);		
		// add a specific tile
		tileGID = winterLayer->tileGIDAt(CCPointMake(0, 19));
		winterLayer->setTileGID(tileGID, tilePos);
#endif

	}
}