コード例 #1
0
ファイル: main.cpp プロジェクト: sheshn/EngineS
    void ProcessInput(const Input& input)
    {
        if (input.IsKeyPressed(Key::ESCAPE))
        {
            input.SetCursorVisible(true);
            m_isMouseGrabbed = false;
        }

        if (input.IsKeyDown(Key::W))
        {
            m_cameraTransform->position += m_cameraTransform->GetForward() * m_speed;
        }

        if (input.IsKeyDown(Key::S))
        {
            m_cameraTransform->position += m_cameraTransform->GetBack() * m_speed;
        }

        if (input.IsKeyDown(Key::A))
        {
            m_cameraTransform->position += m_cameraTransform->GetLeft() * m_speed;
        }

        if (input.IsKeyDown(Key::D))
        {
            m_cameraTransform->position += m_cameraTransform->GetRight() * m_speed;
        }

        if (m_isMouseGrabbed)
        {
            glm::vec2 deltaPos = input.GetMousePosition() - m_centerPosition;

            bool rotY = deltaPos.x != 0;
            bool rotX = deltaPos.y != 0;

            if (rotY)
            {
                m_cameraTransform->rotation *= glm::normalize(glm::angleAxis(glm::radians(deltaPos.x * m_sensitivity), m_cameraTransform->GetUp()));
            }

            if (rotX)
            {
                m_cameraTransform->rotation *= glm::normalize(glm::angleAxis(glm::radians(deltaPos.y * m_sensitivity), m_cameraTransform->GetRight()));
            }

            if (rotY || rotX)
            {
                input.SetMousePosition(m_centerPosition);
            }
        }

        if (input.IsMouseButtonPressed(Mouse::BUTTON_LEFT))
        {
            input.SetCursorVisible(false);
            input.SetMousePosition(m_centerPosition);
            m_isMouseGrabbed = true;
        }
    }
コード例 #2
0
	void Player::Update(const Input& input, Game& game, const Map& map, std::list<GameObject*>& objects)
	{
		Move(input, map, objects);
		PickItems(objects);

		if (input.IsKeyDown(bindings_->GetBinding(PlayerAction::DropBomb)))
		{
			if (availableBombs_ > 0)
			{
				bool result = game.CreateBomb(position_.X, position_.Y, power_);
				if (result == true)
					availableBombs_--;
			}
		}

		if (availableBombs_ < maxBombs_)
		{
			bombReload_++;
			if (bombReload_ >= BombReloadTime)
			{
				availableBombs_++;
				bombReload_ = 0;
			}
		}
	}
コード例 #3
0
ファイル: Overlay.cpp プロジェクト: mister51213/EscapeNY
// CODE_CHANGE: Made function parameter const
void Overlay::Update( const Input & User )
{
	if( m_reachedGoal )
	{
		if( User.IsKeyDown( 'Y' ) )
		{
			m_wantsReset = true;
			ResetGoalFlag();
		}
	}
}
コード例 #4
0
ファイル: sfInput.cpp プロジェクト: freemaul/SFML
static VALUE Input_isKeyDown(VALUE vSelf, VALUE vKey) {
	// Get C++ object pointer from vSelf
	Input *pSelf;
	Data_Get_Struct(vSelf, Input, pSelf);
	return pSelf->IsKeyDown((Key::Code)NUM2INT(vKey)) ? Qtrue : Qfalse;
}
コード例 #5
0
ファイル: killerg_nc.cpp プロジェクト: killgxlin/killerg2d
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	Engine::Init();

	Input input;
	input.Init();

	Window window;
	window.Init(800, 600, "killerg2d");

	ResMgr resmgr;
	resmgr.Init();
	
	FrameRate framerate;
	framerate.Init(600);

	Timer timer;
	timer.Init();

	SpiritAnimate spirit;
	spirit.Init("abc.txt");


	int x = 100, y = 100;
	int model = 0;
	while( !input.IsKeyDown(SDLK_ESCAPE) )
	{
		timer.Update();

		input.Update();

		if( input.IsKeyDown(SDLK_LEFT) )
			x-=1;

		if( input.IsKeyDown(SDLK_RIGHT) )
			x+=1;

		if( input.IsKeyDown(SDLK_UP) )
			y-=1;

		if( input.IsKeyDown(SDLK_DOWN) )
			y+=1;

		if( input.IsKeyDown(SDLK_x) )
			spirit.Play();

		if( input.IsKeyDown(SDLK_y) )
			spirit.Stop();

		spirit.Update(timer.GetIntervalF());

		window.Clear();

		spirit.Draw(&window, x, y);

		window.Flush();

		framerate.WaitFrame();
	}

	timer.Destroy();

	framerate.Destroy();

	resmgr.Destroy();

	window.Destroy();

	input.Destroy();


	Engine::Destroy();


	
}
コード例 #6
0
	void Player::Move(const Input& input, const Map& map, const std::list<GameObject*>& objects)
	{
		int xMove = 0;
		int yMove = 0;

		// This method first calculates the player attempted move (xMove and yMove).
		int realSpeed = RealSpeed();
		if (input.IsKeyDown(bindings_->GetBinding(PlayerAction::MoveUp)))
			yMove -= realSpeed;
		if (input.IsKeyDown(bindings_->GetBinding(PlayerAction::MoveLeft)))
			xMove -= realSpeed;
		if (input.IsKeyDown(bindings_->GetBinding(PlayerAction::MoveDown)))
			yMove += realSpeed;
		if (input.IsKeyDown(bindings_->GetBinding(PlayerAction::MoveRight)))
			xMove += realSpeed;
		
		Rectangle newPosition(position_);
		int xMoveUnit = (xMove == 0) ? 0 : xMove / abs(xMove);
		int yMoveUnit = (yMove == 0) ? 0 : yMove / abs(yMove);
		
		bool canMove = true;
		// Then we try to move there by going 1 point by 1 point.
		// We loop while the previous iteration made us move.
		// We try to move on each axis by 1 point as long as we have 'move points' (stored in xMove and yMove) for this axis.
		while(canMove == true)
		{
			canMove = false;
			if (xMove != 0)
			{
				newPosition.X += xMoveUnit;
				if (map.CanMoveTo(this, newPosition, objects))
				{
					xMove -= xMoveUnit;
					canMove = true;
				}
				else
				{
					newPosition.X -= xMoveUnit;
				}
			}
			if (yMove != 0)
			{
				newPosition.Y += yMoveUnit;
				if (map.CanMoveTo(this, newPosition, objects))
				{
					yMove -= yMoveUnit;
					canMove = true;
				}
				else
				{
					newPosition.Y -= yMoveUnit;
				}
			}
		} // At the end of the loop, we reached the closest point to the desired arrival.
		
		// Finally, we simply store the move direction and the new position.
		int xDiff = newPosition.X - position_.X;
		int yDiff = newPosition.Y - position_.Y;

		isMoving_ = (xDiff != 0) || (yDiff != 0);
		if (xDiff < 0)
			direction_ = MoveDirection::Left;
		else if (xDiff > 0)
			direction_ = MoveDirection::Right;
		if (yDiff < 0)
			direction_ = MoveDirection::Up;
		else if (yDiff > 0)
			direction_ = MoveDirection::Down;

		position_ = newPosition;
	}
