Ejemplo n.º 1
0
CCPoint PtMap::spawnPoint()
{
	CCStringToStringDictionary *spawnPoint = _gameObjects->objectNamed("playerspawn");
	int x = spawnPoint->objectForKey("x")->toInt();
	int y = spawnPoint->objectForKey("y")->toInt();
	return ccp(x,y);
}
Ejemplo n.º 2
0
bool PtMap::checkCollisionForPosition(CCPoint position)
{
	bool collidable = false;
	position = tileCoordForPosition(position);
	int tileGID = _metaLayer->tileGIDAt(position);
	// Collision checking
	// In previous Versions, this method checked for every eventuality (Water, NPCs, etc) and that was very expensive.
	// Right now, it only checks for the Collidable property. Every NPC that steps on a tile makes it collidable and passable again after it
	// leaves. Water is collidable, but reacts on Action and has its own water property.
	if (tileGID)
	{
		CCStringToStringDictionary *properties = _tileMap->propertiesForGID(tileGID);
		if (properties)
		{
			CCString *collision = properties->objectForKey("Collidable");
			if (collision && strcmp(collision->toStdString().c_str(),"True") == 0) 
			{
				// If Collidable is true, return Yes
				collidable = true;
			}
			else 
			{
				// If not, ... well.
				collidable = false;
			}	
		}		
	}
	
	return collidable;
}
Ejemplo n.º 3
0
CCPoint PtMap::npcSpawnForId(int npcID) 
{
	CCStringToStringDictionary * pDic = (CCStringToStringDictionary*)_npcs->objectAtIndex(npcID);
	int x = pDic->objectForKey("x")->toInt();
	int y = pDic->objectForKey("y")->toInt();
	return ccp(x,y);
}
Ejemplo n.º 4
0
void FlurryAnalyticsX::logEvent(const char *eventName, const char *paramName, const char* paramValue) {
    CCStringToStringDictionary* params = new CCStringToStringDictionary();
    CCString* value = new CCString( paramValue );
    std::string strKey = paramName;
    params->setObject(value, strKey);

    logEvent( eventName, params );
    
    CC_SAFE_RELEASE_NULL( value );
    CC_SAFE_RELEASE_NULL( params );
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
	if ( !CCLayer::init() )
	{
		return false;
	}
	
	SimpleAudioEngine::sharedEngine()->preloadEffect("pickup.caf");
	SimpleAudioEngine::sharedEngine()->preloadEffect("hit.caf");
	SimpleAudioEngine::sharedEngine()->preloadEffect("move.caf");
	SimpleAudioEngine::sharedEngine()->playBackgroundMusic("TileMap.caf");
	
	_enemies = new CCMutableArray<CCSprite *>;
	_projectiles = new CCMutableArray<CCSprite *>;
	
	_tileMap = CCTMXTiledMap::tiledMapWithTMXFile("TileMap.tmx");
    _tileMap->retain();
    
	_background = _tileMap->layerNamed("Background");
    _background->retain();
    
	_foreground = _tileMap->layerNamed("Foreground");
    _foreground->retain();
	
	_meta = _tileMap->layerNamed("Meta");
	_meta->retain();
	
	CCTMXObjectGroup *objects = _tileMap->objectGroupNamed("Objects");
	CCAssert(objects != NULL, "'Objects' object group not found");
	
	CCStringToStringDictionary *spawnPoint = objects->objectNamed("SpawnPoint");
	CCAssert(spawnPoint != NULL, "SpawnPoint object not found");
	int x = spawnPoint->objectForKey("x")->toInt();
	int y = spawnPoint->objectForKey("y")->toInt();
	
    this->addChild(_tileMap);

	_player = CCSprite::spriteWithFile("Player.png");
	_player->retain();
	_player->setPosition(ccp (x, y));
	this->addChild(_player);
	
	this->setViewpointCenter(_player->getPosition());
	
	CCMutableArray<CCStringToStringDictionary*> *allObjects = objects->getObjects();
	CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
	for (it = allObjects->begin(); it != allObjects->end(); ++it)
	{
		if ((*it)->objectForKey(std::string("Enemy")) != NULL)
		{
			int x = (*it)->objectForKey("x")->toInt();
			int y = (*it)->objectForKey("y")->toInt();
			this->addEnemyAt(x, y);
		}
	}
	
	this->setIsTouchEnabled(true);
	
	_numCollected = 0;
	
	_mode = 0;
	
	this->schedule(schedule_selector(HelloWorld::testCollisions));
	
	return true;
}
Ejemplo n.º 6
0
bool Soko::InitialiseLevel(char *LevelName)
{
	mLevel = 0;
	mGameRunning = true;

	// Neat way to remove the label when we restart
	mpLevelCompleteLabel->stopAllActions();
	if (mpLevelCompleteLabel->getOpacity() != 0)
		mpLevelCompleteLabel->runAction(CCFadeOut::actionWithDuration(0.5));

	// Load in tilemap
	this->setTileMap( CCTMXTiledMap::tiledMapWithTMXFile(LevelName) );
	
	this->getTileMap()->retain();
	this->getTileMap()->setScale(0.40);
	this->getTileMap()->setPosition(ccp(128+32,128));
	this->addChild(this->getTileMap());

	// Now place the boxes - they are stored in the map but as Objects,
	// rather than tiles, since I know they will move
	CCTMXObjectGroup *pMobiles = this->getTileMap()->objectGroupNamed("Mobiles");
	CCAssert(pMobiles != NULL, "Error no Mobiles layer in tile map");

	CCMutableArray< CCStringToStringDictionary * > *pObjs = pMobiles->getObjects();
	for( CCMutableArray< CCStringToStringDictionary * >::CCMutableArrayIterator it = pObjs->begin();
		it != pObjs->end(); ++it)
	{
		CCStringToStringDictionary *pDict = *it;
		if ( pDict->objectForKey("name")->toStdString().compare("Box") == 0 )
		{
			int BoxX = pDict->objectForKey("x")->toInt();
			int BoxY = pDict->objectForKey("y")->toInt();
			// Since meta layer is by pixel, rather than by tile
			// Grid coord needs to be divided by 64

			// TODO - Box texture should change when it is over a goal point.
			// Works fine, so long as box doesn't start on a goal
			CCSprite *pBoxSprite = CCSprite::spriteWithTexture(mpSpriteBatchNode->getTexture(),
															CCRectMake(64,0,64,64));
			// No scaling needed since it is a child of layer
			pBoxSprite->setTag(1);
			pBoxSprite->setPosition( ccp(BoxX+32, BoxY+32) );
			this->getTileMap()->addChild(pBoxSprite);
		}
	}

	// Position the player
	mpPlayer = new Player();
	mpPlayer->init(); // Should this happen automatically? It doesn't.
	// TODO - Should do this in player init() fn?
	mpPlayer->mpSprite = CCSprite::spriteWithTexture(mpSpriteBatchNode->getTexture(),
															CCRectMake(0,0,64,64));
	CCStringToStringDictionary *spawnPoint = pMobiles->objectNamed("PlayerStart");
	CCAssert(spawnPoint != NULL, "PlayerStart object not found in Mobiles layer");
	int PX = spawnPoint->objectForKey("x")->toInt();
	int PY = spawnPoint->objectForKey("y")->toInt();

	// I don't see why I can't just set player position - needs to be mpSprite position
	mpPlayer->mpSprite->setPosition( ccp(PX+32, PY+32) );

	this->getTileMap()->addChild(mpPlayer->mpSprite);
	mpPlayer->mIsMoving = false;
	return true;
}