Exemplo n.º 1
0
void startGame()
{
	reset_hints();
	endMenu();
	wait(1);
	level_load("mainLevel.wmb");
//	level_load("menuLevel2.wmb");
//wait(1); // wait until last_error becomes valid
	on_esc = NULL;
	gameCameraInit();
	startIngameGUI();
	playMusicGameDay();
	startSnow();
	
	// Start a new day
	dayOrNight = DAY;
	dayTime = 28800;
	
	hut_restart();
	item_restart();
	show_dayhint();

	set(mtl_model, PASS_SOLID);
	random_seed(8);
	
	VECTOR tempVector;
	int i;
	for(i = 0; i < 100; i++)
	{
		vec_set(tempVector, vector(random(6400)-3200, random(6400)-3200, 0));
		if(vec_length(tempVector) < 800)
		{
			i--;
			continue;
		}
		
		tempVector.z = 5000;
		tempVector.z -= c_trace(tempVector, vector(tempVector.x, tempVector.y, -5000), SCAN_TEXTURE|IGNORE_PASSABLE|IGNORE_FLAG2);
		if(hit.nz < 0.5)
		{
			i--;
			continue;
		}
		
//		ENTITY *tree = ent_create("pine_3.mdl", tempVector, 0);
		ENTITY *tree = ent_create("pine_3_reduced.mdl", tempVector, 0);
		set(tree, PASSABLE|SHADOW);
		vec_scale(tree.scale_x, random(0.5) + 0.5);
		tree.pan = random(360);
		tree->emask &= ~DYNAMIC;
		
	}
	
	random_seed(0);
	pssm_run(4);
wait(1); // f*****g wait(1) seems to fix something which breaks everything

	var sunlightFactor = 0;
	var dayCounter = 0;
	while(isGameOver < 2)
	{
		if (isGameOver == 0)
		{
			updateGui();
			goblin_loop();
			item_spawn_loop();
			
			dayTime += DAY_TIME_SPEED * time_step * 1;
			if(dayTime >= 86400)
			{
				dayTime -= 86400;
				dayCounter += 1;
				
				goblinSpawnDelay = maxv(16.0*3.0-dayCounter*2, 1);
			}
			
			hours = integer(dayTime/60.0/60.0);
			minutes = (integer(dayTime)-hours*60.0*60.0)/60.0;
			
			sunlightFactor = sinv((dayTime-28800.0)/(60.0*60.0*12.0)*180.0);
			
			// Day start
			if(dayTime >= 28800 && dayOrNight == NIGHT && dayTime < 72000)
			{
				dayOrNight = 3;
				fadeWithBlack(startDay);
			}
			
			// Day
			if(sunlightFactor > 0.0)
			{
				sun_light = sunlightFactor*60;
			}
			
			// Night start
			if(dayTime >= 72000 && dayOrNight == DAY)
			{
				dayOrNight = 3;
				fadeWithBlack(startNight);
			}
			
			// Night
			if(sunlightFactor <= 0.0)
			{
				sun_light = -sunlightFactor*30;
			}
			
			sun_angle.pan = (dayTime-28800.0)/(60.0*60.0*12.0)*180.0;
			sun_angle.tilt = abs(ang(asinv(sunlightFactor)))*70.0/180.0+10.0;
			
			d3d_fogcolor1.red = sun_light*255.0/100.0;
			d3d_fogcolor1.green = sun_light*255.0/100.0;
			d3d_fogcolor1.blue = sun_light*255.0/100.0;
		}
		
		/*if (key_l) {
			while(key_l) wait(1);
			shake();
		}*/
		
		
		if (key_esc) {
			while(key_esc) wait(1);
			break;
		}
		wait(1);
	}
	isGameOver = 0;	
	backToMenu();
}
Exemplo n.º 2
0
int main()
{
	srand(time(0));
	ResourceHolder<sf::Font, Fonts::ID> fonts;
	ResourceHolder<sf::Texture, Textures::ID> textures;
	//ResourceHolder<sf::SoundBuffer, Sounds::ID> sounds;
	try
	{
		fonts.load(Fonts::WhiteRabbit, "Assets/whiterabbit.ttf");
		textures.load(Textures::Buttons, "Assets/buttons.png");
		textures.load(Textures::Timtam, "Assets/cmcquiz.png");
	}
	catch(std::runtime_error &e)
	{
		//would be better off using a log file for release code.
		return 1;
	}

	Window mainWindow(sf::Vector2f(800, 600), "Soft Eng Game");

	
	Button mainPlayButton(textures.get(Textures::Buttons), sf::Vector2f(250,  75), sf::Vector2f(25, 500),
		sf::IntRect(0, 0, 250, 75), sf::IntRect(0, 75, 250,  75));
	Button mainQuitButton(textures.get(Textures::Buttons), sf::Vector2f(250,  75), sf::Vector2f(525, 500),
		sf::IntRect(0, 150, 250, 75), sf::IntRect(0, 225, 250,  75));

	//QuizSelect stuff
	Button quizMenuContinue(textures.get(Textures::Buttons), sf::Vector2f(250, 75), sf::Vector2f(250, 500),
		sf::IntRect(0, 300, 250, 75), sf::IntRect(0, 375, 250, 75));

	sf::Text selectQuiz("Select Quiz", fonts.get(Fonts::WhiteRabbit), 24);
	selectQuiz.setPosition(150, 150);
	sf::Text selectTime("Select Time", fonts.get(Fonts::WhiteRabbit), 24);
	selectTime.setPosition(500, 150);

	std::vector<QuestionButton> quizButtons;
	std::vector<std::string> quizFilenames;
	Util::getFilenamesInDir(quizFilenames, "Quizes");
	for(int i = 0; i < quizFilenames.size(); i++)
	{
		quizButtons.push_back(QuestionButton(quizFilenames[i], fonts.get(Fonts::WhiteRabbit), 24, sf::Vector2f(200, 100), sf::Vector2f(100, 200 +( i * 100)), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
	}

	std::vector<QuestionButton> timerButtons;
	timerButtons.push_back(QuestionButton("15", fonts.get(Fonts::WhiteRabbit), 48, sf::Vector2f(200, 100), sf::Vector2f(500, 200), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
	timerButtons.push_back(QuestionButton("25", fonts.get(Fonts::WhiteRabbit), 48, sf::Vector2f(200, 100), sf::Vector2f(500, 300), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
	timerButtons.push_back(QuestionButton("35", fonts.get(Fonts::WhiteRabbit), 48, sf::Vector2f(200, 100), sf::Vector2f(500, 400), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));

	//EndMenu Stuff
	Button endRetry(textures.get(Textures::Buttons), sf::Vector2f(250, 75), sf::Vector2f(25, 500),
		sf::IntRect(0, 450, 250, 75), sf::IntRect(0, 525, 250, 75)); 
	Button endQuit(textures.get(Textures::Buttons), sf::Vector2f(250,  75), sf::Vector2f(525, 500),
		sf::IntRect(0, 150, 250, 75), sf::IntRect(0, 225, 250,  75));

	sf::Vector2f endLogoPos(100, 0);

	std::vector<QuestionButton> endAnswers;
	endAnswers.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 24, sf::Vector2f(640, 120), sf::Vector2f(80, 120), sf::Color(116, 40, 148, 255), sf::Color(116, 40, 148, 255)));
	endAnswers.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 24, sf::Vector2f(640, 120), sf::Vector2f(80, 250), sf::Color::Green, sf::Color::Green));
	endAnswers.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 24, sf::Vector2f(640, 120), sf::Vector2f(80, 380), sf::Color::Red, sf::Color::Red));

	
	


	//MAIN MENU
	Menu startMenu(mainWindow.getWindow(), mainPlayButton, mainQuitButton, 10, 20, 15, 45, textures.get(Textures::Timtam),
		sf::Vector2f(75, 200));
		

	bool play = startMenu.run();
	
	
	while(play)
	{
		play = false;
		//quiz reader, gets a list of quizes from a dir and displays them.
		//pick one and return with that number.

		//pick a filename / quiz file.
		std::string quizFile;

		//QUIZ CHOICE AND TIMER MENU
		QuizMenu quizMenu(mainWindow.getWindow(), quizMenuContinue, selectQuiz, selectTime, quizButtons, timerButtons, 
			textures.get(Textures::Timtam), sf::Vector2f(100, 0));

		int timeToAns = 0;
		timeToAns = quizMenu.run(quizFile);
		//use the quiz at that index.

		if(timeToAns == 15 || timeToAns == 25 || timeToAns == 35)
		{
			//get the list of Q's
			Quiz quiz = Util::getQuiz("Quizes/" + quizFile, timeToAns);

			std::vector<QuestionButton> questionButtons;
			questionButtons.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 18, sf::Vector2f(640, 120), sf::Vector2f(80, 210), sf::Color(116, 40, 148, 255), sf::Color(116, 40, 148, 255)));
			questionButtons.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 18, sf::Vector2f(300, 120), sf::Vector2f(80, 340), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
			questionButtons.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 18, sf::Vector2f(300, 120), sf::Vector2f(80, 470), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
			questionButtons.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 18, sf::Vector2f(300, 120), sf::Vector2f(420, 340), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
			questionButtons.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 18, sf::Vector2f(300, 120), sf::Vector2f(420, 470), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));

			std::vector<AnswerCombo> answers;


		
			Game game(&mainWindow.getWindow(), quiz, questionButtons, 
				sf::Sprite(textures.get(Textures::Timtam), 
				sf::IntRect(0, 0, textures.get(Textures::Timtam).getSize().x, textures.get(Textures::Timtam).getSize().y)),
				fonts.get(Fonts::WhiteRabbit),
				32,
				sf::Color::Black);
			answers = game.run();

			if(answers.size() > 0)
			{
				//takes in answers.
				EndMenu endMenu(&mainWindow.getWindow(), endRetry, endQuit, textures.get(Textures::Timtam), endLogoPos,
					answers, endAnswers);
				play = endMenu.run();
			}
		}
	}
	

	return 0;
}
Exemplo n.º 3
0
void createMenu()
{
	startMenu();
	{
		startSubMenu("View");
		{
			startSubMenu("Presets");
			{
				for (int i = 0; i < PRESET_COUNT; ++i)
				{
					createMenuEntry(getPresetName(i), setPreset, i);
				}
			}
			endSubMenu();
			startSubMenu("Screen Layout");
			{
				createMenuEntry("Side by Side", setScreenLayout, (int)SIDE_BY_SIDE);
				createMenuEntry("Overlay", setScreenLayout, (int)OVERLAY);
			}
			endSubMenu();
			startSubMenu("Depth");
			{
				for (int i = 0; i < NUM_OF_DEPTH_TYPES; ++i)
				{
					createMenuEntry(g_DepthColoring[i], setDepthDrawing, i);
				}
			}
			endSubMenu();
			startSubMenu("Image");
			{
				for (int i = 0; i < NUM_OF_IMAGE_TYPES; ++i)
				{
					createMenuEntry(g_ImageColoring[i], setImageDrawing, i);
				}
			}
			endSubMenu();
			createMenuEntry("Pointer Mode On/Off", togglePointerMode, 0);
			createMenuEntry("Show/Hide Background", toggleBackground, 0);
			createMenuEntry("Show/Hide Help Screen", toggleHelpScreen, 0);
		}
		endSubMenu();
		startSubMenu("Device");
		{
			startSubMenu("Streams");
			{
				startSubMenu("Depth");
				{
					createMenuEntry("On/Off", toggleDepthState, 0);
					startSubMenu("Registration");
					{
						for (int i = 0; i < g_Registration.nValuesCount; ++i)
						{
							unsigned int nValue = g_Registration.pValues[i];
							createMenuEntry(g_Registration.pValueToName[nValue], changeRegistration, nValue);
						}
					}
					endSubMenu();
					startSubMenu("Resolution");
					{
						createMenuEntry("QVGA", setDepthResolution, XN_RES_QVGA);
						createMenuEntry("VGA", setDepthResolution, XN_RES_VGA);
					}
					endSubMenu();
					startSubMenu("FPS");
					{
						createMenuEntry("25", setDepthFPS, 25);
						createMenuEntry("30", setDepthFPS, 30);
						createMenuEntry("60", setDepthFPS, 60);
					}
					endSubMenu();
					createMenuEntry("Reset Cropping", resetDepthCropping, 0);
				}
				endSubMenu();
				startSubMenu("Image");
				{
					createMenuEntry("On/Off", toggleImageState, 0);
					startSubMenu("Resolution");
					{
						createMenuEntry("QVGA", setImageResolution, XN_RES_QVGA);
						createMenuEntry("VGA", setImageResolution, XN_RES_VGA);
						createMenuEntry("SXGA", setImageResolution, XN_RES_SXGA);
						createMenuEntry("UXGA", setImageResolution, XN_RES_UXGA);
					}
					endSubMenu();
					startSubMenu("FPS");
					{
						createMenuEntry("25", setImageFPS, 25);
						createMenuEntry("30", setImageFPS, 30);
						createMenuEntry("60", setImageFPS, 60);
					}
					endSubMenu();
					createMenuEntry("Reset Cropping", resetImageCropping, 0);
				}
				endSubMenu();
				startSubMenu("IR");
				{
					createMenuEntry("On/Off", toggleIRState, 0);
					startSubMenu("Resolution");
					{
						createMenuEntry("QVGA", setIRResolution, XN_RES_QVGA);
						createMenuEntry("VGA", setIRResolution, XN_RES_VGA);
						createMenuEntry("SXGA", setIRResolution, XN_RES_SXGA);
					}
					endSubMenu();
					startSubMenu("FPS");
					{
						createMenuEntry("25", setIRFPS, 25);
						createMenuEntry("30", setIRFPS, 30);
						createMenuEntry("60", setIRFPS, 60);
					}
					endSubMenu();
					createMenuEntry("Reset Cropping", resetIRCropping, 0);
				}
				endSubMenu();
				startSubMenu("Primary Stream");
				{
					for (int i = 0; i < g_PrimaryStream.nValuesCount; ++i)
					{
						createMenuEntry(g_PrimaryStream.pValues[i], changePrimaryStream, i);
					}
				}
				endSubMenu();
			}
			endSubMenu();
            
			createMenuEntry("Mirror", toggleMirror, 0);
		}
		endSubMenu();
		startSubMenu("Capture");
		{
			startSubMenu("Depth Format");
			{
				for (int i = 0; i < g_DepthFormat.nValuesCount; ++i)
				{
					unsigned int nValue = g_DepthFormat.pValues[i];
					createMenuEntry(g_DepthFormat.pIndexToName[i], captureSetDepthFormat, nValue);
				}
			}
			endSubMenu();
			startSubMenu("Image Format");
			{
				for (int i = 0; i < g_ImageFormat.nValuesCount; ++i)
				{
					unsigned int nValue = g_ImageFormat.pValues[i];
					createMenuEntry(g_ImageFormat.pIndexToName[i], captureSetImageFormat, nValue);
				}
			}
			endSubMenu();
			startSubMenu("IR Format");
			{
				for (int i = 0; i < g_IRFormat.nValuesCount; ++i)
				{
					unsigned int nValue = g_IRFormat.pValues[i];
					createMenuEntry(g_IRFormat.pIndexToName[i], captureSetIRFormat, nValue);
				}
			}
			endSubMenu();
			createMenuEntry("Browse", captureBrowse, 0);
			createMenuEntry("Start", captureStart, 0);
			createMenuEntry("Start (5 sec delay)", captureStart, 5);
			createMenuEntry("Restart", captureRestart, 0);
			createMenuEntry("Stop", captureStop, 0);
		}
		endSubMenu();
		startSubMenu("Statistics");
		{
			createMenuEntry("Start Collecting", statisticsStart, 0);
			createMenuEntry("Stop Collecting", statisticsStop, 0);
			createMenuEntry("Clear", statisticsClear, 0);
		}
		endSubMenu();
		startSubMenu("Player");
		{
			createMenuEntry("Pause/Resume", togglePause, 0);
			createMenuEntry("Skip 1 frame forward", seek, 1);
			createMenuEntry("Skip 10 frame forward", seek, 10);
			createMenuEntry("Skip 1 frame backwards", seek, -1);
			createMenuEntry("Skip 10 frame backwards", seek, -10);
		}
		endSubMenu();
		createMenuEntry("Quit", closeSample, ERR_OK);
	}
	endMenu();
}