示例#1
0
void EnemyGrunt::split() {
	_attack = false;
	_target = _position;

	// Accumulate pushes
	std::vector<QuadtreeOccupant*> occupants;

	sf::FloatRect rangeRect = ltbl::rectFromBounds(_position - sf::Vector2f(_stats->_splitRadius, _stats->_splitRadius), _position + sf::Vector2f(_stats->_splitRadius, _stats->_splitRadius));

	getRoom()->getQuadtree().queryRegion(occupants, rangeRect);

	sf::Vector2f moveDir(0.0f, 0.0f);

	for (int i = 0; i < occupants.size(); i++) {
		Entity* pEntity = static_cast<Entity*>(occupants[i]);

		if (pEntity != this && (pEntity->_type == 1 || pEntity->_type == 2)) {
			sf::Vector2f dir = _position - ltbl::rectCenter(pEntity->getAABB());

			float dist = ltbl::vectorMagnitude(dir);

			if (dist < _stats->_splitRadius) {
				moveDir += ltbl::vectorNormalize(dir) * (_stats->_splitRadius - dist) / _stats->_splitRadius;
			}
		}
	}

	if (moveDir != sf::Vector2f(0.0f, 0.0f))
		_target += ltbl::vectorNormalize(moveDir) * _stats->_walkRate * 0.017f * 1.5f;

	_pTarget = nullptr;
	_hold = false;
}
示例#2
0
文件: Snake.cpp 项目: jjkjiang/Snake
// updates the snake by checking for changes in direction before getting the direction,
// and determines if the snake is colliding into something, moving or eating a fruit
int Snake::updateSnake(const sf::Keyboard::Key& dir, sf::Vector2f fruitPos) {
    playerMove.setDirection(dir);
    // what's worse, creating a new temporary movementDir everytime or calling getDirection 4x?
    sf::Keyboard::Key movementDir = playerMove.getDirection();

    if (collision()) {
        return 2;
    }

    Vector2f nextPos = head->shape.getPosition();
    if (movementDir == sf::Keyboard::Up) {
        nextPos.y -= pixelSizeY;
    }
    if (movementDir == sf::Keyboard::Down) {
        nextPos.y += pixelSizeY;
    }
    if (movementDir == sf::Keyboard::Left) {
        nextPos.x -= pixelSizeX;
    }
    if (movementDir == sf::Keyboard::Right) {
        nextPos.x += pixelSizeX;
    }

    if (nextPos == fruitPos) {
        eatFruit(nextPos);
        return 1;
    } else {
        moveDir(nextPos);
    }
    return 0;
}
示例#3
0
int main()
{

	initscr();
	start_color();
	noecho();
	initGame();
//	system("clear");
	char ch;
	ch=getch();
	int ret; 
	while(ch!='\x1b')
	{
		moveDir(ch);
		if(moveFlag)
		{
			randGenerate();
			updateView();
			moveFlag=0;
		}
		if(CONTINUE !=	winOrLose())
		{
			break;
		}	
		ch=getch();
	}
	
	endwin();
}
示例#4
0
void FlyCamera::HandleKeyboardInput(double dt) {
	glm::vec3 vRight = m_worldTransform[0].xyz;
	glm::vec3 vUp = m_worldTransform[1].xyz;
	glm::vec3 vForward = m_worldTransform[2].xyz;
	glm::vec3 moveDir(0.0f);
	if (glfwGetKey(m_window, GLFW_KEY_W) == GLFW_PRESS ||
		(glfwGetMouseButton(m_window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS
		&& glfwGetMouseButton(m_window, GLFW_MOUSE_BUTTON_2) == GLFW_PRESS)) {
		moveDir -= vForward;
	}
	if (glfwGetKey(m_window, GLFW_KEY_S) == GLFW_PRESS) {
		moveDir += vForward;
	}
	if (glfwGetKey(m_window, GLFW_KEY_A) == GLFW_PRESS)	{
		moveDir -= vRight;
	}
	if (glfwGetKey(m_window, GLFW_KEY_D) == GLFW_PRESS)	{
		moveDir += vRight;
	}
	if (glfwGetKey(m_window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
		moveDir += glm::vec3(0.0f, 1.0f, 0.0f);
	}
	if (glfwGetKey(m_window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) {
		moveDir -= glm::vec3(0.0f, 1.0f, 0.0f);
	}
	float fLength = glm::length(moveDir);
	if (fLength > 0.01f) {
		moveDir = glm::normalize(moveDir) * (float)dt * m_flySpeed;
		SetPosition(GetPosition() + moveDir);
	}
}
示例#5
0
文件: server.c 项目: thiagordp/TF
void Mover(char *comando, usuario_t *user, int sock)
{
    char *foo;

    printf("Operacao de mover\n");

    token = strtok(comando, " ");
    operation = token;
    token = strtok(NULL, " ");
    option = token;
    token = strtok(NULL, " ");
    text = token;
    token = strtok(NULL, " ");
    foo = token;

    printf(" Operacao: %s\n", operation);
    printf(" Opcao:    %s\n", option);
    printf(" Texto:    %s\n", text);
    printf(" Foo:      %s\n", foo);

    char **tokens = NULL;
    size_t x;
    tokenize(text, "/", &tokens, &x);

    for (size_t i = 0; i < x; i++)
    {
        printf("|%s|\n", tokens[i]);
    }

    sem_wait(&semClienteMover);
    diretorio_t *dir = procuraDiretorioRec(tokens, x, root);

    // mv arquivo destino dir
    if (strcmp(foo, "dir") == 0)
    {
        printf("mover diretorio\n");
        // procura pela pasta de destino

        moveDir(option, user->dirAtual->diretorio, dir);
        // procurar o end. de destino
        // copiar...
    }
    else if (strcmp(foo, "arq") == 0)
    {
        // procurar o end. de destino
        // copiar...

        // procura pela pasta de destino
        printf("mover arquivo\n");
        moveArquivo(option, user->dirAtual->diretorio, dir);
    }
    printf("sleep...\n");

    strcpy(foo, printCaminho(user));
    sleep(10);
    sem_post(&semClienteMover);
    write(sock, foo, strlen(foo) + 1);
}
示例#6
0
bool HardcoreProtester::tryChasingFrackman() {
	int l = -1; Direction d = none; FrackMan *f = getStudentWorld()->getFrackMan();
	getStudentWorld()->getSearch()->search(this, f->getX(), f->getY(), d, l);
	if (l != -1 && l <= chaseDist) {
		moveDir(d);
		return true;
	}
	return false;
}
示例#7
0
文件: ui.c 项目: jeremysrand/a2bejwld
static void joystickMove(tJoyPos position)
{
    switch (position) {
        case JOY_POS_DOWN:
            moveDir(DIR_DOWN);
            break;
            
        case JOY_POS_DOWN_LEFT:
            moveTwoDirs(DIR_DOWN, DIR_LEFT);
            break;
            
        case JOY_POS_LEFT:
            moveDir(DIR_LEFT);
            break;
            
        case JOY_POS_UP_LEFT:
            moveTwoDirs(DIR_UP, DIR_LEFT);
            break;
            
        case JOY_POS_UP:
            moveDir(DIR_UP);
            break;
            
        case JOY_POS_UP_RIGHT:
            moveTwoDirs(DIR_UP, DIR_RIGHT);
            break;
            
        case JOY_POS_RIGHT:
            moveDir(DIR_RIGHT);
            break;
            
        case JOY_POS_DOWN_RIGHT:
            moveTwoDirs(DIR_DOWN, DIR_RIGHT);
            break;
            
        default:
        case JOY_POS_CENTER:
            break;
    }
}
示例#8
0
FUNCTION int Q5SO(obj Q5AK, int Q4IE, int Q58B)
{
  loc location;
  int Q5NC;
  location = loc( getLocation(Q5AK) );
  for(int Q5CS = Q58B; Q5CS > 0x00; Q5CS --)
  {
    moveDir(location, Q4IE);
  }
  Q5NC = moveMultiCheck(Q5AK, location, Q43W);
  if(Q5NC <= 0x00)
  {
    int Q5GH = (Q4IE + 0x04) % 0x08;
    while((Q5NC <= 0x00) && (Q58B > 0x01))
    {
      Q58B --;
      moveDir(location, Q5GH);
      Q5NC = moveMultiCheck(Q5AK, location, Q43W);
    }
  }
  return(Q5NC);
}
示例#9
0
int DeadProtester::doSomething() {
	if (ticks) {
		ticks--;
		return CONTINUE;
	}
	setVisible(true); //don't show up on screen until it starts moving
	if (getX() == 60 && getY() == 60) return SELF_DIED;
	ticks = waitingTicks;
	int l = -1; Direction d = none;
	getStudentWorld()->getSearch()->search(this, 60, 60, d, l);
	moveDir(d);
	return CONTINUE;
}
示例#10
0
void FlyCamera::HandleKeyboardInput(double dt)
{
	//Get the cameras forward/up/right
	glm::mat4 trans = GetTransform();
	glm::vec3 vRight = trans[0].xyz;
	glm::vec3 vUp = trans[1].xyz;
	glm::vec3 vForward = trans[2].xyz;
	glm::vec3 moveDir(0.0f);

	if (glfwGetKey(m_pWindow, GLFW_KEY_W) == GLFW_PRESS)
	{
		moveDir -= vForward;
	}

	if (glfwGetKey(m_pWindow, GLFW_KEY_S) == GLFW_PRESS)
	{
		moveDir += vForward;
	}

	if (glfwGetKey(m_pWindow, GLFW_KEY_A) == GLFW_PRESS)
	{
		moveDir -= vRight;
	}

	if (glfwGetKey(m_pWindow, GLFW_KEY_D) == GLFW_PRESS)
	{
		moveDir += vRight;
	}

	if (glfwGetKey(m_pWindow, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
	{
		moveDir += glm::vec3(0.0f, 1.0f, 0.0f);
	}
	if (glfwGetKey(m_pWindow, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS)
	{
		moveDir -= glm::vec3(0.0f, 1.0f, 0.0f);
	}

	float fLength = glm::length(moveDir);
	if (fLength > 0.01f)
	{
		moveDir = ((float)dt * m_fFlySpeed) * glm::normalize(moveDir);
		SetPosition(GetPosition() + moveDir);
	}
}
示例#11
0
void EnemyGrunt::subUpdate(float dt, int subStep, int numSubSteps) {
	float numSubstepsInv = 1.0f / numSubSteps;

	// Walls
	sf::FloatRect newAABB = getAABB();

	if (getRoom()->wallCollision(newAABB)) {
		setPosition(ltbl::rectCenter(newAABB));
		_hitWall = true;
	}

	// Accumulate pushes
	std::vector<QuadtreeOccupant*> occupants;

	sf::FloatRect rangeRect = ltbl::rectFromBounds(_position - sf::Vector2f(_radius, _radius), _position + sf::Vector2f(_radius, _radius));

	getRoom()->getQuadtree().queryRegion(occupants, rangeRect);

	sf::Vector2f moveDir(0.0f, 0.0f);

	for (int i = 0; i < occupants.size(); i++) {
		Entity* pEntity = static_cast<Entity*>(occupants[i]);

		if (pEntity != this && (pEntity->_type == 1 || pEntity->_type == 2)) {
			float entityRadius = std::max(pEntity->getAABB().width, pEntity->getAABB().height);

			sf::Vector2f dir = _position - ltbl::rectCenter(pEntity->getAABB());

			float dist = ltbl::vectorMagnitude(dir);

			if (dist < entityRadius + _radius)
				moveDir += ltbl::vectorNormalize(dir) * numSubstepsInv;
		}
	}

	_position += moveDir;
}
示例#12
0
/**
 * Called when Flag is flying to the pole
 */
void CFlag::processFlipping()
{
	if(m_Pos != m_destination)
	{        
        Vector2D<int> dir = m_destination - m_Pos;
        const float length = dir.GetLength();
        Vector2D<float> base_dir( dir.x/length, dir.y/length );

		if( fabs(length) < SPEED )
		{
			moveTo(m_destination);
		}
		else
		{
			moveDir(base_dir*SPEED);
		}
	}
	else
	{
	    setAction(A_FLAG_WAVE);        
	    setActionSprite();
	    g_pSound->playSound( SOUND_FLAG_LAND );
	    
	    const auto episode = gpBehaviorEngine->getEpisode();
        if(episode == 6)
        {
            Vector2D<int> tilePos = m_Pos;

            tilePos.y = getYDownPos();

            Uint32 new_tile_no = mp_Map->getPlaneDataAt(1, tilePos)+1;
            tilePos = tilePos>>CSF;
            mp_Map->setTile(tilePos.x, tilePos.y, new_tile_no, true);
        }
        mp_Map->unlock();
	}
示例#13
0
FUNCTION int Q5S4(obj ship, int Q5M5, obj Q62O)
{
  int Q4ID = Q5SM(ship, Q5M5);
  int Q58G = getMultiType(ship);
  loc Q4OI;
  loc Q4OJ;
  int Q5NC = getMultiExtents(Q58G, Q4OI, Q4OJ);
  int Q44G = getX(Q4OJ) - getX(Q4OI) + 0x01;
  int Q44I = getY(Q4OJ) - getY(Q4OI) + 0x01;
  loc Q5CP = loc( getLocation(ship) );
  int Q5EE = 0x00;
  int Q5EF = 0x00;
  switch(Q4ID)
  {
  case 0x00:
  case 0x04:
    Q5EF = Q44I;
    break;
  case 0x01:
  case 0x03:
  case 0x05:
  case 0x07:
    Q5EE = Q44G;
    Q5EF = Q44I;
    break;
  case 0x02:
  case 0x06:
    Q5EE = Q44G;
    break;
  default:
    Q5EE = Q44G;
    Q5EF = Q44I;
    break;
  }
  int Q44F = 0x00;
  int Q44H = 0x00;
  switch(Q4ID)
  {
  case 0x00:
    Q44H = 0x00;
    break;
  case 0x01:
    Q44F = 0x02;
    Q44H = 0x00;
    break;
  case 0x02:
    Q44F = 0x02;
    break;
  case 0x03:
    Q44F = 0x02;
    Q44H = 0x04;
    break;
  case 0x04:
    Q44H = 0x04;
    break;
  case 0x05:
    Q44F = 0x06;
    Q44H = 0x04;
    break;
  case 0x06:
    Q44F = 0x06;
    break;
  case 0x07:
    Q44F = 0x06;
    Q44H = 0x00;
    break;
  default:
    break;
  }
  for(; Q5EE > 0x00; Q5EE --)
  {
    moveDir(Q5CP, Q44F);
  }
  for(; Q5EF > 0x00; Q5EF --)
  {
    moveDir(Q5CP, Q44H);
  }
  if(isInMap(Q5CP))
  {
    if(hasObjVar(Q62O, "oldshipcommand"))
    {
      removeObjVar(Q62O, "oldshipcommand");
    }
    int Q5ND = moveMultiCheck(ship, Q5CP, Q43W);
    Q65T = 0x01;
    return(Q5ND);
  }
  Q5RY(ship);
  return(moveMultiMapSwitch(ship, Q5CP, Q43W));
}
示例#14
0
void CRocket::processFlying()
{
    int xBlockPos = target.x - getXPosition();
    int yBlockPos = target.y - getYPosition();
    
    const int xBlockPosAbs = (xBlockPos<0) ? -xBlockPos : xBlockPos;
    const int yBlockPosAbs = (yBlockPos<0) ? -yBlockPos : yBlockPos;
    
    
    if( xBlockPosAbs < MOVE_SPEED && yBlockPosAbs < MOVE_SPEED )
    {
	const Uint16 object = mp_Map->getPlaneDataAt(2, target.x, target.y);
	
	Vector2D<int> speed(xBlockPos, yBlockPos);	    
	moveDir(speed);
	playSound(SOUND_ROCKET_DRIVE);
	
	// Happens when the rocket find a place where to stop
	if(object == 0x6A || object == 0x69)
	{
	    xDirection = CENTER;
	    yDirection = UP;
	    setAction(A_ROCKET_SIT);
	    detectNextTarget(target, xDirection, yDirection);
	    
	    Vector2D<int> newPlayerPos = m_Pos;
	    
	    newPlayerPos.y = getYDownPos();
	    newPlayerPos.x = getXRightPos();
	    
	    mpCarriedPlayer->moveToForce(newPlayerPos);
	    mpCarriedPlayer->solid = true;
	    mpCarriedPlayer->dontdraw = false;
	    mpCarriedPlayer = nullptr;
	    return;
	}

	readDirection(object, xDirection, yDirection );
	
	// If there is an object that changes the direction of the rocket, apply it!	
	detectNextTarget(target, xDirection, yDirection);		
    }
    
    Vector2D<int> speed;
    
    if(yDirection == UP)
    {
	speed.y = -MOVE_SPEED;
    }
    else if(yDirection == DOWN)
    {
	speed.y = MOVE_SPEED;
    }    
    
    if(xDirection == RIGHT)
    {
	speed.x = MOVE_SPEED;
    }
    else if(xDirection == LEFT)
    {
	speed.x = -MOVE_SPEED;
    }
    
    if(mpCarriedPlayer != nullptr)
    {
	mpCarriedPlayer->moveDir(speed);
    }
    moveDir(speed);
}
//-----------------------------------------------------------------------------
// Purpose: Apply joystick to CUserCmd creation
// Input  : frametime - 
//			*cmd - 
//-----------------------------------------------------------------------------
void CInput::JoyStickMove( float frametime, CUserCmd *cmd )
{
	// complete initialization if first time in ( needed as cvars are not available at initialization time )
	if ( !m_fJoystickAdvancedInit )
	{
		Joystick_Advanced();
		m_fJoystickAdvancedInit = true;
	}

	// verify joystick is available and that the user wants to use it
	if ( !in_joystick.GetInt() || 0 == inputsystem->GetJoystickCount() )
		return; 

	// Skip out if vgui is active
	if ( vgui::surface()->IsCursorVisible() )
		return;

	if ( m_flRemainingJoystickSampleTime <= 0 )
		return;
	frametime = MIN(m_flRemainingJoystickSampleTime, frametime);
	m_flRemainingJoystickSampleTime -= frametime;

	QAngle viewangles;

	// Get starting angles
	engine->GetViewAngles( viewangles );

	struct axis_t
	{
		float	value;
		int		controlType;
	};
	axis_t gameAxes[ MAX_GAME_AXES ];
	memset( &gameAxes, 0, sizeof(gameAxes) );

	// Get each joystick axis value, and normalize the range
	for ( int i = 0; i < MAX_JOYSTICK_AXES; ++i )
	{
		if ( GAME_AXIS_NONE == m_rgAxes[i].AxisMap )
			continue;

		float fAxisValue = inputsystem->GetAnalogValue( (AnalogCode_t)JOYSTICK_AXIS( 0, i ) );

		if (joy_wwhack2.GetInt() != 0 )
		{
			// this is a special formula for the Logitech WingMan Warrior
			// y=ax^b; where a = 300 and b = 1.3
			// also x values are in increments of 800 (so this is factored out)
			// then bounds check result to level out excessively high spin rates
			float fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
			if (fTemp > 14000.0)
				fTemp = 14000.0;
			// restore direction information
			fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
		}

		unsigned int idx = m_rgAxes[i].AxisMap;
		gameAxes[idx].value = fAxisValue;
		gameAxes[idx].controlType = m_rgAxes[i].ControlMap;
	}

	// Re-map the axis values if necessary, based on the joystick configuration
	if ( (joy_advanced.GetInt() == 0) && (in_jlook.state & 1) )
	{
		// user wants forward control to become pitch control
		gameAxes[GAME_AXIS_PITCH] = gameAxes[GAME_AXIS_FORWARD];
		gameAxes[GAME_AXIS_FORWARD].value = 0;

		// if mouse invert is on, invert the joystick pitch value
		// Note: only absolute control support here - joy_advanced = 0
		if ( m_pitch->GetFloat() < 0.0 )
		{
			gameAxes[GAME_AXIS_PITCH].value *= -1;
		}
	}

	if ( (in_strafe.state & 1) || lookstrafe.GetFloat() && (in_jlook.state & 1) )
	{
		// user wants yaw control to become side control
		gameAxes[GAME_AXIS_SIDE] = gameAxes[GAME_AXIS_YAW];
		gameAxes[GAME_AXIS_YAW].value = 0;
	}

	float forward	= ScaleAxisValue( gameAxes[GAME_AXIS_FORWARD].value, MAX_BUTTONSAMPLE * joy_forwardthreshold.GetFloat() );
	float side		= ScaleAxisValue( gameAxes[GAME_AXIS_SIDE].value, MAX_BUTTONSAMPLE * joy_sidethreshold.GetFloat()  );
	float pitch		= ScaleAxisValue( gameAxes[GAME_AXIS_PITCH].value, MAX_BUTTONSAMPLE * joy_pitchthreshold.GetFloat()  );
	float yaw		= ScaleAxisValue( gameAxes[GAME_AXIS_YAW].value, MAX_BUTTONSAMPLE * joy_yawthreshold.GetFloat()  );

	// If we're inverting our joystick, do so
	if ( joy_inverty.GetBool() )
	{
		pitch *= -1.0f;
	}

	// drive yaw, pitch and move like a screen relative platformer game
	if ( CAM_IsThirdPerson() && thirdperson_platformer.GetInt() )
	{
		if ( forward || side )
		{
			// apply turn control [ YAW ]
			// factor in the camera offset, so that the move direction is relative to the thirdperson camera
			viewangles[ YAW ] = RAD2DEG(atan2(-side, -forward)) + m_vecCameraOffset[ YAW ];
			engine->SetViewAngles( viewangles );

			// apply movement
			Vector2D moveDir( forward, side );
			cmd->forwardmove += moveDir.Length() * cl_forwardspeed.GetFloat();
		}

		if ( pitch || yaw )
		{
			// look around with the camera
			m_vecCameraOffset[ PITCH ] += pitch * joy_pitchsensitivity.GetFloat();
			m_vecCameraOffset[ YAW ]   += yaw * joy_yawsensitivity.GetFloat();
		}

		if ( forward || side || pitch || yaw )
		{
			// update the ideal pitch and yaw
			cam_idealpitch.SetValue( m_vecCameraOffset[ PITCH ] - viewangles[ PITCH ] );
			cam_idealyaw.SetValue( m_vecCameraOffset[ YAW ] - viewangles[ YAW ] );
		}
		return;
	}

	float	joySideMove = 0.f;
	float	joyForwardMove = 0.f;
	float   aspeed = frametime * gHUD.GetFOVSensitivityAdjust();

	// apply forward and side control
	C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
	
	int iResponseCurve = 0;
	if ( pLocalPlayer && pLocalPlayer->IsInAVehicle() )
	{
		iResponseCurve = pLocalPlayer->GetVehicle() ? pLocalPlayer->GetVehicle()->GetJoystickResponseCurve() : joy_response_move_vehicle.GetInt();
	}
	else
	{
		iResponseCurve = joy_response_move.GetInt();
	}	
	
	float val = ResponseCurve( iResponseCurve, forward, PITCH, joy_forwardsensitivity.GetFloat() );
	joyForwardMove	+= val * cl_forwardspeed.GetFloat();
	val = ResponseCurve( iResponseCurve, side, YAW, joy_sidesensitivity.GetFloat() );
	joySideMove		+= val * cl_sidespeed.GetFloat();

	Vector2D move( yaw, pitch );
	float dist = move.Length();

	// apply turn control
	float angle = 0.f;

	if ( JOY_ABSOLUTE_AXIS == gameAxes[GAME_AXIS_YAW].controlType )
	{
		float fAxisValue = ResponseCurveLook( joy_response_look.GetInt(), yaw, YAW, pitch, dist, frametime );
		angle = fAxisValue * joy_yawsensitivity.GetFloat() * aspeed * cl_yawspeed.GetFloat();
	}
	else
	{
		angle = yaw * joy_yawsensitivity.GetFloat() * aspeed * 180.0;
	}
	viewangles[YAW] += angle;
	cmd->mousedx = angle;

	// apply look control
	if ( IsX360() || in_jlook.state & 1 )
	{
		float angle = 0;
		if ( JOY_ABSOLUTE_AXIS == gameAxes[GAME_AXIS_PITCH].controlType )
		{
			float fAxisValue = ResponseCurveLook( joy_response_look.GetInt(), pitch, PITCH, yaw, dist, frametime );
			angle = fAxisValue * joy_pitchsensitivity.GetFloat() * aspeed * cl_pitchspeed.GetFloat();
		}
		else
		{
			angle = pitch * joy_pitchsensitivity.GetFloat() * aspeed * 180.0;
		}
		viewangles[PITCH] += angle;
		cmd->mousedy = angle;
		view->StopPitchDrift();
		if( pitch == 0.f && lookspring.GetFloat() == 0.f )
		{
			// no pitch movement
			// disable pitch return-to-center unless requested by user
			// *** this code can be removed when the lookspring bug is fixed
			// *** the bug always has the lookspring feature on
			view->StopPitchDrift();
		}
	}

	// apply player motion relative to screen space
	if ( CAM_IsThirdPerson() && thirdperson_screenspace.GetInt() )
	{
		float ideal_yaw = cam_idealyaw.GetFloat();
		float ideal_sin = sin(DEG2RAD(ideal_yaw));
		float ideal_cos = cos(DEG2RAD(ideal_yaw));
		float side_movement = ideal_cos*joySideMove - ideal_sin*joyForwardMove;
		float forward_movement = ideal_cos*joyForwardMove + ideal_sin*joySideMove;
		cmd->forwardmove += forward_movement;
		cmd->sidemove += side_movement;
	}
	else
	{
		cmd->forwardmove += joyForwardMove;
		cmd->sidemove += joySideMove;
	}

	if ( IsPC() )
	{
		CCommand tmp;
		if ( FloatMakePositive(joyForwardMove) >= joy_autosprint.GetFloat() || FloatMakePositive(joySideMove) >= joy_autosprint.GetFloat() )
		{
			KeyDown( &in_joyspeed, NULL );
		}
		else
		{
			KeyUp( &in_joyspeed, NULL );
		}
	}

	// Bound pitch
	viewangles[PITCH] = clamp( viewangles[ PITCH ], -cl_pitchup.GetFloat(), cl_pitchdown.GetFloat() );

	engine->SetViewAngles( viewangles );
}
示例#16
0
void  FlyComponent::update(float deltaTime)
{
    m_speedMultiplier = m_pInputManager->isKeyDown(Input::Key::LeftShift) ? 2.f : 1.f;

    auto pGameObject = getGameObject().lock();
    if (pGameObject == nullptr) return;
    Transform transform = pGameObject->getTransform();

    // translate
    glm::vec3 moveDir(0);
    if( m_pInputManager->isKeyDown(Input::Key::W) ) moveDir = -transform.getForward();
    if( m_pInputManager->isKeyDown(Input::Key::S) ) moveDir =  transform.getForward();
    if( m_pInputManager->isKeyDown(Input::Key::D) ) moveDir =  transform.getRight();
    if( m_pInputManager->isKeyDown(Input::Key::A) ) moveDir = -transform.getRight();
    if( m_pInputManager->isKeyDown(Input::Key::Q) ) moveDir =  transform.getUp();
    if( m_pInputManager->isKeyDown(Input::Key::E) ) moveDir = -transform.getUp();
    if (moveDir != glm::vec3(0))
    {
        transform.translate(moveDir * m_speedMultiplier * deltaTime);
    }


    // check for rotation
    static bool sbMouseButtonDown = false;
    if (m_pInputManager->isMouseButtonDown(Input::MouseButton::Left) ||  m_pInputManager->isKeyDown(Input::Key::Space))
    {
        static glm::ivec2 prevPos(0);

        if (sbMouseButtonDown == false)
        {
            sbMouseButtonDown = true;
            prevPos = m_pInputManager->getMousePosition();
        }

        glm::ivec2 pos(0);
        pos = m_pInputManager->getMousePosition();

        glm::ivec2 deltaPos = pos - prevPos;

        prevPos = pos;

        glm::mat4 mMat;

        // pitch
        if (deltaPos.y != 0)
        {
            glm::quat rotation = glm::angleAxis((float)-deltaPos.y / 150.0f, transform.getRight());
            transform.rotate(rotation);
        }

        // yaw
        if (deltaPos.x != 0)
        {
            glm::quat rotation = glm::angleAxis((float)-deltaPos.x / 150.0f, glm::vec3(0,1,0));
            transform.rotate(rotation);
        }
    }
    else
    {
        sbMouseButtonDown = false;
    }

    pGameObject->setTransform(transform);

}
示例#17
0
FUNCTION int Q4WT(obj user, obj Q5AO, obj Q5AB, obj Q5AP, int bank)
{
  loc Q575 = loc( getLocation(user) );
  loc Q4VS = loc( getLocation(Q5AB) );
  moveDir(Q4VS, 0x04);
  list Q51X = list( 0x100E, 0x100F, 0x1010, 0x1013 );
  int num = random(0x00, (numInList(Q51X) - 0x01));
  int Q51W = Q51X[num];
  obj key = NULL();
  obj Q47G = NULL();
  if(bank)
  {
    fixBank(user);
    Q47G = getItemAtSlot(user, 0x1D);
    if(Q47G == NULL())
    {
      Q47G = getBackpack(user);
      bank = 0x00;
    }
  }
  else
  {
    Q47G = getBackpack(user);
  }
  if(Q47G == NULL())
  {
    key = createGlobalObjectAt(Q51W, Q575);
    barkTo(user, user, "A house key is now at my feet.");
  }
  else
  {
    key = createGlobalObjectIn(Q51W, Q47G);
    if(bank)
    {
      barkTo(user, user, "A house key is now in my safety deposit box.");
    }
    else
    {
      barkTo(user, user, "A house key is now in my backpack.");
    }
  }
  if(key == NULL())
  {
    bark(user, "Ack, a key could not be created!");
    deleteObject(Q5AO);
    return(0x00);
  }
  attachScript(key, "key");
  list Q5Z5;
  if(hasObjVar(Q5AO, "myhousedoors"))
  {
    getObjListVar(Q5Z5, Q5AO, "myhousedoors");
  }
  int Q55T = numInList(Q5Z5);
  for(int Q4EJ = 0x00; Q4EJ < Q55T; Q4EJ ++)
  {
    Q5AB = Q5Z5[Q4EJ];
    Q45B(Q5AB, key);
  }
  if(Q5AP != NULL())
  {
    Q45B(Q5AP, key);
  }
  attachScript(key, "housekey");
  return(0x01);
}
示例#18
0
文件: ui.c 项目: jeremysrand/a2bejwld
static bool pollKeyboard(void)
{
    bool result = false;
    uint8_t ch;
    
    if (!kbhit())
        return result;
    
    ch = cgetc();
    switch (ch) {
        case 'i':
        case 'I':
        case CH_CURS_UP:
            if (!isAppleButtonPressed()) {
                moveDir(DIR_UP);
                break;
            }
            // Fallthrough...
        case 139:
            result = swapDir(DIR_UP);
            break;
            
        case 'j':
        case 'J':
        case CH_CURS_LEFT:
            if (!isAppleButtonPressed()) {
                moveDir(DIR_LEFT);
                break;
            }
            // Fallthrough...
        case 136:
            result = swapDir(DIR_LEFT);
            break;
            
        case 'k':
        case 'K':
        case CH_CURS_RIGHT:
            if (!isAppleButtonPressed()) {
                moveDir(DIR_RIGHT);
                break;
            }
            // Fallthrough...
        case 149:
            result = swapDir(DIR_RIGHT);
            break;
            
        case 'm':
        case 'M':
        case CH_CURS_DOWN:
            if (!isAppleButtonPressed()) {
                moveDir(DIR_DOWN);
                break;
            }
            // Fallthrough...
        case 138:
            result = swapDir(DIR_DOWN);
            break;
            
        case CH_ESC:
        case 'q':
        case 'Q':
            if (gShouldSave) {
                videomode(VIDEOMODE_80x24);
                mixedTextMode();
                gotoxy(0, 0);
                cprintf("Saving your game so you can continue\r\n    later...");
                saveGame();
            }
            quitGame();
            break;
            
        case 'r':
        case 'R':
            refreshScore(0);
            startNewGame();
            gShouldSave = false;
            return true;
            
        case 'o':
        case 'O':
            selectOptions();
            showAndClearDblLoRes();
            drawBoard();
            break;
            
        case 'h':
        case 'H':
            getHint();
            break;
            
        case '?':
            printInstructions();
            showAndClearDblLoRes();
            drawBoard();
            break;
            
        default:
            badThingHappened();
            break;
    }
    
    return result;
}
示例#19
0
int Protester::doSomething() {
	if (dead) return SELF_DIED;
	if (ticks) {
		ticks--;
		return CONTINUE;
	}
	//if protester isn't waiting, it'll start waiting from the next tick
	ticks = waitingTicks;

	//if protester hits frackman check if it killed him, return PLAYER_DIED from here
	if (getStudentWorld()->collides(this, getStudentWorld()->getFrackMan(), 4.0)) {
		getStudentWorld()->playSound(SOUND_PROTESTER_YELL);
		if(getStudentWorld()->getFrackMan()->decHealth(2)) return PLAYER_DIED;
		ticks = 16 * waitingTicks + 1; //15 non-resting ticks
		return CONTINUE;
	}
	//check if frackman is in a straight line to the protester
	FrackMan *f = getStudentWorld()->getFrackMan();
	Direction dir = none; int length = -1;
	if (getStudentWorld()->getSearch()->search(this, f->getX(), f->getY(), dir, length)) {
		//frackman is reachable in a straight line
		moveDir(dir);
		return CONTINUE;
	}
	//try chasing frackman if protester can trace frackman's cellphone signal
	if(tryChasingFrackman()) return CONTINUE; //if it could chase frackman 

	//try walking in some direction
	if (!numStepsInDir) {
		//looks for a new direction that the protester can move into
		///DEBUGGING: looks for a NEW direction?
		int randInt = -1, dx = 0, dy = 0;
		do {
			randInt = rand() % 4; //0->up, 1->down, 2->right, 3->left
			if (randInt == 0 && getDirection() == up ||
				randInt == 1 && getDirection() == down ||
				randInt == 2 && getDirection() == right ||
				randInt == 3 && getDirection() == left) continue; //choose a new direction so ignore randInt if direction is the same
			dx = randInt == 2 ? 1 : randInt == 3 ? -1 : 0;
			dy = randInt == 0 ? 1 : randInt == 1 ? -1 : 0;
		} while (!getStudentWorld()->getSearch()->isMovable(getX()+dx, getY()+dy));
		switch (randInt) {
		case 0: changeDir(up); break;
		case 1: changeDir(down); break;
		case 2: changeDir(right); break;
		case 3: changeDir(left); break;
		default: break;
		}
		numStepsInDir = rand() % 53 + 8;
	}
	if (stepsSincePerp >= 200) {
		if (getDirection() == up || getDirection() == down) {
			if (getX() < 30) {
				if (getStudentWorld()->getSearch()->isMovable(getX() + 1, getY())) changeDir(right);
			} else if (getStudentWorld()->getSearch()->isMovable(getX() - 1, getY())) changeDir(left);
		} else if (getDirection() == right || getDirection() == left) {
			if (getY() < 30) {
				if (getStudentWorld()->getSearch()->isMovable(getX(), getY() + 1)) changeDir(up);
			} else if (getStudentWorld()->getSearch()->isMovable(getX(), getY() - 1)) changeDir(down);
		}
		numStepsInDir = rand() % 53 + 8;
	}
	if(moveDir(getDirection())) numStepsInDir--; //if it's possible to move in that direction
	else numStepsInDir = 0; //chose a new direction next non-resting tick

	return CONTINUE;
}