示例#1
0
文件: osglogo.cpp 项目: BodyViz/osg
osg:: Node* createTextLeft(const osg::BoundingBox& bb, const std::string& label, const std::string& subscript)
{
    osg::Geode* geode = new osg::Geode();


    osg::StateSet* stateset = geode->getOrCreateStateSet();
    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);


    //std::string font("fonts/times.ttf");
    std::string font("fonts/arial.ttf");

    osgText::Text* text = new  osgText::Text;
 
    text->setFont(font);
    text->setFontResolution(110,120);
    text->setAlignment(osgText::Text::RIGHT_CENTER);
    text->setAxisAlignment(osgText::Text::XZ_PLANE);
    text->setCharacterSize((bb.zMax()-bb.zMin())*1.0f);
    text->setPosition(bb.center()-osg::Vec3((bb.xMax()-bb.xMin()),-(bb.yMax()-bb.yMin())*0.5f,(bb.zMax()-bb.zMin())*0.1f));
    //text->setColor(osg::Vec4(0.37f,0.48f,0.67f,1.0f)); // Neil's original OSG colour
    text->setColor(osg::Vec4(0.20f,0.45f,0.60f,1.0f)); // OGL logo colour
    text->setText(label);

#if 1
    text->setBackdropType(osgText::Text::OUTLINE);
//   text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT);

    text->setBackdropImplementation(osgText::Text::POLYGON_OFFSET);
//    text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER);
//    text->setBackdropImplementation(osgText::Text::DEPTH_RANGE);
//    text->setBackdropImplementation(osgText::Text::STENCIL_BUFFER);
    
    text->setBackdropOffset(0.05f);
    text->setBackdropColor(osg::Vec4(0.0f, 0.0f, 0.5f, 1.0f));
#endif


#if 1
    text->setColorGradientMode(osgText::Text::OVERALL);
    osg::Vec4 lightblue(0.30f,0.6f,0.90f,1.0f);
    osg::Vec4 blue(0.10f,0.30f,0.40f,1.0f);
    text->setColorGradientCorners(lightblue, blue, blue, lightblue);
#else
    text->setColorGradientMode(osgText::Text::OVERALL);
    osg::Vec4 light = osg::Vec4(0.0f, 1.0f, 1.0f, 1.0f);
    osg::Vec4 dark = osg::Vec4(0.0f, 0.0f, 0.5f, 1.0f);
    text->setColorGradientCorners(light, dark, dark, light);
