bool BreakBlocksScene::init()
{
    if (!CCLayer::init())
    {
        return false;
    }
    
    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
    
    auto size = CCDirector::sharedDirector()->getWinSize();
    auto center = ccp(size.width * 0.5f, size.height * 0.5f);
    
    this->presenter = new BreakBlocksPresenter();
    this->presenter->initialize(0.0f, 0.0f, size.width, size.height);
    
    auto ball = this->presenter->getBall();
    ball->addListener(this->ballChangedHandler);
    
    this->ball = CCSprite::create("ball.png");
    this->ball->setPosition(ball->getCenterX(), ball->getCenterY());
    this->addChild(this->ball);
    
    auto bar = this->presenter->getBar();
    bar->addListener(this->barChangedHandler);
    
    this->bar = CCSprite::create("bar.png");
    this->bar->setPosition(bar->getCenterX(), bar->getCenterY());
    this->addChild(this->bar);
    
    auto blockTexture = CCTextureCache::sharedTextureCache()->addImage("block.png");
    for (int i = 0; i < this->presenter->getBlockCount(); i++)
    {
        auto b = this->presenter->getBlock(i);
        b->addListener(this->blockChangedHandler);
        
        auto block = CCSprite::createWithTexture(blockTexture);
        block->setPositionX(b->getCenterX());
        block->setPositionY(b->getCenterY());
        block->setTag(b->getId());
        this->blocks.push_back(block);
        this->addChild(block);
    }
    
    this->label = CCLabelTTF::create("", "Thonburi", 50.0f);
    this->label->setPosition(center);
    this->addChild(this->label, 100);
    
    this->schedule(schedule_selector(BreakBlocksScene::update));
    
    return true;
}
Esempio n. 2
0
void Character::updateMove(){
	int oldPositionX = getPositionX();
	if (_destPosition.x > oldPositionX + _moveSpeed){
		setPositionX(oldPositionX + _moveSpeed);
	}
	else if (_destPosition.x < oldPositionX - _moveSpeed){
		setPositionX(oldPositionX - _moveSpeed);
	}
	else{
		setPositionX(_destPosition.x);
	}

	int oldPositionY = getPositionY();
	if (_destPosition.y > oldPositionY + _moveSpeed){
		setPositionY(oldPositionY + _moveSpeed);
	}
	else if (_destPosition.y < oldPositionY - _moveSpeed){
		setPositionY(oldPositionY - _moveSpeed);
	}
	else{
		setPositionY(_destPosition.y);
	}

}
Esempio n. 3
0
void HelloWorld::update( float dt)
{
	float mapSpeed=2.5f;
	float playerV=1.0f;
	auto map=this->getChildByTag(102);
	Player * player=(Player *)this->getChildByTag(101);
	map->setPositionX(map->getPositionX()-mapSpeed);
	if (map->getPositionX()<=-640*9)
	{
		map->setPositionX(0);
		player->setPosition(Vec2(48,768));
		return;
	}
	checkDown();
	if (m_pPlayer->getDirection()==DIRECTION_UP)
	{
		if (m_pPlayer->getPlayerSpeed()-playerV>=0)
		{
			m_pPlayer->setPlayerSpeed(m_pPlayer->getPlayerSpeed()-playerV);
			m_pPlayer->setPositionY(m_pPlayer->getPositionY()+m_pPlayer->getPlayerSpeed());
		}
		else
		{
			m_pPlayer->setPlayerSpeed(0);
			m_pPlayer->setDirection(DIRECTION_DOWN);
		}
	}
	else if (m_pPlayer->getDirection()==DIRECTION_DOWN)
	{
		
		m_pPlayer->setPlayerSpeed(m_pPlayer->getPlayerSpeed()+playerV);
		m_pPlayer->setPositionY(m_pPlayer->getPositionY()-m_pPlayer->getPlayerSpeed());
	}
	checkDie();
	
}
Esempio n. 4
0
void HeroSprite::update(float dt)
{
	if (!_isStartGame) return;
	Point wroldPos = this->getParent()->convertToWorldSpace(getPosition());
	if (_isGameOver && wroldPos.y < -getContentSize().height)
	{
		_isStartGame = false;
	}
	_time += dt * 2.5f;
	//215 = 49 * t
	float s = this->_velocity * _time + _accelerated * _time * _time / 2;
	MoveDir dir = _previousPos.y > getPositionY() ? MoveDir_Down : MoveDir_Up;
	this->changeDir(dir);
	_previousPos = getPosition();
	if (getPositionX() > VisibleRect::right().x + getContentSize().width / 2)
	{
		setPositionX(-getContentSize().width / 2);
	}
	else if (getPositionX() < -getContentSize().width / 2)
	{
		setPositionX(VisibleRect::right().x + getContentSize().width / 2);
	}
	setPosition(Point(getPositionX() + _offset, this->_startPos + s));
}
Esempio n. 5
0
void BaseCar::enterCircleCallBack()
{
    auto winSize = Director::getInstance()->getWinSize();
    auto pos = getPosition();
    auto centerX = winSize.width / 2;
    auto centerY = winSize.height / 2;

    double deltaX;

    double angle;

    if (pos.x > centerX) {
        deltaX = pos.x - POS_R.x;
        angle = deltaX / R_OUTER;
        if (pos.y > centerY) {
            angle = PI / 2 - angle;
        } else {
            angle = PI * 3 / 2 + angle;
        }
        setPositionX(POS_R.x + cos(angle) * _curRadius);
        setPositionY(POS_R.y + sin(angle) * _curRadius);
        setRotation3D(Vec3(0 , 0 , - convertTo180(angle - PI / 2)));
    } else {
        deltaX = POS_L.x - pos.x;
        angle = deltaX / R_OUTER;
        if (pos.y > centerY) {
            angle = PI / 2 + angle;
        } else {
            angle = PI * 3 / 2 - angle;
        }
        setPositionX(POS_L.x + cos(angle) * _curRadius);
        setPositionY(POS_L.y + sin(angle) * _curRadius);
        setRotation3D(Vec3(0 , 0 , - convertTo180(angle - PI / 2)));
    }

}
void Plane::update(float dt) {

    setPositionX(getPositionX()+speedX);
    if (getScaleX()>0) {
        if (getPositionX()<-getContentSize().width) {
            unscheduleUpdate();
            planes->removeObject(this);
            getParent()->removeChild(this);
        }
    } else {
        if (getPositionX()>visibleSize.width+getContentSize().width) {
            unscheduleUpdate();
            planes->removeObject(this);
            getParent()->removeChild(this);
        }
    }
}
Esempio n. 7
0
void Ball::move(){
    setPositionX(getPositionX()+speedX);
    setPositionY(getPositionY()+speedY);
    
    if (getPositionX()<r) {
        speedX = MABS(speedX);
    }
    if (getPositionY()<r) {
        speedY = MABS(speedY);
    }
    if (getPositionX()>boundWidth-r) {
        speedX = -MABS(speedX);
    }
    if (getPositionY()>boundHeight-r) {
        speedY = -MABS(speedY);
    }
}
Esempio n. 8
0
//=============================================================================
// update
// typically called once per frame
// frameTime is used to regulate the speed of movement and animation
//=============================================================================
void Shield::update(float frameTime)
{

    //spriteData.x += velocity.x * frameTime;
    //velocity.x = 0;
    //spriteData.y += velocity.y * frameTime;
    //velocity.y = 0;

    Entity::update(frameTime);

	if(!attached) //if it's attached, we just want to draw it where the avatar is
	{
		//when go off the left side of screen
		if(visible && getPositionX() + getWidth() * getScale() <= 0)
		{
			setPositionX(0);
			setVelocity(VECTOR2(0,0));
			visible = false;
		}
	
		// Update position
		incPositionX(velocity.x * frameTime);
		incPositionY(velocity.y * frameTime);

		// Convert World Coord to Screen Coord
		setScreenCoordX();
		setScreenCoordY();
	}

	if(health==2)
		this->setColorFilter(graphicsNS::BLACK);
	//MIGHT HAVE TO USE ANIMATIONS



    //// wrap around screen
    //if (spriteData.x > GAME_WIDTH)                  // if off screen right
    //    spriteData.x = -shipNS::WIDTH;              // position off screen left
    //else if (spriteData.x < -shipNS::WIDTH)         // else if off screen left
    //    spriteData.x = GAME_WIDTH;                  // position off screen right
    //if (spriteData.y < -shipNS::HEIGHT)             // if off screen top
    //    spriteData.y = GAME_HEIGHT;                 // position off screen bottom
    //else if (spriteData.y > GAME_HEIGHT)            // else if off screen bottom
    //    spriteData.y = -shipNS::HEIGHT;             // position off screen top
}
Esempio n. 9
0
void PlayerSprite::update(float dt) {
    /*
      Update player status

      Args:
        dt: float, interval between frame

      Returns:
        void
     */
    if (_body && isVisible()) {
        setPositionX(_body->GetPosition().x * PTM_RATIO);
        setPositionY(_body->GetPosition().y * PTM_RATIO);
    }
    
    // update arrow
    this->transferArrow();
}
Esempio n. 10
0
bool Block::init() {
    Sprite::init();
    Size size = Size(rand() % 20 + 5, rand() % 30 + 10);
    Size visibleSize = Director::getInstance()->getVisibleSize();
    setPhysicsBody(PhysicsBody::createBox(size));
    setTextureRect(Rect(0, 0, size.width, size.height));
    setColor(Color3B(0, 0 , 0));
    
    setContentSize(size);
    
//    setPositionX(visibleSize.width + size.width / 2);
    setPositionX(visibleSize.width);
    getPhysicsBody()->setDynamic(false);
    
    scheduleUpdate();
    getPhysicsBody()->setContactTestBitmask(2);
    return true;
}
Esempio n. 11
0
void SODOctopus::update()
{
	if (isActive() )
	{
		Uint32 now = TIMESERVICE->time();
		if (now > finishTime)
			setActive(false);
		else if (now > beginTime + bootstrapTime)
		{
			Uint32 dt = now - (beginTime + bootstrapTime);
			Point delta = dst_pos - ori_pos;

			Point step = (delta * dt) / (totalTime- bootstrapTime);
			Point newPos = ori_pos + step;
			setPositionX((int)newPos.x);
			setPositionY((int)newPos.y);
		}
	}
}
// Manage physics from this loop
// Please don't alter the Ogre scene manager directly. Instead use the designated methods (setPositionX, setPositionY, setPositionZ, setRoll, setPitch, setYaw, animate)
void loop(Ogre::SceneManager* smgr){
	int dir = 1;
	int timeStep = 10;
	while(true){
		// If the message array has any elements, the render loop is applying changes from physics loop
		// If so, abort this timestep
		if((*::message).size() == 1){
			continue;
		}
		Sleep(timeStep);
		Ogre::SceneManager::MovableObjectIterator iterator = smgr->getMovableObjectIterator("Entity");
		while(iterator.hasMoreElements()){
			// If the message array has any elements, the render loop is applying changes from physics loop
			// If so, abort this timestep
			if((*::message).size() == 1){
				continue;
			}
			Ogre::Entity* entity = static_cast<Ogre::Entity*>(iterator.getNext());

			// <>< <>< Make the cute fishy swim <>< <><
			// This only moves fish
			if(entity->hasAnimationState("swim")){
			
				Ogre::SceneNode* sceneNode = entity->getParentSceneNode();

				// Update position
				Ogre::Vector3 pos = sceneNode->getPosition();
				if(pos.x > 120){
					dir = -1;
					setYaw(entity, 180);
				}
				if(pos.x < -120){
					dir = 1;
					setYaw(entity, 180);
				}
				setPositionX(entity, sceneNode->getPosition().x + dir);
				animate(entity, "swim");
			}

		}
	}
}
Esempio n. 13
0
void Obstacle::update()
{
	if (GAME_STATUS != GAME_STATUS_PLAYING)
		return;
	addCount++;
	if (addCount == 60)
	{
		addOne(0);
		addCount = 0;
	}
	for (int i = obstacleList->count() - 1; i >= 0; i--)
	{
		auto s = (Sprite*)obstacleList->getObjectAtIndex(i);
		s->setPositionX(s->getPositionX() - 3);
		if (s->getPositionX() < -s->getContentSize().width / 2)
		{
			obstacleList->removeObjectAtIndex(i);
			this->removeChild(s);
		}
	}
}
Esempio n. 14
0
void BackgroundLayer::setViewPointByPlayer(Player *player) {
	auto pos = player->getPosition();

	/*
	* for simpilication, we consider that the movement of the player
	* will only be related with the movement of each image of columns
	*/
	int countColumn = _imageColumnEndPos - _imageColumnStartPos + 1;
	int countRow = _imageRowEndPos - _imageRowStartPos + 1;

	auto parent = player->getParent();
	auto viewSize = parent->getContentSize();

	if (pos.x >= viewSize.width / 2 && pos.x <= viewSize.width * (countColumn - 0.5)) {
		parent->setPositionX(viewSize.width / 2 - pos.x);
	}
	if (pos.y >= viewSize.height / 2 && pos.y <= viewSize.height * (countRow - 0.5)) {
		parent->setPositionY(viewSize.height / 2 - pos.y);
	}
	return;
}
Esempio n. 15
0
void TopData::setupElementScoreNode(Node *parent, LevelDict *levelDict, Color4B color, float positionY)
{
    int count = 0;
    for (int i = 0; i < LEVEL_ELEMENT_COUNT; i++)
    {
        if(levelDict->elements[i] > 0)
        {
            count++;
        }
    }
    
    float eachWidth = 100;
    float totoleWidth = eachWidth * count;
    float startX = totoleWidth / 2 * -1 + 10;
    
    int index = 0;
    for (int i = 0; i < LEVEL_ELEMENT_COUNT; i++)
    {
        if(levelDict->elements[i] > 0)
        {
            auto topElementNode = CSLoader::createNode("TopImageTextNode.csb");
            topElementNode->setTag(MAIN_SCENE_TOP_ELEMENT_NODE + i);
            topElementNode->setPositionY(positionY);
            topElementNode->setPositionX(startX + eachWidth * index + eachWidth / 2);
            
            auto imageSprite = topElementNode->getChildByName<Sprite *>("image");
            imageSprite->setTexture("res/img/element" + Value(i).asString() + ".png");
            
            auto textRestElement = topElementNode->getChildByName<ui::Text *>("text");
            textRestElement->setTextColor(color);
            textRestElement->setString(Value(levelDict->elements[i]).asString());
            
            parent->addChild(topElementNode);
            index++;
        }
    }
}
Esempio n. 16
0
void UiElement::update(){
	if(m_Camera){
		setPositionX(m_Camera->getWorldPosX()+m_ScreenPosX);
		setPositionY(m_Camera->getWorldPosY()+m_ScreenPosY);
	}
}
Esempio n. 17
0
bool LayerUserInfo::init()
{
    if(!BaseLayer::init())
    {
        return false;
    }
    
    auto root = CSLoader::createNode("LayerFriendDetails.csb");
    addChild(root);
    auto btnBack = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_back"));
    auto tmpImgIcon = dynamic_cast<ImageView*>(CSLoader::seekNodeByName(root, "image_user_avatar"));
    auto imgHead = ShaderSprite::createAndDownload("Default/image_defualt_user_icon_large.png", "Default/image_defualt_user_icon_large.png", "Default/image_mask_circle.png");
    imgHead->setPosition(tmpImgIcon->getPosition());
    root->addChild(imgHead, tmpImgIcon->getLocalZOrder());
    tmpImgIcon->removeFromParent();
    
    auto text_title= dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_title"));
    auto nickName = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_nick_name"));
    auto account = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_account"));
    auto spriteSex = dynamic_cast<Sprite*>(CSLoader::seekNodeByName(root, "sprite_sex"));
    auto textNickname = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_nike_name"));
    auto textAccount = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_account"));
    auto textSex = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_friend_session"));
    auto titleDiamond = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_diamond"));
    auto imgTextfieldBg = dynamic_cast<ImageView*>(CSLoader::seekNodeByName(root, "img_diamond_bg"));
    auto textfieldDiamond = dynamic_cast<TextField*>(CSLoader::seekNodeByName(root, "textfield_diamond"));
    mBtnConfirm = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_diamond"));
    
    text_title->setString(tools::local_string("personal_info","个人资料"));
    nickName->setString(tools::local_string("nickname","昵称"));
    account->setString(tools::local_string("account","账号"));
    mBtnConfirm->setTitleText(tools::local_string("confirm_change_password","确定"));
    titleDiamond->setString(tools::local_string("give_diamond","赠送钻石"));
    mCheckboxHiteMoments = dynamic_cast<CheckBox*>(CSLoader::seekNodeByName(root, "checkbox_friend_session"));
    mBtnSendMsg = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_send_message"));
    mBtnDeleteFriend = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_delete_friend"));
    
    btnBack->addClickEventListener([&](Ref *ref)
    {
        if(IsInvitation)
        {
            auto layer = dynamic_cast<LayerInvitationList*>(this->getParent());
            if(layer)
            {
                layer->refresh_deal_data();
            }
        }
        this->removeFromParent();
    });
    imgHead->setSpriteTexture(mInfo.picname());
    spriteSex->setTexture(mInfo.sex() == msg::Sex::MALE ? gMaleIcon : gFemaleIcon);
    textSex->setString(mInfo.sex() == msg::Sex::MALE ? tools::local_string("block_his_moment", "屏蔽他的朋友圈") : tools::local_string("block_her_moment", "屏蔽她的朋友圈"));
    textNickname->setString(mInfo.nickname());
    spriteSex->setPositionX(textNickname->getPositionX() - textNickname->getContentSize().width - 30);
    textAccount->setString(tools::to_string(mInfo.userid()));
    mCheckboxHiteMoments->setSelected(false);
    setCheckBoxTextures(mCheckboxHiteMoments);
    mCheckboxHiteMoments->addClickEventListener([&](Ref *ref)
    {
        auto checkbox = dynamic_cast<CheckBox*>(ref);
        bool isSelect = checkbox->isSelected();
        
        
        
        int userId = mInfo.userid();
        log("屏蔽userId = %d", userId);
        auto processor = PM->BlockUser_up(userId, isSelect);
        send_data(processor, REQ_SHIELD_FRIEND);
    });
    mEditboxtDiamond = GameTools::createEditBoxFromTextField(imgTextfieldBg, textfieldDiamond);
    mEditboxtDiamond->setInputMode(EditBox::InputMode::NUMERIC);
    mEditboxtDiamond->setReturnType(EditBox::KeyboardReturnType::DONE);
    mEditboxtDiamond->setMaxLength(10);
    mEditboxtDiamond->setFontColor(Color3B::WHITE);
    mEditboxtDiamond->setPlaceHolder("0");
    mEditboxtDiamond->setDelegate(this);
    
    mBtnConfirm->addClickEventListener([&](Ref *ref){
        
        log("send Diamond: %s, len = %d", mEditboxtDiamond->getText(), strlen(mEditboxtDiamond->getText()));
        if(strlen(mEditboxtDiamond->getText()) <= 0 || !GameTools::isRegexMath(mEditboxtDiamond->getText(), GameTools::INPUT_TYPE::NUMBER))
        {
            Toast::ToastShow(tools::local_string("input_whole","只支持数字"));
            return;
        }
        GameTools::editBoxLoseInputFocus();
        requestDiamond();
        
    });
    //处理搜索消息
    if(!IsInvitation)
        InitNormal();
    else
    {
        
        //处理请求消息
        mBtnSendMsg->setTitleText(tools::local_string("operate", "同意"));
        mBtnSendMsg->addClickEventListener([&](Ref *ref)
                                          {
                                              sendInvitationFriend(true);
                                          });
        mBtnDeleteFriend->setTitleText(tools::local_string("disagree_friend_request", "拒绝"));
        mBtnDeleteFriend->addClickEventListener([&](Ref *ref)
                                          {
                                              sendInvitationFriend(false);
                                          });
        
    }
    send_data(PM->null_up(), REQ_MOMENT_BLOCK_LIST);//每次都请求已屏蔽的朋友圈列表
    return true;
}
Esempio n. 18
0
void MoveText::AddTextData(TextData textData)
{
    
    float new_Axis = 0.0f;
    float old_Axis = 0.0f;
    
    auto textWidget = Text::create(textData.TextInfo, m_TTFFontName, textData.FontSize);
    
    switch (textData.Direction) {
        case Direction::Up :
            if (m_LastUpTextWidget != nullptr)
            {
                new_Axis = textData.PositionY;
                old_Axis = m_LastUpTextWidget->getPositionY();
                if (old_Axis < new_Axis + m_LastUpTextWidget->getContentSize().height)
                {
                    textData.PositionY =  old_Axis - m_LastUpTextWidget->getContentSize().height;
                    if(textData.PositionX < 100)  textData.PositionX = 120;
                }
            }
            m_LastUpTextWidget = textWidget;
            break;
        case Direction::Down :
            
            if (m_LastDownTextWidget != nullptr)
            {
                new_Axis = textData.PositionY;
                old_Axis = m_LastDownTextWidget->getPositionY();
                if (old_Axis > new_Axis - m_LastDownTextWidget->getContentSize().height)// * 0.8
                {
                    textData.PositionY =  old_Axis + m_LastDownTextWidget->getContentSize().height;// * 0.8;
                    if (textData.PositionX > Director::getInstance()->getVisibleSize().height)
                    {
                        textData.PositionX = Director::getInstance()->getVisibleSize().height - 120;
                    }
                }
            }
            m_LastDownTextWidget = textWidget;
            break;
    }
    
    
//    textWidget->setScale(0.1F);
    textWidget->setColor(textData.Color);
    textWidget->setTextAreaSize(Size(450,40));
    textWidget->setTextHorizontalAlignment(TextHAlignment::CENTER);
    
    textData.TextWidget = textWidget;
    textData.ParenNode->addChild(textWidget);
    
    textWidget->setPositionX(textData.PositionX);
    textWidget->setPositionY(textData.PositionY);
    
    Vec2 movePos;
    switch (textData.Direction)
    {
        case Direction::Up :
            if (textData.isBattleText) {
                movePos = Vec2(textWidget->getPositionX(), textWidget->getPositionY() + 70);
            }
            else {
                movePos = Vec2(textWidget->getPositionX(), textWidget->getPositionY() + 200);
            }
            break;
        case Direction::Down :
            if (textData.isBattleText) {
                movePos = Vec2(textWidget->getPositionX(), textWidget->getPositionY() - 70);
            }
            else {
                movePos = Vec2(textWidget->getPositionX(), textWidget->getPositionY() - 200);
            }
            break;
    }
    //同时执行移动和渐出
//    auto spawn = Spawn::create(moveTo, fadeOut, nullptr);
//    顺序执行多个动作
//    auto seq= Sequence::create(scaleBig,scaleLitt,spawn,
    
    // best modify
    //渐出
    auto fadeOut = FadeOut::create(0.8f);
    //放大
    auto scaleBig = ScaleTo::create(0.2F, 2.5F);
    //缩小
    auto scaleLitt = ScaleTo::create(0.2F, 1.50F);
    //移动
    auto moveTo = MoveTo::create(1.5F, movePos);
    //结束回调
    auto callFunc = CallFunc::create([this, textData, textWidget]()
                                     {
                                         if (textWidget->getParent())
                                         {
                                             textWidget->stopAllActions();
                                             textWidget->removeFromParent();
                                         }
                                         
                                         switch (textData.Direction)
                                         {
                                             case Direction::Up:
                                                 if(m_LastUpTextWidget == textData.TextWidget)
                                                 {
                                                     m_LastUpTextWidget = nullptr;
                                                 }
                                                 break;
                                             case Direction::Down:
                                                 if(m_LastDownTextWidget == textData.TextWidget)
                                                 {
                                                     m_LastDownTextWidget = nullptr;
                                                 }
                                                 
                                                 break;
                                         }
                                         
                                     });
    
    if (textData.isBattleText) {
        // 战斗文字
        textWidget->setScale(1.3F);
        moveTo = MoveTo::create(0.4F, movePos);
        
        auto seq= Sequence::create(moveTo, callFunc, nullptr);
        auto seq2 = Sequence::create(DelayTime::create(1), fadeOut, nullptr);
        
        textWidget->runAction(seq);
        textWidget->runAction(seq2);
    }
    else {
        // 非战斗
        textWidget->setScale(0.1F);
        auto seq= Sequence::create(scaleBig, scaleLitt, moveTo, callFunc, nullptr);
        textWidget->runAction(seq);
    }
    
 }
