Ejemplo n.º 1
0
void CreditsScene::initCreditsThings()
{
    {
        auto node = PixelNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setPosition3D({30.2,-26,0});
        node->configSopx("sopx/welco/back.png.sopx");
        _hub->addChild(node);
        node->setScale(0.4);
        _pxBack = node;

    }

    {
        auto node = PixelTextNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setScale(0.27);
        node->setPosition3D({30.4,-26,0});
        node->configText("back",1);
        node->configMixColor({1.f, 200.f/255.f, 51.f/255.f,1.f});
        _hub->addChild(node);
    }

    {

        auto _image = RoadPlane::create();
        _image->configImage("images/credits.png");
        _image->configBlend(true);
        _image->setScale(0.1);
        _image->setCameraMask(_mainCamera->getCameraMask());
        _image->runAction(MoveBy::create(30, Vec3{0,40,0}));
        _hub->addChild(_image);
    }

}
Ejemplo n.º 2
0
bool CreditsScene::init()
{
    assert(TRBaseScene::init());



    auto layer = Layer::create();
    this->addChild(layer);

    auto size = Director::getInstance()->getVisibleSize();

    auto camera = Camera::createPerspective(60, size.width/size.height, 0.1, 1000000);
    camera->setCameraFlag(CameraFlag::USER1);
    layer->addChild(camera);
    camera->setCameraMask((unsigned short)CameraFlag::USER1);
    camera->setPosition3D({0,0,50});
    camera->lookAt({0,0,0}, {0,1,0});
    _mainLayer = layer;
    _mainCamera = camera;


    auto hub = Node::create();
    hub->setPosition3D({0,0,0});
    hub->setCameraMask(_mainCamera->getCameraMask());
    _mainLayer->addChild(hub);
    _hub = hub;

    initCreditsThings();
    initTouchThings();


    return true;
}
Ejemplo n.º 3
0
void LightTest::addSprite()
{
    auto s = Director::getInstance()->getWinSize();

    //{
    //    std::string fileName = "Sprite3DTest/plane.c3b";
    //    auto sprite = Sprite3D::create(fileName);
    //    sprite->setRotation3D(Vec3(-90.0, 0.0, 0.0));
    //    sprite->setScale(5.0f);
    //    sprite->setPosition(Vec2(0.0, -50.0));
    //    addChild(sprite);
    //    sprite->setCameraMask(2);
    //}

    {
        std::string fileName = "Sprite3DTest/orc.c3b";
        auto sprite = Sprite3D::create(fileName);
        sprite->setRotation3D(Vec3(0.0, 180.0, 0.0));
        sprite->setPosition(Vec2(0.0, 0.0));
        sprite->setScale(2.0);
        auto sp = Sprite3D::create("Sprite3DTest/axe.c3b");
        sprite->getAttachNode("Bip001 R Hand")->addChild(sp);
        auto animation = Animation3D::create(fileName);
        if (animation)
        {
            auto animate = Animate3D::create(animation);
            sprite->runAction(RepeatForever::create(animate));
        }

        addChild(sprite);
        sprite->setCameraMask(2);
    }

    {
        std::string fileName = "Sprite3DTest/sphere.c3b";
        auto sprite = Sprite3D::create(fileName);
        sprite->setPosition(Vec2(30.0, 0.0));
        addChild(sprite);
        sprite->setCameraMask(2);
    }

    {
        std::string fileName = "Sprite3DTest/sphere.c3b";
        auto sprite = Sprite3D::create(fileName);
        sprite->setScale(0.5f);
        sprite->setPosition(Vec2(-50.0, 0.0));
        addChild(sprite);
        sprite->setCameraMask(2);
    }

    {
        std::string fileName = "Sprite3DTest/sphere.c3b";
        auto sprite = Sprite3D::create(fileName);
        sprite->setScale(0.5f);
        sprite->setPosition(Vec2(-30.0, 10.0));
        addChild(sprite);
        sprite->setCameraMask(2);
    }
}
Ejemplo n.º 4
0
void WindBar::initWindThings()
{
    {
        auto node = PlanePixelNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setScale(1);
        node->setPosition3D({0,0,0});
        auto pixelData = loadScatPixelFile("hunters/sopx/wind_pillar.png.sopx");
        node->configBatch(PlanePixelBatchTuple{Vec3{0,0,0}, 1, &pixelData}, true);
        _hubNode->addChild(node);
        _pxBg = node;
    }


    {
        auto node = PlanePixelNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setScale(0.8);
        node->setPosition3D({0,2,0});
        auto pixelData = loadScatPixelFile("hunters/sopx/wind_strenth.png.sopx");
        node->configBatch(PlanePixelBatchTuple{Vec3{0,0,0}, 1, &pixelData}, false);
        _hubNode->addChild(node);
        _pxStrenth = node;
        _pxStrenth->setVisible(false);
    }
    {
        auto node = PlanePixelNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setScale(0.8);
        node->setPosition3D({0,0.5,0});
        auto pixelData = loadScatPixelFile("hunters/sopx/wind_direction.png.sopx");
        node->configBatch(PlanePixelBatchTuple{Vec3{0,0,0}, 1, &pixelData}, false);
        _hubNode->addChild(node);
        _pxDirection = node;
        _pxDirection->setVisible(false);
    }

    {
        auto node = PixelTextNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setScale(0.6f,0.9f);
        node->setPosition3D({1.5,25,0.5});
        node->configText("wind",1);
        node->configMixColor({49.f/255.f, 36.f/255.f, 33.f/255.f,1.f});
        _hubNode->addChild(node);
        _ptWind = node;
    }

    {
        auto node = PixelTextNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setScale(0.8f,0.9f);
        node->setPosition3D({2,20,0.5});
        node->configText("0",1);
        node->configMixColor({49.f/255.f, 36.f/255.f, 33.f/255.f,1.f});
        _hubNode->addChild(node);
        _ptStrenth = node;
    }
}
Ejemplo n.º 5
0
bool Physics3DCollisionCallbackDemo::init()
{
    if (!Physics3DTestDemo::init())
        return false;

    {
        Physics3DRigidBodyDes rbDes;

        float scale = 2.0f;
        std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("Sprite3DTest/boss.c3b");
        for (auto& it : trianglesList) {
            it *= scale;
        }

        rbDes.mass = 0.0f;
        rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
        auto rigidBody = Physics3DRigidBody::create(&rbDes);
        auto component = Physics3DComponent::create(rigidBody);
        auto sprite = Sprite3D::create("Sprite3DTest/boss.c3b");
        sprite->addComponent(component);
        sprite->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
        sprite->setScale(scale);
        sprite->setCameraMask((unsigned short)CameraFlag::USER1);
        this->addChild(sprite);
        //preload
        //
        rigidBody->setCollisionCallback([=](const Physics3DCollisionInfo &ci){
            if (!ci.collisionPointList.empty()){
                if (ci.objA->getMask() != 0){
                    auto ps = PUParticleSystem3D::create("Particle3D/scripts/mp_hit_04.pu");
                    ps->setPosition3D(ci.collisionPointList[0].worldPositionOnB);
                    ps->setScale(0.05f);
                    ps->startParticleSystem();
                    ps->setCameraMask(2);
                    this->addChild(ps);
                    ps->runAction(Sequence::create(DelayTime::create(1.0f), CallFunc::create([=](){
                        ps->removeFromParent();
                    }), nullptr));
                    ci.objA->setMask(0);
                }
            }
            //CCLOG("------------BoxB Collision Info------------");
            //CCLOG("Collision Point Num: %d", ci.collisionPointList.size());
            //for (auto &iter : ci.collisionPointList){
            //	CCLOG("Collision Position On A: (%.2f, %.2f, %.2f)", iter.worldPositionOnA.x, iter.worldPositionOnA.y, iter.worldPositionOnA.z);
            //	CCLOG("Collision Position On B: (%.2f, %.2f, %.2f)", iter.worldPositionOnB.x, iter.worldPositionOnB.y, iter.worldPositionOnB.z);
            //	CCLOG("Collision Normal On B: (%.2f, %.2f, %.2f)", iter.worldNormalOnB.x, iter.worldNormalOnB.y, iter.worldNormalOnB.z);
            //}
            //CCLOG("------------BoxB Collision Info------------");
        });
    }

    physicsScene->setPhysics3DDebugCamera(_camera);
    return true;
}
Ejemplo n.º 6
0
bool BasicPhysics3DDemo::init()
{
    if (!Physics3DTestDemo::init())
        return false;

    //create floor
    Physics3DRigidBodyDes rbDes;
    rbDes.mass = 0.0f;
    rbDes.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f));
    
    auto floor = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes);
    floor->setTexture("Sprite3DTest/plane.png");
    floor->setScaleX(60);
    floor->setScaleZ(60);
    this->addChild(floor);
    floor->setCameraMask((unsigned short)CameraFlag::USER1);
    floor->syncNodeToPhysics();
    //static object sync is not needed
    floor->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
    
    //create several boxes using PhysicsSprite3D
    rbDes.mass = 1.f;
    rbDes.shape = Physics3DShape::createBox(Vec3(0.8f, 0.8f, 0.8f));
    float start_x = START_POS_X - ARRAY_SIZE_X/2;
    float start_y = START_POS_Y;
    float start_z = START_POS_Z - 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;
                
                auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes);
                sprite->setTexture("Images/CyanSquare.png");
                sprite->setPosition3D(Vec3(x, y, z));
                sprite->syncNodeToPhysics();
                sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
                sprite->setCameraMask((unsigned short)CameraFlag::USER1);
                sprite->setScale(0.8f);
                this->addChild(sprite);
            }
        }
    }

    physicsScene->setPhysics3DDebugCamera(_camera);

    return true;
}
Ejemplo n.º 7
0
void PowerBar::initPowerThings()
{
    {
        auto node = PixelNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setScale(1.2,1);
        node->setPosition3D({0,0,0});
        node->configSopx("hunters/sopx/strenth_rect.png.sopx");
        node->configBlend(true);
        _hubNode->addChild(node);
        _pxRect = node;

    }

    {
        auto node = PixelNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setScale(1.2,1);
        node->setPosition3D({0,0,0});
        node->configSopx("hunters/sopx/strenth_content.png.sopx");
        node->configBlend(true);

        _hubNode->addChild(node);
        _pxContent = node;
    }
    {
        auto node = PixelTextNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setScale(1.1f,2.f);
        node->setPosition3D({-12,8,0});
        node->configText("00#",2.0);
        node->configMixColor({0.f/255.f, 183.f/255.f, 233.f/255.f,1.f});
        _hubNode->addChild(node);
        _ptAngle = node;
    }



    {
        auto node = PixelNode::create();
        node->setCameraMask(_mainCamera->getCameraMask());
        node->setScale(0.15);
        node->setPosition3D({0,0,-10});
        node->configSopx("hunters/sopx/power_arrow.png.sopx");
        node->configBlend(true);
        _mainCamera->addChild(node);
        _pxArrow = node;
        node->setVisible(false);
    }
}
Ejemplo n.º 8
0
//Throwing Object
void HelloWorld::shootBoxfunc(const cocos2d::Vec3 &des)
{
	//Vec3 linearVel = des -camera->getPosition3D();
	//linearVel.normalize();
	//linearVel *= 100.0f;

	Physics3DRigidBodyDes rbDes;
	rbDes.originalTransform.translate(car_cabine->getPosition3D());
	rbDes.mass = 1.f;
	rbDes.shape = Physics3DShape::createSphere(0.25);
	auto sprite = PhysicsSprite3D::create("box.c3t", &rbDes);
	sprite->setTexture("Gun.png");

	auto rigidBody = static_cast<Physics3DRigidBody*>(sprite->getPhysicsObj());
	rigidBody->setLinearFactor(Vec3::ONE);
	rigidBody->setLinearVelocity(des*15);
	rigidBody->setAngularVelocity(Vec3::ZERO);
	rigidBody->setCcdMotionThreshold(0.5f);
	rigidBody->setCcdSweptSphereRadius(0.4f);

	sprite->setPosition3D(Vec3(car_cabine->getPosition3D().x, car_cabine->getPosition3D().y+4, car_cabine->getPosition3D().z));
	sprite->setScale(0.5f);
	sprite->syncNodeToPhysics();
	sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); 
	sprite->setCameraMask((unsigned short)CameraFlag::USER2);
	this->addChild(sprite,1);
}
void UnlockPortals::AddParticle(int count)
{
	if (IsUnlocked())
		return;

	m_numParticlesLeft -= count;
	m_curParticleTotal += count;
	if (IsUnlocked())
	{
		setSpriteFrame(m_unlockImage);
		setPhysicsBody(m_unlockCollision);
		removeAllChildrenWithCleanup(true);
		if (m_boundaryImg != "none")
		{
			auto boundary = cocos2d::Sprite::create();
			boundary->setAnchorPoint(cocos2d::Vec2(0, 0));
			boundary->setTexture(m_boundaryImg);
			boundary->setTextureRect(m_unlockRect);
			cocos2d::Texture2D::TexParams params = cocos2d::Texture2D::TexParams();
			params.magFilter = GL_LINEAR;
			params.minFilter = GL_LINEAR;
			params.wrapS = GL_REPEAT;
			params.wrapT = GL_REPEAT;
			boundary->getTexture()->setTexParameters(params);
			boundary->setCameraMask(4);
			addChild(boundary,22);
			boundary->setPosition(m_unlockRect.origin + cocos2d::Vec2(m_imgXOffset, m_imgYOffset));
		}
	}
	else
	{
		setSpriteFrame(cocos2d::SpriteFrameCache::getInstance()->spriteFrameByName(m_particleBaseImg + std::to_string(m_curParticleTotal) + m_particleBaseImgExt));
	}
}
Ejemplo n.º 10
0
bool BattleScene::init()
{
	Layer::init();
	currentLayer = this;
	Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB565);

	setCamera();
	controlCamera();
	setCameraMask(2);
	createBackground();
	enableTouch();
	initUILayer();
	GameMaster::create();

	MessageDispatchCenter::getInstance()->registerMessage(MessageType::BLOOD_MINUS, [](Actor * heroActor)
	{
		uiLayer->bloodDrop(heroActor);
	});
	MessageDispatchCenter::getInstance()->registerMessage(MessageType::ANGRY_CHANGE, [](Actor * heroActor)
	{
		uiLayer->angryChange(heroActor);
	});

	scheduleUpdate();
	return true;
}
Ejemplo n.º 11
0
void Physics3DTestDemo::shootBox( const cocos2d::Vec3 &des )
{
    Physics3DRigidBodyDes rbDes;
    Vec3 linearVel = des - _camera->getPosition3D();
    linearVel.normalize();
    linearVel *= 100.0f;
    rbDes.originalTransform.translate(_camera->getPosition3D());
    rbDes.mass = 1.f;
    rbDes.shape = Physics3DShape::createBox(Vec3(0.5f, 0.5f, 0.5f));
    auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes);
    sprite->setTexture("Images/Icon.png");

    auto rigidBody = static_cast<Physics3DRigidBody*>(sprite->getPhysicsObj());
    rigidBody->setLinearFactor(Vec3::ONE);
    rigidBody->setLinearVelocity(linearVel);
    rigidBody->setAngularVelocity(Vec3::ZERO);
    rigidBody->setCcdMotionThreshold(0.5f);
    rigidBody->setCcdSweptSphereRadius(0.4f);

    this->addChild(sprite);
    sprite->setPosition3D(_camera->getPosition3D());
    sprite->setScale(0.5f);
    sprite->syncNodeToPhysics();
    
    //optimize, only sync node to physics
    sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); //sync node to physics
    
    sprite->setCameraMask((unsigned short)CameraFlag::USER1);
}
void UnlockPortals::SetUnlockCollision(cocos2d::Vec2 collBoxSize, cocos2d::Vec2 collBoxOffset)
{
	m_unlockCollision = cocos2d::PhysicsBody::createBox(cocos2d::Size(collBoxSize), cocos2d::PhysicsMaterial(1.0f, 0.0f, 0.0f), collBoxOffset);
	m_lockCollision->setContactTestBitmask(0x0);
	m_lockCollision->setCollisionBitmask(0x1 << curOffset);
	m_unlockCollision->setDynamic(false);
	m_unlockCollision->setGravityEnable(true);
	m_unlockCollision->setRotationEnable(false);
	m_unlockCollision->retain();
	m_unlockRect = cocos2d::Rect(collBoxOffset.x - collBoxSize.x / 2, collBoxOffset.y - collBoxSize.y /3, collBoxSize.x, collBoxSize.y);

	if (curOffset < 30)
		++curOffset;
	else
		curOffset = 27;

	if (IsUnlocked() && m_boundaryImg != "none")
	{
		setPhysicsBody(m_unlockCollision);
		removeAllChildrenWithCleanup(true);
		auto boundary = cocos2d::Sprite::create();
		boundary->setAnchorPoint(cocos2d::Vec2(0, 0));
		boundary->setTexture(m_boundaryImg);
		boundary->setTextureRect(m_unlockRect);
		cocos2d::Texture2D::TexParams params = cocos2d::Texture2D::TexParams();
		params.magFilter = GL_LINEAR;
		params.minFilter = GL_LINEAR;
		params.wrapS = GL_REPEAT;
		params.wrapT = GL_REPEAT;
		boundary->getTexture()->setTexParameters(params);
		boundary->setCameraMask(4);
		addChild(boundary,22);
		boundary->setPosition(m_unlockRect.origin + cocos2d::Vec2(m_imgXOffset, m_imgYOffset));
	}
}
Ejemplo n.º 13
0
void BattleScene::createBackground()
{//create the 3d world
	auto background3D = Sprite3D::create("model/scene/changing.c3b");
	background3D->setScale(2.65);
	background3D->setPosition3D(Vec3(-2300, -1000, 0));
	background3D->setRotation3D(Vec3(90, 0, 0));
	background3D->setCameraMask(2);
	addChild(background3D);
}
Ejemplo n.º 14
0
void HelloWorld::initScene()
{
    Size visibleSize = Director::getInstance()->getVisibleSize();
    auto vp = Camera::getDefaultViewport();
    auto node = CSLoader::createNode("res/Scene3DNoParticle.csb");
    node->setCameraMask((unsigned short)CameraFlag::USER1, true);
    addChild(node);
    _headNode = node->getChildByTag(57);
    {
        _camera = Camera::createPerspective(60,visibleSize.width/visibleSize.height * 0.5,0.1f,800);
        _camera->setCameraFlag(CameraFlag::USER1);
        //
        //        _camera->setPosition3D(Vec3(-0.01,0,0));
        _camera->setFrameBufferObject(Director::getInstance()->getDefaultFBO());
        _camera->setViewport(experimental::Viewport(vp._left,vp._bottom, vp._width/2, vp._height));
        _headNode->addChild(_camera);
        
        _camera2 = Camera::createPerspective(60,visibleSize.width/visibleSize.height * 0.5,0.1f,800);
        _camera2->setCameraFlag(CameraFlag::USER1);
        //
        //        _camera->setPosition3D(Vec3(-0.01,0,0));
        _camera2->setFrameBufferObject(Director::getInstance()->getDefaultFBO());
        _camera2->setViewport(experimental::Viewport(vp._left + vp._width/2,vp._bottom, vp._width/2, vp._height));
        _headNode->addChild(_camera2);
    }
    
    //add skybox
    {
        auto textureCube = TextureCube::create("skybox/left.jpg", "skybox/right.jpg",
                                           "skybox/top.jpg", "skybox/bottom.jpg",
                                           "skybox/front.jpg", "skybox/back.jpg");
        auto skyBox = Skybox::create();
        skyBox->retain();
        
        skyBox->setTexture(textureCube);
        addChild(skyBox);
        skyBox->setCameraMask((unsigned short)CameraFlag::USER1);
    }
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
    listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    CCASSERT(_headNode, "");
}
void HelloWorld::update(float delta)
{
	if (count % 240 == 0)
	{
		/**
			エフェクトファイルを読み込みます。

			You read an effect file.

			您讀取效果文件。

			您读取效果文件。
		*/
		auto effect = efk::Effect::create("Laser01.efk");
		if (effect != nullptr)
		{
			/**
				エミッターを生成し、パラメーターを設定してレイヤーに追加します。

				You generate an emitter, set parameters and add it to the layer.

				您會生成一個發射極,並通過將參數添加到該層。

				您会生成一个发射极,并通过将参数添加到该层。
			*/
			auto emitter = efk::EffectEmitter::create(manager);
			emitter->setEffect(effect);
			emitter->setPlayOnEnter(true);

			emitter->setPosition3D(Vec3(0, 0, 0));
			emitter->setRotation3D(Vec3(0, 90, 0));
			emitter->setScale(3);
			emitter->setCameraMask(2);
			this->addChild(emitter);

			// No need (because it uses autorelease after 1.41)
			//effect->release();
		}
	}

	/**
		毎フレーム、マネージャーを更新します。

		You update the manager every frame.

		您將更新每一幀,經理。

		您将更新每一帧,经理。
	*/
	manager->update();

	manager->setCameraMatrix(camera->getViewMatrix());
	manager->setProjectionMatrix(camera->getProjectionMatrix());

	count++;
}
BlueParticles::BlueParticles(cocos2d::Vec2 position, std::string img, cocos2d::Vec2 powerDirection, float power)
	:	m_power(power),
		m_area(cocos2d::Rect(0,0,0,0)),
		m_direction(powerDirection.getNormalized())
{
	setCameraMask(4);
	setPosition(position);
	init();
	this->setTexture(img);
}
Ejemplo n.º 17
0
OBBTest::OBBTest():
_drawAABB(nullptr),
_pick(false),
_camera(nullptr)
{
    auto listener = EventListenerTouchAllAtOnce::create();
    listener->onTouchesBegan = CC_CALLBACK_2(OBBTest::onTouchesBegan, this);
    listener->onTouchesEnded = CC_CALLBACK_2(OBBTest::onTouchesEnded, this);
    listener->onTouchesMoved = CC_CALLBACK_2(OBBTest::onTouchesMoved, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    auto s = Director::getInstance()->getWinSize();
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    auto winSize = Director::getInstance()->getWinSize();
    
    // add title
    auto label = LabelTTF::create("OBB", "Arial", 24);
    label->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x,
                       Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - 30);
    
    this->addChild(label, -1);
    
    //add the menu item for back to main menu
    label = LabelTTF::create("MainMenu", "Arial", 24);
    auto menuItem = MenuItemLabel::create(label);
    menuItem->setCallback([&](cocos2d::Ref *sender) {
        Director::getInstance()->replaceScene(Chapter9::createScene());
    });
    auto menu = Menu::create(menuItem, nullptr);
    menu->setPosition( Vec2::ZERO );
    menuItem->setPosition( Vec2(origin.x+visibleSize.width - 80, origin.y + 25) );
    this->addChild(menu, 1);
    
    auto layer3D=Layer::create();
    addChild(layer3D);
    
    // add camera
    _camera=Camera::createPerspective(60, (GLfloat)winSize.width/winSize.height, 1, 1000);
    _camera->setCameraFlag(CameraFlag::USER1);// set camera flag
    _camera->setPosition3D(Vec3(0, 50, 230));
    _camera->lookAt(Vec3(0,0,0), Vec3(0,1,0));
    layer3D->addChild(_camera);
    
    _drawAABB = DrawNode3D::create();
    
    Vec3 extents = Vec3(60, 30, 100);
    AABB aabb = AABB(-extents, extents);
    _obb = OBB(aabb);
    layer3D->addChild(_drawAABB);
    
    layer3D->setCameraMask(2);
    
    scheduleUpdate();
}
Ejemplo n.º 18
0
//------------------------------------------------------------------
//
// CSUserCameraTest
//
//------------------------------------------------------------------
CSUserCameraTest::CSUserCameraTest()
{
    auto node = CSLoader::createNode("UserCamera.csb");
    
    auto sprite3D = Sprite3D::create("dragon/dragon.c3b");
    sprite3D->setPosition3D(Vec3(100, 95, 80));
    sprite3D->setCameraMask((unsigned int)CameraFlag::USER1);
    
    addChild(node);
    addChild(sprite3D);
}
Ejemplo n.º 19
0
void OsgForm::setCameraMaskFromLineEdit()
{
    QLineEdit *le = dynamic_cast<QLineEdit *>(sender());
    if (!le) return;

    QString maskString = le->text();
    bool ok = false;
    unsigned newMask = maskString.toUInt(&ok, 16);
    if (ok) {
        setCameraMask(newMask);
    }
}
Ejemplo n.º 20
0
void BattleFieldUI::showVictoryUI()
{//show the victory UI when win
	//diable AI

	//color layer
	auto layer = LayerColor::create(Color4B(10, 10, 10, 150));
	layer->ignoreAnchorPointForPosition(false);
	layer->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 0));
	//add victory
	auto victory = Sprite::createWithSpriteFrameName("victory.png");
	victory->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 3));
	victory->setScale(0.1);
	layer->addChild(victory, 1);
	layer->setGlobalZOrder(100);
	victory->setGlobalZOrder(100);
	//victory runaction
	auto action = EaseElasticOut::create(ScaleTo::create(1.5, 1));
	victory->runAction(action);

	auto listener = EventListenerTouchOneByOne::create();
	//touch event
	listener->onTouchBegan = [](Touch*, Event*)
	{
		return true;
	};
	listener->onTouchEnded = [this](Touch*, Event*)
	{
		//clear GlobalVaribals
		HeroPool.clear();
		DragonPool.clear();
		SlimePool.clear();
		RatPool.clear();
		BossPool.clear();
		PigletPool.clear();

		HeroManager.clear();
		MonsterManager.clear();
		GameMaster::reset();

		//stop schedule
		currentLayer->unscheduleUpdate();
		Director::getInstance()->getScheduler()->unschedule("gameController", currentLayer);
		//stop sound
		experimental::AudioEngine::stop(AUDIO_ID.BATTLEFIELDBGM);
		//replace scene
		Director::getInstance()->replaceScene(ChooseRoleScene::createScene());
	};
	victory->setCameraMask(2);
	auto eventDispatcher = layer->getEventDispatcher();
	eventDispatcher->addEventListenerWithSceneGraphPriority(listener, layer);

	addChild(layer);
}
Ejemplo n.º 21
0
bool GlassDemoScene::init()
{
    assert(TRBaseScene::init());
    _layer = Layer::create();

    this->addChild(_layer);

    auto size = Director::getInstance()->getVisibleSize();

    auto _formCamera = Camera::createPerspective(60, size.width/size.height, 0.01, 1000);
    _formCamera->setPosition3D({0,0,0});
    _formCamera->lookAt(Vec3{0,0,-20},Vec3{0,1,0});
    _formCamera->setCameraFlag(CameraFlag::USER1);
    _layer->addChild(_formCamera);
    _formCamera->setCameraMask((unsigned short)CameraFlag::USER1);
    _camera = _formCamera;

    _glass = DynamicGlass::create(1.2,1.2,10,10);
    _glass->setCameraMask(_camera->getCameraMask());
    _layer->addChild(_glass);
    _glass->setPosition3D({0,0,0});





    this->addCommonBtn({0.1f,0.95f}, "back", [](){
        Director::getInstance()->popScene();
    });
    this->addCommonBtn({0.1f,0.9f}, "hit", [this](){
        _glass->hit(1.0);
    });

    this->addCommonBtn({0.1f,0.85f}, "reset", [this](){
        _glass->reset();
    });

    ///acce
    _acceEffect = AcceEffectSpace::create();
    _acceEffect->setCameraMask(_camera->getCameraMask());
    _acceEffect->setPosition3D({0,0,0});
    _layer->addChild(_acceEffect);

    this->addCommonBtn({0.9f, 0.8f}, "per +", [this](){_percent += 0.1;});
    this->addCommonBtn({0.9f, 0.75f}, "per -", [this](){_percent -= 0.1;});

    scheduleUpdate();

    return  true;
}
Ejemplo n.º 22
0
void CameraFrameBufferTest::onEnter()
{
    auto sizeInpixels = Director::getInstance()->getWinSizeInPixels();
    auto size = Director::getInstance()->getWinSize();
    auto fboSize = Size(sizeInpixels.width * 1, sizeInpixels.height * 1.5);
    auto fbo = experimental::FrameBuffer::create(1, fboSize.width, fboSize.height);
    
    CameraBaseTest::onEnter();
    //auto sprite = Sprite::createWithTexture(fbo);
    //sprite->setPosition(Vec2(100,100));
    //std::string filename = "Sprite3DTest/girl.c3b";
    //auto sprite = Sprite3D::create(filename);
    //sprite->setScale(1.0);
    //auto animation = Animation3D::create(filename);
    //if (animation)
    //{
    //    auto animate = Animate3D::create(animation);
        
    //    sprite->runAction(RepeatForever::create(animate));
    //}
    //sprite->setPosition(Vec2(100,100));
    auto rt = experimental::RenderTarget::create(fboSize.width, fboSize.height);
    auto rtDS = experimental::RenderTargetDepthStencil::create(fboSize.width, fboSize.height);
    fbo->attachRenderTarget(rt);
    fbo->attachDepthStencilTarget(rtDS);
    auto sprite = Sprite::createWithTexture(fbo->getRenderTarget()->getTexture());
    sprite->setScale(0.3);
    sprite->runAction(RepeatForever::create(RotateBy::create(1, 90)));
    sprite->setPosition(size.width/2, size.height/2);
    addChild(sprite);
    
    auto sprite2 = Sprite::create(s_pathGrossini);
    sprite2->setPosition(Vec2(size.width/5,size.height/5));
    addChild(sprite2);
    sprite2->setCameraMask((unsigned short)CameraFlag::USER1);
    auto move = MoveBy::create(1.0, Vec2(100,100));
    sprite2->runAction(
                       RepeatForever::create(
                                             Sequence::createWithTwoActions(
                                                                            move, move->reverse())
                                             )
                       );
    
    auto camera = Camera::create();
    camera->setCameraFlag(CameraFlag::USER1);
    camera->setDepth(-1);
    camera->setFrameBufferObject(fbo);
    fbo->setClearColor(Color4F(1,1,1,1));
    addChild(camera);
}
Ejemplo n.º 23
0
void OsgForm::tweakCameraMaskBit(int state)
{
    QCheckBox * cb = dynamic_cast<QCheckBox *>(sender());
    if (!cb) return;

    int idx = m_checkBoxes.indexOf(cb);
    if (idx < 0) return;
    osg::Node::NodeMask mask = ui->osg3dView->getCamera()->getCullMask();
    unsigned bit = 1 << idx;
    if (state == Qt::Checked) {
        mask |= bit;
    } else {
        mask &= ~bit;
    }
    setCameraMask(mask);
}
Ejemplo n.º 24
0
bool BattleFieldUI::init()
{
	Layer::init();

	avatarInit();
	bloodbarInit();
	angrybarInit();
	touchButtonInit();
	timeInit();

	setGlobalZOrder(10);
	setCameraMask(2);
	experimental::AudioEngine::stopAll();
	AUDIO_ID.BATTLEFIELDBGM = experimental::AudioEngine::play2d(BGM_RES.BATTLEFIELDBGM, true, 0.6);
	return true;
}
Ejemplo n.º 25
0
float Mage::hurt(BasicCollider* collider, bool dirKnockMode)
{
	if (_isalive == true) {
		auto damage = collider->getDamage();
		//calculate the real damage
		bool critical = false;
		auto knock = collider->getKnock();
		if (CCRANDOM_0_1() < collider->getCriticalChance()) {
			damage *= 1.5;
			critical = true;
			knock *= 2;
		}
		damage = damage + damage * CCRANDOM_MINUS1_1() * 0.15 - _defense;
		damage = floor(damage);
		if (damage <= 0) damage = 1;
		_hp -= damage;
		if (_hp > 0) {
			if (critical == true) {
				knockMode(collider, dirKnockMode);
				hurtSoundEffects();
			}
			else hurtSoundEffects();
		}
		else {
			_hp = 0;
			_isalive = false;
			dyingMode(getPosTable(collider), knock);
		}

		auto blood = _hpCounter->showBloodLossNum(damage, this, critical);
		blood->setCameraMask(2);
		if (_name == "Rat")
			blood->setPositionZ(Director::getInstance()->getVisibleSize().height * 0.25);
		addEffect(blood);
		//Transfer data to UILayer
		struct MESSAGE_BLOOD_MINUS  bloodMinus = { _name, _maxhp, _hp, _bloodBar, _bloodBarClone, _avatar };
		MessageDispatchCenter::getInstance()->dispatchMessage(BLOOD_MINUS, this);
		struct MESSAGE_ANGRY_CHANGE angryChange = { _name, _angry,_angryMax };
		MessageDispatchCenter::getInstance()->dispatchMessage(ANGRY_CHANGE, this);

		_angry += damage;
		return damage;
	}
	return 0;
}
Ejemplo n.º 26
0
void City_layer::create_human1(Vec3 pos,float scale)
{
    
    
    auto sprite = Charecter1::create();
    sprite->setScale(scale);
    this->addChild(sprite);
    sprite->setPosition3D(pos);
    sprite->setCameraMask(2);
    vecObj.pushBack(sprite);
//    
//    Vec3 corners[8]={};
//    AABB aabbsp1=sprite->getAABB();
//    aabbsp1.getCorners(corners);
//    _aabb.push_back(aabbsp1);
//    node1->drawCube(corners, Color4F(0,0,1,1));
    
    
}
Ejemplo n.º 27
0
PixelPlane* DynamicGlassPool::genIdleGlass()
{
    auto node = PixelPlane::create("3d/pp_glass.fsh",EditState::s()->getBgmTextureFile());
    node->setScale(1);
    node->setCameraMask(_camera->getCameraMask());
    _layer->addChild(node);
    const float len = 0.5;
    for (int i = 0; i < 5; i++) {
        float z = i*0.2;
        Vec3 bl = {-len,-len,z};
        Vec3 br = {len,-len,z};
        Vec3 tl = {-len,len,z};
        Vec3 tr = {len,len,z};
        node->drawRoad(bl, br, tl, tr);
    }
    node->setGlassLength(len*2);

    node->setVisible(false);
    return node;
}
bool HelloWorld::init()
{
	if ( !Scene::init() )
	{
		return false;
	}
	
	auto rsize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();

	auto sprite = BillBoard::create("HelloWorld.png");
	sprite->setPosition3D(Vec3(0, 0, 0));
	sprite->setScale(0.1);
	sprite->setCameraMask(2);
	this->addChild(sprite);
	
	// 3D
	auto s = Director::getInstance()->getWinSize();
	camera = Camera::createPerspective(60, (GLfloat)s.width / s.height, 1, 1000);
	camera->setPosition3D(Vec3(100, 100, 100));
	camera->lookAt(Vec3(0, 0, 0), Vec3(0, 1, 0));
	camera->setCameraFlag(cocos2d::CameraFlag::USER1);

	this->addChild(camera);

	// for update
	this->scheduleUpdate();

	/**
		efk::EffectManagerのインスタンスを生成します。

		You create an instance of efk::EffectManager.

		您創建一個efk::EffectManager的實例。

		您创建一个efk::EffectManager的实例。
	*/
	manager = efk::EffectManager::create(rsize);

	return true;
}
Ejemplo n.º 29
0
void PowerBar::initPathThings()
{

    _pathHubNode = Node::create();
    float y = heroPositionType2floatYposition(HeroPositionType::HPT_3);
    _pathHubNode->setPosition3D({0,y,QuestDef::ARROW_SHOOT_Z});
    _pathHubNode->setRotation3D({90,0,-90});
    _pathHubNode->setScale(1);
    _pathHubNode->setCameraMask(_mainCamera->getCameraMask());
    _pathHubNode->setZOrder(10);
    _mainLayer->addChild(_pathHubNode);
    _pathHubNode->setVisible(false);

    for (int i = 0; i < N_PATH_POINTS; i++) {
        auto n = PixelNode::create();
        n->setCameraMask(_mainCamera->getCameraMask());
        n->configSopx("hunters/sopx/path_point.png.sopx");
//        n->configBlend(true);
        _pathHubNode->addChild(n);
        _pxPathPoints[i] = n;
    }
}
Ejemplo n.º 30
0
bool Slime::init()
{
	Entity::init();

	Physics3DRigidBodyDes rbDes;
	rbDes.mass = 10.0f;
	rbDes.shape = Physics3DShape::createSphere(13.f);

	m_RigidBody = Physics3DRigidBody::create(&rbDes);
	Quaternion quat;
	Quaternion::createFromAxisAngle(Vec3(0.f, 1.f, 0.f), CC_DEGREES_TO_RADIANS(180), &quat);
	auto component = Physics3DComponent::create(m_RigidBody, Vec3(0.f, -10.f, 0.f)/*,quat*/);
	m_RigidBody->setMask(CollisionMask::CM_Slime);
	m_RigidBody->setCollisionCallback(CC_CALLBACK_1(Slime::collisionCallback, this));
	m_RigidBody->setUserData(this);
	m_RigidBody->setLinearFactor(Vec3(1, 1, 1));
	m_RigidBody->setFriction(0.5f);
	m_RigidBody->setAngularVelocity(Vec3::ZERO);
	m_RigidBody->setCcdMotionThreshold(0.5f);
	m_RigidBody->setCcdSweptSphereRadius(0.4f);

	component->setBtMask(CM_Slime);
	component->setBtGroup(ColGroup_Slime);

	auto sprite = Sprite3D::create("model/slime/slime.c3b", "model/slime/baozi.jpg");
	sprite->addComponent(component);
	sprite->setScale(9);
	sprite->setPosition3D(Vec3(200, 0, 0));
	sprite->setRotation3D(Vec3(0, -90, 0));
	sprite->setCameraMask((int)CameraFlag::USER1);
	component->syncNodeToPhysics();
	component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);

	m_Appearence = sprite;
	addChild(m_Appearence);

	return true;
}