Example #1
0
void MenuScene::displayWorm()
{
    row_col size = {20, 18};
    FreePlayGround* playGround = FreePlayGround::create();
    playGround->create(size);
    playGround->setScale(1.4f);
    auto contentSize = playGround->getContentSize();
    playGround->setPosition(Vec2(-contentSize.width / 2, -contentSize.height / 2) + VisibleRect::center());
    playGround->setRotation(45);
    
    auto action = ScaleTo::create(4, 1.2);
    auto action2 = ScaleTo::create(4, 1.4);
    playGround->runAction(RepeatForever::create(Sequence::create(action, action2, nullptr)));
    
    this->addChild(playGround);
    
    setPlayGround(playGround);
    
    auto worm = FreeWorm::create();
    start_point start;
    start.info = {0, 9};
    start.direction = 1;
    
    worm->born(playGround, start);
    worm->setOpacity(150);
    worm->crawl();
}
Example #2
0
void Cat::distroy()
{
	body->setVisible(false);
	tail->setVisible(false);
	rightHand->setVisible(false);
	leftHand->setVisible(false);
	born();
}
Example #3
0
Entity& Entity::makeParticle(std::function<void(RenderingContext&)> born, std::function<void(RenderingContext&)> live, std::function<void(RenderingContext&)> die)
{

    born(getContext());

    this->live = live;
    this->die = die;

    return *this;
}
Example #4
0
void Dog::distroy()
{
	body->setVisible(false);
	explode->setVisible(false);
	explode->stopAllActions();

	log("Dog %d Crashed!!", id);
	born();
	//NotificationCenter::getInstance()->postNotification("test", NULL);
}
Example #5
0
GLUTEngine& GLUTEngine::getInstance()
{
	if( engine_instance == NULL )
	{
		if( has_been_destroyed == true )
			reborn();
		else
			born();
	}

	return *engine_instance; // return a reference: client code can't delete it
}
Example #6
0
void Dog::display()
{
	//body
	body = Sprite::create("DrDog1.png");
	
	Animation* bodyAni = Animation::create();
	bodyAni->addSpriteFrameWithFile("DrDog1.png");
	bodyAni->addSpriteFrameWithFile("DrDog2.png");
	bodyAni->setLoops(-1);
	bodyAni->setDelayPerUnit(0.2f);

	bodyAct = Animate::create(bodyAni);
	bodyAct->retain();
	addChild(body);


	//explode
	explode = Sprite::create("boom1.png");
	addChild(explode);

	Animation* explodeAnimation = Animation::create();
	char name[20];
	for (int i = 1; i <= 5; i++)
	{
		sprintf(name, "boom%d.png", i);
		explodeAnimation->addSpriteFrameWithFile(name);
	}
	explodeAnimation->setDelayPerUnit(0.2f);

	Animate* explodeAni = Animate::create(explodeAnimation);

	CallFunc* callFunc = CallFunc::create([&]()->void {distroy(); });

	actions = Sequence::create(explodeAni, callFunc, NULL);
	actions->retain();

	hitRect = body->getBoundingBox();

	/*DrawNode* draw = DrawNode::create();
	this->addChild(draw);
	Vec2 point1[4];
	point1[0] = Point(hitRect.getMinX(), hitRect.getMaxY());
	point1[1] = Point(hitRect.getMaxX(), hitRect.getMaxY());
	point1[2] = Point(hitRect.getMaxX(), hitRect.getMinY());
	point1[3] = Point(hitRect.getMinX(), hitRect.getMinY());
	draw->drawPolygon(point1, 4, Color4F(1,0,0,0), 1, Color4F(1,0,0,1));*/

	born();
}
/*
    TEST_SMP1(ClassName, FunNAme, expectAns, firstData)
    TEST_SMP2(ClassName, FunNAme, expectAns, firstData, secondData)

    int first;
    int expectAns;


    first = 1;
    expectAns = 1;
    TEST_SMP1(Solution, smallestRepunitDivByK, expectAns, first);
*/
int main() {
    vector<int> first;
    vector<int> expectAns;
    ListNode root[100];

    first = {2,1,5};
    expectAns = {5,5,0};
    TEST_SMP1(Solution, nextLargerNodes, expectAns, born(first, root));

    first = {2,7,4,3,5};
    expectAns = {7,0,5,5,0};
    TEST_SMP1(Solution, nextLargerNodes, expectAns, born(first, root));

    first = {1,7,5,1,9,2,5,1};
    expectAns = {7,9,9,9,0,5,0,0};
    TEST_SMP1(Solution, nextLargerNodes, expectAns, born(first, root));


    first = {2,1, 1,5};
    expectAns = {5,5,5,0};
    TEST_SMP1(Solution, nextLargerNodes, expectAns, born(first, root));

    return 0;
}
Example #8
0
bool Cat::init()
{
	if (!Node::init())
	{
		return false;
	}

	bulletDelay = 0;
	isReady = false;
	isDead = false;

	display();
	born();

	/*temp1 = Rect::ZERO;
	temp2 = Rect::ZERO;*/

	return true;
}
Example #9
0
bool XRandBG::init(int w, int h, const char* filename, int objsSum, bool m_withUI)
{
	if (m_isInited || w <= 0 || h <= 0) return false;

	resetParameter();
	if (m_withUI)
	{
		XCFGManager.addGroup("背景参数");
		XCFGManager.addAItem<float>(&m_minSpeed, CFG_DATA_FLOAT, "最小速度", 100.0f, 0.01f, 5.0f, nullptr, "背景参数");
		XCFGManager.addAItem<float>(&m_maxSpeed, CFG_DATA_FLOAT, "最大速度", 100.0f, 0.01f, 10.0f, nullptr, "背景参数");
		XCFGManager.addAItem<float>(&m_minScale, CFG_DATA_FLOAT, "最小缩放", 10.0f, 0.01f, 0.5f, nullptr, "背景参数");
		XCFGManager.addAItem<float>(&m_maxScale, CFG_DATA_FLOAT, "最大缩放", 10.0f, 0.01f, 1.25f, nullptr, "背景参数");
		XCFGManager.addAItem<float>(&m_minEnergy, CFG_DATA_FLOAT, "最小能量", 10000.0f, 1.0f, 400.0f, nullptr, "背景参数");
		XCFGManager.addAItem<float>(&m_maxEnergy, CFG_DATA_FLOAT, "最大能量", 10000.0f, 1.0f, 800.0f, nullptr, "背景参数");
		XCFGManager.addAItem<float>(&m_minStrength, CFG_DATA_FLOAT, "最小强度", 500.0f, 1.0f, 20.0f, nullptr, "背景参数");
		XCFGManager.addAItem<float>(&m_maxStrength, CFG_DATA_FLOAT, "最大强度", 500.0f, 1.0f, 40.0f, nullptr, "背景参数");
		XCFGManager.addAItem<float>(&m_minRecoveryRate, CFG_DATA_FLOAT, "最小恢复", 1000.0f, 1.0f, 150.0f, nullptr, "背景参数");
		XCFGManager.addAItem<float>(&m_maxRecoveryRate, CFG_DATA_FLOAT, "最大恢复", 1000.0f, 1.0f, 250.0f, nullptr, "背景参数");
	}

	m_w = w;
	m_h = h;
	m_buff.resize(m_w * m_h);

	if (!m_fbo.init(m_w, m_h, COLOR_GRAY)) return false;
	if (!m_tex.load(filename)) return false;

	m_avgBornTimer = 5.0f;
	m_bornTime = XRand::randomf(0.75f, 1.25f) * m_avgBornTimer;
	m_objs.resize(objsSum + 2);
	for (int i = 0; i < m_objs.size(); ++i)
	{
		m_freeObjs.push_back(&m_objs[i]);
	}
	for (int i = 0; i < objsSum; ++i)	//初始化5个粒子
		born();

	m_isInited = true;
	return true;
}
Example #10
0
void createSceneProgrammatically(GLInstancingRenderer& renderer)
{
	int strideInBytes = sizeof(float)*9;

	bool noHeightField = false;
	int barrelShapeIndex = -1;
	int cubeShapeIndex = -1;
	int tetraShapeIndex = -1;

	float position[4]={0,0,0,0};
	btQuaternion born(btVector3(1,0,0),SIMD_PI*0.25*0.5);

	float orn[4] = {0,0,0,1};
//	float rotOrn[4] = {born.getX(),born.getY(),born.getZ(),born.getW()};//
	float rotOrn[4] ={0,0,0,1};
	

	float color[4] = {1,1,1,1};
	int index=0;


	




	float cubeScaling[4] = {1,1,1,1};
	{
		int numVertices = sizeof(cube_vertices)/strideInBytes;
		int numIndices = sizeof(cube_indices)/sizeof(int);
		cubeShapeIndex = renderer.registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
	}

	


	if (1)
	for (int i=0;i<NUM_OBJECTS_X;i++)
	{
		for (int j=0;j<NUM_OBJECTS_Y;j++)
		{
			int k=0;
			
			for (;k<NUM_OBJECTS_Z;k++)
			{

				float mass = 1.f;//j? 1.f : 0.f;

				position[0]=(i*X_GAP-NUM_OBJECTS_X/2)+(j&1);
				position[1]=1+(j*Y_GAP);//-NUM_OBJECTS_Y/2);
				position[2]=(k*Z_GAP-NUM_OBJECTS_Z/2)+(j&1);
				position[3] = 0.f;
				
				renderer.registerGraphicsInstance(cubeShapeIndex,position,rotOrn,color,cubeScaling);
				
				index++;
			}
		}
	}

	
	{

		{
			int numVertices = sizeof(tetra_vertices)/strideInBytes;
			int numIndices = sizeof(tetra_indices)/sizeof(int);
			tetraShapeIndex = renderer.registerShape(&tetra_vertices[0],numVertices,tetra_indices,numIndices);
		}

		{
			float groundScaling[4] = {2.5,2,2.5,1};
		
			for (int i=0;i<50;i++)
				for (int j=0;j<50;j++)
			if (1)
			{
				void* ptr = (void*) index;
				float posnew[4];
				posnew[0] = i*5.01-120;
				posnew[1] = 0;
				posnew[2] = j*5.01-120;
				posnew[3] = 1.f;

				color[0] = 1.f;
				color[1] = 0.f;
				color[2] = 0.f;
				renderer.registerGraphicsInstance(tetraShapeIndex,posnew,orn,color,groundScaling);
			}
		}
	}


}
Example #11
0
void XRandBG::update(float steptime)
{
	if (!m_isInited) return;
	float curTime = steptime * 0.001f;
	//出生的处理
	//m_bornTime -= curTime;
	//if (m_bornTime <= 0.0f)
	//{
	//	born();
	//	m_bornTime = XRand::randomf(0.75f, 1.25f) * m_avgBornTimer;
	//}
	//状态更新
	//方案1:
	//for (int i = 0; i < m_usedObjs.size(); ++i)
	//{
	//	if (!m_usedObjs[i]->update(curTime)) continue;

	//	m_freeObjs.push_back(m_usedObjs[i]);
	//	m_usedObjs.erase(m_usedObjs.begin() + i);
	//	--i;
	//	born();
	//}
	//方案2:
	int deadSum = 0;
	for (auto it = m_usedObjs.begin(); it != m_usedObjs.end();)
	{
		if (!(*it)->update(curTime))
		{
			++it;
			continue;
		}
		m_freeObjs.push_back(*it);
		it = m_usedObjs.erase(it);
		++deadSum;
	}
	for (int i = 0; i < deadSum; ++i)
	{//不分开处理会crash
		born();
	}
	//显示
	XVec2 texSize(m_tex.getOpWidth(), m_tex.getOpHeight());
	m_fbo.useFBO();
	XEG.clearScreen(XFColor::black);
	//XGL::setBlendAlpha();
	XGL::setBlendAdd();
	XVec2 s, pos;
#ifdef WITH_DRAW_OP
	glActiveTexture(GL_TEXTURE0);
	XGL::EnableTexture2D();
	XGL::BindTexture2D(m_tex.getTexGLID());
	glBegin(GL_QUADS);

	for (auto it = m_usedObjs.begin(); it != m_usedObjs.end(); ++it)
	{
		s = texSize * (*it)->m_scale * 0.5f;
		pos = (*it)->m_pos;

		glColor4fv(XFColor(1.0f, (*it)->m_alpha));
		glTexCoord2fv(XVec2::zero);
		glVertex2fv(pos - s);
		glTexCoord2fv(XVec2::zeroOne);
		glVertex2f(pos.x - s.x, pos.y + s.y);
		glTexCoord2fv(XVec2::one);
		glVertex2fv(pos + s);
		glTexCoord2fv(XVec2::oneZero);
		glVertex2f(pos.x + s.x, pos.y - s.y);
	}

	glEnd();
#else
	for (auto it = m_usedObjs.begin(); it != m_usedObjs.end(); ++it)
	{
		tmpSize = texSize * (*it)->m_scale;
		XRender::drawBlankPlane((*it)->m_pos - tmpSize * 0.5f,
			tmpSize, m_tex.getTexGLID(), nullptr, XFColor(1.0f, (*it)->m_alpha));
	}
#endif
	glReadPixels(0, 0, m_w, m_h, GL_LUMINANCE, GL_UNSIGNED_BYTE, m_buff.getBuffer());
	m_fbo.removeFBO();
}
Example #12
0
void GLUTEngine::reborn()
{
	born(); // create a new instance
			// and panic
	atexit(kill);
}