Lightning* LightningManager::addLightning(const Ogre::Vector3& p, const Ogre::Vector3& d, const Ogre::Real l, const Ogre::uint32& div)
	{
		if (!mCreated || mLightnings.size() == 3)
		{
			return static_cast<Lightning*>(NULL);
		}

		Ogre::SceneNode* sn = mVClouds->getSceneManager()->getRootSceneNode()->createChildSceneNode();
		sn->setPosition(p);

		Lightning* lightning = new Lightning(mVClouds->getSceneManager(), sn, Ogre::Vector3(0,0,0), d, l, div, 3, mLightningTimeMultiplier, mVClouds->getGeometrySettings().Radius/9500);
		lightning->create();
		lightning->_updateRenderQueueGroup(
			mVClouds->getGeometryManager()->_getCurrentDistance().y < mVClouds->getGeometryManager()->getHeight().y/2 ?
			mVClouds->getRenderQueueGroups().vcloudsLightningsUnder : mVClouds->getRenderQueueGroups().vcloudsLightningsOver);
		lightning->getBillboardSet()->setVisible(mVClouds->isVisible());

		mSceneNodes.push_back(sn);
		mLightnings.push_back(lightning);

		for(Ogre::uint32 k = 0; k < mListeners.size(); k++)
		{
			mListeners.at(k)->lightningAdded(lightning);
		}

		return lightning;
	}