//    text->setColorGradientCorners(dark, light, light, dark);
#endif

    geode->addDrawable( text );


    if (!subscript.empty())
    {
        //osgText::Text* subscript = new  osgText::Text(new osgText::TextureFont(font,45));

        osgText::Text* subscriptText = new osgText::Text;
        subscriptText->setFont(font);
        subscriptText->setText(subscript);
        subscriptText->setAlignment(osgText::Text::RIGHT_CENTER);
        subscriptText->setAxisAlignment(osgText::Text::XZ_PLANE);
        subscriptText->setPosition(bb.center()-osg::Vec3((bb.xMax()-bb.xMin())*4.3f,-(bb.yMax()-bb.yMin())*0.5f,(bb.zMax()-bb.zMin())*0.6f));
        subscriptText->setColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); // black

        geode->addDrawable( subscriptText );
    }
        
    return geode;
}
int main(void) {


	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );				
	sf::RenderWindow window(sf::VideoMode (600,400), "ComboPuzzle");
	window.setFramerateLimit(150);
	sf::RenderStates state;
	sf:: Color lightblue(230,230,250,0);
	TimedResourceHolder timed_resources;
	sf::FloatRect reset_bounds = timed_resources.reset_button.getGlobalBounds();
	sf::FloatRect menu_bounds = timed_resources.menu_button.getGlobalBounds();
	sf::Clock clock;
	sf:: Time time;
	Blocktree mainTree;
	MainMenu mainmenu;
	
	
	while (window.isOpen())												//Main Loop, while the game is running this loop is occuring
	{
		
		sf::Event event;
		while(mainmenu.gamestatus != 1 && window.isOpen()){             //This loop is the main menu loop. Mainmenu.gamestatus represents what gets rendered. 
			while(window.pollEvent(event)){                             //This sub-loop only occurs when gamestatus != 1, i.e. we haven't clicked start.
				if (event.type == sf::Event::Closed )
					window.close();
				if (event.type == sf::Event::MouseButtonPressed)
					mainmenu.clickOccur(window);
			}
			window.clear(lightblue);
			mainmenu.drawScreen(window);
			mainTree.drop_clock.restart();
			mainTree.timerClock.restart();
			window.display();
		}
		
		
		// everything below is timed puzzle game
		time = clock.restart();
		timed_resources.changeScore(mainTree.score);

																		
		while(window.pollEvent(event))								//checks to see if any event has occured. various functions are executed depending on the event below.
		{
			if (event.type == sf::Event::Closed )
				window.close();

			if(event.type == sf::Event::MouseButtonPressed && mainTree.is_game_over() != true)
				
				if(sf::Keyboard::isKeyPressed(sf::Keyboard::R) || sf::Keyboard::isKeyPressed(sf::Keyboard::C)){  //executes clickOccur_clear which checks the rows/columns and erases them.
					if(mainTree.clickOccur_clear(window,reset_bounds, menu_bounds, mainmenu)){
						timed_resources.changeComboUpdate(mainTree.combo_count-1);
						timed_resources.changeScoreUpdate(mainTree.last_score);
					}
				}

				else { 
					
					if(sf::Mouse::isButtonPressed(sf::Mouse::Left)){
						int id_to_swap = mainTree.clickOccur_swap(window,reset_bounds, menu_bounds, mainmenu);  // this branch is for swapping. 
						int id_to_swap2;

						while (sf::Mouse::isButtonPressed(sf::Mouse::Left)){
						
							time = clock.restart();
							timed_resources.changeScore(mainTree.score);
							timed_resources.changeDropTime(mainTree.updateGame_blocks(time));					// a compact version of the larger loop with rendering and updating
							window.clear(lightblue);															// occurs when the mouse is held down. 
							mainTree.drawTree(window, state);
							timed_resources.drawAll(window,state,mainTree);
							id_to_swap2 = mainTree.clickOccur_swap(window,reset_bounds, menu_bounds, mainmenu);
							if (mainTree.is_game_over() == true)
								goto ifGameEnds;

							if(id_to_swap == -2 || id_to_swap2 == -2){
								clock.restart();
							}

							else if (id_to_swap >-1 && id_to_swap2 >-1)
								mainTree.draw_select(id_to_swap,id_to_swap2,window,state);						// the blocks that are being clicked on render their selected sprites
							timed_resources.changeComboUpdate(mainTree.combo_count-1);
							window.display();
							if (mainmenu.gamestatus == 0) break;

					}
			
					if(mainTree.swap_colours(id_to_swap,id_to_swap2) == 0)										//colour swap occurs once the mouse button has been let go of
						timed_resources.gamestatus_changeString("Invalid Swap!");
					else timed_resources.gamestatus_changeString("");
						timed_resources.changeComboUpdate(mainTree.combo_count-1);
					}
				}
			if (event.type == sf::Event::MouseButtonPressed && mainTree.is_game_over() == true){
			
				if(mainTree.gameover_reset(window,reset_bounds,menu_bounds,mainmenu));
				timed_resources.gamestatus_changeString("");
			}
		}


		ifGameEnds:
		timed_resources.changeDropTime(mainTree.updateGame_blocks(time));										//rendering occurs, updates occur.
		window.clear(lightblue);
		mainTree.drawTree(window, state);
		
		timed_resources.changeComboUpdate(mainTree.combo_count-1);
		timed_resources.drawAll(window,state,mainTree);
		
	 
		if (mainTree.is_game_over() == true){                                          //records the high score if it hasn't been recorded yet and the game is over
			if(mainTree.highScore_recorded == false){
				if(timed_resources.write_highScore())
				mainTree.highScore_recorded =true;
			}
			if(mainTree.highScore_recorded == false)
			timed_resources.gamestatus_changeString("You lost!\n Click reset\n to start again\n High Score\n Error!");

			else timed_resources.gamestatus_changeString("You lost!\n Click reset\n to start again\n High Score\n Recorded!");
			mainTree.drop_clock.restart();

			window.display();
			
		
			
		}
	
		else{
			window.display();
		}
	}

}