Ejemplo n.º 1
0
/**
 * Moves a board in all the possible directions and adds the new states to the queue.
 * @param board The board to be moved.
 * @param queue The priority queue holding all board states.
 */
std::pair<bool, Board*> MoveAllDirectionsAndAddToQueue(Board* &board,
    std::priority_queue<Board*, std::vector<Board*>, QueueCompareClass> &queue) {

    // For all 4 directions, try to move in that direction.
    for (unsigned int i = 0; i < 4; ++i) {
        int direction = DIRECTIONS[i];
        // If the board can move in that direction, then move it.
        // If it can't, then do nothing.
        if (CanMoveInDirection(direction, board)) {
            // Create a copy of the current board, and move the copy.
            Board* new_board = new Board(*board);
            // Actually move the board.
            MoveInDirection(direction, new_board);
            // Set the previous board state.
            new_board->SetPreviousState(board);
            // Check if the board is at the goal state, if so then stop.
            if (new_board->IsAtGoalState()) {
                return std::make_pair(true, new_board);
            }
            // Do not add the new state to the queue if the new board is the
            // same as the previous state.
            if (board->GetPreviousState() &&
                *(board->GetPreviousState()) == *new_board) {
                delete new_board;
                new_board = NULL;
            } else {
                queue.push(new_board);
            }
        }
    }

    return std::make_pair(false, reinterpret_cast<Board*>(NULL));
}
Ejemplo n.º 2
0
void Worm::Update(float dt)
{
   g_a->SetColor(0,1,0,1);
   g_a->SetSize(0.125f);
   Vector2 targetPos( 
      m_planetOrbit == NULL ? Vector2(0,0) : 
         Vector2(m_planetOrbit->GetPosition().X, 
                 m_planetOrbit->GetPosition().Y) + g_orbitPointVec);
   if(m_planetOrbit != NULL)
      g_a->SetPosition( targetPos );
   theWorld.Add(g_a,10);

   switch(g_moveState)
   {      
   case PlanetOrbit:
      {
         assert(m_planetOrbit != NULL);
         float angle = PIOver4 * dt * m_speed / m_planetOrbit->GetSize().X;
         g_orbitPointVec = Vector2::Rotate(g_orbitPointVec, angle);
         MoveInDirection(targetPos - m_head->GetPosition(), m_speed * dt);
      }
      break;
   case PlanetClick: 
      {
         MoveInDirection(targetPos - m_head->GetPosition(), m_speed * dt);
         if(m_planetOrbit->GetPosition().X - GetPosition().X <= 0.1 &&
            m_planetOrbit->GetPosition().Y - GetPosition().Y <= 0.1 )
            g_moveState = PlanetOrbit;
      }
      break;
   case Mouse:
      {
         MoveInDirection(MathUtil::ScreenToWorld(g_screenCoords) - 
                            m_head->GetPosition(),
                         m_speed * dt);
      }
      break;
   case NotMoving: break;
   default: assert(!"shouldn't get here");
   }
}
Ejemplo n.º 3
0
void PacmanEnemy::HandleMovementFinished(int iCurrentTime)
{
    int iAIDir = m_pAI->GetMove(this, m_iMapX, m_iMapY);

    if (iAIDir != -1)
    {
        if (rand()%3 == 0 && CanMoveInDirection(iAIDir))
            m_iDir = iAIDir;
        MoveInDirection(m_iDir, iCurrentTime);
    }
    else
    {
        // Don't move!
        return;
    }
}
Ejemplo n.º 4
0
void Humanoid::HandleInput()
{

	// CHANGED
	// added this check so that AI controlled entities don't try to handle input
	// Rolf, 6-9-04
	if (cPlayer != CHARACTER_PLAYER1 && cPlayer != CHARACTER_PLAYER2)
		return;

	Vector vMoveDirection(0.0f, 0.0f, 0.0f);

	Vector vCamZ=Game::pWorld->pCamera->GetZ();
	Vector vCamX=Game::pWorld->pCamera->GetX();

	float fXRot=0, fYRot=0;
		
	//get analog stick input
	if (pActionMap->GetJoystick())
	{
		vMoveDirection.fComp[0]=(float)pActionMap->GetJoystick()->CheckImmediateInput(JOYSTICK_AXIS_LX);
		vMoveDirection.fComp[2]=(float)-pActionMap->GetJoystick()->CheckImmediateInput(JOYSTICK_AXIS_LY);

		//manual deadzoning
		if(vMoveDirection.fComp[0]<DEBUG_DEADZONE&&vMoveDirection.fComp[0]>-DEBUG_DEADZONE)
			vMoveDirection.fComp[0]=0;

		if(vMoveDirection.fComp[2]<DEBUG_DEADZONE&&vMoveDirection.fComp[2]>-DEBUG_DEADZONE)
			vMoveDirection.fComp[2]=0;

		//analog camera controls
		fXRot=(float)pActionMap->GetJoystick()->CheckImmediateInput(JOYSTICK_AXIS_RX)*0.001f*90;
		fYRot=(float)pActionMap->GetJoystick()->CheckImmediateInput(JOYSTICK_AXIS_RY)*0.001f*90;
	}

	//Check keyboard movement input
	if (DirectInput::GetKeyboard()->CheckImmediateInput(DIK_A))
		vMoveDirection.fComp[0]=-1000;
	if (DirectInput::GetKeyboard()->CheckImmediateInput(DIK_D))
		vMoveDirection.fComp[0]=1000;
	if (DirectInput::GetKeyboard()->CheckImmediateInput(DIK_W))
		vMoveDirection.fComp[2]=1000;
	if (DirectInput::GetKeyboard()->CheckImmediateInput(DIK_S))
		vMoveDirection.fComp[2]=-1000;

	//Handle character movement
	vMoveDirection*=0.007f;	
	vMoveDirection=vCamZ*vMoveDirection.fComp[2]+vCamX*vMoveDirection.fComp[0];
	MoveInDirection(&vMoveDirection);

	//digital camera control
	if(pActionMap->CheckAction(iActionArray[HUMANOID_SWING_CAMERA_LEFT], DEVICE_ALL, false))//if (DirectInput::GetKeyboard()->CheckImmediateInput(DIK_LEFT))
		fXRot=90;
	if(pActionMap->CheckAction(iActionArray[HUMANOID_SWING_CAMERA_RIGHT], DEVICE_ALL, false))////if (DirectInput::GetKeyboard()->CheckImmediateInput(DIK_RIGHT))
		fXRot=-90;

	//Handle camera movement
	Game::pWorld->pCamera->RotateY(fXRot*Timer::GetElapsedTime());
//	RenderManager::GetCamera(cPlayer)->RotateLocalX(fYRot*Timer::GetElapsedTime());

	//Handle jump
	if(bJump&&pActionMap->CheckAction(iActionArray[HUMANOID_JUMP], DEVICE_ALL, false))
		Jump();

	//Handle switching arrows
	if(pActionMap->CheckAction(iActionArray[HUMANOID_SWITCH_ARROW], DEVICE_ALL, true))
	{
		iSelectedArrow++;
		if(iSelectedArrow>=Arrow::ARROW_TYPE_NUM)
			iSelectedArrow=0;
	}

	//Handle arrow firing
	bIsCharging=false;
	if(bShootArrow&&pActionMap->CheckAction(iActionArray[HUMANOID_SHOOT_ARROW], DEVICE_ALL, false))
	{
		bIsCharging=true;
		fChargeTime+=Timer::GetElapsedTime();
	}
		
	if(!bIsCharging&&fChargeTime)
	{
		ShootArrow(fChargeTime);
		fChargeTime=0;
	}
}
Ejemplo n.º 5
0
void WalkCircleThread( PVOID _pvoid ) {
	//srand( time( NULL ) );

	PPARAMS pParams = (PPARAMS)_pvoid;

	const SIZE circleSize = { 40, 40 };

	HDC hdc;

	POINT startPoint;

	std::srand( std::time( NULL ) );

	Direction direction;

	direction = (Direction)( ( std::rand() ) % (int)Direction::N_OF_DIRECTIONS );

	startPoint = {
		std::rand() % ( pParams->m_clientRect.right  - circleSize.cx ),
		std::rand() % ( pParams->m_clientRect.bottom - circleSize.cy )
	};

	RECT circleDims = { 
		startPoint.x,
		startPoint.y,
		startPoint.x + circleSize.cx,
		startPoint.y + circleSize.cy
	}; // left top right bottom

	const UINT step = 1;

	// Проверяем на необходимость выхода из потока
	while ( ! pParams->m_bKill )
	{
		// Определяем направление движения окружности
		DetermineDirection( direction, circleDims, pParams->m_clientRect );

		// Определяем след. позицию окружности
		MoveInDirection( circleDims, direction, step );

		// Получаем свою квоту на перерисовку
		WaitForSingleObject( pParams->m_semaphore, INFINITE );

		// Блокируем отрисовку в других потоках
		EnterCriticalSection( &pParams->m_drawBlocker );

		// Рисуем окружность
		Ellipse( pParams->m_hdc, circleDims );

		// Снимаем блокировку
		LeaveCriticalSection( &pParams->m_drawBlocker );

		// Ожидаем завершения отрисовки во всех остальных потоках
		EnterSynchronizationBarrier( &pParams->m_drawFinished,
			SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY );

		// Даем возможность другому потоку подменить семафор
		EnterSynchronizationBarrier( &pParams->m_drawFinished,
			SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY );
	}
}