Exemple #2
0
// on "init" you need to initialize your instance
bool MainLayer::init()
{
	bool bRet = false;
	do
	{
		//////////////////////////////////////////////////////////////////////////
		// super init first
		//////////////////////////////////////////////////////////////////////////
        
		CC_BREAK_IF(! CCLayer::init());
        
		//////////////////////////////////////////////////////////////////////////
		// add your codes below...
		//////////////////////////////////////////////////////////////////////////
		this->setTouchEnabled(true);
        
		background = CCSprite::create("map.jpg");
		background->setAnchorPoint(ccp(0,0));
		background->setPosition(CCPointZero);
		this->addChild(background);
        
        
		createTileMap();
        
		gameHUD = GameHUD::sharedHUD();
        
		currentLevel = 0;
		addWaves();
        
		m_emitter = CCParticleRain::create();
		//m_emitter->retain();
		this->addChild(m_emitter, 10);
		m_emitter->setLife(4);
        
		m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png") );
        
		Lightning* l = Lightning::create(ccp(160,maxHeight), ccp(200, 20));
		l->setVisible(false);
		this->addChild(l, 1, 999);
		this->schedule(schedule_selector(MainLayer::strikeLight), 5.0f);
        
		this->schedule(schedule_selector(MainLayer::gameLogic), 0.1f);
        
		bRet = true;
	} while (0);
    
	return bRet;
}
Exemple #3
0
Lightning *Lightning::create(const char *fileName, unsigned int capacity, float detail, float thickness, float displace)//根据details 来设定sprite的容量
{
    Lightning *pRet = new Lightning();
    pRet->initWithFile("edge.png", capacity);
    pRet->fileName = "edge.png";
    pRet->lines = CCArray::create();
    pRet->detail = detail;
    pRet->thickness = thickness;
    pRet->displace = displace;
    ccBlendFunc blendFunc = {GL_ONE, GL_ONE};
    pRet->setBlendFunc(blendFunc);
    pRet->alpha = 1.0f;
    pRet->fadeOutRate = 3.3f;
    pRet->color = ccc3(0.2*255, 0.2*255, 0.7*255);
    pRet->scheduleUpdate();

    pRet->autorelease();
    return pRet;
}
Exemple #4
0
void BreakFast::Update(float delta_time)
{
    ps->ProcessEntities(delta_time);
    es->ProcessAll();
    
    Position* paddle_pos = es->GetComponent<Position>(paddle);
    Position* ball_pos = es->GetComponent<Position>(ball);
    if(ball_pos->pos.y < 0)
    {
        Player* state = es->GetComponent<Player>(paddle);
        if(--state->lives > 0)
        {
            ResetPaddle();
            ResetBall();
        }
        else
        {
            SetNextPhase(new BreakFast());
        }
    }
    
    Lightning* effect = es->GetComponent<Lightning>(lightning);
    effect->ClearPoints();
    
    TouchDevice* device = application->GetTouchDevice();
    
    if(device->GetNumTouches() > 1 && ball_in_play)
    {
        
        const Touch* touch = device->GetTouchByIndex(1);
        effect->SetPoint(0, paddle_pos->pos);
        effect->SetPoint(1, ball_pos->pos);
        effect->SetPoint(2, Vector2(touch->x, touch->y));
        
        Vector2 force(touch->x - ball_pos->pos.x, touch->y - ball_pos->pos.y);
        force.Normalise();
        force *= 10;
        
        Physics* phys = es->GetComponent<Physics>(ball);
        phys->force = force;
    }
    effect->Update(delta_time);
}
Exemple #5
0
	void Lightning::create()
	{
		remove();

		Ogre::Vector3 end = mOrigin + mDirection*mLength;
		Ogre::Vector3 current, last = mOrigin;

		// Create ray segments
		for(Ogre::uint32 k = 1; k < mDivisions+1; k++)
		{
			Ogre::Vector3 current = mOrigin + mDirection*mLength*(static_cast<Ogre::Real>(k)/mDivisions);

			current += (mLength/(mDivisions*3))*Ogre::Vector3(
				Ogre::Math::RangeRandom(-1, 1), Ogre::Math::RangeRandom(-1, 1), Ogre::Math::RangeRandom(-1, 1));

			mSegments.push_back(Segment(last, current));

			mRealLength += (current-last).length();

			last = current;
		}

		// Create the associated billboard set
		mBillboardSet = mSceneManager->createBillboardSet();
		mBillboardSet->setMaterialName("SkyX_Lightning");
		mBillboardSet->setBillboardType(Ogre::BBT_ORIENTED_SELF);

		Ogre::Real width = mWidthMultiplier*3*(static_cast<Ogre::Real>(mRecursivity)/4+1)*Ogre::Math::RangeRandom(0.5f, 2.5f-mRecursivity/3);

		// Create the associated billboard for each segment
		Ogre::Real delta;
		Ogre::Vector2 bounds;
		Ogre::Billboard* bb;
		for(Ogre::uint32 k = 0; k < mSegments.size(); k++)
		{
			delta = 1.0f / mSegments.size();
			bounds = Ogre::Vector2(k*delta,(k+1)*delta);

			bounds = Ogre::Vector2(mBounds.x, mBounds.x) + bounds*(mBounds.y-mBounds.x);

			bb = mBillboardSet->createBillboard((mSegments.at(k).a+mSegments.at(k).b)/2);
			bb->setDimensions(width, (mSegments.at(k).a-mSegments.at(k).b).length());
			bb->setColour(Ogre::ColourValue(0,bounds.x,bounds.y));
			bb->mDirection = (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy();

			bb = mBillboardSet->createBillboard(mSegments.at(k).a + (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy()*width/2);
			bb->setDimensions(width, width);
			bb->setColour(Ogre::ColourValue(1,bounds.x,bounds.x));
			bb->mDirection = (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy();
			
			bb = mBillboardSet->createBillboard(mSegments.at(k).b - (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy()*width/2);
			bb->setDimensions(width, width);
			bb->setColour(Ogre::ColourValue(1,bounds.y,bounds.y));
			bb->mDirection = -(mSegments.at(k).a-mSegments.at(k).b).normalisedCopy();
		
			width *= 1-(1.0f/(mRecursivity*mRecursivity))*(1.0f/mSegments.size());
		}

		mBillboardSet->_updateBounds();

		mSceneNode->attachObject(mBillboardSet);

		mBillboardSet->setCustomParameter(0, Ogre::Vector4(1,0,0,0));

		// Ramifications
		if (mRecursivity > 0)
		{
			Ogre::Real angle;
			Ogre::Vector3 dir;
			Ogre::Real lengthMult;
			for (Ogre::uint32 k = 0; k < mDivisions-1; k++)
			{
				angle = (mSegments.at(k).b-mSegments.at(k).a).normalisedCopy().dotProduct(
					((mSegments.at(k+1).b-mSegments.at(k+1).a).normalisedCopy()));

				if (angle < Ogre::Math::RangeRandom(mAngleRange.x, mAngleRange.y))
				{
					dir = (mSegments.at(k).b-mSegments.at(k).a).normalisedCopy();
					dir.x *= Ogre::Math::RangeRandom(0.8f, 1.2f);
					dir.y *= Ogre::Math::RangeRandom(0.8f, 1.2f);
					dir.z *= Ogre::Math::RangeRandom(0.8f, 1.2f);
					dir.normalise();

					delta = 1.0f / mSegments.size();
					bounds = Ogre::Vector2(mBounds.x+(mBounds.y-mBounds.x)*(k+1)*delta,1);

					lengthMult = Ogre::Math::RangeRandom(0.1f, 0.7f);

					Lightning* lightning = new Lightning(mSceneManager, mSceneNode, mSegments.at(k).b, dir, lengthMult*mLength, 2+mDivisions*lengthMult, mRecursivity-1, mTimeMultiplier, mWidthMultiplier, bounds);
					lightning->create();
					
					mChildren.push_back(lightning);
				}
			}
		}

		mCreated = true;
	}
void LightningStrikeEvent::process(NetConnection*)
{
   if (mLightning)
      mLightning->processEvent(this);
}