Esempio n. 19
0
bool MenuManager::init()
{
    SpriteFrameCache::getInstance()->
    addSpriteFramesWithFile("UI/Menu.plist");

    Menuset = Layer::create();
    Menuset->retain();
    Menuset->setAnchorPoint(Point(0, 0));

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

    // Init Switch
    auto switchClose = cocos2d::ui::Button::create("close.png", "", "", cocos2d::ui::Widget::TextureResType::PLIST);
    switchClose->setAnchorPoint(Point(0.5f, 0.5f));
    switchClose->setName("SWITCH_CLOSE");
    switchClose->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    Menuset->addChild(switchClose, 1);
    switchClose->setPositionX(visibleSize.width - (switchClose->getSize().width / 2.0f));
    switchClose->setPositionY(switchClose->getSize().height / 2.0f);

    auto switchOpen = cocos2d::ui::Button::create("open1.png", "", "", cocos2d::ui::Widget::TextureResType::PLIST);
    switchOpen->setAnchorPoint(Point(0.5f, 0.5f));
    switchOpen->setName("SWITCH_OPEN");
    switchOpen->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    Menuset->addChild(switchOpen, 1);
    switchOpen->setPositionX(visibleSize.width - (switchOpen->getSize().width / 2.0f));
    switchOpen->setPositionY(switchOpen->getSize().height / 2.0f);
    switchOpen->setVisible(false);
    switchOpen->setEnabled(false);

    // Init ButtonBar
    auto buttonbar = Sprite::createWithSpriteFrameName("open3.png");
    buttonbar->setAnchorPoint(Point(1.0f, 0.0f));
    Menuset->addChild(buttonbar, 0, "BAR");
    buttonbar->setPosition(switchOpen->getPositionX(), (switchOpen->getSize().height / 2.0f) - (buttonbar->getContentSize().height / 2.0f));
    buttonbar->setScale(0.0f, 1.0f);

    // Init Button
    Size buttonBarSize = buttonbar->getContentSize();
    Vec2 buttonBarPosition = buttonbar->getPosition();

    auto buttonMission = cocos2d::ui::Button::create("1_mission.png", "", "", cocos2d::ui::Widget::TextureResType::PLIST);
    buttonMission->setAnchorPoint(Point(0, 0));
    buttonMission->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    buttonbar->addChild(buttonMission, 1, "MISSION_FUNCTION");
    buttonMission->setPosition(Vec2(buttonBarSize.width * 0.1f, buttonMission->getSize().height * 0.1f));

    auto buttonTown = cocos2d::ui::Button::create("2_town.png", "", "", cocos2d::ui::Widget::TextureResType::PLIST);
    buttonTown->setAnchorPoint(Point(0, 0));
    buttonTown->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    buttonbar->addChild(buttonTown, 1, "MAIN_FUNCTION");
    buttonTown->setPosition(Vec2(buttonBarSize.width * 0.25f, buttonMission->getSize().height * 0.06f));

    auto buttonTrainer = cocos2d::ui::Button::create("3_trainer.png", "", "", cocos2d::ui::Widget::TextureResType::PLIST);
    buttonTrainer->setAnchorPoint(Point(0, 0));
    buttonTrainer->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    buttonbar->addChild(buttonTrainer, 1, "TRAINER_FUNCTION");
    buttonTrainer->setPosition(Vec2(buttonBarSize.width * 0.4f, buttonMission->getSize().height * 0.08f));

    auto buttonMember = cocos2d::ui::Button::create("4_member.png", "", "", cocos2d::ui::Widget::TextureResType::PLIST);
    buttonMember->setAnchorPoint(Point(0, 0));
    buttonMember->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    buttonbar->addChild(buttonMember, 1, "MEMBER_FUNCTION");
    buttonMember->setPosition(Vec2(buttonBarSize.width * 0.56f, buttonMission->getSize().height * 0.05f));

    auto buttonSystem = cocos2d::ui::Button::create("5_system.png", "", "", cocos2d::ui::Widget::TextureResType::PLIST);
    buttonSystem->setAnchorPoint(Point(0, 0));
    buttonSystem->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    buttonbar->addChild(buttonSystem, 1, "SYSTEM_FUNCTION");
    buttonSystem->setPosition(Vec2(buttonBarSize.width * 0.71f, buttonMission->getSize().height * 0.06f));

    buttonbar->setVisible(false);
    buttonMission->setEnabled(false);
    buttonTown->setEnabled(false);
    buttonTrainer->setEnabled(false);
    buttonMember->setEnabled(false);
    buttonSystem->setEnabled(false);

    //button1->setEnabled(false);
    //button2->setEnabled(false);
    //button3->setEnabled(false);
    //button4->setEnabled(false);
    //button5->setEnabled(false);

    //auto graybar = Sprite::create("res/graybar.png");
    //graybar->setAnchorPoint(Point(0, 0));

    //auto mainitem = cocos2d::ui::Button::create("res/MainMenuButton.png");
    //mainitem->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    //mainitem->setAnchorPoint(Point(0, 0));

    //auto missionitem = ui::Button::create("res/MissionMenuButton.png");
    //missionitem->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    //missionitem->setAnchorPoint(Point(0, 0));

    //auto structitem = ui::Button::create("res/StructMenuButton.png");
    //structitem->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    //structitem->setAnchorPoint(Point(0, 0));
    //structitem->setName("STRUCT_FUNCTION");

    //auto memberitem = ui::Button::create("res/MemberMenuButton.png");
    //memberitem->addTouchEventListener(CC_CALLBACK_2(MenuManager::buttonCallback, this));
    //memberitem->setAnchorPoint(Point(0, 0));

    //Menuset->addChild(graybar, 0);
    //Menuset->addChild(mainitem, 1, "MAIN_FUNCTION");
    //Menuset->addChild(missionitem, 1, "MISSION_FUNCTION");
    //Menuset->addChild(structitem, 1, "STRUCT_FUNCTION");
    //Menuset->addChild(memberitem, 1, "MEMBER_FUNCTION");

    //mainitem->setPosition(Point(5,6));
    //missionitem->setPosition(Point(100,6));
    //structitem->setPosition(Point(195,6));
    //memberitem->setPosition(Point(290,6));

    return true;
}
void UINumberPicker::moveAllCell(const Point &deltaDis)
{
    //为提升组件的体验,该方法的执行效率必须尽可能的高效,尽可能减少循环次数
    for (size_t i = 0; i < sortChildrenArray.size(); i++)
    {
        auto cell = sortChildrenArray[i];
        switch (_pickerDirection)
        {
            case PickerDirection::VERTICAL:
            {
//                float oldY = cell->getPositionY();
                cell->moveByDy(deltaDis.y);
                if (cell->getPositionY() < -item_height)
                {
//                    float dItemY = fabsf( cell->getPositionY() - item_height );//(dy < 0)
                    cell->setPositionY( (virtualItemCount + 2) * item_height + cell->getPositionY());
                }
                if (cell->getPositionY() > (virtualItemCount + 1) * item_height)
                {
                    float dItemY = cell->getPositionY() - (virtualItemCount + 1) * item_height;//(dy < 0)
                    cell->setPositionY(-item_height + dItemY);
                }
                break;
            }
            case PickerDirection::HORIZONTAL:
            {
//                float oldX = cell->getPositionX();
                cell->moveByDx(deltaDis.x);
                if (cell->getPositionX() < -item_width)
                {
                    cell->setPositionX( (virtualItemCount + 2) * item_width + cell->getPositionX());
                }
                if (cell->getPositionX() > (virtualItemCount + 1) * item_width)
                {
                    float dItemX = cell->getPositionX() - (virtualItemCount + 1) * item_width;//(dy < 0)
                    cell->setPositionX(-item_width + dItemX);
                }
                break;
            }
            default:
                break;
        }
    }
    
    switch (_pickerDirection)
    {
        case PickerDirection::VERTICAL:
        {
            //对sortChildrenArray按坐标排序,由上到下
            std::sort(sortChildrenArray.begin(), sortChildrenArray.end(),
                      [](const Node * a,const Node * b)->bool
                      {
                          if (a->getPositionY() < b->getPositionY())
                          {
                              return false;
                          }
                          return true;
                      }
            );
            break;
        }
        case PickerDirection::HORIZONTAL:
        {
            //对sortChildrenArray按坐标排序,由左到右
            std::sort(sortChildrenArray.begin(), sortChildrenArray.end(),
                      [](const Node *a,const Node *b)->bool
                      {
                          if (a->getPositionX() > b->getPositionX())
                          {
                              return false;
                          }
                          return true;
                      });
            break;
        }
        default:
            break;
    }
    //给cell赋值
    //ps: 位于middleCellIndex索引处的cell不会重新赋值
    for (int i = 1; i <= m_middleCellIndex; i++)
    {
        if (sortChildrenArray[m_middleCellIndex + i - 1]->getCellValue() == m_maxValue)
        {
            sortChildrenArray[m_middleCellIndex + i]->setCellValue(m_minValue);
        }
        else
        {
            sortChildrenArray[m_middleCellIndex + i]->setCellValue(sortChildrenArray[m_middleCellIndex + i - 1]->getCellValue() + 1);
        }
        if (sortChildrenArray[m_middleCellIndex - i + 1]->getCellValue() == m_minValue)
        {
            sortChildrenArray[m_middleCellIndex - i]->setCellValue(m_maxValue);
        }
        else
        {
            sortChildrenArray[m_middleCellIndex - i]->setCellValue( sortChildrenArray[m_middleCellIndex - i + 1]->getCellValue() - 1);
        }
    }
}
Esempio n. 21
0
bool DealApplyFamily::init()
{
	if (!GameDialog::init())
	{
		return false;
	}

	m_pTipLayerWithBt2 = GameTipLayer::create<GameTipLytBt2Cfg>();



	auto bgSprite = cocos2d::Sprite::create("userinfo/bgdialog0.png");
	auto sz = bgSprite->getContentSize();
	bgSprite->setPosition(sz.width / 2, sz.height / 2);
	setContentSize(sz);
	addChild(bgSprite);


	

	m_btMenuItemClose = MenuItemSpriteWithLabel::create("dialog/btclose.png", 3, CC_CALLBACK_1(GameDialog::onMenuItemCloseSelected, this));
	m_btMenuItemClose->setPosition(sz.width - 25, sz.height - 28);
	auto menu = Menu::create(m_btMenuItemClose, nullptr);
	menu->setPosition(Vec2::ZERO);
	addChild(menu, 100);
	
	m_pLabelContent = cocos2d::Label::createWithTTF("申请加入俱乐部", "fzlt.ttf", 30);

	SetLabelString(m_pLabelContent,"申请加入俱乐部?");
	m_pLabelContent->setTextColor(Color4B::WHITE);
	m_pLabelContent->setMaxLineWidth(510);
	m_pLabelContent->setAnchorPoint(Point(0,0.5)) ;
	m_pLabelContent->setPosition(Point(339-25, 255));
	bgSprite->addChild(m_pLabelContent,1);

	auto pMenu = cocos2d::Menu::create(nullptr);
	pMenu->setPosition(cocos2d::Vec2::ZERO);
	unsigned uBtCount = 2;

	static cocos2d::Vec2 s_ptBt[] = {
		cocos2d::Vec2(220, 57),
		cocos2d::Vec2(460, 57)
	};
	std::string strBt[2] = {"同意","拒绝"} ;
	for (unsigned u = 0; u < uBtCount; ++u)
	{
		//auto menuItem = MenuItemFrameSprite::create("userinfo/btred.png", 3, CC_CALLBACK_1(DealApplyFamily::onMenuItemSelect, this,u));
        auto menuItem = MenuItemScale9Sprite::create(0, Size(203, 70), CC_CALLBACK_1(DealApplyFamily::onMenuItemSelect, this,u));
		auto szBt = menuItem->getContentSize();
		auto label = cocos2d::Label::createWithTTF(strBt[u], "fzltbd.ttf", 30);
		label->setTextColor(Color4B::WHITE);
		label->setPosition(szBt.width / 2, szBt.height / 2);
		menuItem->addChild(label);
		menuItem->setPosition(s_ptBt[u]);
		pMenu->addChild(menuItem);


		SetLabelString(label,strBt[u].c_str());
	}
	bgSprite->addChild(pMenu);
	//m_pTouchGrabber = nullptr;

	
	auto pMenuItem0 = MenuItemSpriteWithLabel::create("quickshop/btautobuyjettonunsel.png", 2, nullptr);
	auto pMenuItem1 = MenuItemSpriteWithLabel::create("quickshop/btautobuyjettonsel.png", 2, nullptr);
	auto pLabel0 = CreateLabelMSYH(24);
	auto pLabel1 = CreateLabelMSYH(24);
	pMenuItem0->SetEnabledColor(Color4B::WHITE);
	pMenuItem1->SetEnabledColor(Color4B::WHITE);
	SetLabelString(pLabel0, "拒绝再次申请");
	SetLabelString(pLabel1, "拒绝再次申请");
	pMenuItem0->SetLabel(pLabel0);
	pMenuItem1->SetLabel(pLabel1);
	pLabel0->setPositionX(120);
	pLabel1->setPositionX(120);
	m_pMenuItemAutoBuyJetton2Max = MenuItemToggle::create(pMenuItem0);
	m_pMenuItemAutoBuyJetton2Max->addSubItem(pMenuItem1);
	m_pMenuItemAutoBuyJetton2Max->setPosition(450, 149);

	pMenu->addChild(m_pMenuItemAutoBuyJetton2Max);

	m_pMenuItemAutoBuyJetton2Max->setSelectedIndex(0);

	httpIcon = CreateUserHeadSprite("defaulticon.png", "family/iconclipmask.png", bgSprite, Vec2(75,217), "family/gf_family_icon.png");
	lableName = CreateLabelMSYHAndAnchorPosClrAddTo(30,"",Vec2(0,0.5),210-25,255,Color4B(0xff,0xffd2,0x00,0xff),bgSprite,0);


	return true ;
}
void NewGameScene_japan::update(float t) {
	
	Size visibleSize = Director::getInstance()->getWinSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	auto plane = (Player *) this->getChildByTag(0);

	Rect pp(plane->getPositionX(), plane->getPositionY(), plane->playerWidth, plane->playerWidth);
	auto p_x = this->getPositionX();
	auto p_y = this->getPositionY();


    //enemy roof
	for (int i = 0; i < allEnemyRoof.size(); i++) {
		auto enemy = allEnemyRoof.at(i);
		Rect er(enemy->getPositionX(), enemy->getPositionY(), 115, 103);
		auto shake1 = MoveTo::create(0.01, Point(p_x, p_y - 15.0f));
		auto shake2 = MoveTo::create(0.01, Point(p_x, p_y + 15.0f));

		auto shake3 = MoveTo::create(0.01, Point(p_x, p_y));

		if (pp.intersectsRect(er) && HP > 1) {
				HP--;
				enemy->removeFromParent();
				allEnemyRoof.eraseObject(enemy);
                i--;
				this->runAction(Sequence::create(shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, NULL));


				auto label = Label::createWithTTF("HP -1", "fonts/Marker Felt.ttf", 24);
				label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
				auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
				auto action_3 = RepeatForever::create(Move_Down_3);
				label->setColor(Color3B::RED);
				label->runAction(action_3);
				this->addChild(label, 8);
				
		}
		else if (pp.intersectsRect(er) && HP == 1){

			enemy->removeFromParent();
			allEnemyRoof.eraseObject(enemy);
            i--;
			this->runAction(Sequence::create(shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, NULL));

            auto label = Label::createWithTTF("HP -1", "fonts/Marker Felt.ttf", 24);
            label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
            auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
            auto action_3 = RepeatForever::create(Move_Down_3);
            label->setColor(Color3B::RED);
            label->runAction(action_3);
            this->addChild(label, 8);
            
			this->pause();
			Director::getInstance()->replaceScene(TransitionMoveInB::create(2, GameOver::createScene()));


		}
	}
    
    //enemy fallen
    for (int i = 0; i < allEnemyFallen.size(); i++) {
        auto enemy = allEnemyFallen.at(i);
        Rect er(enemy->getPositionX(), enemy->getPositionY(), 40, 50);
        auto shake1 = MoveTo::create(0.01, Point(p_x, p_y - 50.0f));
        auto shake2 = MoveTo::create(0.01, Point(p_x, p_y + 50.0f));
        
        auto shake3 = MoveTo::create(0.01, Point(p_x, p_y));
        
       if (pp.intersectsRect(er)) {
                //HP--;
                enemy->removeFromParent();
                allEnemyFallen.eraseObject(enemy);
                i--;
                this->runAction(Sequence::create(shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, NULL));
                enemy_killed ++;
            if (enemy_killed == 1) {
                auto label = Label::createWithTTF("First Blood! \n +1000!", "fonts/Marker Felt.ttf", 60);
                label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
                auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
                auto action_3 = RepeatForever::create(Move_Down_3);
                label->setColor(Color3B::BLACK);
                label->runAction(action_3);
                this->addChild(label, 8);
                score += 1000;
            }else if(enemy_killed == 2){
                auto label = Label::createWithTTF("Double Kill! \n +2000", "fonts/Marker Felt.ttf", 60);
                label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
                auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
                auto action_3 = RepeatForever::create(Move_Down_3);
                label->setColor(Color3B::BLACK);
                label->runAction(action_3);
                this->addChild(label, 8);
                score += 2000;
            }else{
                auto label = Label::createWithTTF("Ninja Kill! \n +3000", "fonts/Marker Felt.ttf", 60);
                label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
                auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
                auto action_3 = RepeatForever::create(Move_Down_3);
                label->setColor(Color3B::BLACK);
                label->runAction(action_3);
                this->addChild(label, 8);
                score == 3000;
            }
       }

        
       // }
//       else if (pp.intersectsRect(er) && HP == 1){
//            
//            enemy->removeFromParent();
//            allEnemyFallen.eraseObject(enemy);
//            i--;
//            this->runAction(Sequence::create(shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, NULL));
//            
//            auto label = Label::createWithTTF("HP -1", "fonts/Marker Felt.ttf", 24);
//            label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
//            auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
//            auto action_3 = RepeatForever::create(Move_Down_3);
//            label->setColor(Color3B::RED);
//            label->runAction(action_3);
//            this->addChild(label, 8);
//
//            this->pause();
//            Director::getInstance()->replaceScene(TransitionMoveInB::create(2, GameOver::createScene()));
//        }
    }
    
    //enemy left crow
    for (int i = 0; i < allEnemyLeftCrow.size(); i++) {
        auto enemy = allEnemyLeftCrow.at(i);
        Rect er(enemy->getPositionX(), enemy->getPositionY(), 75, 63);
        auto shake1 = MoveTo::create(0.01, Point(p_x, p_y - 50.0f));
        auto shake2 = MoveTo::create(0.01, Point(p_x, p_y + 50.0f));
        
        auto shake3 = MoveTo::create(0.01, Point(p_x, p_y));
        
        if (pp.intersectsRect(er) && HP > 1) {
            
            
            HP--;
            enemy->removeFromParent();
            allEnemyLeftCrow.eraseObject(enemy);
            i--;
            this->runAction(Sequence::create(shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, NULL));
            
            auto label = Label::createWithTTF("HP -1", "fonts/Marker Felt.ttf", 24);
            label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
            auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
            auto action_3 = RepeatForever::create(Move_Down_3);
            label->setColor(Color3B::RED);
            label->runAction(action_3);
            this->addChild(label, 8);
            
        }
        else if (pp.intersectsRect(er) && HP == 1){
            
            enemy->removeFromParent();
            allEnemyLeftCrow.eraseObject(enemy);
            i--;
            this->runAction(Sequence::create(shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, NULL));
            
            auto label = Label::createWithTTF("HP -1", "fonts/Marker Felt.ttf", 24);
            label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
            auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
            auto action_3 = RepeatForever::create(Move_Down_3);
            label->setColor(Color3B::RED);
            label->runAction(action_3);
            this->addChild(label, 8);
            
            this->pause();
            Director::getInstance()->replaceScene(TransitionMoveInB::create(2, GameOver::createScene()));
        }
    }
    
    //enemy right crow
    for (int i = 0; i < allEnemyRightCrow.size(); i++) {
        auto enemy = allEnemyRightCrow.at(i);
        Rect er(enemy->getPositionX(), enemy->getPositionY(), 75, 63);
        auto shake1 = MoveTo::create(0.01, Point(p_x, p_y - 50.0f));
        auto shake2 = MoveTo::create(0.01, Point(p_x, p_y + 50.0f));
        
        auto shake3 = MoveTo::create(0.01, Point(p_x, p_y));
        
        if (pp.intersectsRect(er) && HP > 1) {
            
            
            HP--;
            enemy->removeFromParent();
            allEnemyRightCrow.eraseObject(enemy);
            i--;
            this->runAction(Sequence::create(shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, NULL));
            
            auto label = Label::createWithTTF("HP -1", "fonts/Marker Felt.ttf", 24);
            label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
            auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
            auto action_3 = RepeatForever::create(Move_Down_3);
            label->setColor(Color3B::RED);
            label->runAction(action_3);
            this->addChild(label, 8);
            
        }
        else if (pp.intersectsRect(er) && HP == 1){
            
            enemy->removeFromParent();
            allEnemyRightCrow.eraseObject(enemy);
            i--;
            this->runAction(Sequence::create(shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, shake1, shake2, shake3, NULL));
            
            auto label = Label::createWithTTF("HP -1", "fonts/Marker Felt.ttf", 24);
            label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
            auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
            auto action_3 = RepeatForever::create(Move_Down_3);
            label->setColor(Color3B::RED);
            label->runAction(action_3);
            this->addChild(label, 8);
            
            this->pause();
            Director::getInstance()->replaceScene(TransitionMoveInB::create(2, GameOver::createScene()));
        }
    }
    
    auto labelHp = (Label *) this->getChildByTag(110);
    labelHp->setString(StringUtils::format("Hp: %d", HP));

	//score height

	auto labelHeight = (Label *) this->getChildByTag(111);
	if (score < 10000000)score++;
	labelHeight->setString(StringUtils::format("%d", score));
    
    //star
    for (int i = 0; i < allStar.size(); i++) {
        auto star = allStar.at(i);
        Rect er(star->getPositionX(), star->getPositionY(), 40, 50);
        
        if (pp.intersectsRect(er)) {
            //MenuItemImage *specialSkill= (MenuItemImage*)this->getChildByTag(112);
            
            //this->addChild(specialSkill);
            //skill button
//            
//            auto abilityButtonItem = MenuItemImage::create(
//                                                           "bang.png",
//                                                           "bang.png",
//                                                           CC_CALLBACK_1(NewGameScene_japan::playerAbility_Teleportation, this)
//                                                           );
//            
//            abilityButtonItem->setScale(bg_scale);
//            
//            abilityButtonItem->setPosition(bg_origin + abilityButtonItem->getBoundingBox().size/2);
//            this->addChild(abilityButtonItem);
            //abilityButtonTouched = true;
            HP ++;
            star->removeFromParent();
            allStar.eraseObject(star);
            i--;
            auto label = Label::createWithTTF("HP +1", "fonts/Marker Felt.ttf", 24);
            label->setPosition(Point(origin.x + visibleSize.width / 2, 0));
            auto Move_Down_3 = MoveBy::create(1, Vec2(0, visibleSize.height / 2));
            auto action_3 = RepeatForever::create(Move_Down_3);
            label->setColor(Color3B::RED);
            label->runAction(action_3);
            this->addChild(label, 8);
        }
    }
    
    labelHp->setString(StringUtils::format("Hp: %d", HP));
    
	{
		
		auto my_player = (Player *) this->getChildByTag(0);
		
		float a = -0.1*bg_size.height / (0.25 * (bg_size.width - my_player->playerWidth - 2 * borderWidth) * (bg_size.width - my_player->playerWidth - 2 * borderWidth));

		if (my_player->isInAir&&!my_player->isMovingLeft)
		{


			my_player->setPositionX(my_player->getPositionX() + 20);
			float y = a * (my_player->getPositionX() - bg_origin.x - borderWidth - 0.5 * my_player->playerWidth)*(my_player->getPositionX() - bg_origin.x + borderWidth - bg_size.width + 0.5 * my_player->playerWidth);
			my_player->setPositionY(y + bg_size.height*0.16);

			if (my_player->getPositionX() >= bg_origin.x + bg_size.width - borderWidth - my_player->playerWidth / 2)
			{
				my_player->isInAir = false;
				my_player->setPosition(bg_origin.x + bg_size.width - borderWidth - my_player->playerWidth / 2, bg_origin.y + bg_size.height*0.16);

			}
			/*
			else if (this->getPositionX() >= origin.x + bgSize.x / 2 && isLeft)
			{
			this->setScaleX((this->getScaleX()) * -1.f);
			isLeft = false;
			}
			*/

		}
		else if (my_player->isInAir&&my_player->isMovingLeft)
		{

			my_player->setPosition(my_player->getPositionX() - 20, bg_origin.y + bg_size.height*0.16);
			float y = a * (my_player->getPositionX() - bg_origin.x - borderWidth - 0.5 * my_player->playerWidth)*(my_player->getPositionX() - bg_origin.x + borderWidth - bg_size.width + 0.5 * my_player->playerWidth);
			my_player->setPositionY(y + bg_size.height*0.16);

			if (my_player->getPositionX() <= bg_origin.x + borderWidth + my_player->playerWidth / 2)
			{
				my_player->isInAir = false;
				my_player->setPosition(bg_origin.x + borderWidth + my_player->playerWidth / 2, bg_origin.y + bg_size.height*0.16);
				

			}
			/*
			else if (this->getPositionX() <= origin.x + bgSize.x / 2 && !isLeft)
			{
			this->setScaleX((this->getScaleX()) * -1.f);
			isLeft = true;
			}
			*/
		}


	}   
}
Esempio n. 23
0
void ItemTortoiseFly::updateStatus()
{
	if (_status == NORMAL)
	{
		stopAllActions();
		if (_dir == Common::LEFT)
		{
			runAnimation("TortoiseFlyLeft");
		}
		else
		{
			runAnimation("TortoiseFlyRight");

		}
	}
	else if (_status == DROPPING)
	{
		stopAllActions();

		// 设置它下降的速度
		_speedDown = _mario->_speedDown + 10;
		_mario->_speedDown = 10;

		if (_dir == Common::LEFT)
		{
			runAnimation("TortoiseMoveLeft");
		}
		else
		{
			runAnimation("TortoiseMoveRight");
		}
	}
	else if (_status == ONLAND)
	{
		// .....
	}
	else if (_status == SLEEP)
	{
		stopAllActions();
		runAnimation("TortoiseDead");

		scheduleOnce(schedule_selector(ItemTortoiseFly::Recover), 10);
		setGodMode(0.2f);
		// 微调位置
		if (_mario->getPositionX() < getPositionX())
		{
			setPositionX(_mario->getPositionX() + _mario->boundingBox().size.width + 1);
		}
		else
		{
			setPositionX(_mario->getPositionX() - boundingBox().size.width - 1);
		}

	}
	else if (_status == CRAZY)
	{
		unschedule(schedule_selector(ItemTortoiseFly::Recover));
		_speed = 200;
		_speedDown = _speedAcc = 10;
	}
}
Esempio n. 24
0
void MyMap::mapupdate(float x){
	auto h = (Hero*)mlayer->getChildByTag(TAG_HERO_CLASS);
	if(h->status != HERO_STATUS_FALLEN)
	{
		if(1)
		{
			Vector<Sprite*>::iterator it;
			for(int i = 0;i<curMaplist.size();i++){
				auto tmp = (Sprite*)curMaplist.at(i);
				float posx = 0;
				switch (layerMark)
				{
				case MID_SCENE:
					{
						posx = 0; 
						break;
					}
				case FAR_SCENE:
					{
						posx = 0.2;
						break;
					}
				case FARFAR_SCENE:
					{
						posx = 0.5;
						break;
					}
				default:
				break;
				}
			tmp->setPositionX(tmp->getPositionX()+posx);
			}
		}
		else
		{
			mapWidth++;
		}
	}
	auto lm = (Sprite*)curMaplist.at(curMaplist.size()-1);
	if(x+lm->getContentSize().width > lm->getPositionX()+Director::getInstance()->getVisibleSize().width)
	{
		auto newMap = Sprite::create(BG_PIC[layerMark-1]);
		if(mapCount == 1){
			newMap->setFlippedX(true);
		}
		mapCount = mapCount*(-1);
		newMap->setAnchorPoint(Vec2(0,0));

		if(layerMark != FARFAR_SCENE){
			newMap->setPosition(Vec2(lm->getPositionX()+lm->getContentSize().width-2,0)); 
		}
		else
		{
			newMap->setPosition(Vec2(lm->getPositionX()+lm->getContentSize().width-2,(layerMark-2)*groundHeight));
		}

		mlayer->addChild(newMap,-layerMark,TAG_MAP);
		curMaplist.pushBack(newMap);
	}
	auto fm = (Sprite*)curMaplist.at(0);
	if(fm->getPositionX()+fm->getContentSize().width<x-200)
	{
		fm->removeFromParentAndCleanup(true);
		curMaplist.eraseObject(fm);
	}
}
Esempio n. 25
0
// on "init" you need to initialize your instance
bool OptionsScene::init()
{
	//////////////////////////////
	// 1. super init first
	if (!Layer::init())
	{
		return false;
	}

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

	// Creating Menu

	auto background = Sprite::create("images/OptionsScreen/fondo.jpg");

	background->setPosition(Point((visibleSize.width / 2),
		(visibleSize.height / 2)));

	addChild(background, 0);


	auto backItem = MenuItemImage::create("images/OptionsScreen/volver.jpg", "images/OptionsScreen/volver.jpg", CC_CALLBACK_1(OptionsScene::goToMainMenu, this));
	auto resetItem = MenuItemImage::create("images/OptionsScreen/reset.jpg", "images/OptionsScreen/reset.jpg", CC_CALLBACK_1(OptionsScene::reset, this));


	auto back = Menu::create(backItem, NULL);
	auto reset = Menu::create(resetItem, NULL);

	back->setPositionX(1147); back->setPositionY(654);
	reset->setPosition(Vec2(197, 85));


	addChild(back, 1);
	addChild(reset, 10);

	this->easy = Sprite::create("images/OptionsScreen/facil.jpg");
	this->easy->setPosition(197, 418);
	this->addChild(easy, 10);

	this->medium = Sprite::create("images/OptionsScreen/media.jpg");
	this->medium->setPosition(411, 418);
	this->addChild(medium, 10);

	this->hard = Sprite::create("images/OptionsScreen/dificil.jpg");
	this->hard->setPosition(625, 418);
	this->addChild(hard, 10);

	this->music = Sprite::create("images/OptionsScreen/on.jpg");
	this->music->setPosition(304, 260);
	this->addChild(music, 10);

	switch (Global::_max_time)
	{
	case 30:
		hard->setOpacity(125);
		medium->setOpacity(125);
		easy->setOpacity(255);
		break;
	case 15:
		hard->setOpacity(125);
		medium->setOpacity(255);
		easy->setOpacity(125);
		break;
	case 10:
		hard->setOpacity(255);
		medium->setOpacity(125);
		easy->setOpacity(125);
		break;
	default:
		break;
	}

	auto event_listener = EventListenerTouchAllAtOnce::create();

	if (!Global::musicPlayed)
		this->music->setTexture("images/OptionsScreen/off.jpg");
	else
		this->music->setTexture("images/OptionsScreen/on.jpg");


	event_listener->onTouchesBegan = [=](const std::vector<Touch*>& pTouches, Event* event)
	{
		auto touch = *pTouches.begin();
		auto openGl_location = touch->getLocation();

		float distance;
		distance = this->easy->getPosition().getDistance(touch->getLocation());
		if (distance < 30) {
			setDifficult(0);
			return;
		}
		distance = this->medium->getPosition().getDistance(touch->getLocation());
		if (distance < 30) {
			setDifficult(1);
			return;
		}
		distance = this->hard->getPosition().getDistance(touch->getLocation());
		if (distance < 30) {
			setDifficult(2);
			return;
		}
		distance = this->music->getPosition().getDistance(touch->getLocation());
		if (distance < 40) {
			musicOnOff();
			return;
		}
	};

	this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(event_listener, easy);


	return true;
}
Esempio n. 26
0
bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto visibleSize = Director::getInstance()->getVisibleSize();
    auto origin = Director::getInstance()->getVisibleOrigin();



	camera = Camera::createPerspective(30, (float)visibleSize.width / visibleSize.height, 1.0, 1000);
	camera->setBackgroundBrush(CameraBackgroundBrush::createColorBrush(Color4F(0.0f, 1.0f, 1.0f, 0.5f), 1.0f));
	camera->setPosition3D(Vec3(0.0f, 50.0f, 100.0f));
	camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0, 1.0, 0.0));
	camera->setCameraFlag(CameraFlag::USER2);
	this->addChild(camera);

	/**
	//Create Plane
	Physics3DRigidBodyDes rbd_plan;
	rbd_plan.mass = 0.0f;
	rbd_plan.shape = Physics3DShape::createBox(Vec3(500, 5.0f, 500));
	auto physics_rbd_plan = Physics3DRigidBody::create(&rbd_plan);
	physics_rbd_plan->setFriction(20);
	auto component_plan = Physics3DComponent::create(physics_rbd_plan);
	_plan = Sprite3D::create("box.c3t");
	_plan->setTexture("plane.png");
	_plan->setScale(30.0f);
	_plan->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	_plan->setScaleX(500);
	_plan->setScaleY(5);
	_plan->setScaleZ(500);
	_plan->setPositionZ(0);
	_plan->setPositionY(0);
	_plan->setPositionX(0);
	_plan->setGlobalZOrder(-1);
	_plan->addComponent(component_plan);
	component_plan->syncNodeToPhysics();
	component_plan->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
	_plan->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(_plan, 1);
	**/
	Terrain::DetailMap r("dirt.jpg");
	Terrain::TerrainData data("heightmap16.jpg", "alphamap.png", r, r, r, r, Size(32, 32), 5.0f, 1.0f);
	auto _terrain = Terrain::create(data, Terrain::CrackFixedType::SKIRT);
	_terrain->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	_terrain->setPositionZ(0);
	_terrain->setPositionY(0);
	_terrain->setPositionX(0);
	_terrain->setLODDistance(64, 128, 192);
	_terrain->setDrawWire(false);
	_terrain->setMaxDetailMapAmount(4);
	_terrain->setSkirtHeightRatio(2);
	_terrain->setCameraMask((unsigned short)CameraFlag::USER2);
	//create terrain
	std::vector<float> heidata = _terrain->getHeightData();
	auto size = _terrain->getTerrainSize();
	Physics3DColliderDes colliderDes;
	colliderDes.shape = Physics3DShape::createHeightfield(size.width, size.height, &heidata[0], 1.0f, _terrain->getMinHeight(), _terrain->getMaxHeight(), true, false, true);
	auto collider = Physics3DCollider::create(&colliderDes);
	auto component = Physics3DComponent::create(collider);
	_terrain->addComponent(component);
	component->syncNodeToPhysics();
	component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
	this->addChild(_terrain);

	
	//////////////////////////////////////////////// car
	Physics3DRigidBodyDes rbd_cabine;
	rbd_cabine.disableSleep = true;
	rbd_cabine.mass = 500.0f;
	rbd_cabine.shape = Physics3DShape::createBox(Vec3(4, 2.0f, 8));
	physics_rbd_cabine = Physics3DRigidBody::create(&rbd_cabine);
	auto cabine_component = Physics3DComponent::create(physics_rbd_cabine);
	car_cabine = Sprite3D::create("T-90.c3t");
	car_cabine->setTexture("Main Body 2.png");
	car_cabine->setScale(3);
	//car_cabine->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	car_cabine->setPositionX(0);
	car_cabine->setPositionY(10);
	car_cabine->setPositionZ(0);
	car_cabine->setGlobalZOrder(-1);
	car_cabine->addComponent(cabine_component);
	cabine_component->syncNodeToPhysics();
	cabine_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	car_cabine->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(car_cabine, 1);


	Physics3DRigidBodyDes rbd_wheel1;
	rbd_wheel1.disableSleep = true;
	rbd_wheel1.mass = 15.0f;
	//rbd_wheel1.shape = Physics3DShape::createCylinder(3, 1);
	rbd_wheel1.shape = Physics3DShape::createSphere(1.5);
	auto physics_rbd_wheel1 = Physics3DRigidBody::create(&rbd_wheel1);
	auto wheel1_component = Physics3DComponent::create(physics_rbd_wheel1);
	wheel1 = Sprite3D::create();
	//wheel1->setTexture("Gun.png");
	//wheel1->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	wheel1->setPositionX(0);
	wheel1->setPositionY(10);
	wheel1->setPositionZ(0);
	wheel1->setGlobalZOrder(-1);
	wheel1->addComponent(wheel1_component);
	wheel1_component->syncNodeToPhysics();
	wheel1_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	wheel1->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(wheel1, 1);

	Physics3DRigidBodyDes rbd_wheel2;
	rbd_wheel2.disableSleep = true;
	rbd_wheel2.mass = 15.0f;
	//rbd_wheel2.shape = Physics3DShape::createCylinder(3, 1);
	rbd_wheel2.shape = Physics3DShape::createSphere(1.5);
	auto physics_rbd_wheel2 = Physics3DRigidBody::create(&rbd_wheel2);
	auto wheel2_component = Physics3DComponent::create(physics_rbd_wheel2);
	wheel2 = Sprite3D::create();
	//wheel2->setTexture("Gun.png");
	//wheel2->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	wheel2->setPositionX(0);
	wheel2->setPositionY(10);
	wheel2->setPositionZ(0);
	wheel2->setGlobalZOrder(-1);
	wheel2->addComponent(wheel2_component);
	wheel2_component->syncNodeToPhysics();
	wheel2_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	wheel2->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(wheel2, 1);

	Physics3DRigidBodyDes rbd_wheel3;
	rbd_wheel3.disableSleep = true;
	rbd_wheel3.mass = 15.0f;
	rbd_wheel3.shape = Physics3DShape::createSphere(1.5);
	//rbd_wheel3.shape = Physics3DShape::createCylinder(3, 1);
	physics_rbd_wheel3 = Physics3DRigidBody::create(&rbd_wheel3);
	auto wheel3_component = Physics3DComponent::create(physics_rbd_wheel3);
	wheel3 = Sprite3D::create();
	//wheel3->setTexture("Gun.png");
	//wheel3->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	wheel3->setPositionX(0);
	wheel3->setPositionY(10);
	wheel3->setPositionZ(0);
	wheel3->setGlobalZOrder(-1);
	wheel3->addComponent(wheel3_component);
	wheel3_component->syncNodeToPhysics();
	wheel3_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	wheel3->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(wheel3, 1);

	Physics3DRigidBodyDes rbd_wheel4;
	rbd_wheel4.disableSleep = true;
	rbd_wheel4.mass = 15.0f;
	//rbd_wheel4.shape = Physics3DShape::createCylinder(3, 1);
	rbd_wheel4.shape = Physics3DShape::createSphere(1.5);
	physics_rbd_wheel4 = Physics3DRigidBody::create(&rbd_wheel4);
	auto wheel4_component = Physics3DComponent::create(physics_rbd_wheel4);
	wheel4 = Sprite3D::create();
	//wheel3->setTexture("Gun.png");
	//wheel4->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	wheel4->setPositionX(0);
	wheel4->setPositionY(10);
	wheel4->setPositionZ(0);
	wheel4->setGlobalZOrder(-1);
	wheel4->addComponent(wheel4_component);
	wheel4_component->syncNodeToPhysics();
	wheel4_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	wheel4->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(wheel4, 1);

	Physics3DRigidBodyDes rbd_wheel_bar;
	rbd_wheel_bar.disableSleep = true;
	rbd_wheel_bar.mass = 400.0f;
	rbd_wheel_bar.shape = Physics3DShape::createBox(Vec3(2, 2.0f, 6));
	physics_rbd_wheel_bar = Physics3DRigidBody::create(&rbd_wheel_bar);
	auto car_wheel_bar_component = Physics3DComponent::create(physics_rbd_wheel_bar);
	car_wheel_bar = Sprite3D::create();
	//car_wheel_bar->setTexture("Gun.png");
	car_wheel_bar->setScale(0.01);
	car_wheel_bar->setPositionX(0);
	car_wheel_bar->setPositionY(10);
	car_wheel_bar->setPositionZ(0);
	//car_wheel_bar->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
	car_wheel_bar->setGlobalZOrder(-1);
	car_wheel_bar->addComponent(car_wheel_bar_component);
	car_wheel_bar_component->syncNodeToPhysics();
	car_wheel_bar_component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
	car_wheel_bar->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(car_wheel_bar, 1);

	auto constraint = Physics3DHingeConstraint::create(physics_rbd_cabine, physics_rbd_wheel1, Vec3(0.0f, 0.0, 6.0f), Vec3(0.f, -3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f));
	psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint);
	auto constraint2 = Physics3DHingeConstraint::create(physics_rbd_cabine, physics_rbd_wheel2, Vec3(0.0f, 0.0, 6.0f), Vec3(0.f, 3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f));
	psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint2);


	constraint5 = Physics3DHingeConstraint::create(physics_rbd_cabine, physics_rbd_wheel_bar, Vec3(0.0f, 0.0, -6.0f), Vec3(0.f, 0.0f, 0.f), Vec3(0.0f, 1.0, 0.0f), Vec3(0.f, 1.0f, 0.f));
	constraint5->setLimit(CC_DEGREES_TO_RADIANS(-0.5), CC_DEGREES_TO_RADIANS(0.5));
	psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint5);


	auto constraint3 = Physics3DHingeConstraint::create(physics_rbd_wheel_bar, physics_rbd_wheel3, Vec3(0.0f, 0.0, -3.0f), Vec3(0.f, -3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f));
	psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint3);
	auto constraint4 = Physics3DHingeConstraint::create(physics_rbd_wheel_bar, physics_rbd_wheel4, Vec3(0.0f, 0.0, -3.0f), Vec3(0.f, 3.0f, 0.f), Vec3(1.0f, 0.0, 0.0f), Vec3(0.f, 1.0f, 0.f));
	psychics_scene->getPhysics3DWorld()->addPhysics3DConstraint(constraint4);


	//add a point light
	auto light = PointLight::create(Vec3(0, 50, 0), Color3B(255, 255, 255), 150);
	addChild(light);
	//set the ambient light 
	auto ambient = AmbientLight::create(Color3B(55, 55, 55));
	addChild(ambient);


	/**
	Physics3DRigidBodyDes boxesrbDes;
	boxesrbDes.mass = 1.f;
	boxesrbDes.shape = Physics3DShape::createBox(Vec3(5, 5, 5));
	float start_x = 10- ARRAY_SIZE_X / 2;
	float start_y = 0 + 5.0f;
	float start_z = 10 - ARRAY_SIZE_Z / 2;

	for (int k = 0; k<ARRAY_SIZE_Y; k++)
	{
		for (int i = 0; i<ARRAY_SIZE_X; i++)
		{
			for (int j = 0; j<ARRAY_SIZE_Z; j++)
			{
				float x = 1.0*i + start_x;
				float y = 5.0 + 1.0*k + start_y;
				float z = 1.0*j + start_z;
				boxesrbDes.originalTransform.setIdentity();
				boxesrbDes.originalTransform.translate(x, y, z);

				auto sprite = PhysicsSprite3D::create("box.c3t", &boxesrbDes);
				sprite->setTexture("plane.png");
				sprite->setCameraMask((unsigned short)CameraFlag::USER1);
				sprite->setScale(1.0f / sprite->getContentSize().width);
				this->addChild(sprite);
				sprite->setPosition3D(Vec3(x, y, z));
				sprite->syncNodeToPhysics();

				sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
			}
		}
	}

	**/



	auto listener = EventListenerTouchAllAtOnce::create();
	listener->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this);
	listener->onTouchesMoved = CC_CALLBACK_2(HelloWorld::onTouchesMoved, this);
	listener->onTouchesEnded = CC_CALLBACK_2(HelloWorld::onTouchesEnded, this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);


	//psychics_scene->setPhysics3DDebugCamera(camera); 
	schedule(schedule_selector(HelloWorld::myupdate), .005);
	//this->scheduleUpdate();
	
    return true;
}
Esempio n. 27
0
 void        setPosition(float _x, float _y) { setPositionX(_x); setPositionY(_y); }
