Exemple #1
0
void InputManager::handleInput()
{
    // Events
    SDL_Event event;
    while (SDL_PollEvent(&event))
    {
        bool used = false;

        // Key press events
        if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
            used = handleKeyboardInput(event);
            
        if (event.type == SDL_JOYAXISMOTION || event.type == SDL_JOYBALLMOTION ||
            event.type == SDL_JOYHATMOTION || event.type == SDL_JOYBUTTONDOWN ||
            event.type == SDL_JOYBUTTONUP)
            handleJoystickInput(event);

        // Quit event
        else if (event.type == SDL_QUIT)
            stateManager->setState(QUIT_STATE);

        // Push input to GUI when not used
        if (!used)
            forwardInput(event);
    }
}
Exemple #2
0
void gameloop(int randTiles[])
{
	float frame = 0.0;
	int dir = 0;
	
	//game_input->clearKeys();
	
	while (gameIsRunning)
	{
		
		game_timer.start();

		/**
		game_input->readInput();

		if (game_input->windowClosed())
		{
			gameIsRunning = false;
		}
		**/


		while( SDL_PollEvent( &game_event ) )
        {
            //Handle events for the dot
            handleKeyboardInput();

            //If the user has Xed out the window
            if( game_event.type == SDL_QUIT )
            {
                //Quit the program
                gameIsRunning = false;
            }
        }
        
        p1.moveChar();


		

		dir = p1.getDir() * 32;

		if (p1.isWalk())
		{
			frame += 0.05;
			if (frame > 3.0)
			{
				frame = 0.0;
			}
		}
		else 
		{
			frame = 0.0;
		}
		

		game_graphics->beginScene();
		drawGrass(randTiles);

		drawOverlay();

		game_graphics->drawSprite(p1.playerBMP, (int)frame * 32, dir, p1.getX(), p1.getY(), 32, 32);

		//showXY();
		
		game_graphics->drawSprite(sepBar, 0, 0, 640, 0, 7, 480);
	    
	    drawStats();
	    
		game_graphics->endScene();

		if (inMenu)
		{
			gameMenu->displayMenu();
			
		}

		
		//Cap the frame rate
        if( game_timer.get_ticks() < 1000 / FRAMES_PER_SECOND )
        {
            SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - game_timer.get_ticks() );
        }
		
		
		
	}
}
Exemple #3
0
void InputOptionsState::step_impl()
{
	IMGUI& imgui = IMGUI::getSingleton();
	imgui.doCursor();
	imgui.doImage(GEN_ID, Vector2(400.0, 300.0), "background");
	imgui.doOverlay(GEN_ID, Vector2(0.0, 0.0), Vector2(800.0, 600.0));

	std::string lastActionKey = InputManager::getSingleton()->getLastActionKey();

	// left player side:
	imgui.doText(GEN_ID, Vector2(34.0, 10.0), TextManager::OP_LEFT_PLAYER);

	if (imgui.doButton(GEN_ID, Vector2(80.0, 60.0), getDeviceName(mLeftBlobbyDevice)))
	{
		if (mLeftBlobbyDevice == "mouse")
		{
			mLeftBlobbyDevice = "keyboard";
		}
		else if (mLeftBlobbyDevice == "keyboard")
		{
			mLeftBlobbyDevice = "joystick";
		}
		else if (mLeftBlobbyDevice == "joystick")
		{
			if (mRightBlobbyDevice != "mouse")
			{
				mLeftBlobbyDevice = "mouse";
			}
			else
			{
				mLeftBlobbyDevice = "keyboard";
			}
		}
	}
	//if mouse device is selected:
	if (mLeftBlobbyDevice == "mouse")
	{
		handleMouseInput(0, mLeftBlobbyMouseJumpbutton);
	}
	if ((mLeftBlobbyMouseJumpbutton == -2) && (InputManager::getSingleton()->getLastMouseButton() == -1))
		mLeftBlobbyMouseJumpbutton = -1;
	//if keyboard device is selected:
	if (mLeftBlobbyDevice == "keyboard")
	{
		handleKeyboardInput(0, lastActionKey, mLeftBlobbyKeyboard);
	}
	//if joystick device is selected:
	if (mLeftBlobbyDevice == "joystick")
	{
		handleJoystickInput(0, mLeftBlobbyJoystick);
	}

	//right player side:
	imgui.doText(GEN_ID, Vector2(434.0, 10.0), TextManager::OP_RIGHT_PLAYER);

	if (imgui.doButton(GEN_ID, Vector2(480.0, 60.0), getDeviceName(mRightBlobbyDevice)))
	{
		if (mRightBlobbyDevice == "mouse")
		{
			mRightBlobbyDevice = "keyboard";
		}
		else if (mRightBlobbyDevice == "keyboard")
		{
			mRightBlobbyDevice = "joystick";
		}
		else if (mRightBlobbyDevice == "joystick")
		{
			if (mLeftBlobbyDevice != "mouse")
			{
				mRightBlobbyDevice = "mouse";
			}
			else
			{
				mRightBlobbyDevice = "keyboard";
			}
		}
	}
	//if mouse device is selected:
	if (mRightBlobbyDevice == "mouse")
	{
		handleMouseInput(400, mRightBlobbyMouseJumpbutton);
	}
	if ((mRightBlobbyMouseJumpbutton == -2) && (InputManager::getSingleton()->getLastMouseButton() == -1))
		mRightBlobbyMouseJumpbutton = -1;
	//if keyboard device is selected:
	if (mRightBlobbyDevice == "keyboard")
	{
		handleKeyboardInput(400, lastActionKey, mRightBlobbyKeyboard);
	}
	//if joystick device is selected:
	if (mRightBlobbyDevice == "joystick")
	{
		handleJoystickInput(400, mRightBlobbyJoystick);
	}

	//check if a capture window is open, to set all widgets inactive:
	if (mLeftBlobbyKeyboard[IA_LEFT] != "" && mLeftBlobbyKeyboard[IA_RIGHT] != "" && mLeftBlobbyKeyboard[IA_JUMP] != "" && mLeftBlobbyJoystick[IA_LEFT] != "" && mLeftBlobbyJoystick[IA_RIGHT] != "" && mLeftBlobbyJoystick[IA_JUMP] != "" && mLeftBlobbyMouseJumpbutton != -1 && mRightBlobbyKeyboard[IA_LEFT] != "" && mRightBlobbyKeyboard[IA_RIGHT] != "" && mRightBlobbyKeyboard[IA_JUMP] != "" && mRightBlobbyJoystick[IA_LEFT] != "" && mRightBlobbyJoystick[IA_RIGHT] != "" && mRightBlobbyJoystick[IA_JUMP] != "" && mRightBlobbyMouseJumpbutton != -1)
	{
		imgui.doCursor(true);
		imgui.doInactiveMode(false);
	}
	else
	{
		imgui.doInactiveMode(true);
		imgui.doCursor(false);
	}

	//Capture dialogs:
	getMouseInput(mLeftBlobbyMouseJumpbutton, TextManager::OP_JUMPING);

	getKeyboardInput(mLeftBlobbyKeyboard[IA_LEFT], TextManager::OP_MOVING_LEFT, lastActionKey);
	getKeyboardInput(mLeftBlobbyKeyboard[IA_RIGHT], TextManager::OP_MOVING_RIGHT, lastActionKey);
	getKeyboardInput(mLeftBlobbyKeyboard[IA_JUMP], TextManager::OP_JUMPING, lastActionKey);

	getJoystickInput(mLeftBlobbyJoystick[IA_LEFT], TextManager::OP_MOVING_LEFT);
	getJoystickInput(mLeftBlobbyJoystick[IA_RIGHT], TextManager::OP_MOVING_RIGHT);
	getJoystickInput(mLeftBlobbyJoystick[IA_JUMP], TextManager::OP_JUMPING);

	getMouseInput(mRightBlobbyMouseJumpbutton, TextManager::OP_JUMPING);

	getKeyboardInput(mRightBlobbyKeyboard[IA_LEFT], TextManager::OP_MOVING_LEFT, lastActionKey);
	getKeyboardInput(mRightBlobbyKeyboard[IA_RIGHT], TextManager::OP_MOVING_RIGHT, lastActionKey);
	getKeyboardInput(mRightBlobbyKeyboard[IA_JUMP], TextManager::OP_JUMPING, lastActionKey);

	getJoystickInput(mRightBlobbyJoystick[IA_LEFT], TextManager::OP_MOVING_LEFT);
	getJoystickInput(mRightBlobbyJoystick[IA_RIGHT], TextManager::OP_MOVING_RIGHT);
	getJoystickInput(mRightBlobbyJoystick[IA_JUMP], TextManager::OP_JUMPING);

	if (imgui.doButton(GEN_ID, Vector2(224.0, 530.0), TextManager::LBL_OK))
	{
		save();
		switchState(new OptionState());
	}
	if (imgui.doButton(GEN_ID, Vector2(424.0, 530.0), TextManager::LBL_CANCEL))
	{
		switchState(new OptionState());
	}
}
Exemple #4
0
void InGame::run()
{
	sf::RenderWindow& window = config.window;
	window.setFramerateLimit(60);

	while (window.isOpen())
	{
		//input & update phase
		systemPtr->updateQuadTree();
		networkPtr->update();

		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();

			if (event.type == sf::Event::KeyPressed)
			{
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape) && !systemPtr->isInBattle())
                    interfacePtr->switchInGaemMenu();
                
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
                    systemPtr->interact();
			}

			interfacePtr->updateGUI(event);
		}

		interfacePtr->updateMiniMap();

		//handle keyboard input, move character, interact...etc
		if (systemPtr->isInBattle())
        {
            handleKeyboardInput_battle();
            //if the battle is over, delete the battle
            if(systemPtr->isBattleOver())
            {
                systemPtr->deleteBattle();
            }
        }
		else if (interfacePtr->isDisplayingInGameMenu())
		{
			handleKeybardInput_InGameMenu();
		}
		else if(interfacePtr->isDisplayingDialogue())
		{
		}
        else
        {
            handleKeyboardInput();
        }

		//if this is server, send status update to client
		if (networkPtr->isServer())
			server_sendUpdate();
		else //if this is client, send status update to server
			client_sendUpdate();

		config.cursor.update();

		//rendering phase
		window.clear();
		interfacePtr->draw();
		//window.draw(config.cursor);
		window.display();
	}
}