当前位置: 首页>>代码示例>>C++>>正文


C++ Platform::getSize方法代码示例

本文整理汇总了C++中Platform::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Platform::getSize方法的具体用法?C++ Platform::getSize怎么用?C++ Platform::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Platform的用法示例。


在下文中一共展示了Platform::getSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Update

void Editor::Update() {
    if ( myKeys[sf::Keyboard::Back].pressed ) {
        myStage->getArea(0)->Clear();
        myNextScreen = ScreenMenu;
    }
    sf::Vector2i mouseCell((int)myMouse.x/32,(int)myMouse.y/32);

    myGUI->Update( myMouse );


    /*
    *   Mouse is on GUI
    */
    if ( myGUI->onGUI() ) {

        /*
        *   TOOLBAR
        */
        if ( myGUI->getGUI( ) == myToolBar ) {
            if ( myMouseLeft && myGUI->onWidget() && myGUI->getWidget()->getType() == widget_button ) {
                Button * btn = static_cast<Button*>(myGUI->getWidget());

                if ( myBrush == btn->getValue() ) myBrush = brush_null;

                else switch(btn->getValue() ) {
                    case brush_platform:
                    case brush_enemy:
                    case brush_spawn: {
                        myBrush = btn->getValue();
                        break;
                    }

                    case action_save: {
                        myStage->Save();
                        myAlert->setText("Map saved...");
                        myAlert->Display();
                        break;
                    }

                    case action_load: {
                        myStage->Load();
                        myAlert->setText("Map loaded...");
                        myAlert->Display();
                        break;
                    }
                    }
            }
        }


    }
    /*
    *   Otherwise
    */
    else {
        if ( myBrush != brush_null ) myPlatformHelper.SetPosition( mouseCell.x*32, mouseCell.y*32);
        // =========================================================================================
        //  Brush: Platform
        // =========================================================================================
        if ( myBrush == brush_platform ) {
            if ( !myPlatform) {
                if ( myMouseLeft ) {
                    int erase = 0;
                    Area * a = myStage->getArea(0);

                    for( vector<Platform*>::iterator it = a->myPlatforms.begin(); it != a->myPlatforms.end(); ++it) {
                        Platform * p = *it;
                        if ( p->getPos().x > myMouse.x || p->getPos().x + p->getSize().x < myMouse.x ||
                                p->getPos().y > myMouse.y || p->getPos().y + p->getSize().y < myMouse.y ) continue;
                        delete p;
                        a->myPlatforms.erase(it);
                        erase = 1;
                        break;
                    }

                    if ( !erase ) {

                        Platform * p = new Platform();
                        myPlatform = p;
                        p->setPos( sf::Vector2f(mouseCell.x*32, mouseCell.y*32) );
                        myCell = mouseCell;
                        a->myPlatforms.push_back(p);
                    }
                }
            }
            else {
                if ( myMouseLeftDown ) {
                    int x_dif = mouseCell.x - myCell.x;
                    int y_dif = mouseCell.y - myCell.y;
                    if ( x_dif < 0 ) {
                        myPlatform->setX( myCell.x*32+x_dif*32 );
                        x_dif = -x_dif;
                    }
                    else myPlatform->setX( myCell.x*32);

                    if ( y_dif < 0 ) {
                        myPlatform->setY( myCell.y*32+y_dif*32 );
                        y_dif = -y_dif;
                    }
                    else myPlatform->setY( myCell.y*32);
//.........这里部分代码省略.........
开发者ID:Salepate,项目名称:Games,代码行数:101,代码来源:editor.cpp

示例2: onInitialize

bool NickScene::onInitialize()
{
    Vector3 nodeCenter = Vector3(0.0f, 0.0f, 0.0f);
    
	//-----------------------------------------------------------------
	// create the initial platform which has a button that user can hit
    // to turn the globe on
	//-----------------------------------------------------------------
	m_graph->pushNode();
	{
        nodeCenter = Vector3(0.0f, 100.0f, 300.0f);
        
        //start position Waypoint this is where the player starts/resets
        m_WPstart  = new Start(this, "Objects/goal.obj", 0.125f);
        if ( !m_WPstart->initialize(new LightShader(0.2f, 1.0, 8, RAND_COLOR))) { GLOG("ERROR: could not create OBJmodel\n"); return false; }
        m_WPstart->setPosition(nodeCenter + Vector3(0.0f, 0.0f, 10.0f));
        m_WPstart->addToDynamicWorld(m_dynamicsWorld);
        m_graph->attach(m_WPstart);

		// create a platform
		Platform *platform = new Platform(this, Vector3(40.0f, 1.0f, 40.0f));
		if ( !platform->initialize(new LightShader(0.2f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize initial platform\n"); return false; }
		platform->setPosition(nodeCenter + Vector3(0.0f, -0.5f, 0.0f));
		platform->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(platform);
    }
	m_graph->popNode();
	
    
    //-----------------------------------------------------------------
	// create long platform that has cannons shooting at it
	//-----------------------------------------------------------------
	m_graph->pushNode();
	{
        nodeCenter += Vector3(0.0f, -30.0f, -130.0f);
        
		// create a platform
		Platform *platform = new Platform(this, Vector3(10.0f, 1.0f, 220.0f));
		if ( !platform->initialize(new LightShader(0.3f, 1.0f, 8, RAND_LIGHT_COLOR))) { GLOG("WARNING: Could not initialize cannon platform\n"); }
		platform->setPosition(nodeCenter + Vector3(0.0f, 0.0f, 0.0f));
		platform->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(platform);
        
        bool rightSide = false;
        for (int i = 0; i < 10; i++) {
            float cannonZ = (platform->getSize().z * 0.5f) - 50.0f - (i * 15.0f);
            float fireTime = 0.4f + RANDF(1.0f);
            
            // add a cannon aiming at the platform
            Cannon *cannon = new Cannon(this, Vector3(3.0f, 3.0f, 6.0f), 120.0f, fireTime);
            if (!cannon->initialize(new LightShader(0.1f, 1.0f, 8, Color(0.1f, 0.8f, 0.2f)))) { GLOG("WARNING: could not initialize first cannon\n"); }
            float cannonX = rightSide ? 20.0f : -20.0f;
            cannon->setPosition(nodeCenter + Vector3(cannonX, 10.0f, cannonZ));
            float yaw = rightSide ? 90.0f : -90.0f;
            cannon->setOrientation(yaw, -20.0f, 0.0f);
            cannon->addToDynamicWorld(m_dynamicsWorld);
            m_graph->attach(cannon);
            rightSide = !rightSide;
            
            m_cannons.push_back(cannon);
        }
        
        // create a button that will stop the cannons
        NickButton *stop_cannon_button = new NickButton(this, &NickScene::stopCannonsHit, Vector3(8.0f, 0.5f, 4.0f));
        if (!stop_cannon_button->initialize(new LightShader(0.3f, 1.0f, 8, RAND_COLOR))) { GLOG("ERROR: could not create stop_cannon_button\n"); }
		stop_cannon_button->setPosition(nodeCenter + Vector3(0.0f, stop_cannon_button->getSize().y, -105.0f));
		stop_cannon_button->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(stop_cannon_button);
    }
	m_graph->popNode();
    
    
    //-----------------------------------------------------------------
	// create platform after the cannon platform, which just has cube pyramid
    // that covers a gap to the next platform
	//-----------------------------------------------------------------
	m_graph->pushNode();
	{
        nodeCenter += Vector3(0.0f, 0.0f, -120.0f);
        
        // create a checkpoint now that user has gotten through cannons
        NickCheckPoint *cp = new NickCheckPoint(this, "Objects/goal.obj", 0.125f);
		if ( !cp->initialize(new LightShader(0.2f, 1.0, 8, RAND_COLOR))) { GLOG("ERROR: could not create OBJmodel\n"); return false; }
		cp->setPosition(nodeCenter + Vector3(8.0f, 0.5f, 0.0f));
		m_allCheckpoints.push_back(cp);
		cp->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(cp);
        cp->attachParticleSystem(new WaypointParticleSystem(200));
        
		// create a platform
		Platform *platform = new Platform(this, Vector3(50.0f, 1.0f, 12.0f));
		if ( !platform->initialize(new LightShader(0.2f, 0.8f, 8, RAND_COLOR))) { GLOG("ERROR: Could not initialize gap platform\n"); return false; }
		platform->setPosition(nodeCenter + Vector3(25.0f, -0.5f, 0.0f));
		platform->addToDynamicWorld(m_dynamicsWorld);
		m_graph->attach(platform);
        
        // cube pyramid right before gap
        m_graph->pushNode();
		Vector3 cubeSize = Vector3(1.5f, 1.5f, 0.5f);
		Vector3 startPoint = nodeCenter + Vector3(49.0f, cubeSize.y / 2.0f, -5.0f);
//.........这里部分代码省略.........
开发者ID:ChuckNice,项目名称:SBU_Sources,代码行数:101,代码来源:nicks_scene.cpp


注:本文中的Platform::getSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。