Esempio n. 28
0
void ModelDataModel::setPosition(const Vector3f position)
{
    setPositionX(position[0]);
    setPositionY(position[1]);
    setPositionZ(position[2]);
}
Esempio n. 29
0
//配置队伍UI
void MainUILayer::configureTeamUI()
{
	Size size = Director::getInstance()->getVisibleSize();

	//队伍UI
	team = Sprite::createWithSpriteFrameName("team.png");
	team->setPosition(size.width/2, size.height - 320);
	this->addChild(team);
	auto text_myTeam = Sprite::createWithSpriteFrameName("titlename_team.png");
	text_myTeam->setPosition(text_myTeam->getContentSize().width / 2 - 40, team->getContentSize().height - 33);
	team->addChild(text_myTeam);

	//领导力UI
	auto text_leadship = Sprite::createWithSpriteFrameName("leadship.png");
	text_leadship->setPosition(text_leadship->getContentSize().width / 2 + 5, 35);
	team->addChild(text_leadship);
	auto leadship = LabelTTF::create("145/300", "Arial", 32);
	leadship->setPosition(150, 35);
	leadship->setAnchorPoint(Vec2(0, 0.5));
	team->addChild(leadship);

	//团队实力UI
	auto text_teamlv = Sprite::createWithSpriteFrameName("teamlv.png");
	text_teamlv->setPosition(text_leadship->getContentSize().width/2 + 290, 35);
	team->addChild(text_teamlv);
	auto teamlv = LabelTTF::create("100", "Arial", 32);
	teamlv->setPosition(450, 35);
	teamlv->setAnchorPoint(Vec2(0, 0.5));
	team->addChild(teamlv);

	//队长标志
	auto sign_captain = Sprite::createWithSpriteFrameName("sign_captain.png");
	sign_captain->setPosition(35, 215);
	team->addChild(sign_captain);

	//队长
	auto captain = Sprite::create("ui/littlecard_0001.png");
	captain->setPosition(97, 160);
	auto captain_fram = Sprite::createWithSpriteFrameName("littlecard_frame_class4_elite.png");
	captain_fram->setPosition(captain->getContentSize().width / 2, captain->getContentSize().height / 2);
	captain->addChild(captain_fram);
	team->addChild(captain);

	//max_text
	text_max[0] = Sprite::createWithSpriteFrameName("arenamain_max.png");
	text_max[0]->setPosition(97, 91);
	team->addChild(text_max[0]);
	text_level[0] = Node::create();
	auto text_lv_00 = Sprite::createWithSpriteFrameName("lv.png");
	text_lv_00->setPositionX(-15);
	text_level[0]->addChild(text_lv_00);
	auto text_lv_value_00 = LabelTTF::create("99", "Arial", 25);
	text_lv_value_00->setPositionX(25);
	text_level[0]->addChild(text_lv_value_00);
	text_level[0]->setPosition(97, 91);
	team->addChild(text_level[0]);
	text_level[0]->setVisible(false);

	//位置1
	auto teammate1_role = Sprite::create("ui/littlecard_0331.png");
	teammate1_role->setPosition(232, 160);
	auto teammate1_frame = Sprite::createWithSpriteFrameName("littlecard_frame_class4_elite.png");
	teammate1_frame->setPosition(teammate1_role->getContentSize().width /2 , teammate1_role->getContentSize().height/2);
	teammate1_role->addChild(teammate1_frame);
	team->addChild(teammate1_role);
	text_max[1] = Sprite::createWithSpriteFrameName("arenamain_max.png");
	text_max[1]->setPosition(232, 91);
	team->addChild(text_max[1]);
	text_level[1] = Node::create();
	auto text_lv_01 = Sprite::createWithSpriteFrameName("lv.png");
	text_lv_01->setPositionX(-15);
	text_level[1]->addChild(text_lv_01);
	auto text_lv_value_01 = LabelTTF::create("99", "Arial", 25);
	text_lv_value_01->setPositionX(25);
	text_level[1]->addChild(text_lv_value_01);
	text_level[1]->setPosition(232, 91);
	team->addChild(text_level[1]);
	text_level[1]->setVisible(false);

	//位置2
	auto teammate2_role = Sprite::create("ui/littlecard_0333.png");
	teammate2_role->setPosition(339, 160);
	auto teammate2_frame = Sprite::createWithSpriteFrameName("littlecard_frame_class4_elite.png");
	teammate2_frame->setPosition(teammate2_role->getContentSize().width /2 , teammate2_role->getContentSize().height/2);
	teammate2_role->addChild(teammate2_frame);
	team->addChild(teammate2_role);
	text_max[2] = Sprite::createWithSpriteFrameName("arenamain_max.png");
	text_max[2]->setPosition(339, 91);
	team->addChild(text_max[2]);
	text_level[2] = Node::create();
	auto text_lv_02 = Sprite::createWithSpriteFrameName("lv.png");
	text_lv_02->setPositionX(-15);
	text_level[2]->addChild(text_lv_02);
	auto text_lv_value_02 = LabelTTF::create("99", "Arial", 25);
	text_lv_value_02->setPositionX(25);
	text_level[2]->addChild(text_lv_value_02);
	text_level[2]->setPosition(339, 91);
	team->addChild(text_level[2]);
	text_level[2]->setVisible(false);

	//位置3
	auto teammate3_role = Sprite::create("ui/littlecard_0355.png");
	teammate3_role->setPosition(446, 160);
	auto teammate3_frame = Sprite::createWithSpriteFrameName("littlecard_frame_class4_elite.png");
	teammate3_frame->setPosition(teammate3_role->getContentSize().width /2 , teammate3_role->getContentSize().height/2);
	teammate3_role->addChild(teammate3_frame);
	team->addChild(teammate3_role);
	text_max[3] = Sprite::createWithSpriteFrameName("arenamain_max.png");
	text_max[3]->setPosition(446, 91);
	team->addChild(text_max[3]);
	text_level[3] = Node::create();
	auto text_lv_03 = Sprite::createWithSpriteFrameName("lv.png");
	text_lv_03->setPositionX(-15);
	text_level[3]->addChild(text_lv_03);
	auto text_lv_value_03 = LabelTTF::create("99", "Arial", 25);
	text_lv_value_03->setPositionX(25);
	text_level[3]->addChild(text_lv_value_03);
	text_level[3]->setPosition(446, 91);
	team->addChild(text_level[3]);
	text_level[3]->setVisible(false);

	//位置4
	auto teammate4_role = Sprite::create("ui/littlecard_0415.png");
	teammate4_role->setPosition(553, 160);
	auto teammate4_frame = Sprite::createWithSpriteFrameName("littlecard_frame_class4_elite.png");
	teammate4_frame->setPosition(teammate4_role->getContentSize().width /2 , teammate4_role->getContentSize().height/2);
	teammate4_role->addChild(teammate4_frame);
	team->addChild(teammate4_role);
	text_max[4] = Sprite::createWithSpriteFrameName("arenamain_max.png");
	text_max[4]->setPosition(553, 91);
	team->addChild(text_max[4]);
	text_level[4] = Node::create();
	auto text_lv_04 = Sprite::createWithSpriteFrameName("lv.png");
	text_lv_04->setPositionX(-15);
	text_level[4]->addChild(text_lv_04);
	auto text_lv_value_04 = LabelTTF::create("99", "Arial", 25);
	text_lv_value_04->setPositionX(25);
	text_level[4]->addChild(text_lv_value_04);
	text_level[4]->setPosition(553, 91);
	team->addChild(text_level[4]);
	text_level[4]->setVisible(false);

	//邮箱UI
	auto normal_mail = Sprite::createWithSpriteFrameName("state_mail.png");
	auto menuItem = MenuItemSprite::create(normal_mail, normal_mail, normal_mail, CC_CALLBACK_1(MainUILayer::menu_mail_callback,this));
	auto menu = Menu::create(menuItem, NULL);
	menu->setPosition(550, 270);
	team->addChild(menu);

	//闪烁动画
	this->schedule(SEL_SCHEDULE(&MainUILayer::textlevel_flash), 1.0f);
}
void UINumberPicker::updateDisplayList()
{
    _selectedItem = nullptr;
    
    _itemsLayer->removeAllChildrenWithCleanup(true);
    sortChildrenArray.clear();
    
    displayRect.size = getContentSize();
    displayRect.origin = getParent()->convertToWorldSpace(getPosition());
    
    int numOfCell = virtualItemCount + 2;
    
    m_middleCellIndex = (int)numOfCell/2;
    
    if (show_value < m_minValue || show_value > m_maxValue)
    {
        show_value = m_minValue;
    }
    int upIndex = show_value - 1;
    int downIndex = show_value;
    
    for (int i = 0; i < numOfCell; i++)
    {
        auto cell = PickerCell::create();
        cell->setContentSize(Size(item_width, item_height));
        cell->setDirection(_pickerDirection);
        switch (_pickerDirection)
        {
            case PickerDirection::VERTICAL:
            {
                cell->setPositionX(getContentSize().width/2);
                if (i <= m_middleCellIndex)
                {
                    cell->setPositionY((m_middleCellIndex - i) * item_height);
                    
                    cell->setCellValue(downIndex);
                    downIndex += 1;
                    if (downIndex > m_maxValue)
                    {
                        downIndex = m_minValue;
                    }
                }
                else
                {
                    cell->setPositionY(i * item_height);
                    
                    if (upIndex < m_minValue)
                    {
                        upIndex = m_maxValue;
                    }
                    cell->setCellValue(upIndex);
                    upIndex -= 1;
                }
                break;
            }
            case PickerDirection::HORIZONTAL:
            {
                cell->setPositionY(0);
                if (i <= m_middleCellIndex)
                {
                    cell->setPositionX((m_middleCellIndex - i) * item_width);
                    
                    cell->setCellValue(downIndex);
                    downIndex += 1;
                    if (downIndex > m_maxValue)
                    {
                        downIndex = m_minValue;
                    }
                }
                else
                {
                    cell->setPositionX(i * item_width);
                    
                    if (upIndex < m_minValue)
                    {
                        upIndex = m_maxValue;
                    }
                    cell->setCellValue(upIndex);
                    upIndex -= 1;
                }
                break;
            }
            default:
                break;
        }
        
        if (i == 0)
        {
            setCell(cell);
        }        
        sortChildrenArray.push_back(cell);
        _itemsLayer->addChild(cell);
    }
}