Beispiel #1
0
void WatchDogClass::CheckControls()
{
	WControls.Update();
	
	SolidSystem = WControls.SolidGrid;
	CanTakeDistance = WControls.TakeDistance;
	
	LastTime = CurrentTime;
	CurrentTime = glfwGetTime();
	DiffTime = CurrentTime - LastTime;
	
	MainMotorsSpeed = WControls.MainMotorsVelocity;
	float speed, aspeed;
	switch (MainMotorsSpeed) 
	{
		case SPEED1:
			speed = Speed1;
			aspeed = Angle1;
			break;
		case SPEED2:
			speed = Speed2;
			aspeed = Angle2;
			break;
		case SPEED3:
			speed = Speed3;
			aspeed = Angle3;
			break;
	}
	
	if(WControls.MovingForward && !FronCollision)
	{
		MainMotorsMove = FORWARD;
		Position += Vector3f(speed * DiffTime, Angle);
	}
	else if(WControls.MovingBackward && !BackCollision)
	{
		MainMotorsMove = BACKWARD;
		Position -= Vector3f(speed * DiffTime, Angle);
	}
	else if(WControls.MovingLeft)
	{
		MainMotorsMove = RIGHT;
		
		if(Angle>360.0f)Angle-=360.0f;
		Angle+=aspeed * DiffTime;
	}
	else if(WControls.MovingRight)
	{
		MainMotorsMove = LEFT;
		
		if(Angle<0.0f)Angle+=360.0f;
		Angle-=aspeed * DiffTime;
	}
	else
		MainMotorsMove = STOP;
	
	
	if(WControls.MovingGripperUp)
		OtherMove = UP_GRIPPER;
	else if(WControls.MovingGripperDown)
		OtherMove = DOWN_GRIPPER;
	else if(WControls.MovingGripperClose)
		OtherMove = CLOSE_GRIPPER;
	else if(WControls.MovingGripperOpen)
		OtherMove = OPEN_GRIPPER;
	else 
		OtherMove = STOP;
	
	
	
	if(WControls.MovingCamUp)
		SlaveMove = CAM2_UP;
	else if(WControls.MovingCamDown)
		SlaveMove= CAM2_DOWN;
	else if(WControls.MovingCamLeft)
		SlaveMove = CAM2_LEFT;
	else if(WControls.MovingCamRight)
		 SlaveMove = CAM2_RIGHT;
	else if(WControls.Laser)
	{
		if(LaserON)
		{
			SlaveMove = LASERS_OFF;
			LaserON = false;
		}
		else 
		{
			SlaveMove = LASERS_ON;
			LaserON = false;
		}
	}
	else 
		SlaveMove = IDLE;

	if(GetKeyNewpress('P') && (USB->Error || !USB->HIDisOpen))
		USB->HIDReOpen();
	
	SendInstruction();
}
Beispiel #2
0
int main()
{
	//gamestates
	Menu* menu;
	PlayGame* play;
	Pause* pause;
	Splash* splash;
	//ScoreScreen* controls;
	Controls* controls;
	ScoreScreen* scoreScreen;

	// Create the main window 
	//Screen dimension constants

	
	sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "Space Wars!");
	
	/*Initialsie the game modes*/
	menu = new Menu(SCREEN_WIDTH, SCREEN_HEIGHT);
	play = new PlayGame(SCREEN_WIDTH, SCREEN_HEIGHT);
	pause = new Pause(SCREEN_WIDTH, SCREEN_HEIGHT);
	splash = new Splash(SCREEN_WIDTH, SCREEN_HEIGHT);
	controls = new Controls(SCREEN_WIDTH, SCREEN_HEIGHT);
	scoreScreen = new ScoreScreen(SCREEN_WIDTH, SCREEN_HEIGHT);

	//clock & frame rate
	sf::Clock mclock;
	sf::Time timeSinceLastUpdate;
	window.setFramerateLimit(60);
	// Start game loop 
	while (window.isOpen())
	{
		//get time between frames
		timeSinceLastUpdate = mclock.getElapsedTime();
		float time = timeSinceLastUpdate.asSeconds();//get update time
		mclock.restart();


		// Process events 
		sf::Event Event;
		while (window.pollEvent(Event))
		{
			// Close window : exit 
			if (Event.type == sf::Event::Closed)
				window.close();

			// Escape key : exit 
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
				window.close();
		}
		//updates
		switch (GameStateController::GetInstance()->getGameState())
		{
		case GameStateController::MENU:
			menu->Update(time, window, Event);
			break;
		case GameStateController::PLAY:
			play->Update(time, timeSinceLastUpdate);
			break;
		case GameStateController::CREDITS:
			break;
		case GameStateController::PAUSE:
			break;
		case GameStateController::SPLASH:
			break;
		case GameStateController::SCORESCREEN:
			scoreScreen->Update();
			break;
		case GameStateController::CONTROLS:
			controls->Update(time, window, Event);
			break;
		}//end switch

		//prepare frame
		window.clear(sf::Color::White);

		//draw
		switch (GameStateController::GetInstance()->getGameState())
		{
		case GameStateController::MENU:
			menu->Draw(window);
			break;
		case GameStateController::PLAY:
			play->Draw(window);
			break;
		case GameStateController::CREDITS:
			break;
		case GameStateController::PAUSE:
			break;
		case GameStateController::SPLASH:
			break;
		case GameStateController::SCORESCREEN:
			scoreScreen->Draw(window);
			break;
		case GameStateController::CONTROLS:
			controls->Draw(window);
			break;
		}//end switch


		// Finally, display rendered frame on screen 
		window.display();
	} //loop back for next frame
	
	//delete pointers
	delete menu;
	delete play;
	delete pause;
	delete splash;
	delete controls;

	return EXIT_SUCCESS;
}