static Vec2 cpVert2Point(const cpVect &vert)
{
    return Vec2(vert.x, vert.y);
}
Beispiel #2
0
	void drawCenter(const Vec2 &center, const Size<double> &size)
	{
		draw(Vec2(center.x - size.width / 2, center.y - size.height / 2), size);
	}
Beispiel #3
0
void RichText::formarRenderers()
{
    if (_ignoreSize)
    {
        float newContentSizeWidth = 0.0f;
        float newContentSizeHeight = 0.0f;
        
        Vector<Node*>* row = (_elementRenders[0]);
        float nextPosX = 0.0f;
        for (ssize_t j=0; j<row->size(); j++)
        {
            Node* l = row->at(j);
            l->setAnchorPoint(Vec2::ZERO);
            l->setPosition(Vec2(nextPosX, 0.0f));
            _elementRenderersContainer->addChild(l, 1);
            Size iSize = l->getContentSize();
            newContentSizeWidth += iSize.width;
            newContentSizeHeight = MAX(newContentSizeHeight, iSize.height);
            nextPosX += iSize.width;
        }
        _elementRenderersContainer->setContentSize(Size(newContentSizeWidth, newContentSizeHeight));
    }
    else
    {
        float newContentSizeHeight = 0.0f;
        float *maxHeights = new float[_elementRenders.size()];
        
        for (size_t i=0; i<_elementRenders.size(); i++)
        {
            Vector<Node*>* row = (_elementRenders[i]);
            float maxHeight = 0.0f;
            for (ssize_t j=0; j<row->size(); j++)
            {
                Node* l = row->at(j);
                maxHeight = MAX(l->getContentSize().height, maxHeight);
            }
            maxHeights[i] = maxHeight;
            newContentSizeHeight += maxHeights[i];
        }
        
        
        float nextPosY = _customSize.height;
        for (size_t i=0; i<_elementRenders.size(); i++)
        {
            Vector<Node*>* row = (_elementRenders[i]);
            float nextPosX = 0.0f;
            nextPosY -= (maxHeights[i] + _verticalSpace);
            
            for (ssize_t j=0; j<row->size(); j++)
            {
                Node* l = row->at(j);
                l->setAnchorPoint(Vec2::ZERO);
                l->setPosition(Vec2(nextPosX, nextPosY));
                _elementRenderersContainer->addChild(l, 1);
                nextPosX += l->getContentSize().width;
            }
        }
        _elementRenderersContainer->setContentSize(_contentSize);
        delete [] maxHeights;
    }
    
    size_t length = _elementRenders.size();
    for (size_t i = 0; i<length; i++)
	{
        Vector<Node*>* l = _elementRenders[i];
        l->clear();
        delete l;
	}    
    _elementRenders.clear();
    
    if (_ignoreSize)
    {
        Size s = getVirtualRendererSize();
        this->setContentSize(s);
    }
    else
    {
        this->setContentSize(_customSize);
    }
    updateContentSizeWithTextureSize(_contentSize);
    _elementRenderersContainer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
}
Vec2 Vec2::operator +( const float rhs ) const
{
  return Vec2( x + rhs, y + rhs );
}
Vec2 Vec2::operator *( const float s ) const
{
  return Vec2( x * s, y * s );
}
bool PlatformerEntityController::update(TimeValue time)
{
    // Check there is a character controller to work with
    if (!getEntity()->characterController_)
    {
        LOG_ERROR << "Entity does not have a character controller: " << *getEntity();
        return true;
    }

    // The maximum update rate is tied to the physics update rate
    auto timePerSubstep = physics().getSubstepSize();

    // Work out how many physics steps there are to run
    timeSinceLastUpdate_ += std::min(time, TimeValue(0.1f));
    auto substepCount = timeSinceLastUpdate_ / timePerSubstep;
    if (substepCount == 0)
        return true;

    // Roll over any unused time to future frames
    timeSinceLastUpdate_ -= timePerSubstep * substepCount;

    auto seconds = (physics().getSubstepSize() * substepCount).toSeconds();

    // If 10ms has elapsed then add a new past world position
    auto currentTime = platform().getTime();
    if (pastWorldPositions_.empty() || (currentTime - pastWorldPositions_[0].time).toMilliseconds() > 10.0f)
        pastWorldPositions_.prepend(PastWorldPosition(currentTime, getEntity()->getWorldPosition().toVec2()));

    // Cull outdated past world positions (> 100ms old)
    while ((currentTime - pastWorldPositions_.back().time).toMilliseconds() > 100.0f)
        pastWorldPositions_.popBack();

    // Determine actual velocity after accounting for collisions, this is only possible if there are sufficient samples
    if (pastWorldPositions_.size() >= 2)
    {
        const auto& p0 = pastWorldPositions_[0];

        for (auto i = 1U; i < pastWorldPositions_.size(); i++)
        {
            if ((p0.time - pastWorldPositions_[i].time).toSeconds() > 0.05f)
            {
                velocity_ = (p0.position - pastWorldPositions_[i].position) /
                    (p0.time - pastWorldPositions_[i].time).toSeconds();
                break;
            }
        }
    }

    // Check for a down axis collision and use the result to track falling distances and report falls
    fallDistance_ = 0.0f;
    auto collisionNormal = Vec3();
    if (physics().getCharacterControllerDownAxisCollision(getEntity()->characterController_, collisionNormal))
    {
        // Report a fall if the character controller was previously not on the ground
        if (reportFallWhenNextOnGround_)
        {
            fallDistance_ = maximumYSinceLastOnGround_ - getEntity()->getWorldPosition().y;
            reportFallWhenNextOnGround_ = false;
        }

        maximumYSinceLastOnGround_ = getEntity()->getWorldPosition().y;
    }
    else
    {
        // The controller is not in contact with the ground so a fall should be reported when the controller is next on
        // the ground, the final fall distance is determined based on how high the controller got since it was last on
        // the ground.
        reportFallWhenNextOnGround_ = true;
        maximumYSinceLastOnGround_ = std::max(maximumYSinceLastOnGround_, getEntity()->getWorldPosition().y);
    }

    // Keyboard control of movement
    auto movement = Vec2();
    if (isUserInputAllowed_ && platform().isKeyPressed(moveLeftKey_))
        movement -= Vec2::UnitX;
    if (isUserInputAllowed_ && platform().isKeyPressed(moveRightKey_))
        movement += Vec2::UnitX;
    if (isJumping_)
        movement.x *= jumpHorizontalMovementScale_;

    // Calculate any movement offset needed for jumping
    auto jumpOffset = 0.0f;
    if (isJumping_)
    {
        // Check whether the character controller has hit something above it. If it has, and the surface hit is fairly
        // close to horizontal, then the jump terminates immediately
        if (physics().getCharacterControllerUpAxisCollision(getEntity()->characterController_, collisionNormal))
            isJumping_ = collisionNormal.dot(-Vec3::UnitY) < 0.95f;

        if (isJumping_)
        {
            auto jumpTimeElapsed = (currentTime - jumpStartTime_).toSeconds();
            if (jumpTimeElapsed >= jumpTime_ * 2.0f)
                isJumping_ = false;
            else
            {
                // Calculate the vertical jump movement for this timestep
                auto t0 = jumpTimeElapsed / jumpTime_;
                auto t1 = std::max(jumpTimeElapsed - seconds, 0.0f) / jumpTime_;

                auto jumpExponent = 2.0f;

                jumpOffset =
                    jumpHeight_ * (powf(fabsf(1.0f - t1), jumpExponent) - powf(fabsf(1.0f - t0), jumpExponent));
            }
        }
    }

    // Apply gravity as a movement vector
    if (!isJumping_ && isGravityEnabled_)
        movement += physics().getGravityVector().toVec2().normalized();

    // Calculate accelerations
    auto horizontalAcceleration = maximumHorizontalSpeed_ / timeToMaximumHorizontalSpeed_.toSeconds();
    auto verticalAcceleration = maximumVerticalSpeed_ / timeToMaximumVerticalSpeed_.toSeconds();

    if (movement.x != 0.0f)
        velocity_.x += movement.x * horizontalAcceleration;
    else
        velocity_.x -= Math::absClamp(Math::getSign(velocity_.x) * horizontalAcceleration, fabsf(velocity_.x));

    if (movement.y != 0.0f)
        velocity_.y += movement.y * verticalAcceleration;
    else
        velocity_.y -= Math::absClamp(Math::getSign(velocity_.y) * verticalAcceleration, fabsf(velocity_.y));

    // Clamp to maximum velocities
    velocity_.x = Math::absClamp(velocity_.x, maximumHorizontalSpeed_);
    velocity_.y = Math::absClamp(velocity_.y, maximumVerticalSpeed_);

    // If the fall following a jump has hit the maximum fall speed then clamp to the maximum speed and terminate the
    // jump
    if (velocity_.y + (jumpOffset / seconds) < -maximumVerticalSpeed_)
    {
        velocity_.y = -maximumVerticalSpeed_;
        isJumping_ = false;
        jumpOffset = 0.0f;
    }

    // Move the character controller
    physics().moveCharacterController(getEntity()->characterController_, velocity_ * seconds + Vec2(0.0f, jumpOffset),
                                      seconds);

    return true;
}
Vec2 Vec2::operator -() const
{
  return Vec2( -x, -y );
}
bool ControlButtonTest_HelloVariableSize::init()
{
    if (ControlScene::init())
    {
        auto screenSize = Director::getInstance()->getWinSize();
        
        // Defines an array of title to create buttons dynamically
        std::vector<std::string> vec;
        vec.push_back("Hello");
        vec.push_back("Variable");
        vec.push_back("Size");
        vec.push_back("!");
        
        auto layer = Node::create();
        addChild(layer, 1);
        
        double total_width = 0, height = 0;
        
        int i = 0;
        
        for (auto& title : vec)
        {
            // Creates a button with this string as title
            ControlButton *button = standardButtonWithTitle(title.c_str());
            if (i == 0)
            {
                button->setOpacity(50);
                button->setColor(Color3B(0, 255, 0));
            }
            else if (i == 1)
            {
                button->setOpacity(200);
                button->setColor(Color3B(0, 255, 0));
            }
            else if (i == 2)
            {
                button->setOpacity(100);
                button->setColor(Color3B(0, 0, 255));
            }
            
            button->setPosition(total_width + button->getContentSize().width / 2, button->getContentSize().height / 2);
            layer->addChild(button);
            
            // Compute the size of the layer
            height = button->getContentSize().height;
            total_width += button->getContentSize().width;
            i++;
        }

        layer->setAnchorPoint(Vec2 (0.5, 0.5));
        layer->setContentSize(Size(total_width, height));
        layer->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
        
        // Add the black background
        auto background = Scale9Sprite::create("extensions/buttonBackground.png");
        background->setContentSize(Size(total_width + 14, height + 14));
        background->setPosition(screenSize.width / 2.0f, screenSize.height / 2.0f);
        addChild(background);
        return true;
    }
    return false;
}
Beispiel #9
0
void RunnerSprite::extralInit(){
    auto roleGroup = this->mMap->getObjectGroup("role");
    ValueMap obj = static_cast<ValueMap>(roleGroup->getObject("player"));
    
    float spX = obj["x"].asFloat();
    float spY = obj["y"].asFloat();

    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("playerrun.plist", "playerrun.png");
    mRunner = cocos2d::Sprite::createWithSpriteFrameName("image1.png");
    mRunner->setPosition(Vec2(spX,spY));
    mRunner->setAnchorPoint(Vec2(0.5,0.0));
    
    mMap->addChild(mRunner);
    auto runAnim = Animation::create();
    for(int i = 1;i<17;i++){
        char nameBuf[100] = {0};
        sprintf(nameBuf, "image%d.png",i);
        auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(nameBuf);
        runAnim->addSpriteFrame(frame);
    }
    runAnim->setDelayPerUnit(0.06f);
    runAnim->setRestoreOriginalFrame(true);
    AnimationCache::getInstance()->addAnimation(runAnim,"runAction");
    
    
    
    auto colGroup = mMap->getObjectGroup("collision");
    auto colObj = colGroup->getObjects();
    CCLOG("objs %lu",colObj.size());
    
    barriers.reserve(colObj.size());
    
    for(ValueVector::iterator it  = colObj.begin(); it != colObj.end(); ++it) {
        ValueMap mp = it->asValueMap();
        barriers.push_back(Rect(mp["x"].asFloat(), mp["y"].asFloat(), mp["width"].asFloat(), mp["height"].asFloat()));
    }
    
    auto colGroup2 = mMap->getObjectGroup("collision");
    auto colObj2 = colGroup2->getObjects();
    CCLOG("objs %lu",colObj.size());
    
    goldens.reserve(colObj2.size());
    goldenSs.reserve(colObj2.size());
    int i = 0;
    for(ValueVector::iterator it  = colObj2.begin(); it != colObj2.end(); ++it) {
        ValueMap mp = it->asValueMap();
        goldens.push_back(Rect(mp["x"].asFloat(), mp["y"].asFloat(), mp["width"].asFloat(), mp["height"].asFloat()));
        auto gold =  Sprite::create("gold.png");
        gold->setAnchorPoint(Vec2(0.5,0.5));
        gold->setPosition(Vec2(mp["x"].asFloat(), mp["y"].asFloat() + 180));
        gold->setScale(0.2, 0.2);
        gold->setTag(2800+i);
        mMap->getLayer("ground")->addChild(gold);
        goldenSs.push_back(gold);
        i++;
    }
    
    
    setRunState(kROLERUN);
    
    auto runAim = RepeatForever::create(Animate::create(AnimationCache::getInstance()->getAnimation("runAction"))) ;
    this->mRunner->runAction(runAim);
    
    gNum = 0;
    mNum = 0;

}
Beispiel #10
0
ShaderNode::ShaderNode()
:_center(Vec2(0.0f, 0.0f))
,_resolution(Vec2(0.0f, 0.0f))
,_time(0.0f)
{
}
RenderTextureZbuffer::RenderTextureZbuffer()
{
    auto listener = EventListenerTouchAllAtOnce::create();
    listener->onTouchesBegan = CC_CALLBACK_2(RenderTextureZbuffer::onTouchesBegan, this);
    listener->onTouchesMoved = CC_CALLBACK_2(RenderTextureZbuffer::onTouchesMoved, this);
    listener->onTouchesEnded = CC_CALLBACK_2(RenderTextureZbuffer::onTouchesEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    auto size = Director::getInstance()->getWinSize();
    auto label = Label::createWithTTF("vertexZ = 50", "fonts/Marker Felt.ttf", 64);
    label->setPosition(Vec2(size.width / 2, size.height * 0.25f));
    this->addChild(label);

    auto label2 = Label::createWithTTF("vertexZ = 0", "fonts/Marker Felt.ttf", 64);
    label2->setPosition(Vec2(size.width / 2, size.height * 0.5f));
    this->addChild(label2);

    auto label3 = Label::createWithTTF("vertexZ = -50", "fonts/Marker Felt.ttf", 64);
    label3->setPosition(Vec2(size.width / 2, size.height * 0.75f));
    this->addChild(label3);

    label->setPositionZ(50);
    label2->setPositionZ(0);
    label3->setPositionZ(-50);

    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/bugs/circle.plist");
    mgr = SpriteBatchNode::create("Images/bugs/circle.png", 9);
    this->addChild(mgr);
    sp1 = Sprite::createWithSpriteFrameName("circle.png");
    sp2 = Sprite::createWithSpriteFrameName("circle.png");
    sp3 = Sprite::createWithSpriteFrameName("circle.png");
    sp4 = Sprite::createWithSpriteFrameName("circle.png");
    sp5 = Sprite::createWithSpriteFrameName("circle.png");
    sp6 = Sprite::createWithSpriteFrameName("circle.png");
    sp7 = Sprite::createWithSpriteFrameName("circle.png");
    sp8 = Sprite::createWithSpriteFrameName("circle.png");
    sp9 = Sprite::createWithSpriteFrameName("circle.png");

    mgr->addChild(sp1, 9);
    mgr->addChild(sp2, 8);
    mgr->addChild(sp3, 7);
    mgr->addChild(sp4, 6);
    mgr->addChild(sp5, 5);
    mgr->addChild(sp6, 4);
    mgr->addChild(sp7, 3);
    mgr->addChild(sp8, 2);
    mgr->addChild(sp9, 1);

    sp1->setPositionZ(400);
    sp2->setPositionZ(300);
    sp3->setPositionZ(200);
    sp4->setPositionZ(100);
    sp5->setPositionZ(0);
    sp6->setPositionZ(-100);
    sp7->setPositionZ(-200);
    sp8->setPositionZ(-300);
    sp9->setPositionZ(-400);

    sp9->setScale(2);
    sp9->setColor(Color3B::YELLOW);
}
Beispiel #12
0
void GameNext::update(float dt)
{
    //Director::getInstance()->replaceScene(GameMain::createScene());
    
    //std::string str = Value(game_round-1).asString();
    second = second + 1;
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    if(second == 10){

        
        std::string pass_pic = "next/next" + gr_pic + "_" + gl_pic + ".png";
        auto gameover_pass_pic = Sprite::create(pass_pic);
        gameover_pass_pic->setPosition(Vec2(origin.x + visibleSize.width/2-20,
                                            origin.y + visibleSize.height/2+150));
        this->addChild(gameover_pass_pic,103);
        
    }else if (second == 50)
    {
        //if(game_level-1==5)
        if(game_level-1==2)
        {
            Director::getInstance()->replaceScene(First::createScene());
        }
        else if((game_level-1)<=2)
        {
            Director::getInstance()->replaceScene(GameMain::createScene());

        }
    }


    
    
    /*
    if(second == 10)
    {
        auto gameover_bg = Sprite::create("setting/passpic_bg.png");
        gameover_bg->setPosition(Vec2(origin.x + visibleSize.width/2,
                                      origin.y + visibleSize.height/2));
        
        
        
        log("%f",visibleSize.width/2);
        log("%f",visibleSize.height/2);
        
        
        
        this->addChild(gameover_bg,102);
        
        std::string pass_pic = "level/level"+ str +".png";
        auto gameover_pass_pic = Sprite::create(pass_pic);
        gameover_pass_pic->setPosition(Vec2(origin.x + visibleSize.width/2-20,
                                            origin.y + visibleSize.height/2+150));
        this->addChild(gameover_pass_pic,103);
        
    }else if (second == 30)
    {
        
        std::string pass_pic = "level/level"+ str +"_ok.png";
        auto gameover_bg = Sprite::create(pass_pic);
        gameover_bg->setPosition(Vec2(origin.x + visibleSize.width/2+250,
                                      origin.y + visibleSize.height/2+180));
        this->addChild(gameover_bg,103);
    }else if (second == 50)
    {
        
        std::string pass_pic = "level/level"+ str +"_got.png";
        auto gameover_bg = Sprite::create(pass_pic);
        gameover_bg->setPosition(Vec2(origin.x + visibleSize.width/2,
                                      origin.y + visibleSize.height/2-50));
        this->addChild(gameover_bg,103);
        
        
        
        auto feed_this = CCLabelTTF::create("",  "Arial", 50);
        feed_this->setColor(cocos2d::Color3B(100, 60, 60));
        feed_this->retain();
        feed_this->setPosition(origin.x + visibleSize.width/2-10,
                               origin.y + visibleSize.height/2-68);
        char str_1[100];
        sprintf(str_1, " %d ", feed_index);
        feed_this->setString(str_1);
        feed_this->setVisible(true);
        this->addChild(feed_this, 103);
        
    }else if (second == 70)
    {
        std::string pass_pic = "level/level"+ str +"_oh.png";
        auto gameover_bg = Sprite::create(pass_pic);
        gameover_bg->setPosition(Vec2(origin.x + visibleSize.width/2+285,
                                      origin.y + visibleSize.height/2-60));
        this->addChild(gameover_bg,103);
    }else if (second == 120)
    {
        if(baby>0)
        {
            std::string pass_pic = "level/level"+ str +"_gotnew.png";
            auto gameover_bg = Sprite::create(pass_pic);
            gameover_bg->setPosition(Vec2(origin.x + visibleSize.width/2+30,
                                          origin.y + visibleSize.height/2-240));
            this->addChild(gameover_bg,103);
        }else{
            if (completed==1) {
                //全部游戏完成,放恭喜画面
                Director::getInstance()->replaceScene(Baby::create());
            }else{
                Director::getInstance()->replaceScene(HelloWorld::createScene());
                
            }
        }
    }else if (second == 150)
    {
        if(baby>0)
        {
            std::string pass_pic = "level/level"+ str +"_oh.png";
            auto gameover_bg = Sprite::create(pass_pic);
            gameover_bg->setPosition(Vec2(origin.x + visibleSize.width/2+285,
                                          origin.y + visibleSize.height/2-240));
            this->addChild(gameover_bg,103);
        }
    }else if (second == 180)
    {
        if (completed==1) {
            //全部游戏完成,放恭喜画面
            Director::getInstance()->replaceScene(Baby::create());
        }else{
            Director::getInstance()->replaceScene(HelloWorld::createScene());
            
        }
    }
     */
    
}
Beispiel #13
0
// on "init" you need to initialize your instance
bool S_About::init()
{
	m_bClose = false;

	// super init 

	if ( !BaseScene::init((E::P.C100)) )
	{
		return false;
	}

	m_titleBar = TitleBar::create(S("About", "关于"));
	this->addChild(m_titleBar, 1000);

	m_heartBtn = EdgedBallButton::create(CC_CALLBACK_1(S_About::menuCallback, this));
	m_heartBtn->setScale(0.3f);
	m_heartBtn->setPosition(Vec2(48, 40));
	m_heartBtn->setTag(TAG_BACK);
	m_titleBar->addChild(m_heartBtn, 1000);

	m_heartIcon = Sprite::create("ui/ob_go_back.png");
	m_heartIcon->setColor(C3B(E::P.C700));
	m_heartIcon->setScale(0.9f);
	m_heartIcon->setAnchorPoint(Vec2(0.5, 0.5));
	m_heartIcon->setPosition(m_heartBtn->getContentSize() / 2);
	m_heartBtn->addChild(m_heartIcon, 1000);
	
	// create solid color background
	m_btmBg = BallButton::create(E::P.C50);
	m_btmBg->setScale(0.3f);
	m_btmBg->setPosition(Vec2(E::visibleWidth/2, 128+(-9/15.0f)*128));
//	m_btmBg->setTag(TAG_BTM_BG);
	this->addChild(m_btmBg, 0);

	// create solid color background
	m_bgTop = LayerColor::create(C4B(E::P.C100));
//	m_bgTop->setTag(TAG_BG_TOP);
	m_bgTop->setContentSize(Size(E::visibleWidth, E::visibleHeight - BTM_HEIGHT));
	m_bgTop->setPosition(0, BTM_HEIGHT);
	this->addChild(m_bgTop, 0);

	// create the shadow
	m_shadow = Sprite::create("ui/shadow.png");
	m_shadow->setScale(1.0f);
	m_shadow->setAnchorPoint(Vec2(0, 1));
	m_shadow->setScaleX(E::visibleWidth / DESIGNED_WIDTH);
	m_shadow->setPosition(0, BTM_HEIGHT);
//	m_shadow->setTag(TAG_SHADOW);
	m_shadow->setOpacity(0);
	this->addChild(m_shadow, 0);

//============================================================
	auto icon = Sprite::create("icon.png");
	icon->setScale(0.6f);
	icon->setPosition(E::visibleWidth/2, E::originY + 640 - 24);
	this->addChild(icon, 0);
	
	auto lbTitle = Label::createWithTTF(GAME_TITLE, FONT_BOLD, 24, 
		Size(256, 32), TextHAlignment::CENTER, TextVAlignment::CENTER);
	lbTitle->setPosition(E::visibleWidth/2, E::originY + 480 + 32);
	lbTitle->setAnchorPoint(Vec2(0.5, 0.5));
	lbTitle->setColor(C3B(E::P.C900));
	this->addChild(lbTitle, 0);

	auto lbVersion = Label::createWithTTF("Ver: " VERSION, FONT_MAIN, 24, 
		Size(256, 32), TextHAlignment::CENTER, TextVAlignment::CENTER);
	lbVersion->setPosition(E::visibleWidth/2, E::originY + 480);
	lbVersion->setAnchorPoint(Vec2(0.5, 0.5));
	lbVersion->setColor(C3B(E::P.C900));
	this->addChild(lbVersion, 0);

#define OFFSET_Y__ (320)
	
	auto iconCharmy = Sprite::create("g_charmy_av.png");
	iconCharmy->setScale(0.6f);
	iconCharmy->setAnchorPoint(Vec2(0, 0.5));
	iconCharmy->setPosition(E::originX + 24, E::originY + OFFSET_Y__);
	this->addChild(iconCharmy, 0);

	auto lbCharmy = Label::createWithTTF(S("CharmySoft", "尘泯网络"), FONT_BOLD, 28, 
		Size(320, 64), TextHAlignment::CENTER, TextVAlignment::CENTER);
	lbCharmy->setPosition(E::visibleWidth/2 + 80, E::originY + OFFSET_Y__ + 48);
	lbCharmy->setAnchorPoint(Vec2(0.5, 0.5));
	lbCharmy->setColor(C3B(E::P.C900));
	this->addChild(lbCharmy, 0);

	auto lbCharmyDetail = Label::createWithTTF(S("Charmy Game and Software Development", "尘羽泯游戏软件开发"), FONT_MAIN, 24, 
		Size(320, 64), TextHAlignment::CENTER, TextVAlignment::CENTER);
	lbCharmyDetail->setPosition(E::visibleWidth/2 + 80, E::originY + OFFSET_Y__ );
	lbCharmyDetail->setAnchorPoint(Vec2(0.5, 0.5));
	lbCharmyDetail->setColor(C3B(E::P.C900));
	this->addChild(lbCharmyDetail, 0);

	auto lbLink = Label::createWithTTF(S("http://www.CharmySoft.com", "www.CharmySoft.com"), FONT_MAIN, 24, 
		Size(256, 64), TextHAlignment::CENTER, TextVAlignment::CENTER);
	lbLink->setPosition(E::visibleWidth/2 + 80, E::originY + OFFSET_Y__ - 48);
	lbLink->setAnchorPoint(Vec2(0.5, 0.5));
	lbLink->setColor(C3B(E::P.C900));
	this->addChild(lbLink, 0);

	/*
	
	auto lbVersion = Label::createWithTTF(S("VERSION", "版本"), FONT_BOLD, 24, 
				Size(128, 32), TextHAlignment::LEFT, TextVAlignment::CENTER);
	lbVersion->setPosition(24, E::originY + 480);
	lbVersion->setAnchorPoint(Vec2(0, 0));
	lbVersion->setColor(C3B(E::P.C900));
	this->addChild(lbVersion, 0);
	*/

	auto lbThanks = Label::createWithTTF("Several icons used in this app are from the Google Material Design Icons", FONT_MAIN, 16, 
		Size(DESIGNED_WIDTH, 64), TextHAlignment::CENTER, TextVAlignment::CENTER);
	lbThanks->setPosition(E::visibleWidth/2, E::originY + BTM_HEIGHT + 24);
	lbThanks->setAnchorPoint(Vec2(0.5, 0.5));
	lbThanks->setColor(C3B(E::P.C900));
	this->addChild(lbThanks, 0);

//============================================================


	m_shareBtnBg = BallButton::create(E::P.C700);
	m_shareBtnBg->setScale(0.2f);
	m_shareBtnBg->setPosition(Vec2(E::visibleWidth/2 -(m_shareBtnBg->getContentSize().width*0.35f*2 + 48)/2, -16));
	this->addChild(m_shareBtnBg, 0);

	auto sShareIcon = Sprite::create("ui/b_share.png");
	sShareIcon->setColor(C3B(E::P.C50));
	sShareIcon->setAnchorPoint(Vec2(0, 0));

	m_rateBg = BallButton::create(E::P.C700);
	m_rateBg->setScale(0.2f);
	m_rateBg->setPosition(Vec2(E::visibleWidth/2, -16));
	this->addChild(m_rateBg, 0);

	auto sRateIcon = Sprite::create("ui/b_rate.png");
	sRateIcon->setColor(C3B(E::P.C50));
	sRateIcon->setAnchorPoint(Vec2(0, 0));

	m_websiteBtnBg = BallButton::create(E::P.C700);
	m_websiteBtnBg->setScale(0.2f);
	m_websiteBtnBg->setPosition(Vec2(E::visibleWidth/2 + (m_shareBtnBg->getContentSize().width*0.35f*2 + 48)/2, -16));
	this->addChild(m_websiteBtnBg, 0);

	auto sWebsiteIcon = Sprite::create("ui/b_website.png");
	sWebsiteIcon->setColor(C3B(E::P.C50));
	sWebsiteIcon->setAnchorPoint(Vec2(0, 0));

	auto shareItem = MenuItemSprite::create(
		BallButton::create(E::P.C700),
		BallButton::create(E::P2.C500),
		CC_CALLBACK_1(S_About::menuCallback, this));

	shareItem->setScale(0.35f);
	shareItem->setTag(TAG_SHARE);
	shareItem->addChild(sShareIcon);

	auto rateItem = MenuItemSprite::create(
		BallButton::create(E::P.C700),
		BallButton::create(E::P2.C500),
		CC_CALLBACK_1(S_About::menuCallback, this));

	rateItem->setScale(0.35f);
	rateItem->setTag(TAG_RATE);
	rateItem->addChild(sRateIcon);

	
	auto websiteItem = MenuItemSprite::create(
		BallButton::create(E::P.C700),
		BallButton::create(E::P2.C500),
		CC_CALLBACK_1(S_About::menuCallback, this));

	websiteItem->setScale(0.35f);
	websiteItem->setTag(TAG_WEBSITE);
	websiteItem->addChild(sWebsiteIcon);


	// create menu
	m_menu = Menu::create(shareItem, rateItem, websiteItem, NULL);
	m_menu->setPosition(Vec2(E::visibleWidth/2, 64 + 4 -16));
	m_menu->alignItemsHorizontallyWithPadding(24);
	m_menu->setEnabled(false);
	m_menu->setOpacity(0);
	this->addChild(m_menu, 1);

	runAnimations(false);

	return true;
}
Beispiel #14
0
Vec2 GameWindow::GetWindowMPos()
{
    double mousex, mousey;
    glfwGetCursorPos(wnd, &mousex, &mousey);
    return Vec2(mousex, mousey);
}
Beispiel #15
0
void LightManager::InitPositions()
{
	m_positions.push_back(Vec2(0,0)); //dummy
	m_positions.push_back(Vec2(50 + 15, 95 - 10)); //1
	m_positions.push_back(Vec2(222+18, 94 - 7));
	m_positions.push_back(Vec2(60 + 15, 201- 7)); //2
	m_positions.push_back(Vec2(217 + 15, 200 - 5));
	m_positions.push_back(Vec2(86 + 10, 290 - 5)); //3
	m_positions.push_back(Vec2(209 + 13, 290 - 5));
	m_positions.push_back(Vec2(93 + 11, 356)); //4
	m_positions.push_back(Vec2(204 + 10, 357 - 3));
	m_positions.push_back(Vec2(102 + 10, 414-1)); //5
	m_positions.push_back(Vec2(202 + 5, 416 - 3));
	m_positions.push_back(Vec2(110 + 7, 468)); //6
	m_positions.push_back(Vec2(194 + 11, 470));
}
Beispiel #16
0
bool RunnerSprite::isCollisionWithRight(cocos2d::Rect box){
    auto manBox = mRunner->boundingBox();
    Vec2 manPoint = Vec2(manBox.getMaxX(),manBox.getMidY());
    return box.containsPoint(manPoint);
}
Beispiel #17
0
static Vec2 calculateItemPositionWithAnchor(Widget* item, const Vec2& itemAnchorPoint)
{
    Vec2 origin(item->getLeftBoundary(), item->getBottomBoundary());
    Size size = item->getContentSize();
    return origin + Vec2(size.width * itemAnchorPoint.x, size.height * itemAnchorPoint.y);
}
Beispiel #18
0
bool RewardGoodsNode::initWithKey( RewardGoodsKey key )
{
	if ( 0 == _nodeTag) setTag( -1 );
	_goodeskey = key;

	switch ( key )
	{
	case RewardKey_1:
		{
			int randCardIndex = random(1,9);

			if ( 0 != _nodeTag)	randCardIndex = _nodeTag;
			setTag( randCardIndex );

			std::string cardFilePath = __String::createWithFormat("%s%d.png", Img_Card_FilePath, randCardIndex )->getCString();
			auto goods = Sprite::create( cardFilePath );
			goods->setAnchorPoint( Vec2(0.5, 0.5) );
			goods->setScale( 0.40f );
			goods->setPosition( Vec2(0, 25 ));
			goods->setName( "goods" );
			goods->setCascadeOpacityEnabled(true);
			addChild(goods);

			auto goodsK = Sprite::create( StringUtils::format("ccsRes/cardOptionLayer/CardFrame%d.png", (randCardIndex-1)/3+1) );
			goodsK->setScale( 1.7f);
			goodsK->setPosition(goods->getContentSize() / 2);
			goodsK->setCascadeOpacityEnabled(true);
			goods->addChild(goodsK);

			for ( int i = 0; i<4; i++ )
			{
				auto goodsStar = Sprite::create( "ccsRes/CompoundCardLayer/hecheng14.png" );
				goodsStar->setPosition( Vec2( 309 - i*50, 408) );
				goodsStar->setCascadeOpacityEnabled(true);
				goods->addChild(goodsStar);
			}
		}
		break;

	case RewardKey_2:
		{
			int randCardIndex = random(1,9);
			if ( 0 != _nodeTag)	randCardIndex = _nodeTag;
			setTag( randCardIndex );

			std::string cardFilePath = __String::createWithFormat("%s%d.png", Img_Card_FilePath, randCardIndex )->getCString();
			auto goods = Sprite::create( cardFilePath );
			goods->setAnchorPoint( Vec2(0.5, 0.5) );
			goods->setScale( 0.40f );
			goods->setPosition( Vec2(0, 25 ));
			goods->setName( "goods" );
			goods->setCascadeOpacityEnabled(true);
			addChild(goods);

			auto goodsK = Sprite::create( StringUtils::format("ccsRes/cardOptionLayer/CardFrame%d.png", (randCardIndex-1)/3+1) );
			goodsK->setScale( 1.7f);
			goodsK->setPosition( goods->getContentSize()/2 );
			goodsK->setCascadeOpacityEnabled(true);
			goods->addChild(goodsK);

			for ( int i = 0; i<3; i++ )
			{
				auto goodsStar = Sprite::create( "ccsRes/CompoundCardLayer/hecheng14.png" );
				goodsStar->setPosition( Vec2( 309 - i*50, 408) );
				goodsStar->setCascadeOpacityEnabled(true);
				goods->addChild(goodsStar);
			}

		}
		break;

	case RewardKey_3:
	case RewardKey_24:
		{
			auto goods = Sprite::create( "ccsRes/roleOptionLayer/juese5.png" );
			goods->setName( "goods" );
			goods->setPosition( Vec2(0, 10) );
			goods->setScale( 1.3f );
			addChild( goods );
		}
		break;

	case RewardKey_4:
	case RewardKey_5:
	case RewardKey_14:
	case RewardKey_21:
	case RewardKey_22:
	case RewardKey_23:
		{
			auto goods = Sprite::create( "ccsRes/ShopLayer/goumai10.png" );
			goods->setPosition( Vec2(0, 5) );
			goods->setName( "goods" );
			addChild( goods );
		}
		break;

	case RewardKey_6:
		{
			auto goods = Sprite::create( "ccsRes/ShopLayer/goumai21.png" );
			goods->setPosition( Vec2(0, 15) );
			goods->setName( "goods" );
			addChild( goods );
		}
		break;

	case RewardKey_7:
	case RewardKey_15:
		{
			int randCardIndex = random(1,9);
			if ( 0 != _nodeTag)	randCardIndex = _nodeTag;
			setTag( randCardIndex );

			std::string cardFilePath = __String::createWithFormat("%s%d.png", Img_Card_FilePath, randCardIndex )->getCString();
			auto goods = Sprite::create( cardFilePath );
			goods->setAnchorPoint( Vec2(0.5, 0.5) );
			goods->setScale( 0.40f );
			goods->setPosition( Vec2(0, 25 ));
			goods->setName( "goods" );
			goods->setCascadeOpacityEnabled(true);
			addChild(goods);

			auto goodsK = Sprite::create( StringUtils::format("ccsRes/cardOptionLayer/CardFrame%d.png", (randCardIndex-1)/3+1) );
			goodsK->setScale( 1.7f);
			goodsK->setPosition( goods->getContentSize()/2 );
			goodsK->setCascadeOpacityEnabled(true);
			goods->addChild(goodsK);

			for ( int i = 0; i<1; i++ )
			{
				auto goodsStar = Sprite::create( "ccsRes/CompoundCardLayer/hecheng14.png" );
				goodsStar->setPosition( Vec2( 309 - i*50, 408) );
				goodsStar->setCascadeOpacityEnabled(true);
				goods->addChild(goodsStar);
			}

		}
		break;

	case RewardKey_8:
	case RewardKey_19:
	case RewardKey_20:
		{
			int randCardIndex = random(1,9);
			if ( 0 != _nodeTag)	randCardIndex = _nodeTag;
			setTag( randCardIndex );

			std::string cardFilePath = __String::createWithFormat("%s%d.png", Img_Card_FilePath, randCardIndex )->getCString();
			auto goods = Sprite::create( cardFilePath );
			goods->setAnchorPoint( Vec2(0.5, 0.5) );
			goods->setScale( 0.40f );
			goods->setPosition( Vec2(0, 25 ));
			goods->setName( "goods" );
			goods->setCascadeOpacityEnabled(true);
			addChild(goods);

			auto goodsK = Sprite::create( StringUtils::format("ccsRes/cardOptionLayer/CardFrame%d.png", (randCardIndex-1)/3+1) );
			goodsK->setScale( 1.7f);
			goodsK->setPosition( goods->getContentSize()/2 );
			goodsK->setCascadeOpacityEnabled(true);
			goods->addChild(goodsK);

			for ( int i = 0; i<2; i++ )
			{
				auto goodsStar = Sprite::create( "ccsRes/CompoundCardLayer/hecheng14.png" );
				goodsStar->setPosition( Vec2( 309 - i*50, 408) );
				goodsStar->setCascadeOpacityEnabled(true);
				goods->addChild(goodsStar);
			}
		}
		break;

	case RewardKey_9:
		{
			auto goods = Sprite::create( "ccsRes/roleOptionLayer/juese3.png" );
			goods->setPosition( Vec2(0, 10) );
			goods->setName( "goods" );
			goods->setScale( 1.3f );
			addChild( goods );
		}
		break;

	case RewardKey_10:
	case RewardKey_16:
	case RewardKey_17:
	case RewardKey_18:
		{
			auto goods = Sprite::create( "ccsRes/roleOptionLayer/juese4.png" );
			goods->setPosition( Vec2(0, 10) );
			goods->setScale( 1.3f );
			goods->setName( "goods" );
			addChild( goods );
		}
		break;

	case RewardKey_11:
		{
			auto goods = Sprite::create( "ccsRes/WujinModeLayer/goodschongci.png" );
			goods->setPosition( Vec2(0, 25) );
			goods->setName( "goods" );
			addChild( goods );
		}
		break;

	case RewardKey_12:
		{
			auto goods = Sprite::create( "ccsRes/WujinModeLayer/goodsHudun.png" );
			goods->setPosition( Vec2(0, 25) );
			goods->setName( "goods" );
			addChild( goods );
		}
		break;

	case RewardKey_13:
		{
			auto goods = Sprite::create( "ccsRes/WujinModeLayer/dazhao.png" );
			goods->setPosition( Vec2(0, 25) );
			goods->setName( "goods" );
			addChild( goods );
		}
		break;

	default:
		break;
	}

	_nodeTag = getTag();

	// 数量
// 	auto goodsNum = TextAtlas::create( __String::createWithFormat(".%d", NewDataMgr::getInstance()->getRewardGoodsListWithKey( key )->GoodsNum )->getCString(), 
// 		"ccsRes/AtlasLabel/jiesuan22.png", 20,28, ".");
// 	goodsNum->setPosition(Vec2(0, -60));
// 	addChild( goodsNum );

	return true;
}
Beispiel #19
0
Bonus_1_2::Bonus_1_2(Node*scene,Vec2 pos)
{
	
	string str = "cloud02.png";


	initBase();
	is_Bonus = true;


	Scene_UI*sce = (Scene_UI*)scene;
	menu = MenuItemSprite::create(Sprite::createWithSpriteFrameName(str), Sprite::createWithSpriteFrameName(str), [=](Ref*)
	{
		is_selected = !is_selected;

		if (is_selected)
		{
			for (int i = 0; i < sce->monster_queue.size(); i++)
			{
				;
				{
					((Bonus_UI*)sce->monster_queue[i])->sprite_selected->setVisible(false);
					((Bonus_UI*)sce->monster_queue[i])->is_selected = false;
				}
			}
			is_selected = true;
			sprite_selected->setVisible(true);
			return;
		}
		sprite_selected->setVisible(false);

	});
	menu->setPosition(pos);
	menu;;




	men = Menu::create(menu, nullptr);
	men->setPosition(0, 0);
	scene->addChild(men);


	sprite = Sprite::createWithSpriteFrameName(str);

	scene->addChild(sprite);
	sprite->setPosition(pos);
	sprite;;



	sprite_selected = Sprite::createWithSpriteFrameName("point01.png");

	{
		auto ani = Animation::create();
		ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("point01.png"));
		ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("point02.png"));
		ani->setDelayPerUnit(3.0 / 30.0);
		ani->setRestoreOriginalFrame(false);
		ani->setLoops(-1);

		sprite_selected->runAction(Animate::create(ani));
	}
	sprite_selected->setPosition(sprite->getContentSize().width / 2, sprite->getContentSize().height );
	sprite->addChild(sprite_selected);
	sprite_selected->setVisible(false);





	hp_sprite_2 = Sprite::createWithSpriteFrameName("MonsterHP02.png");
	hp_sprite_2->setPosition(Vec2(sprite->getContentSize().width / 4, sprite->getContentSize().height - 5));
	sprite->addChild(hp_sprite_2);
	hp_sprite_1 = Sprite::createWithSpriteFrameName("MonsterHP01.png");
	hp_sprite_1->setPosition(Vec2(sprite->getContentSize().width / 4, sprite->getContentSize().height - 5));
	sprite->addChild(hp_sprite_1);
	hp_sprite_1->setAnchorPoint(Vec2(0, 0.5));
	hp_sprite_2->setAnchorPoint(Vec2(0, 0.5));
	hp_sprite_1->setScaleY(0.7);




	sprite_effect_slow = Sprite::createWithSpriteFrameName("PShit-12.png");
	sprite->addChild(sprite_effect_slow);

	auto ani1 = Animation::create();
	ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PShit-12.png"));
	ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PShit-11.png"));

	ani1->setDelayPerUnit(0.1);
	ani1->setRestoreOriginalFrame(false);
	ani1->setLoops(-1);
	sprite_effect_slow->runAction(Animate::create(ani1));
	sprite_effect_slow->setPosition(sprite->getContentSize().width / 2, 20);


	sprite_effect_slow->setVisible(false);








	hp_sprite_1->setVisible(false);
	hp_sprite_2->setVisible(false);











	/*init Õ¼ÓÃλÖÃ*/

	queue_takeplace_pos.push_back(Vec2(PublicFunc::convertToX(pos.x), PublicFunc::convertToY(pos.y)));



	for (int i = 0; i < queue_takeplace_pos.size(); i++)
	{
		sce->data->push_back(queue_takeplace_pos[i]);
	}



}
Beispiel #20
0
void RecordDetailCell::update_data(msg::Processor_300_PokerGetHandHistory_DOWN& records, ssize_t idx,bool isDetail ,float offset)
{
    
    if (isDetail) {
        root->setPositionY(offset);
    }
    else
    {
        root->setPositionY(0);
        if (detailNode) {
            detailNode->removeFromParent();
            detailNode = nullptr;
        }
    }
    
    int userid = 0;
    std::string picname = "";
    if (records.has_players()) {

        msg::ReplayPlayer player = records.players().replayplayer(idx);
        text_nickname_->setString(player.userdetailinfo().nickname());
        
        picname = player.userdetailinfo().picname();
        userid = player.userdetailinfo().userid();
        
    }
    
    if (records.has_handresultinfo()) {
        int32_t winchip = records.handresultinfo().playerresult(idx).playerwinchips();
        int32_t betchip = records.handresultinfo().playerresult(idx).playerbetchips();
        text_amount_->setString(tools::to_string(winchip - betchip));
    }
    
    int cardSize = records.steps().replaystep(0).propupdate().pokerplayerinfo(idx).holecards_size();
    
    for (int i = 0; i < cardSize; i++) {
        int index = records.steps().replaystep(0).propupdate().pokerplayerinfo(idx).holecards(i);
        const std::string image_name = PDM->get_card_image(index);
        Sprite* card = Sprite::create(image_name);
        card->setScale(0.6);

        card->setPosition(0 + card->getContentSize().width * (i * 0.6f), 0);
        sprite_card_bg_->addChild(card, 1);
    }
    
    int stepSize = records.steps().replaystep_size();
    
    int infoSize = records.steps().replaystep(stepSize - 1).propupdate().pokerplayerinfo_size();
    
    if (infoSize > idx) {
        std::string card_type = records.steps().replaystep(stepSize - 1).propupdate().pokerplayerinfo(idx).hihandtype();
        std::string low_card_type =  records.steps().replaystep(stepSize - 1).propupdate().pokerplayerinfo(idx).lohandtype();
        
        card_type = tools::trim(card_type);
        low_card_type = tools::trim(low_card_type);
        std::string result;
        if(!card_type.empty() && !low_card_type.empty()) {
            result = card_type + "/" + low_card_type;
        }
        if (result.empty()) {
            result = card_type.empty() ? low_card_type : card_type;
        }
        
        text_hand_type_->setString(result);
    }
    else
    {
        text_hand_type_->setString("");
    }
    
    if (isDetail) {
        
        if (detailNode) {
            detailNode->removeFromParent();
            detailNode = nullptr;
        }
        
        detailNode = Node::create();
        this->addChild(detailNode);
        
        
        if(GDM->is_file_exist(picname)) {
            
//            auto sprite_icon_ = ShaderSprite::create(picname, "login_res/game_res/avatar_mask_circle.png");
//            sprite_icon_->setPosition(Vec2(76,offset -40));
//            sprite_icon_->setScale(76 / sprite_icon_->getContentSize().width,
//                                   76 / sprite_icon_->getContentSize().height);
//            
//            detailNode->addChild(sprite_icon_);
        }
        else
        {
            Sprite * sprite_icon_ = Sprite::create("main_avatar_bg.png");
            sprite_icon_->setPosition(Vec2(76,offset -40));
            detailNode->addChild(sprite_icon_);
        }
        

        
        
        std::vector<int> lines(4,0);
        
        if (records.has_players()) {
            
            
            for(auto& replayStep : records.steps().replaystep())
            {
                if (replayStep.pokerstep().has_blinds()) {
                    for(auto& blind : replayStep.pokerstep().blinds().blind())
                    {
                        if (blind.userid() == userid) {
                            switch (replayStep.pokerstep().round()) {
                                case msg::PokerRoundType::Preflop:
                                {
                                    lines.at(0)++;
                                    
                                }
                                    break;
                                case msg::PokerRoundType::Flop:
                                {
                                    lines.at(1)++;
                                }
                                    break;
                                case msg::PokerRoundType::Turn:
                                {
                                    lines.at(2)++;
                                }
                                    break;
                                case msg::PokerRoundType::River:
                                {
                                    lines.at(3)++;
                                }
                                    break;
                                    
                                default:
                                    break;
                            }
                            
                            
                            std::string title = "";
                            switch (blind.type()) {
                                case msg::BlindType::Smallblind:
                                {
                                    title = "小盲";
                                    
                                }
                                    break;
                                case msg::BlindType::Bigblind:
                                {
                                    
                                    title = "大盲";
                                    
                                }
                                    break;
                                case msg::BlindType::Ante:
                                {
                                    title = "Ante";
                                    
                                }
                                    break;
                                case msg::BlindType::Straddle:
                                {
                                    title = "抓";
                                    
                                }
                                    break;
                                    
                                default:
                                    break;
                            }
                            
                            
                            Text *text = Text::create(title + tools::to_string(blind.amount()), "Arial", 24);
                            text->setColor(Color3B::GRAY);
                            text->setPosition(Vec2(200 + 120 * replayStep.pokerstep().round(),offset + 10 - lines.at(replayStep.pokerstep().round()) * 30));
                            detailNode->addChild(text);
                            
                        }
                    }
                    
                }
                
                if (replayStep.pokerstep().has_playeraction())
                {
                    if (replayStep.pokerstep().playeraction().userid() == userid) {
                        switch (replayStep.pokerstep().round()) {
                            case msg::PokerRoundType::Preflop:
                            {
                                lines.at(0)++;
                                
                            }
                                break;
                            case msg::PokerRoundType::Flop:
                            {
                                lines.at(1)++;
                            }
                                break;
                            case msg::PokerRoundType::Turn:
                            {
                                lines.at(2)++;
                            }
                                break;
                            case msg::PokerRoundType::River:
                            {
                                lines.at(3)++;
                            }
                                break;
                                
                            default:
                                break;
                        }
                        
                        std::string title = "";
                        switch (replayStep.pokerstep().playeraction().action()) {
                            case msg::ActionStatus::FOLD:
                            {
                                title = "弃牌";
                            }
                                break;
                            case msg::ActionStatus::CHECK:
                            {
                                
                                title = "让牌";
                                
                            }
                                break;
                            case msg::ActionStatus::BET:
                            {
                                title = "下注" + tools::to_string(replayStep.pokerstep().playeraction().amount());
                            }
                                break;
                            case msg::ActionStatus::CALL:
                            {
                                title = "跟注" + tools::to_string(replayStep.pokerstep().playeraction().amount());
                            }
                                break;
                            case msg::ActionStatus::RAISE:
                            {
                                title = "加注" + tools::to_string(replayStep.pokerstep().playeraction().amount());
                            }
                                break;
                            case msg::ActionStatus::ALLIN:
                            {
                                title = "全下" + tools::to_string(replayStep.pokerstep().playeraction().amount());
                            }
                                break;
                                
                            default:
                                break;
                        }
                        
                        Text *text = Text::create(title, "Arial", 24);
                        text->setColor(Color3B::GRAY);
                        text->setPosition(Vec2(200 + replayStep.pokerstep().round() * 120,offset + 10 - lines.at(replayStep.pokerstep().round()) * 30));
                        detailNode->addChild(text);

                        
                    }
                    
                }
                
            }
            
            
        }
    
    }
    
}
Vec2 Vec2::operator +( const Vec2 &rhs ) const
{
  return Vec2( *this ) += rhs;
}
Beispiel #22
0
bool HomeScene::init()
{
    if ( !BaseScene::init() )
    {
        return false;
    }
    
	auto bgLayer = LayerColor::create(Color4B(195, 75, 134, 255));
	this->addChild(bgLayer);

	labelNom = U::label("NOM", 150, 1);
	labelNom->setPosition(U::cx - 20, U::cy + 70 + 70);
	this->addChild(labelNom);

	labelNum = U::label("NUM", 150, 1);
	labelNum->setPosition(U::cx + 20, U::cy + 70 - 70);
	this->addChild(labelNum);

	bool tutorial = U::userDefault->getBoolForKey("tutorial", true);

	ScalableSprite *btnPlay = ScalableSprite::create("play.png", [tutorial](){
		if (tutorial)
		{
			U::userDefault->setBoolForKey("tutorial", false);
			Util::director->replaceScene(TransitionSlideInR::create(0.2f, GameScene::createWithLevel(0, 0)));
		}
		else
		{
			int currentChapter = U::userDefault->getIntegerForKey("currentChapter");
			int currentLevel = U::userDefault->getIntegerForKey("currentLevel");
			Util::director->replaceScene(TransitionSlideInR::create(0.2f, GameScene::createWithLevel(currentLevel, currentChapter)));
		}
	});

	if (tutorial)
	{
		btnPlay->setPosition(U::cx, U::height / 4);
	}
	else
	{
		btnPlay->setPosition(U::cx, U::height / 4 + 70);

		ScalableSprite *btnMenu = ScalableSprite::create("menu_green.png", [](){
			Util::director->replaceScene(TransitionSlideInR::create(0.2f, ChapterScene::create()));
		});
		btnMenu->setPosition(U::cx, U::height / 4 - 70);
		this->addChild(btnMenu);
	}
	this->addChild(btnPlay);

	m_share = ScalableSprite::create("share_50.png", [](){
        Util::crossHelper->showActivities();
	});
	m_share->setPosition(10, 10);
	m_share->setAnchorPoint(Vec2(0, 0));
	this->addChild(m_share, 1000);
    
    m_gamecenter = ScalableSprite::create("gamecenter_50.png", [](){
        Util::crossHelper->showGameCenter();
    });
    m_gamecenter->setPosition(90, 10);
    m_gamecenter->setAnchorPoint(Vec2(0, 0));
    this->addChild(m_gamecenter, 1000);

	m_about = ScalableSprite::create("about.png", [this](){
		Util::director->replaceScene(TransitionFlipX::create(0.3f, AboutScene::create()));
	});
	m_about->setPosition(170, 10);
	m_about->setAnchorPoint(Vec2(0, 0));
	this->addChild(m_about, 1000);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	m_gamecenter->setVisible(false);
	m_about->setPosition(90, 10);

	m_exit = ScalableSprite::create("exit.png", [this](){
		Util::crossHelper->askForExit();
	});
	m_exit->setPosition(170, 10);
	m_exit->setAnchorPoint(Vec2(0, 0));
	this->addChild(m_exit, 1000);
#endif
    
    return true;
}
Vec2 Vec2::operator -( const Vec2 &rhs ) const
{
  return Vec2( *this ) -= rhs;
}
Beispiel #24
0
bool GameMenu::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
	CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic(GAMEMENU_WAV,true);

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    auto gameStart = MenuItemImage::create(
                                           PIC_START,
                                           PIC_START,
										   CC_CALLBACK_1(GameMenu::gameStartCallBack,this));
	gameStart->setPosition(Vec2(visibleSize.width/2 , visibleSize.height/2 ));

	auto gameShop = MenuItemImage::create(
										   PIC_SHOP,
                                           PIC_SHOP,
										   CC_CALLBACK_1(GameMenu::gameShopCallBack,this));
	gameShop->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2 + origin.y-80 ));

	auto gameSetting = MenuItemImage::create(
											PIC_SETTING,
                                            PIC_SETTING);
	gameSetting->setPosition(Vec2(visibleSize.width/2 , visibleSize.height/2 + origin.y - 160));

	auto gameQuit = MenuItemImage::create(
											PIC_QUIT,
											PIC_QUIT,
										   CC_CALLBACK_0(GameMenu::gameQuitCallBack,this));
	gameQuit->setPosition(Vec2(visibleSize.width/2 , visibleSize.height/2 + origin.y - 240));

	auto menu = Menu::create(gameStart, gameShop, gameSetting, gameQuit, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);
    
	auto content = "menu";
	auto label = LabelTTF::create(content, "Arial", 24);  
    label->setPosition(Vec2(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - 1.5*label->getContentSize().height));
    this->addChild(label, 1);
	label->setVisible(false);

	auto backGround = Sprite::create(PIC_MENUBACKGROUND);
    backGround->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    this->addChild(backGround, 0);

	//╗§ио¤н╩Й
	auto score = UserData::getInstance()->getPoints();
	auto temp = __String::createWithFormat("%d",score);
	auto temp2 = __String::create("Your total points: ");
	temp2->append(temp->getCString());
	auto scoreLabel = Label::create(temp2->getCString(),"Arial",24);
	scoreLabel->setPosition(Vec2(origin.x + scoreLabel->getContentSize().width/2, origin.y + visibleSize.height - 1.5*label->getContentSize().height));
	scoreLabel->setColor(Color3B(0,100,200));
	this->addChild(scoreLabel);

    return true;
}
Beispiel #25
0
void Bird::Fall(){
		flappyBird->getPhysicsBody()->applyForce(Vec2(0, -30));
	
	
}
bool ControlSaturationBrightnessPicker::initWithTargetAndPos(Node* target, Vec2 pos)
{
    if (Control::init())
    {
        // Add background and slider sprites
        _background=ControlUtils::addSpriteToTargetWithPosAndAnchor("colourPickerBackground.png", target, pos, Vec2(0.0f, 0.0f));
        _overlay=ControlUtils::addSpriteToTargetWithPosAndAnchor("colourPickerOverlay.png", target, pos, Vec2(0.0f, 0.0f));
        _shadow=ControlUtils::addSpriteToTargetWithPosAndAnchor("colourPickerShadow.png", target, pos, Vec2(0.0f, 0.0f));
        _slider=ControlUtils::addSpriteToTargetWithPosAndAnchor("colourPicker.png", target, pos, Vec2(0.5f, 0.5f));
                
        _startPos=pos; // starting position of the colour picker        
        boxPos          = 35;    // starting position of the virtual box area for picking a colour
        boxSize         = _background->getContentSize().width / 2;;    // the size (width and height) of the virtual box for picking a colour from
        return true;
    }
    else
    {
        return false;
    }
}
Beispiel #27
0
void RichText::initRenderer()
{
    _elementRenderersContainer = Node::create();
    _elementRenderersContainer->setAnchorPoint(Vec2(0.5f, 0.5f));
    addProtectedChild(_elementRenderersContainer, 0, -1);
}
Beispiel #28
0
bool UILayer::init()
{
    if (!Layer::init())
        return false;

    auto winSize = Director::getInstance()->getWinSize();

    auto menuItem = MenuItemImage::create(
        "Images/Interface/Exit.png",
        "Images/Interface/Exit_selected.png",
        CC_CALLBACK_1(UILayer::ClickExit, this));
    menuItem->setScale(0.3f, 0.3f);

    auto menu = Menu::create(menuItem, NULL);
    menu->setPosition(winSize.width - 40, 12);
    this->addChild(menu);

    auto hpLabel = Label::createWithSystemFont("\0", DEF_FONT, 23);
    hpLabel->setPosition(Vec2(MAX_MAP_SIZE_X / 2, 143));
    this->addChild(hpLabel, 11, HP_LABEL);

    this->addChild(MakeSprite("Images/Interface/interface.png",         Vec2(MAX_MAP_SIZE_X / 2, 100),          Vec2(1.1f, 1.1f),   Vec2(0.5, 0.5)));
    this->addChild(MakeSprite("Images/Interface/HpBar_interface.png",   Vec2(MAX_MAP_SIZE_X / 2 - 204, 141),    Vec2(0.72f, 1.1f),  Vec2(0.0, 0.5)),    10, HP_BAR);

    this->addChild(MakeCooltimeBox(SKILL_Q, Vec2(MAX_MAP_SIZE_X / 2 - 150, 48)));
    this->addChild(MakeCooltimeBox(SKILL_W, Vec2(MAX_MAP_SIZE_X / 2 - 70, 48)));
    this->addChild(MakeCooltimeBox(SKILL_E, Vec2(MAX_MAP_SIZE_X / 2 + 13, 48)));
    this->addChild(MakeCooltimeBox(SKILL_R, Vec2(MAX_MAP_SIZE_X / 2 + 92, 48)));
    
    m_Cursor = MakeCursor(CURSOR_DEFAULT, "Images/Cursor/cursor_default.png", Vec2(1, 1), Vec2(0, 1));
    m_Cursor->setVisible(true);
    this->addChild(m_Cursor, 10);
    this->addChild(MakeCursor(CURSOR_ATTACK, "Images/Cursor/cursor_attack.png",     Vec2(1, 1),         Vec2(0, 1)),        10);
    this->addChild(MakeCursor(CURSOR_TELEPORT, "Images/Cursor/cursor_teleport.png", Vec2(0.2f, 0.08f),  Vec2(0.5f, 0.5f)),  10);
    this->addChild(MakeCursor(CURSOR_SPLASH, "Images/Cursor/cursor_splash.png",     Vec2(1.5f, 1.5f),   Vec2(0.5f, 0.5f)),  10);
    return true;
}
Beispiel #29
0
ChipmunkTestLayer::ChipmunkTestLayer()
{
#if CC_ENABLE_CHIPMUNK_INTEGRATION      
    // enable events

    auto touchListener = EventListenerTouchAllAtOnce::create();
    touchListener->onTouchesEnded = CC_CALLBACK_2(ChipmunkTestLayer::onTouchesEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
    
    Device::setAccelerometerEnabled(true);
    auto accListener = EventListenerAcceleration::create(CC_CALLBACK_2(ChipmunkTestLayer::onAcceleration, this));
    _eventDispatcher->addEventListenerWithSceneGraphPriority(accListener, this);
    
    // title
    auto label = Label::createWithTTF("Multi touch the screen", "fonts/Marker Felt.ttf", 36.0f);
    label->setPosition(cocos2d::Vec2( VisibleRect::center().x, VisibleRect::top().y - 30));
    this->addChild(label, -1);

    // reset button
    createResetButton();

    // init physics
    initPhysics();

#if 1
    // Use batch node. Faster
    auto parent = SpriteBatchNode::create("Images/dice_atlas.png", 100);
    //auto parent = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
    _spriteTexture = parent->getTexture();
#else
    // doesn't use batch node. Slower
    _spriteTexture = Director::getInstance()->getTextureCache()->addImage("Images/dice_atlas.png");
    //_spriteTexture = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas.png");
    auto parent = Node::create();
#endif
    
    
    
    
    addChild(parent, 0, kTagParentNode);

    addNewSpriteAtPosition(cocos2d::Vec2(200,200));

    // menu for debug layer
    MenuItemFont::setFontSize(18);
    auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(ChipmunkTestLayer::toggleDebugCallback, this));

    auto menu = Menu::create(item, nullptr);
    this->addChild(menu);
    menu->setPosition(cocos2d::Vec2(VisibleRect::right().x-100, VisibleRect::top().y-60));

    scheduleUpdate();
#else
    auto label = Label::createWithTTF("Should define CC_ENABLE_CHIPMUNK_INTEGRATION=1\n to run this test case",
                                            "fonts/arial.ttf",
                                            18);
    auto size = Director::getInstance()->getWinSize();
    label->setPosition(Vec2(size.width/2, size.height/2));
    
    addChild(label);
    
#endif
    
}
Vec2 getAnglePosition(float r, float angle) {
    return Vec2(r*cos(angle), r*sin(angle));
}