Esempio n. 1
0
void update(double dt)
{
	// get the delta time
	elapsedTime += dt;
	deltaTime = dt;

	//get score (easy, no powerup)
	if (checker[3] == 0 && check == 0)
	{
		score += dt;
	}
	//(easy, powerup)
	else if (checker[3] == 0 && check == 1)
	{
		score += dt + 0.2;
	}
	//(hard, no powerup)
	else if (checker[3] == 1 && check == 0)
	{
		score += dt + 1;
	}
	//(hard,powerup)
	else 
	{
		score += dt + 1.2;
	}


	// Updating the location of the character based on the key press
	if (checker[3] == 0)
	{
		if (checker[4] == 0)
		{
			if (keyPressed[K_UP] && charLocation.Y > 0)
			{
				Beep(1440, 30);
				charLocation.Y--;

				//prevent character from moving to location 0,0
				if (charLocation.Y == 0 && charLocation.X == 0)
				{
					charLocation.Y++;
				}
			}
			if (keyPressed[K_LEFT] && charLocation.X > 0)
			{
				Beep(1440, 30);
				charLocation.X--; 

				if (charLocation.Y == 0 && charLocation.X == 0)
				{
					charLocation.X++;
				}
			}
			if (keyPressed[K_DOWN] && charLocation.Y < consoleSize.Y - 1)
			{
				Beep(1440, 30);
				charLocation.Y++; 
			}
			if (keyPressed[K_RIGHT] && charLocation.X < consoleSize.X - 1)
			{
				Beep(1440, 30);
				charLocation.X++; 
			}
		}

		else
		{
			//allows character to move twice as fast
			if (keyPressed[K_UP] && charLocation.Y > 0)
			{
				Beep(1440, 30);
				charLocation.Y-=2; 
			}
			if (keyPressed[K_LEFT] && charLocation.X > 0)
			{
				Beep(1440, 30);
				charLocation.X-=2; 
			}
			if (keyPressed[K_DOWN] && charLocation.Y < consoleSize.Y - 1)
			{
				Beep(1440, 30);
				charLocation.Y+=2; 
			}
			if (keyPressed[K_RIGHT] && charLocation.X < consoleSize.X - 1)
			{
				Beep(1440, 30);
				charLocation.X+=2; 
			}
		}

	}

	//prevents player from moving
	else
	{
		counter[21] += 1;

		if (counter[21] >= 14)
		{
			counter[21] -= counter[21];
			checker[3] = 0;
		}
	}

		//for the dynamic movement of tail1
		if( ((tails[0].loc1.Y - tails[0].loc2.Y) != 18) && (tails[0].loc1.X == tails[0].loc2.X))
		{
			tails[0].loc1.Y++;
		}
		else if ( ((tails[0].loc1.X - tails[0].loc2.X) != 46) && (tails[0].loc1.Y != tails[0].loc2.Y))
		{
			tails[0].loc1.X +=2;
		}
		else if (tails[0].loc1.Y != tails[0].loc2.Y)
		{
			tails[0].loc1.Y--;
		}
		else if (tails[0].loc1.X != tails[0].loc2.X)
		{
			tails[0].loc1.X -=2;
		}

	
		//for the dynamic movement of tail2
		if (check == 1)
		{
			if( ((tails[1].loc1.Y + tails[1].loc2.Y) != 20) && (tails[1].loc1.X == tails[1].loc2.X))
			{
				tails[1].loc1.Y--;
			}
			else if ( ((tails[1].loc1.X + tails[1].loc2.X) != 46) && (tails[1].loc1.Y != tails[1].loc2.Y))
			{
				tails[1].loc1.X-=2;
			}
			else if (tails[1].loc1.Y != tails[1].loc2.Y)
			{
				tails[1].loc1.Y++;
			}
			else if (tails[1].loc1.X != tails[1].loc2.X)
			{
				tails[1].loc1.X+=2;
			}
		}



	if (checker[4] == 0)
	{
		//set conditions of losing life (tail)
		for (int i = 0; i < tailnumber; ++i)
		{
			damagetail (tails[i]); 
		}

		//set conditions of losing life (paw)
		for (int i = 0; i < pawnumber; ++i)
		{
			damagepaw (paws[i]);
		}
	}

	//prevents player from losing life
	else
	{
		counter[22] += 1;

		if (counter[22] >= 20)
		{
			counter[22] -= counter[22];
			checker[4] = 0;
		}
	}


	//set random paw spawn location
	int pawC1 = 0, pawC2 = 1, pawC3 = 2;
	for (int i = 0; i < pawnumber; ++i)
	{
		paw(counter[pawC1], counter[pawC2], counter[pawC3], paws[i]);

		pawC1 += 3;
		pawC2 += 3;
		pawC3 += 3;
	}
	
	//set random item spawn location
	int itemC1 = 12, itemC2 = 13, itemC3 = 14;
	for (int i = 0; i < 3; ++i)
	{
		pickup (counter[itemC1], counter[itemC2], counter[itemC3], pickups[i]);

		itemC1 += 3;
		itemC2 += 3;
		itemC3 += 3;
	}

	//cause item effect
	int pickC1 = 12, pickC2 = 13, pickC3 = 14;
	for (int i = 0; i < 3; ++i)
	{
		pickupeffect (counter[pickC1], counter[pickC2], counter[pickC3], pickups[i]);

		pickC1 += 3;
		pickC2 += 3;
		pickC3 += 3;
	}

	//cause deadspace to alter movement
	if (check == 0)
	{
		deadspace_effect (deadspace[2]);
	}

	else
	{
		deadspace_effect (deadspace[0]);
		deadspace_effect (deadspace[1]);
	}
	


	// return to menu if player hits the escape key
	if (keyPressed[K_ESCAPE])
	{
		Beep (1350,150);
		gotoXY (0,25);
		colour (0x02);
		cout << "Returning to main menu . . ." << endl;
		system ("pause");
		init();
		gameLoop();
	}
}
Esempio n. 2
0
	// Aligning a face to a common reference frame
	void AlignFaceMask(cv::Mat& aligned_face, const cv::Mat& frame, const LandmarkDetector::CLNF& clnf_model, const cv::Mat_<int>& triangulation, bool rigid, double sim_scale, int out_width, int out_height)
	{
		// Will warp to scaled mean shape
		cv::Mat_<double> similarity_normalised_shape = clnf_model.pdm.mean_shape * sim_scale;
	
		// Discard the z component
		similarity_normalised_shape = similarity_normalised_shape(cv::Rect(0, 0, 1, 2*similarity_normalised_shape.rows/3)).clone();

		cv::Mat_<double> source_landmarks = clnf_model.detected_landmarks.reshape(1, 2).t();
		cv::Mat_<double> destination_landmarks = similarity_normalised_shape.reshape(1, 2).t();

		// Aligning only the more rigid points
		if(rigid)
		{
			extract_rigid_points(source_landmarks, destination_landmarks);
		}

		cv::Matx22d scale_rot_matrix = LandmarkDetector::AlignShapesWithScale(source_landmarks, destination_landmarks);
		cv::Matx23d warp_matrix;

		warp_matrix(0,0) = scale_rot_matrix(0,0);
		warp_matrix(0,1) = scale_rot_matrix(0,1);
		warp_matrix(1,0) = scale_rot_matrix(1,0);
		warp_matrix(1,1) = scale_rot_matrix(1,1);

		double tx = clnf_model.params_global[4];
		double ty = clnf_model.params_global[5];

		cv::Vec2d T(tx, ty);
		T = scale_rot_matrix * T;

		// Make sure centering is correct
		warp_matrix(0,2) = -T(0) + out_width/2;
		warp_matrix(1,2) = -T(1) + out_height/2;

		cv::warpAffine(frame, aligned_face, warp_matrix, cv::Size(out_width, out_height), cv::INTER_LINEAR);

		// Move the destination landmarks there as well
		cv::Matx22d warp_matrix_2d(warp_matrix(0,0), warp_matrix(0,1), warp_matrix(1,0), warp_matrix(1,1));
		
		destination_landmarks = cv::Mat(clnf_model.detected_landmarks.reshape(1, 2).t()) * cv::Mat(warp_matrix_2d).t();

		destination_landmarks.col(0) = destination_landmarks.col(0) + warp_matrix(0,2);
		destination_landmarks.col(1) = destination_landmarks.col(1) + warp_matrix(1,2);
		
		// Move the eyebrows up to include more of upper face
		destination_landmarks.at<double>(0,1) -= 15; 
		destination_landmarks.at<double>(16,1) -= 15; 

		destination_landmarks.at<double>(17,1) -= 7; 
		destination_landmarks.at<double>(18,1) -= 7; 
		destination_landmarks.at<double>(19,1) -= 7; 
		destination_landmarks.at<double>(20,1) -= 7; 
		destination_landmarks.at<double>(21,1) -= 7; 
		destination_landmarks.at<double>(22,1) -= 7; 
		destination_landmarks.at<double>(23,1) -= 7; 
		destination_landmarks.at<double>(24,1) -= 7; 
		destination_landmarks.at<double>(25,1) -= 7; 
		destination_landmarks.at<double>(26,1) -= 7; 

		destination_landmarks = cv::Mat(destination_landmarks.t()).reshape(1, 1).t();

		LandmarkDetector::PAW paw(destination_landmarks, triangulation, 0, 0, aligned_face.cols-1, aligned_face.rows-1);
		
		// Mask each of the channels (a bit of a roundabout way, but OpenCV 3.1 in debug mode doesn't seem to be able to handle a more direct way using split and merge)
		vector<cv::Mat> aligned_face_channels(aligned_face.channels());
		
		for (int c = 0; c < aligned_face.channels(); ++c)
		{
			cv::extractChannel(aligned_face, aligned_face_channels[c], c);
		}

		for(size_t i = 0; i < aligned_face_channels.size(); ++i)
		{
			aligned_face_channels[i] = aligned_face_channels[i].mul(paw.pixel_mask);
		}

		if(aligned_face.channels() == 3)
		{
			cv::Mat planes[] = { aligned_face_channels[0], aligned_face_channels[1], aligned_face_channels[2] };
			cv::merge(planes, 3, aligned_face);
		}
		else
		{
			aligned_face = aligned_face_channels[0];
		}
	}
