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


C++ MainMenu::drawScreen方法代码示例

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


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

示例1: main

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:
//.........这里部分代码省略.........
开发者ID:bluenote-1577,项目名称:Finished-Puzzle-Game,代码行数:101,代码来源:GameLoop.cpp


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