コード例 #7
0
ファイル: CurrentApp.cpp プロジェクト: Milswanca/IconicEngine
void CurrentApp::Update(float dt)
{
	//Update the camera for movement
	m_camera->Update(dt);
	m_particleEmitter->update(dt);

	glm::vec3 pos = glm::vec3(100 * cos(CurrentTime() * 0.05f) + 150, 80, 100 * sin(CurrentTime() * 0.05f) + 150);
	m_fairyEmitter->SetPosition(pos);
	m_light->SetPosition(pos);

	for (int i = 0; i < 5; ++i)
	{
		m_AI[i]->update(dt);
	}

	Input* IM = Input::GetInstance();

	glm::mat4 cameraWorld = m_camera->GetTransform();
	PxVec3 displacement = PxVec3(0, 0, 0);
	bool notZero = false;
	bool m_canFly = false;

	if (IM->IsKeyDown('W'))
	{
		displacement -= PxVec3(cameraWorld[2].x, (m_canFly ? cameraWorld[2].y : 0), cameraWorld[2].z);
		notZero = true;
	}
	if (IM->IsKeyDown('A'))
	{
		displacement -= PxVec3(cameraWorld[0].x, (m_canFly ? cameraWorld[0].y : 0), cameraWorld[0].z);
		notZero = true;
	}
	if (IM->IsKeyDown('S'))
	{
		displacement += PxVec3(cameraWorld[2].x, (m_canFly ? cameraWorld[2].y : 0), cameraWorld[2].z);
		notZero = true;
	}
	if (IM->IsKeyDown('D'))
	{
		displacement += PxVec3(cameraWorld[0].x, (m_canFly ? cameraWorld[0].y : 0), cameraWorld[0].z);
		notZero = true;
	}

	if (notZero)
		displacement = displacement.getNormalized();

	if (m_verticleSpeed > -10.0f && !m_canFly || m_verticleSpeed > 0 && m_canFly)
		m_verticleSpeed -= dt;

	displacement.y += m_verticleSpeed;

	PxControllerFilters filters;
	g_PlayerController->move(displacement, 0.01f, dt, filters);

	PxExtendedVec3 playerPos = g_PlayerController->getPosition();
	PxExtendedVec3 footPos = g_PlayerController->getFootPosition();
	//I do these calculations individually inside this vector constructor because PxEtendedVec3 doesn't contain some of the necessary operators to do this.
	vec3 endPos = vec3(2.0f * playerPos.x - footPos.x, 2.0f * playerPos.y - footPos.y, 2.0f * playerPos.z - footPos.z);
	m_camera->SetPosition(endPos);

	//Freeze the physics
	if (m_freezePhysics == false) 
	{ 
		UpdatePhysx(dt); 
	}
	else 
	{ 
		UpdatePhysx(0); 
	}

	//Generate new map
	if (Input::GetInstance()->IsKeyPressed('R'))
	{
		m_terrain->GenerateFromPerlin();
		m_terrain->AddPhysicsShape(g_PhysicsScene, g_Physics);
		m_nodeMap->GenerateFromTerrain(m_terrain);
		m_world->Generate();

		for (unsigned int i = 0; i < g_PhysXActors.size(); ++i)
		{
			PxTransform transform(PxVec3(150, 5 + (1.1f * i), 150));
			g_PhysXActors[i]->setGlobalPose(transform);
		}
	}

	if (Input::GetInstance()->IsKeyPressed('N'))
	{
		m_nodeMap->GenerateFromTerrain(m_terrain);
		m_nodeMap->Draw();
	}

	//Freeze Physics
	if (Input::GetInstance()->IsKeyPressed(GLFW_KEY_PAUSE)) { m_freezePhysics = !m_freezePhysics; }

	//Hide/Show Cursor
	if (Input::GetInstance()->IsKeyPressed(KEY_ESCAPE)) { glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); }
	if (Input::GetInstance()->IsMousePressed(MOUSE_BUTTON_LEFT)) { glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); }

	//Deffered/Forward
	if (Input::GetInstance()->IsKeyPressed(KEY_F5)) { m_isDeffered = !m_isDeffered; }
	if (Input::GetInstance()->IsKeyPressed(KEY_F6)) { m_drawDebug = !m_drawDebug; }
}