Example #1
0
void 
InputHandler::ProcessInput(Game& game)
{
	// Ex006.2: Receive Input Events below...
	SDL_Event e;
	while (SDL_PollEvent(&e) != 0)
	{
		if (e.type == SDL_QUIT)
		{
			game.Quit();
		}
		else if (e.type == SDL_JOYBUTTONDOWN)
		{
			// Ex006.4: Tell the game to fire a player bullet...
			if (e.jbutton.button == 10)
			{
				game.FireSpaceShipBullet();
			}


			// Ex006.2: Tell the game to move the space ship left...
			if (e.jbutton.button == 2) { 
				game.MoveSpaceShipLeft();
			}

			// Ex006.2: Tell the game to move the space ship right...
			if (e.jbutton.button == 3) {
				game.MoveSpaceShipRight();
			}

			
		}
		else if (e.type == SDL_JOYBUTTONUP)
		{
			if (e.jbutton.button == 2 || e.jbutton.button == 3) {
				game.StopSpaceShip();
			}
		}
		
		


	}
}
void 
InputHandler::ProcessButtons(Game& game)
{
	// Ex006.2: Receive Input Events below...
	SDL_Event e;
	float angle = 0;
	while (SDL_PollEvent(&e) != 0)
	{
		if (e.type == SDL_QUIT)
		{
			game.Quit();
		}
		else if (e.type == SDL_JOYBUTTONDOWN && game.getGameOver())
		{
			// shoot from A button, south
			if (e.jbutton.button == 10)
			{
				game.FireSpaceShipBullet(2, 0, SDL_FLIP_VERTICAL);
				
			}

			// shoot from B button, east
			if (e.jbutton.button == 11)
			{
				game.FireSpaceShipBullet(4, 90, SDL_FLIP_NONE);

			}

			// shoot from X button, west
			if (e.jbutton.button == 12)
			{
				game.FireSpaceShipBullet(3, -90, SDL_FLIP_NONE);

			}

			// shoot from Y button, north
			if (e.jbutton.button == 13)
			{
				game.FireSpaceShipBullet(1, 0, SDL_FLIP_NONE);

			}

			//move space ship down
			if (e.jbutton.button == 1)
			{
				game.MoveSpaceShipDown();

			}
			if (e.jbutton.button == 0)
			{
				game.MoveSpaceShipUp();

			}
			// Ex006.2: Tell the game to move the space ship left...
			if (e.jbutton.button == 3)
			{
				game.MoveSpaceShipRight();
			}
			// Ex006.2: Tell the game to move the space ship right...
			if (e.jbutton.button == 2)
			{
				game.MoveSpaceShipLeft();
			}

			if (e.jbutton.button == 6)
			{
				game.Quit();
			}
			
		}
		else if (e.type == SDL_JOYBUTTONUP && game.getGameOver())
		{
			if (e.jbutton.button == 3 || e.jbutton.button == 2 || e.jbutton.button == 1 || e.jbutton.button == 0)
			{
				game.StopMovement();
			}
		}
		else if (game.getGameOver() == false)
		{
			if (e.jbutton.button == 5)
			{
				game.setGameOver(true);
				game.ResetPlayer();
			}
		}
	}
}
Example #3
0
void 
InputHandler::ProcessInput(Game& game)
{
	// Receive Input Events below...
	SDL_Event e;

	while (SDL_PollEvent(&e) != 0)
	{
		if (e.type == SDL_QUIT)
		{
			game.Quit();
		}
		else if (e.type == SDL_JOYBUTTONDOWN)
		{
			switch(e.jbutton.button)
			{
			case A:
				{
					game.FireSpaceShipBullet();
				}
				break;
			case DPADLEFT:
				{
					game.MoveSpaceShipLeft();
				}
				break;
			case DPADRIGHT:
				{
					game.MoveSpaceShipRight();
				}
				break;
			}		
		}
		else if (e.type == SDL_JOYBUTTONUP)
		{
			switch(e.jbutton.button)
			{
			case DPADLEFT:
			case DPADRIGHT:
				{
					game.StopSpaceShipMovement();
				}
				break;
			}
		}
		else if (e.type == SDL_KEYDOWN)
		{
			switch (e.key.keysym.scancode)
			{
				case SDL_SCANCODE_A:
				{
					// Move left
					game.MoveSpaceShipLeft();
				}
				break;
				case SDL_SCANCODE_D:
				{
					// Move Right
					game.MoveSpaceShipRight();
				}
				break;
				case SDL_SCANCODE_SPACE:
				{
					game.FireSpaceShipBullet();
				}
				break;
				case SDL_SCANCODE_W:
				{
					//jump
					game.Jump();
				}
				break;
				case SDL_SCANCODE_P:
				{
					//spawn enemy for debugging
					game.SpawnEnemy(36 * 15, 36 * 14);
				}
				break;
			}
		}
		else if(e.type == SDL_KEYUP)
		{
			switch(e.key.keysym.scancode)
			{
			case SDL_SCANCODE_A:
			case SDL_SCANCODE_D:
			
				{
					// Move Right
				game.StopSpaceShipMovement();
				}
				break;
			}
		}


	}
}