예제 #1
0
void GameLayer::MoveStep(){
    movedflag = true;
    Direction temp = head->getDirec();
    Point po = head->Node::getPosition();
    switch (temp) {
        case up:
            //log("upupup");
            po.y += 20;
            break;
        case down:
            po.y -= 20;
            break;
        case left:
            po.x -= 20;
            break;
        case right:
            po.x += 20;
            break;
            
        default:
            break;
    }
    MoveBody();
    head->setPosition(po);
    
}
예제 #2
0
void Snake::Move()
{

	//Porusza wê¿em. Najpier przesuwa cia³ (MoveBody), a potem g³owê
	//w kirunku zaleznym od aktualnego stanu wê¿a
	std::list<SnakeElement*>::iterator i = RealSnake.begin();
	switch (State)
	{
		case Snake::GoingLeft:
		{
			MoveBody();
			--(**i).GridPosition.x;
			Update();
			break;
		}
		case Snake::GoingRight:
		{
			MoveBody();
			(**i).GridPosition.x++;
			Update();
			break;
		}	
		case Snake::GoingUp:
		{
			MoveBody();
			--(**i).GridPosition.y;
			Update();
			break;
		}
		case Snake::GoingDown:
		{
			MoveBody();
			++(**i).GridPosition.y;
			Update();
			break;
		}
		default:
			break;
	}
}
예제 #3
0
void CNPC_Hydra::RunAI( void )
{
	CheckLength( );

	AdjustLength( );

	BaseClass::RunAI();

	CalcGoalForces( );
	MoveBody( );

	int i;
	for (i = 1; i < CHAIN_LINKS && i < m_body.Count(); i++)
	{
		m_vecChain.Set( i, m_body[i].vecPos );

#if 0
		if (m_body[i].bStuck)
		{
			NDebugOverlay::Box(m_body[i].vecPos, Vector( -2, -2, -2 ), Vector( 2, 2, 2 ), 255, 0, 0, 20, .1);
		}
		else
		{
			NDebugOverlay::Box(m_body[i].vecPos, Vector( -2, -2, -2 ), Vector( 2, 2, 2 ), 0, 255, 0, 20, .1);
		}
		NDebugOverlay::Line( m_body[i].vecPos, m_body[i].vecPos + m_body[i].vecDelta, 0, 255, 0, true, .1);
		NDebugOverlay::Line( m_body[i-1].vecPos, m_body[i].vecPos, 255, 255, 255, true, .1);
#endif

#if 0
		char text[128];
		Q_snprintf( text, sizeof( text ), "%d", i );
		NDebugOverlay::Text( m_body[i].vecPos, text, false, 0.1 );
#endif

#if 0
		char text[128];
		Q_snprintf( text, sizeof( text ), "%4.0f", (m_body[i].vecPos - m_body[i-1].vecPos).Length() * 100 / m_idealSegmentLength - 100);
		NDebugOverlay::Text( 0.5*(m_body[i-1].vecPos + m_body[i].vecPos), text, false, 0.1 );
#endif
	}
	//NDebugOverlay::Box(m_body[i].vecPos, Vector( -2, -2, -2 ), Vector( 2, 2, 2 ), 0, 255, 0, 20, .1);
	//NDebugOverlay::Box( m_vecHeadGoal, Vector( -2, -2, -2 ), Vector( 2, 2, 2 ), 255, 255, 0, 20, .1);
	for (; i < CHAIN_LINKS; i++)
	{
		m_vecChain.Set( i, m_vecChain[i-1] );
	}
}
예제 #4
0
void PlayerEntity::Update(micro_seconds step)
{
	_isGrippingWall = false;

	bool isOnGround = CheckIsTouchingGround();
	bool isGrippingWall = CheckIsGrippingWall();

	number_f frameMoveSpeed = _isDashing && !isOnGround || _currentDashRecovery > 0 ? DashSpeed : MoveSpeed;

	// Restore the status for various abilities which reset
	// touching the ground.
	if (isOnGround || isGrippingWall)
	{
		_canAerialDash = true;
		_jumpsRemaining = MultiJumps;
	}

	int normalizationMultiplier = step / SpeedNormalizer;

	auto currentTranslation = _body.CalculateWorldTranslation();

	if (_currentWallJumpRecovery > 0)
	{
		_currentWallJumpRecovery -= WallJumpRecovery * normalizationMultiplier;
		if (_isWallJumpMovingLeft)
		{
			_body.Velocity.X = -frameMoveSpeed;
		}
		else
		{
			_body.Velocity.X = frameMoveSpeed;
		}
	}
	else if (_isMoveLeft && !_isMoveRight)
	{
		// Stop aerial dashing if the side was reversed.
		if (!_isAerialDashLeft)
		{
			_isAerialDash = false;
		}

		_body.Velocity.X = -frameMoveSpeed;

		// Check if we are clinging to a wall.
		vec_f corner = vec_f(currentTranslation.X - _gripSize.X, currentTranslation.Y);
		if (_physicsSystem->QueryRect(corner, _gripSize))
		{
			_body.Velocity.Y = _body.Velocity.Y < -GripFallSpeed ? -GripFallSpeed : _body.Velocity.Y;
			_isGrippingWall = true;
		}
	}
	else if (_isMoveRight && !_isMoveLeft)
	{
		// Stop aerial dashing if the side was reversed.
		if (_isAerialDashLeft)
		{
			_isAerialDash = false;
		}

		_body.Velocity.X = frameMoveSpeed;

		// Check if we are clinging to a wall.
		vec_f corner = vec_f(currentTranslation.X + _body.Part->Rectangle.X, currentTranslation.Y);
		if (_physicsSystem->QueryRect(corner, _gripSize))
		{
			_body.Velocity.Y = _body.Velocity.Y < -GripFallSpeed ? -GripFallSpeed : _body.Velocity.Y;
			_isGrippingWall = true;
		}
	}
	else
	{
		_body.Velocity.X = 0;

		// Stop aerial dashing if we are stopped.
		_isAerialDash = false;
	}

	if (_isMoveUp)
	{
		_body.Velocity.Y = frameMoveSpeed;
	}
	if (_isMoveDown)
	{
		_body.Velocity.Y = -frameMoveSpeed;
	}

	if (_isJumping)
	{
		_body.Velocity.Y = JumpStrength;
		_isJumping = false;
	}

	if (_isFlying)
	{
		_body.Velocity += vec_f(0, JumpStrength * 2);
	}

	if (_currentDashRecovery > 0)
	{
		_currentDashRecovery -= DashRecovery * normalizationMultiplier;
	}

	if (_currentDashRecovery <= 0)
	{
		_currentDashRecovery = 0;
		_isAerialDash = false;
	}

	if (!_isAerialDash)
	{
		// Apply gravity to the player collision model.
		_body.Velocity -= vec_f(0, GRAVITY * normalizationMultiplier);
	}
	else
	{
		_body.Velocity.Y = 0;
	}

	// Apply limits
	if (_body.Velocity.Y < -MAX_FALL_SPEED)
	{
		// Apply gravity limits to dynamic bodies.
		_body.Velocity.Y = -MAX_FALL_SPEED;
	}
	else if (_body.Velocity.Y > MAX_JUMP_SPEED)
	{
		// Apply jump limits to dynamic bodies.
		_body.Velocity.Y = MAX_JUMP_SPEED;
	}

	// Run physics.
	MoveBody(normalizationMultiplier);
}