bool TaskEventDetectorClient::didEventOccur(bool& event_occured,
                                            const bool save_data_samples,
                                            const int num_data_samples)
{
  task_recorder2_msgs::DataSampleLabel label;
  if(!checkForEvent(label, save_data_samples, num_data_samples))
  {
    return false;
  }
  ROS_ASSERT(label.type == task_recorder2_msgs::DataSampleLabel::BINARY_LABEL);
  event_occured = (label.binary_label.label == task_recorder2_msgs::BinaryLabel::SUCCEEDED);
  return true;
}
Example #2
0
int main(void)
{
    // seed pseudorandom number generator
    srand48(time(NULL));

    // instantiate window
    GWindow window = newGWindow(WIDTH, HEIGHT);

    // instantiate bricks
    initBricks(window);

    // instantiate ball, centered in middle of window
    GOval ball = initBall(window);

    // instantiate paddle, centered at bottom of window
    GRect paddle = initPaddle(window);

    // instantiate scoreboard, centered in middle of window, just above ball
    GLabel label = initScoreboard(window);

    // number of lives initially
    int lives = LIVES;

    // number of bricks initially
    int bricks = ROWS * COLS;

    // number of points initially
    int points = 0;

    // default ball direction is down
    Velocity *velocity = (Velocity *) malloc(sizeof(Velocity));
    velocity->horizontalVelocity = 0.0;
    velocity->verticalVelocity = 2.0;

    char *paddleDirection = malloc(sizeof(char) * 10);
  
    Paddle *bat = (Paddle *) malloc(sizeof(Paddle));
    bat->paddle = paddle;
    bat->direction = paddleDirection;
    bat->x = getX(paddle);
    bat->y = getY(paddle);

    // show the scoreboard
    updateScoreboard(window, label, points);

    // keep playing until game over
    while (lives > 0 && bricks > 0)
    {
        checkForEvent(bat); 

        GObject object = detectCollision(window, ball);
        if (object != NULL)
        {
            if (object == bat->paddle)
            {
                ballHitsPaddle(bat, velocity, ball);
            }
            else if (strcmp(getType(object), "GRect") == 0)
            {
                ballHitsBrick(velocity, &window, &object, &label, &points, &bricks);
            }
        }
        else
        {
            if (hasBallHitTheSides(&ball, &window))
            {
                invertHorizontalDirection(velocity);
            }
            else if (hasBallHitTheTop(&ball, &window))
            {
                invertVerticalDirection(velocity);
            }
            else if (hasBallHitTheBottom(&ball, &window))
            {
                resetGameplay(velocity, &ball, bat, &lives);
            }
        }

        move(ball, velocity->horizontalVelocity, velocity->verticalVelocity);
        pause(10);
    }

    showGameOverMessage(window, label);

    // wait for click before exiting
    waitForClick();

    // game over
    closeGWindow(window);
    return 0;
}