Example #1
0
void Trie::addWord(string s)
{

    Node* current = root;

    if ( s.length() == 0 )
    {
        current->setFolder(); // an empty word
        return;
    }


    //string passed from python contains \0
    for ( int i = 0; i < s.length(); i++ )
    {
        Node* child = current->findChild(s[i]);
        if ( child != NULL )
        {
            current = child;
        }
        else
        {
            Node* tmp = new Node();
            tmp->setContent(s[i]);
            current->addChild(tmp);
            current = tmp;
        }
        if ( i == s.length() -1)
            current->setFolder();
    }

}
Example #2
0
void PageView::addWidgetToPage(Widget *widget, ssize_t pageIdx, bool forceCreate)
{
    if (!widget || pageIdx < 0)
    {
        return;
    }
   
    ssize_t pageCount = this->getPageCount();
    if (pageIdx < 0 || pageIdx >= pageCount)
    {
        if (forceCreate)
        {
            if (pageIdx > pageCount)
            {
                CCLOG("pageIdx is %d, it will be added as page id [%d]",static_cast<int>(pageIdx),static_cast<int>(pageCount));
            }
            Layout* newPage = createPage();
            newPage->addChild(widget);
            addPage(newPage);
        }
    }
    else
    {
        Node * page = _pages.at(pageIdx);
        page->addChild(widget);
    }
}
Example #3
0
void NestedTest::setup()
{
    static int depth = 9;
    
    Node* parent = this;
    
    for (int i = 0; i < depth; i++) {
                
        int size = 225 - i * (225 / (depth * 2));

        auto clipper = ClippingNode::create();
        clipper->setContentSize(Size(size, size));
        clipper->setAnchorPoint(Vec2(0.5, 0.5));
        clipper->setPosition( Vec2(parent->getContentSize().width / 2, parent->getContentSize().height / 2) );
        clipper->setAlphaThreshold(0.05f);
        clipper->runAction(RepeatForever::create(RotateBy::create(i % 3 ? 1.33 : 1.66, i % 2 ? 90 : -90)));
        parent->addChild(clipper);
        
        auto stencil = Sprite::create(s_pathGrossini);
        stencil->setScale( 2.5 - (i * (2.5 / depth)) );
        stencil->setAnchorPoint( Vec2(0.5, 0.5) );
        stencil->setPosition( Vec2(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) );
        stencil->setVisible(false);
        stencil->runAction(Sequence::createWithTwoActions(DelayTime::create(i), Show::create()));
        clipper->setStencil(stencil);

        clipper->addChild(stencil);
        
        parent = clipper;
    }

}
Example #4
0
Node* NodeReader::loadNode(const rapidjson::Value& json)
{
    Node* node = nullptr;
    std::string nodeType = DICTOOL->getStringValue_json(json, CLASSNAME);

    NodeCreateFunc func = _funcs[nodeType];
    if (func != nullptr)
    {
        const rapidjson::Value& options = DICTOOL->getSubDictionary_json(json, OPTIONS);
        node = func(options);
    }
    
    if(node)
    {
        int length = DICTOOL->getArrayCount_json(json, CHILDREN, 0);
        for (int i = 0; i<length; i++)
        {
            const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, CHILDREN, i);
            Node* child = loadNode(dic);
            if (child) 
            {
                node->addChild(child);
                child->release();
            }
        }
    }
    else
    {
        CCLOG("Not supported NodeType: %s", nodeType.c_str());
    }
    
    return node;
}
void
ColladaLight::createAmbientLight(ColladaLightAmbientInstInfo *colInstInfo)
{
    OSG_COLLADA_LOG(("ColladaLight::createAmbientLight\n"));

    LightLoaderState *state =
        getGlobal()->getLoaderStateAs<LightLoaderState>(_loaderStateName);
    OSG_ASSERT(state != NULL);

    ChunkOverrideGroupUnrecPtr coGroup  = ChunkOverrideGroup::create();
    NodeUnrecPtr               coGroupN = makeNodeFor(coGroup);

    coGroup->addChunk(state->getLightModelChunk());

    Node *rootN = getGlobal()->getRoot();

    while(rootN->getNChildren() > 0)
    {
        coGroupN->addChild(rootN->getChild(0));
    }

    if(getGlobal()->getOptions()->getCreateNameAttachments() == true)
    {
        setName(coGroupN, "OpenSG_AmbientLight");
    }

    rootN->addChild(coGroupN);
}
cocos2d::Node* ComponentsTestLayer::createGameScene()
{
    Node *root = NULL;
    do 
	{
        auto visibleSize = Director::getInstance()->getVisibleSize();
        auto origin = Director::getInstance()->getVisibleOrigin();

       
        auto player = Sprite::create("components/Player.png", Rect(0, 0, 27, 40) );
        
        player->setPosition( Point(origin.x + player->getContentSize().width/2,
                                 origin.y + visibleSize.height/2) );
        
        root = cocos2d::Node::create();
        root->addChild(player, 1, 1);
        

        auto itemBack = MenuItemFont::create("Back", [](Object* sender){
        	auto scene = new ExtensionsTestScene();
            scene->runThisTest();
            scene->release();
        });
        
        itemBack->setColor(Color3B(0, 0, 0));
        itemBack->setPosition(Point(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
        auto menuBack = Menu::create(itemBack, NULL);
        menuBack->setPosition(Point::ZERO);
        addChild(menuBack);
        
    }while (0);
    
    return root;
}
Example #7
0
bool FibonacciHeap::link(Node* root)
{
        // Insert Vertex into root list
        if(rootListByRank_[root->rank_] == NULL)
        {
                rootListByRank_[root->rank_] = root;
                return false;
        }
        else
        {
                // Link the two roots
                Node* linkVertex = rootListByRank_[root->rank_];
                rootListByRank_[root->rank_] = NULL;

                if(root->weight_ < linkVertex->weight_ || root == minRoot_)
                {
                        linkVertex->remove();
                        root->addChild(linkVertex);
                        if(rootListByRank_[root->rank_] != NULL)
                                link(root);
                        else
                                rootListByRank_[root->rank_] = root;
                }
                else
                {
                        root->remove();
                        linkVertex->addChild(root);
                        if(rootListByRank_[linkVertex->rank_] != NULL)
                                link(linkVertex);
                        else
                                rootListByRank_[linkVertex->rank_] = linkVertex;
                }
                return true;
        }
}
Example #8
0
void Ball::explode(){
	Node* parent = getParent();
	ParticleSystemQuad* explosion_particle = ParticleSystemQuad::create("explosion_particle.plist");
	explosion_particle->setPosition(getPosition());
//	explosion_particle->setEndColor(Color4F(COLOR_CYAN));
	parent->addChild(explosion_particle,getZOrder());
	removeFromParent();
}
Example #9
0
void NodeTest::addChild() {
    Node *world = CHILD_NODE();
    Node *country1 = CHILD_NODE();
    Node *country2 = CHILD_NODE();
    QCATCH(world->addChild("France", NULL), NullPointerException);
    world->addChild("France", country1);
    QCOMPARE(world->child("France"), country1);
    QCATCH(world->addChild("France", country1), DuplicateException);
    world->addChild("Spain", country2);
    QCOMPARE(world->child("Spain"), country2);
    QCOMPARE(world->children().size(), 2);
    Node *newWorld = world->fork();
    QCATCH(newWorld->addChild("France", country1), DuplicateException);
    Node *city = CHILD_NODE();
    country1->addChild("France", city);
    QCOMPARE(country1->child("France"), city);
}
bool FakeLoading::init()
{
    if (!Layer::init())
    {
        return false;
    }
    
    auto size = Director::getInstance()->getWinSize();
    Node * logoRoot = Node::create();
    logoRoot->setPosition(Point(size.width/2, size.height/2));
    logoRoot->setCascadeOpacityEnabled(true);
    this->addChild(logoRoot);
    
    auto logoBG = Sprite::create(fakeLoadingDefs::SPLASH_SCREEN_BG);
    logoBG->setScaleX(size.width / logoBG->getContentSize().width);
    logoBG->setScaleY(size.height / logoBG->getContentSize().height);
    logoRoot->addChild(logoBG);
    
    auto logo = Sprite::create(fakeLoadingDefs::LOGO_SPRITE);
    logoRoot->addChild(logo);
    
    auto loadingBG = Sprite::create(fakeLoadingDefs::LOADING_BG);
    loadingBG->setPosition(Point(size.width/2, size.height/2));
    loadingBG->setCascadeOpacityEnabled(true);
    loadingBG->setOpacity(0);
    this->addChild(loadingBG);
    
    auto loadingText = Sprite::create(fakeLoadingDefs::LOADING_TEXT);
    loadingText->setPosition(Point(loadingBG->getContentSize()/2.0f) + Point(0.0f, 220.0f));
    loadingBG->addChild(loadingText);
    
    DelayTime * logoDuration = DelayTime::create(3.0f);
    FadeOut * logoFadeOut = FadeOut::create(1.0f);
    
    DelayTime * loadingDelay = DelayTime::create(4.0f);
    FadeIn * loadingFadeIn = FadeIn::create(1.0f);
    DelayTime * loadingDuration = DelayTime::create(3.0f);
    CallFunc * waitForLoadingEnd = CallFunc::create([this](){
        this->scheduleUpdate();
    });
    
    logoRoot->runAction(Sequence::create(logoDuration, logoFadeOut, NULL));
    loadingBG->runAction(Sequence::create(loadingDelay, loadingFadeIn, loadingDuration, waitForLoadingEnd, NULL));
    
    return true;
}
Example #11
0
	void OverlayView::init(Scene* scene) {
		_scene = scene;
		
		Node* node = Node::create();
		node->setPosition(LayoutUtils::visibleCenter());
		_scene->addChild(node);
		
		Sprite* bg = Sprite::create("Overlay.png");
		bg->setScale(2.0f * ImageUtils::scale4OneSizeImage());
		node->addChild(bg, INT_MIN);
		
		Button* btnClose = WidgetUtils::createTTFButton("Close", "orange", [this]() {
			emitSelectClose();
		});
		btnClose->setPosition(100, 95);
		node->addChild(btnClose, INT_MAX);
	}
Example #12
0
Animation::CurvePlug *Animation::acquire( ValuePlug *plug )
{
	// If the plug is already driven by a curve, return it.
	if( CurvePlug *curve = inputCurve( plug ) )
	{
		return curve;
	}

	// Otherwise we need to make one. Try to find an
	// existing Animation driving plugs on the same node.

	AnimationPtr animation;
	if( !plug->node() )
	{
		throw IECore::Exception( "Plug does not belong to a node" );
	}

	for( RecursivePlugIterator it( plug->node() ); it != it.end(); ++it )
	{
		ValuePlug *valuePlug = runTimeCast<ValuePlug>( it->get() );
		if( !valuePlug )
		{
			continue;
		}

		if( CurvePlug *curve = inputCurve( valuePlug ) )
		{
			animation = runTimeCast<Animation>( curve->node() );
			if( animation )
			{
				break;
			}
		}
	}

	// If we couldn't find an existing Animation, then
	// make one.
	if( !animation )
	{
		Node *parent = plug->node()->parent<Node>();
		if( !parent )
		{
			throw IECore::Exception( "Node does not have a parent" );
		}
		animation = new Animation;
		parent->addChild( animation );
	}

	// Add a curve to the animation, and hook it up to
	// the target plug.

	CurvePlugPtr curve = new CurvePlug( "curve0", Plug::In, Plug::Default | Plug::Dynamic );
	animation->curvesPlug()->addChild( curve );

	plug->setInput( curve->outPlug() );

	return curve.get();
}
Example #13
0
Node * SceneGraph::appendChildTo(int index, Node * child) {
    Node * parent = getGraphNode(index);
    parent->addChild(child);
    if(child->getSceneGraphIndex() < 0) {
        nodes.push_back(child);
        child->setSceneGraphIndex(nodes.size() - 1);
    }
    return child;
}
Example #14
0
void NodeTest::hasChild() {
    Node *world = CHILD_NODE();
    Node *country = CHILD_NODE();
    QVERIFY(!world->hasChild("France"));
    world->addChild("France", country);
    QVERIFY(world->hasChild("France"));
    Node *newNewWorld = world->fork()->fork();
    QVERIFY(newNewWorld->hasChild("France"));
}
Node *IfObstacleAheadNode::clone() const
{
    Node *newNode = IfObstacleAheadNode::create();

    foreach (Node *child, children)
        newNode->addChild(child->clone());

    return newNode;
}
Example #16
0
TEST_F(NodeTest, testAddParent)
{
    Node* parentNode = new Node(2);
    parentNode->addChild(_node);
    Node* newParentNode = new Node(3);
    _node->addParent(newParentNode);
    ASSERT_EQ(newParentNode, _node->getParent());
    ASSERT_EQ(parentNode, newParentNode->getParent());
}
Example #17
0
TEST_F(NodeTest, testAddSibling)
{
    Node* parentNode = new Node(2);
    parentNode->addChild(_node);
    Node* siblingNode = new Node(3);
    _node->addSibling(siblingNode, _node);
    ASSERT_EQ(2, parentNode->getNodeList().size());
    ASSERT_EQ(parentNode, siblingNode->getParent());
}
void
ColladaLight::ColladaLightInstInfo::process(void)
{
    Node *lightInstN = dynamic_cast<Node *>(
        getColInst()->getTargetElem()->createInstance(this));

    if(lightInstN == NULL)
        return;

    Node *rootN = getColInst()->getGlobal()->getRoot();

    while(rootN->getNChildren() > 0)
    {
        lightInstN->addChild(rootN->getChild(0));
    }

    rootN->addChild(lightInstN);
}
Example #19
0
Node* Game2048::createNumCard(int curNumber)
{
	Node *cardNode = Node::create();

	auto cardBg = LayerColor::create(Color4B(0xff, 0xfa, 0xcd, 0xff), numSize-offsetW, numSize-offsetW);
	cardBg->ignoreAnchorPointForPosition(false);
	cardBg->setAnchorPoint(Point(0.5, 0.5));
	cardNode->addChild(cardBg);

	auto lblNum = Label::createWithTTF("", "fonts/Marker Felt.ttf", 24);
	
	lblNum->setName("lblName");
	cardNode->addChild(lblNum);

	setCardNodeNumber(cardNode, curNumber);

	return cardNode;
}
Example #20
0
void ECSWorld::createJackiechunCharacter(){
	CharacterInfoComponent* characterInfo = new CharacterInfoComponent();
	characterInfo->avatar = "textures/jackiechun.png";
	characterInfo->name = "BLACK MONKEY";
	characterInfo->MAX_BLOOD = 100;
	characterInfo->MAX_POWER = 100;
	characterInfo->blood = 100;
	characterInfo->power = 100;
	characterInfo->NORMAL_SKILL_POWER = 2.5f;
	characterInfo->SPECIAL_SKILL_POWER = 8;
	//create keletoncomponent
	spine::SkeletonAnimation* skeletonAnimation =
		spine::SkeletonAnimation::createWithFile("spine/JackieChun.json",
		"spine/JackieChun.atlas");
	skeletonAnimation->setAnimation(0, "Stand", true);
	skeletonAnimation->setScale(.4);

	Node* node = RenderLayer::getInstance()->createGameNode();
	node->setAnchorPoint(Vec2(.5, .5));
	node->setContentSize(skeletonAnimation->getContentSize());
	node->addChild(skeletonAnimation);
	node->setVisible(false);

	SkeletonComponent* characterSkeleton = new SkeletonComponent();
	characterSkeleton->skeleton = skeletonAnimation;
	characterSkeleton->node = node;
	characterSkeleton->isCreated = true;

	DecisionComponent* decisionComponent = new DecisionComponent();
	decisionComponent->DECISION_TIME = .4;
	decisionComponent->decisionBase = new EnemyFullAttackAI();
	//decisionComponent->DECISION_TIME = 10000;
	//decisionComponent->decisionBase = new JackiechunDecision2();
	decisionComponent->decisionBase->setWorld(world);

	StateComponent* stateComponent = new StateComponent();
	stateComponent->characterBase = new Jackiechun();


	artemis::Entity &character = (world->getEntityManager()->create());
	character.addComponent(new CharacterTypeComponent(R::CharacterType::JACKIECHUN));
	character.addComponent(new PosComponent(3 * Director::getInstance()->getVisibleSize().width / 4, -1000));
	character.addComponent(new BoundComponent(-30, -10, 30, 80));
	character.addComponent(new WallSensorComponent());
	character.addComponent(new GravityComponent());
	character.addComponent(new PhysicComponent());
	character.addComponent(decisionComponent);
	character.addComponent(stateComponent);
	character.addComponent(characterSkeleton);
	character.addComponent(characterInfo);
	character.setTag("enemy");

	character.refresh();

	((PhysicComponent*)(character.getComponent<PhysicComponent>()))->bounce = 0;

}
Example #21
0
Node *LeftNode::clone() const
{
    Node *newNode = LeftNode::create();

    foreach (Node *child, children)
        newNode->addChild(child->clone());

    return newNode;
}
Example #22
0
/*
 * seems to be working now
 */
void Tree::tritomyRoot(Node * toberoot){
	Node * curroot = this->getRoot();
	if (toberoot == NULL) {
		if (curroot->getChild(0).isInternal()) {
			Node * currootCH = &curroot->getChild(0);
			double nbl = currootCH->getBL();
			curroot->getChild(1).setBL(curroot->getChild(1).getBL() + nbl);
			curroot->removeChild(*currootCH);
			for (int i = 0; i < currootCH->getChildCount(); i++) {
				curroot->addChild(currootCH->getChild(i));
				//currootCH.getChild(i).setParent(curroot);
			}
		} else {
			Node * currootCH = &curroot->getChild(1);
			double nbl = currootCH->getBL();
			curroot->getChild(0).setBL(curroot->getChild(0).getBL() + nbl);
			curroot->removeChild(*currootCH);
			for (int i = 0; i < currootCH->getChildCount(); i++) {
				curroot->addChild(currootCH->getChild(i));
				//currootCH.getChild(i).setParent(curroot);
			}
		}
	} else {
		if (&curroot->getChild(1) == toberoot) {
			Node * currootCH = &curroot->getChild(0);
			double nbl = currootCH->getBL();
			curroot->getChild(1).setBL(curroot->getChild(1).getBL() + nbl);
			curroot->removeChild(*currootCH);
			for (int i = 0; i < currootCH->getChildCount(); i++) {
				curroot->addChild(currootCH->getChild(i));
				//currootCH.getChild(i).setParent(curroot);
			}
		} else {
			Node * currootCH = &curroot->getChild(1);
			double nbl = currootCH->getBL();
			curroot->getChild(0).setBL(curroot->getChild(0).getBL() + nbl);
			curroot->removeChild(*currootCH);
			for (int i = 0; i < currootCH->getChildCount(); i++) {
				curroot->addChild(currootCH->getChild(i));
				//currootCH.getChild(i).setParent(curroot);
			}
		}
	}
}
Example #23
0
// real item
void RealItem::Setup()
{
	Node* num = new Node;
	vlabel = new Label("arial", ": ", alignLeft);
	vlabel->setColor(vec(1,1,1));
	num->addChild(vlabel);
	num->setPosition(vec(6, 0));
	num->setScale(vec(0.5,0.5));
	addChild(num);
}
Example #24
0
Node Node::multMod(const IntLeaf &leaf, const IntLeaf &mod) const {
	Node mult;

	for (std::vector<BaseNode *>::const_iterator itr = children.begin(); itr < children.end(); itr++)
	{
		switch((*itr)->getType()) {
		case BaseNode::INT_LEAF:
			mult.addChild(static_cast<IntLeaf *>(*itr)->multMod(leaf, mod));
			break;
		case BaseNode::NODE:
			mult.addChild(static_cast<Node *>(*itr)->multMod(leaf, mod));
			break;
		default:
			break;
		}
	}

	return mult;
}
Example #25
0
Node Node::getChildren(int32_t index) const {
    Node res;

    for(std::vector<BaseNode *>::const_iterator itr = children.begin(); itr < children.end(); itr++)
    {
        res.addChild(static_cast<const Node *>(*itr)->getChild(index));
    }

    return res;
}
Example #26
0
void ECSWorld::createPicoloCharacter(){
	CharacterInfoComponent* characterInfo = new CharacterInfoComponent();
	characterInfo->avatar = "textures/doi.png";
	characterInfo->name = "BAT";
	characterInfo->MAX_BLOOD = 100;
	characterInfo->MAX_POWER = 100;
	characterInfo->blood = 100;
	characterInfo->power = 100;
	characterInfo->NORMAL_SKILL_POWER = 2.5f;
	characterInfo->SPECIAL_SKILL_POWER = 8;
	//create keletoncomponent
	spine::SkeletonAnimation* skeletonAnimation =
		spine::SkeletonAnimation::createWithFile("spine/doi.json",
		"spine/doi.atlas", .2f);
	skeletonAnimation->setAnimation(0, "flying", true);


	Node* node = RenderLayer::getInstance()->createGameNode();
	node->setAnchorPoint(Vec2(.5, .5));
	node->setContentSize(skeletonAnimation->getContentSize());
	node->addChild(skeletonAnimation);
	node->setVisible(false);

	SkeletonComponent* characterSkeleton = new SkeletonComponent();
	characterSkeleton->skeleton = skeletonAnimation;
	characterSkeleton->node = node;
	characterSkeleton->isCreated = true;

	DecisionComponent* decisionComponent = new DecisionComponent();
	decisionComponent->DECISION_TIME = .5;
	decisionComponent->decisionBase = new PicoloDecision();
	decisionComponent->decisionBase->setWorld(world);

	StateComponent* stateComponent = new StateComponent();
	stateComponent->characterBase = new Picolo();


	artemis::Entity &character = (world->getEntityManager()->create());
	character.addComponent(new CharacterTypeComponent(R::CharacterType::PICOLO));
	character.addComponent(new PosComponent(3 * Director::getInstance()->getVisibleSize().width / 4,-1000));
	character.addComponent(new BoundComponent(-25, 0, 25, 50));
	character.addComponent(new WallSensorComponent());
	character.addComponent(new GravityComponent());
	character.addComponent(new PhysicComponent());
	character.addComponent(decisionComponent);
	character.addComponent(stateComponent);
	character.addComponent(characterSkeleton);
	character.addComponent(characterInfo);
	character.setTag("enemy");

	character.refresh();

	((PhysicComponent*)(character.getComponent<PhysicComponent>()))->bounce = 0;

}
Example #27
0
Node* exploreTree(Node &n){
    Node *root = new Node(n);
    queue<Node*> myQue;
    myQue.push(root);
    while(!myQue.empty()){
        Node *temp = myQue.front();
        myQue.pop();
        if(temp->getPlayer()==minPlayer){
            if(temp->getResult() == 1)
            continue;
            for(int i = 0 ; i < temp->getBoard().size();i++){
                if(temp->getBoard()[i]==0){
                    vector<int> v(temp->getBoard());
                    v[i] = -1;
                    Node *child = new Node(v);
                    child->addParent(temp);
                    temp->addChild(child);
                    myQue.push(child);
                    
                }
            }
        }
        else if(temp->getPlayer()==maxPlayer){
            if(temp->getResult() == -1)
            continue;
            for(int i = 0 ; i < temp->getBoard().size();i++){
                if(temp->getBoard()[i]==0){
                    vector<int> v(temp->getBoard());
                    v[i] = 1;
                    Node *child = new Node(v);
                    temp->addChild(child);
                    child->addParent(temp);
                    myQue.push(child);
                   
                }
            }
        }
    
    
    }
    return root;
}
Example #28
0
Graph::Graph (string fileName) {
    ifstream fin (fileName.c_str());    
    map<int, Node*>::iterator iter_child;
    string line;
    while (getline(fin,line)) {
        if (line != "") {
                vector<string> ids = split(line);
                int parent = stringToInt(ids[0]);
                int child = stringToInt(ids[1]);
                iter = G.find(parent);
                if (iter == G.end()) {//if it exists
                    Node* parNode = new Node(parent);
                    G[parent] = parNode;
                    iter_child = G.find(child);
                    Node* chNode;
                    if (iter_child == G.end()) {
                        chNode = new Node(child);
                        G[child] = chNode;
                    }
                    else
                        chNode = iter_child->second;
                    parNode->addChild(chNode);
                    chNode->addParent(parNode);                    
                }
                else {//create a new node
                    Node* parNode = iter->second;
                    iter_child = G.find(child);
                    Node* chNode;
                    if (iter_child == G.end()) {        
                        chNode = new Node(child);
                        G[child] = chNode;
                    }
                    else
                        chNode = iter_child->second;
                    parNode->addChild(chNode);
                    chNode->addParent(parNode);
                }
        }
    }
    fin.close();
    fixTopParents();
}
Example #29
0
void ECSWorld::createBearIntroduceCharacter(){
	CharacterInfoComponent* characterInfo = new CharacterInfoComponent();
	characterInfo->avatar = "textures/bear.png";
	characterInfo->name = "BEAR";
	characterInfo->MAX_BLOOD = 100;
	characterInfo->MAX_POWER = 100;
	characterInfo->blood = 100;
	characterInfo->power = 100;
	//create keletoncomponent
	spine::SkeletonAnimation* skeletonAnimation =
		spine::SkeletonAnimation::createWithFile("spine/Tuong gau.json",
		"spine/Tuong gau.atlas");
	skeletonAnimation->setAnimation(0, "standing", true);
	skeletonAnimation->setScale(.3);

	Node* node = RenderLayer::getInstance()->createGameNode();
	node->setAnchorPoint(Vec2(.5, .5));
	node->setContentSize(skeletonAnimation->getContentSize());
	node->addChild(skeletonAnimation);
	node->setVisible(false);

	SkeletonComponent* characterSkeleton = new SkeletonComponent();
	characterSkeleton->skeleton = skeletonAnimation;
	characterSkeleton->node = node;
	characterSkeleton->isCreated = true;

	DecisionComponent* decisionComponent = new DecisionComponent();
	decisionComponent->DECISION_TIME = .4;
	decisionComponent->decisionBase = new BearDecision();
	decisionComponent->decisionBase->setWorld(world);
	decisionComponent->decisionBase->isActive = false;

	StateComponent* stateComponent = new StateComponent();
	stateComponent->characterBase = new Bear();


	artemis::Entity &character = (world->getEntityManager()->create());
	character.addComponent(new CharacterTypeComponent(R::CharacterType::BEAR));
	character.addComponent(new PosComponent(3 * Director::getInstance()->getVisibleSize().width / 4,-1000));
	character.addComponent(new BoundComponent(-50, 0, 50, 100));
	character.addComponent(new WallSensorComponent());
	character.addComponent(new GravityComponent());
	character.addComponent(new PhysicComponent());
	character.addComponent(decisionComponent);
	character.addComponent(stateComponent);
	character.addComponent(characterSkeleton);
	character.addComponent(characterInfo);
	character.setTag("enemy");

	character.refresh();

	((PhysicComponent*)(character.getComponent<PhysicComponent>()))->bounce = 0;

}
Example #30
0
	void TransEndView::init(Scene* scene) {
		_scene = scene;
		
		Node* node = Node::create();
		node->setPosition(LayoutUtils::visibleCenter() - Point(240, 160));
		_scene->addChild(node);
		
		// background
		Sprite* bg = Sprite::create("bg.png");
		bg->setScale(2.0f * ImageUtils::scale4OneSizeImage());
		bg->setPosition(Point(240, 160));
		node->addChild(bg, INT_MIN);
		
		// back button
		Button* btnBack = WidgetUtils::createTTFButton("Back", "orange", [this]() {
			emitSelectBack();
		});
		btnBack->setPosition(Point(240, 160));
		node->addChild(btnBack, INT_MAX);
	}