Example #1
0
double NPC::getAfterPersonAngle(int right,int left)
{
	double after_person_angle = getPersonAngle();

	if(right)
	{
		if(getDown())
		{
			after_person_angle += getUpdateVelocityPerson();
		}else
		{
			after_person_angle -= getUpdateVelocityPerson();
		}
	}

	if(left)
	{
		if(getDown())
		{
			after_person_angle -= getUpdateVelocityPerson();
		}else
		{
			after_person_angle += getUpdateVelocityPerson();
		}
	}

	return after_person_angle;
}
Example #2
0
bool	Ia::moveIa()
{
  switch (_direction) {
  case Direction::RIGHT:
    if (getRight()) {
      moveRight();
      return true;
    }
  case Direction::DOWN:
    if (getDown()) {
      moveDown();
      return true;
    }
  case Direction::LEFT:
    if (getLeft()) {
      moveLeft();
      return true;
    }
  case Direction::UP:
    if (getUp()) {
      moveUp();
      return true;
    }
  default:
    isMoving = false;
    mesh->setMD2Animation(irr::scene::EMAT_STAND);
  }
  return false;
}
Example #3
0
bool	Ia::movePuwerUp()
{
  switch (_direction) {
  case Direction::RIGHT:
    if (getRight()) {
      moveRight();
      return true;
    }
  case Direction::DOWN:
    if (getDown()) {
      moveDown();
      return true;
    }
  case Direction::LEFT:
    if (getLeft()) {
      moveLeft();
      return true;
    }
  case Direction::UP:
    if (getUp()) {
      moveUp();
      return true;
    }
  default:
    isMoving = false;
  }
  return false;
}
Example #4
0
// __________________________________________________________________________________________________
void KikiBot::initAction ( KikiAction * action )
{
    KikiPos newPos (position);

    switch (action->getId())
    {
    case ACTION_NOOP:
        return;

    case ACTION_FORWARD:
        newPos += getDir();
        break;
    case ACTION_CLIMB_DOWN:
        newPos += getDir() + getDown();
        break;
    case ACTION_JUMP:
        newPos += getUp();
        break;
    case ACTION_JUMP_FORWARD:
        newPos += getUp() + getDir();
        break;
    case ACTION_FALL_FORWARD:
        newPos += getDown() + getDir();
        break;
    case ACTION_FALL:
        if (direction != KVector())
        {
            //KConsole::printf ("bot push fall direction [%f %f %f]", direction[X], direction[Y], direction[Z]);
            KikiPushable::initAction (action);
            return;
        }
        else
            newPos += getDown();
        break;

    default:

        KikiPushable::initAction (action);
        return;
    }

    if (newPos != KikiPos (position))
    {
        //KConsole::printf ("KikiBot::initAction object will move to pos [%d %d %d]", newPos.x, newPos.y, newPos.z);
        Controller.world->objectWillMoveToPos (this, newPos, action->getDuration());
    }
}
Example #5
0
int main() {
	scanf("%d%d", &a, &b);
	double aU = getUp(a, b);
	double aD = getDown(a, b);
	double answer = std::min(aU, aD);
	if (fabs(answer - INF) < eps) printf("-1\n");
	else printf("%.20f\n", answer);
	return 0;
}
void PluginNetwork::update(void) {
    // first cleanup and init statusLine
    free(statusLine);
    statusLine = NULL;

    this->setActiveInterface();

    unsigned long down = 0;
    unsigned long up = 0;
    if (active) {
        down = getDown();
        up = getUp();
        asprintf(&statusLine, active->format, down, up);
    } else {
        // some hardcoded format, doesn't matter because down and up are 0, but active is NULL
        asprintf(&statusLine, wired.format, down, up);
    }
}
Example #7
0
// __________________________________________________________________________________________________
void KikiBot::moveBot ()
{
    move_action = NULL;

    KikiPos forwardPos = position + getDir();

    if ((jump || jump_once) && 				// jump mode or jump activated while moving
            dir_sgn == 1.0 &&     				// and moving forward
            Controller.world->isUnoccupiedPos (position + getUp())) // and above empty
    {
        if (Controller.world->isUnoccupiedPos (forwardPos + getUp()) &&
                Controller.world->isUnoccupiedPos (forwardPos)) // forward and above forward also empty
        {
            move_action = getActionWithId (KikiBot::ACTION_JUMP_FORWARD);
        }
        else // no space to jump forward -> jump up
        {
            move_action = getActionWithId (KikiBot::ACTION_JUMP);
        }
    }
    else if (Controller.world->isUnoccupiedPos (forwardPos)) // forward is empty
    {
        if (Controller.world->isUnoccupiedPos (forwardPos + getDown()))
        {   // below forward also empty
            move_action = getActionWithId (KikiBot::ACTION_CLIMB_DOWN);
        }
        else // forward down is solid
        {
            move_action = getActionWithId (KikiBot::ACTION_FORWARD);
        }
    }
    else // forward is not empty
    {
        KikiAction * moveAction = getActionWithId (KikiBot::ACTION_FORWARD);
        if (push && Controller.world->mayObjectPushToPos (this, forwardPos, moveAction->getDuration()))
        {
            moveAction->reset();
            // player in push mode and pushing object is possible
            if (Controller.world->isUnoccupiedPos(forwardPos + getDown())) // below forward is empty
            {
                move_action = getActionWithId (KikiBot::ACTION_CLIMB_DOWN);
            }
            else
            {
                move_action = moveAction;
            }
        }
        else // just climb up
        {
            move_action = getActionWithId (KikiBot::ACTION_CLIMB_UP);
        }
    }

    // reset the jump once flag (either we jumped or it's not possible to jump at current position)
    jump_once = false;

    if (move_action)
    {
        move_action->keepRest(); // try to make subsequent actions smooth
        Controller.timer_event->addAction (move_action);
    }
}
Example #8
0
// __________________________________________________________________________________________________
void KikiBot::performAction ( KikiAction * action )
{
    int actionId   = action->getId();
    float relTime  = action->getRelativeTime();
    float dltTime  = action->getRelativeDelta();

    switch (actionId)
    {
    case ACTION_SHOOT:

        if (relTime == 0)
        {
            KikiBullet::shootFromBot (this);
        }

    case ACTION_NOOP:
        return;

    case ACTION_FORWARD:

        left_tire_rot  += dir_sgn * dltTime;
        right_tire_rot += dir_sgn * dltTime;
        current_position = position + relTime * getDir();

        return;

    case ACTION_JUMP:

        current_position = position + cos(M_PI_2 - M_PI_2 * relTime) * getUp();
        return;

    case ACTION_JUMP_FORWARD:

        left_tire_rot  += cos(M_PI_2 - M_PI_2 * dltTime);
        right_tire_rot += cos(M_PI_2 - M_PI_2 * dltTime);
        current_position = position  + (1.0 - cos(M_PI_2 * relTime)) * getDir()
                           + cos(M_PI_2 - M_PI_2 * relTime) * getUp();
        return;

    case ACTION_FALL_FORWARD:

        current_position = position + cos(M_PI_2 - M_PI_2 * relTime) * getDir()
                           + (1.0 - cos(M_PI_2 * relTime)) * getDown();
        return;

    case ACTION_FALL:

        if (direction != KVector())
        {
            KikiPushable::performAction (action);
            return;
        }
        current_position = position + relTime * getDown();
        return;

    case ACTION_CLIMB_UP:

        left_tire_rot  += dir_sgn * dltTime/2;
        right_tire_rot += dir_sgn * dltTime/2;
        climb_orientation = KQuaternion::rotationAroundVector(dir_sgn * relTime * -90.0, KVector(1,0,0));
        break;

    case ACTION_CLIMB_DOWN:

        left_tire_rot  += dir_sgn * dltTime;
        right_tire_rot += dir_sgn * dltTime;
        if (relTime <= 0.2)
        {
            current_position = position + (relTime/0.2)/2 * getDir();
        }
        else if (relTime >= 0.8)
        {
            climb_orientation = KQuaternion::rotationAroundVector(dir_sgn * 90.0, KVector(1,0,0));
            current_position = position + getDir() + (0.5+(relTime-0.8)/0.2/2) * getDown();
        }
        else
        {
            climb_orientation = KQuaternion::rotationAroundVector(dir_sgn * (relTime-0.2)/0.6 * 90.0, KVector(1,0,0));
            KVector rotVec = (orientation * climb_orientation).rotate(KVector(0.0, 1.0, 0.0));
            current_position = position + 0.5 * ((KVector)getDir() + (KVector)getDown() + rotVec);
        }
        break;

    case ACTION_TURN_LEFT:
    case ACTION_TURN_RIGHT:

        if (move_action == NULL && relTime == 0.0) // if not performing move action and start of rotation
        {
            // update orientation now, so next move action will move in desired direction
            if (actionId == ACTION_TURN_LEFT)
            {
                orientation *= KQuaternion::rotationAroundVector(90.0, KVector(0,1,0));
                rest_orientation = KQuaternion::rotationAroundVector(-90.0, KVector(0,1,0));
            }
            else
            {
                orientation *= KQuaternion::rotationAroundVector(-90.0, KVector(0,1,0));
                rest_orientation = KQuaternion::rotationAroundVector(90.0, KVector(0,1,0));
            }
        }

        if (actionId == ACTION_TURN_LEFT)
        {
            left_tire_rot  += -dltTime;
            right_tire_rot +=  dltTime;
            rotate_orientation = KQuaternion::rotationAroundVector(relTime * 90.0, KVector(0,1,0));
        }
        else
        {
            left_tire_rot  +=  dltTime;
            right_tire_rot += -dltTime;
            rotate_orientation = KQuaternion::rotationAroundVector(relTime * -90.0, KVector(0,1,0));
        }
        break;

    default:

        KikiPushable::performAction (action);
        return;
    }

    current_orientation =  orientation * climb_orientation * rotate_orientation * rest_orientation;
}
Example #9
0
void Camera::shiftDown(const float step) {
    cameraMatrix = glm::translate(cameraMatrix, getDown() * step);
}