Esempio n. 3
-1
	// Aligning a face to a common reference frame
	void AlignFaceMask(cv::Mat& aligned_face, const cv::Mat& frame, const CLMTracker::CLM& clm_model, const Mat_<int>& triangulation, bool rigid, double sim_scale, int out_width, int out_height)
	{
		// Will warp to scaled mean shape
		Mat_<double> similarity_normalised_shape = clm_model.pdm.mean_shape * sim_scale;
	
		// Discard the z component
		similarity_normalised_shape = similarity_normalised_shape(Rect(0, 0, 1, 2*similarity_normalised_shape.rows/3)).clone();

		Mat_<double> source_landmarks = clm_model.detected_landmarks.reshape(1, 2).t();
		Mat_<double> destination_landmarks = similarity_normalised_shape.reshape(1, 2).t();

		// Aligning only the more rigid points
		if(rigid)
		{
			extract_rigid_points(source_landmarks, destination_landmarks);
		}

		Matx22d scale_rot_matrix = CLMTracker::AlignShapesWithScale(source_landmarks, destination_landmarks);
		Matx23d warp_matrix;

		warp_matrix(0,0) = scale_rot_matrix(0,0);
		warp_matrix(0,1) = scale_rot_matrix(0,1);
		warp_matrix(1,0) = scale_rot_matrix(1,0);
		warp_matrix(1,1) = scale_rot_matrix(1,1);

		double tx = clm_model.params_global[4];
		double ty = clm_model.params_global[5];

		Vec2d T(tx, ty);
		T = scale_rot_matrix * T;

		// Make sure centering is correct
		warp_matrix(0,2) = -T(0) + out_width/2;
		warp_matrix(1,2) = -T(1) + out_height/2;

		cv::warpAffine(frame, aligned_face, warp_matrix, Size(out_width, out_height), INTER_LINEAR);

		// Move the destination landmarks there as well
		Matx22d warp_matrix_2d(warp_matrix(0,0), warp_matrix(0,1), warp_matrix(1,0), warp_matrix(1,1));
		
		destination_landmarks = Mat(clm_model.detected_landmarks.reshape(1, 2).t()) * Mat(warp_matrix_2d).t();

		destination_landmarks.col(0) = destination_landmarks.col(0) + warp_matrix(0,2);
		destination_landmarks.col(1) = destination_landmarks.col(1) + warp_matrix(1,2);
		
		// Move the eyebrows up to include more of upper face
		destination_landmarks.at<double>(0,1) -= 15; 
		destination_landmarks.at<double>(16,1) -= 15; 

		destination_landmarks.at<double>(17,1) -= 7; 
		destination_landmarks.at<double>(18,1) -= 7; 
		destination_landmarks.at<double>(19,1) -= 7; 
		destination_landmarks.at<double>(20,1) -= 7; 
		destination_landmarks.at<double>(21,1) -= 7; 
		destination_landmarks.at<double>(22,1) -= 7; 
		destination_landmarks.at<double>(23,1) -= 7; 
		destination_landmarks.at<double>(24,1) -= 7; 
		destination_landmarks.at<double>(25,1) -= 7; 
		destination_landmarks.at<double>(26,1) -= 7; 

		destination_landmarks = Mat(destination_landmarks.t()).reshape(1, 1).t();		

		CLMTracker::PAW paw(destination_landmarks, triangulation, 0, 0, aligned_face.cols-1, aligned_face.rows-1);
		
		vector<Mat> aligned_face_channels(aligned_face.channels());
		
		cv::split(aligned_face, aligned_face_channels);

		for(size_t i = 0; i < aligned_face_channels.size(); ++i)
		{
			aligned_face_channels[i] = aligned_face_channels[i].mul(paw.pixel_mask);
		}

		cv::merge(aligned_face_channels, aligned_face);

	}