Пример #1
0
Файл: game.c Проект: rlt3/fast
void
set_game(struct Game *game)
{
  /* remove player if it exists */
  if (game->player != NULL) {
    deconstruct_polygon(game->player);
  }

  deconstruct_polygon_array(game->asteroids, MAX_ASTEROIDS);

  game->player  = construct_player();
  game->running = true;
  game->speed   = 0.05;
  game->fuel    = 3;
  game->level   = 1;

  set_time(game);
  set_level(game);

  /* set input_frames so it rolls over to 0 on the first loop */
  game->past_input_frame  = (INPUT_FRAMES - 1);

  /* preset the input to 'nothing' */
  reset_saved_input(game);
}
Пример #2
0
static void
handle_set_media_message (SnraClient * client, GstStructure * s)
{
  const gchar *protocol, *path;
  int port;
  GstClockTime base_time;
  gint64 tmp;
  gchar *uri;
  gboolean paused;

  protocol = gst_structure_get_string (s, "resource-protocol");
  path = gst_structure_get_string (s, "resource-path");

  if (protocol == NULL || path == NULL)
    return;                     /* Invalid message */

  if (!snra_json_structure_get_int (s, "resource-port", &port))
    return;

  if (!snra_json_structure_get_int64 (s, "base-time", &tmp))
    return;                     /* Invalid message */

  if (!snra_json_structure_get_boolean (s, "paused", &paused))
    return;

  base_time = (GstClockTime) (tmp);

  if (client->player == NULL) {
    construct_player (client);
    if (client->player == NULL)
      return;
  } else {
    gst_element_set_state (client->player, GST_STATE_NULL);
  }

  uri =
      g_strdup_printf ("%s://%s:%d%s", protocol, client->connected_server, port,
      path);
  g_print ("Playing URI %s base_time %" GST_TIME_FORMAT "\n", uri,
      GST_TIME_ARGS (base_time));
  g_object_set (client->player, "uri", uri, NULL);
  g_free (uri);

  gst_element_set_start_time (client->player, GST_CLOCK_TIME_NONE);
  gst_element_set_base_time (client->player, base_time);
  gst_pipeline_use_clock (GST_PIPELINE (client->player), client->net_clock);

  if (client->enabled) {
    if (paused)
      client->state = GST_STATE_PAUSED;
    else
      client->state = GST_STATE_PLAYING;
  } else {
    client->state = DISABLED_STATE;
  }

  gst_element_set_state (client->player, client->state);
}
Пример #3
0
static void
set_media (AurClient * client)
{
  if (client->player == NULL) {
    construct_player (client);
    if (client->player == NULL)
      return;
  }

  gst_element_set_state (client->player, GST_STATE_READY);

  g_print ("Setting media URI %s base_time %" GST_TIME_FORMAT " position %"
      GST_TIME_FORMAT " paused %i\n", client->uri,
      GST_TIME_ARGS (client->base_time), GST_TIME_ARGS (client->position),
      client->paused);
  g_object_set (client->player, "uri", client->uri, NULL);

  gst_element_set_start_time (client->player, GST_CLOCK_TIME_NONE);
  gst_pipeline_use_clock (GST_PIPELINE (client->player), client->net_clock);

  /* Do the preroll */
  gst_element_set_state (client->player, GST_STATE_PAUSED);
  gst_element_get_state (client->player, NULL, NULL, GST_CLOCK_TIME_NONE);

  /* Compensate preroll time if playing */
  if (!client->paused) {
    GstClockTime now = gst_clock_get_time (client->net_clock);
    if (now > (client->base_time + client->position))
      client->position = now - client->base_time;
  }

  /* If position is off by more than 0.5 sec, seek to that position
   * (otherwise, just let the player skip) */
  if (client->position > GST_SECOND/2) {
    /* FIXME Query duration, so we don't seek after EOS */
    if (!gst_element_seek_simple (client->player, GST_FORMAT_TIME,
            GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, client->position)) {
      g_warning ("Initial seekd failed, player will go faster instead");
      client->position = 0;
    }
  }

  /* Set base time considering seek position after seek */
  gst_element_set_base_time (client->player,
      client->base_time + client->position);

  /* Before we start playing, ensure we have selected the right audio track */
  set_language (client);

  if (!client->paused)
    gst_element_set_state (client->player, GST_STATE_PLAYING);
}
Пример #4
0
static void
handle_set_volume_message (SnraClient * client, GstStructure * s)
{
  gdouble new_vol;

  if (!snra_json_structure_get_double (s, "level", &new_vol))
    return;

  if (client->player == NULL)
    construct_player (client);

  if (client->player) {
    // g_print ("New volume %g\n", new_vol);
    g_object_set (G_OBJECT (client->player), "volume", new_vol,
        "mute", (gboolean) (new_vol == 0.0), NULL);
  }
}
void init_in_game_state( game* _pGame )
{
    // allocate the necessary memory for the in_game_state struct
    _pGame->p_current_state = malloc( sizeof( in_game_state ) );

    // game is not paused
    ((in_game_state*)_pGame->p_current_state)->bool_paused = 0;

    // load esc menu image
    ((in_game_state*)_pGame->p_current_state)->p_esc_menu_img = load_image( GC_ig_esc_menu_img, GC_ig_esc_menu_width, GC_ig_esc_menu_height );

    // init current game state flag variable
    ((in_game_state*)_pGame->p_current_state)->game_state = PLAYING;

    // esc menu is not active
    ((in_game_state*)_pGame->p_current_state)->bool_menu_is_active = 0;

    // create the top bar
    ((in_game_state*)_pGame->p_current_state)->p_top_bar = construct_top_bar();

    // load esc menu buttons
    ((in_game_state*)_pGame->p_current_state)->p_continue = load_button( GC_ig_continue_x,
                                                                        GC_ig_continue_y,
                                                                        GC_button_width,
                                                                        GC_button_height,
                                                                        GC_ig_continue_nr_img,
                                                                        GC_ig_continue_se_img );

     ((in_game_state*)_pGame->p_current_state)->p_main_menu = load_button( GC_ig_mm_x,
                                                                          GC_ig_mm_y,
                                                                          GC_button_width,
                                                                          GC_button_height,
                                                                          GC_ig_mm_nr_img,
                                                                          GC_ig_mm_se_img );

    ((in_game_state*)_pGame->p_current_state)->p_exit = load_button( GC_ig_exit_x,
                                                                    GC_ig_exit_y,
                                                                    GC_button_width,
                                                                    GC_button_height,
                                                                    GC_mm_exit_nr_img,
                                                                    GC_mm_exit_se_img );

    // pause main menu backgorund music
    pause_audio();

    _pGame->main_menu_music_is_on = 0;

    // selected button in esc menu is "continue"
    ((in_game_state*)_pGame->p_current_state)->selected_button = CONTINUE_BUTTON;
    ((in_game_state*)_pGame->p_current_state)->p_continue->bool_is_selected = 1;

    // seed the random number generator
    srand( time( NULL ) );

    // construct the map struct, load a random map file from "maps\" directoty
    ((in_game_state*)_pGame->p_current_state)->p_map = construct_map( rand() % GC_number_of_maps );

    // construct the NPCs( pacmen ) based on how many 'N' characters there are in the map( max being GC_max_NPC_count )
    matrix_point* p_NPCs_coords = (matrix_point*)malloc( GC_max_NPC_count * sizeof( matrix_point ) );

    ((in_game_state*)_pGame->p_current_state)->NPC_count = find_NPCs_in_map( ((in_game_state*)_pGame->p_current_state)->p_map, p_NPCs_coords );

    ((in_game_state*)_pGame->p_current_state)->pp_NPCs = (NPC**)malloc( ((in_game_state*)_pGame->p_current_state)->NPC_count * sizeof( NPC ) );

    for ( int i = 0; i < ((in_game_state*)_pGame->p_current_state)->NPC_count; i++ )
        ((in_game_state*)_pGame->p_current_state)->pp_NPCs[i] = construct_NPC( p_NPCs_coords[i].i, p_NPCs_coords[i].j );

    free( p_NPCs_coords );

    // construct the player
    ((in_game_state*)_pGame->p_current_state)->p_player = construct_player();

    ((in_game_state*)_pGame->p_current_state)->game_ended_timer = create_timer( GC_game_ended_duration );

    ((in_game_state*)_pGame->p_current_state)->timer_set = 0;

    // Configure the text that will be outputed(WinBGIm); this is only for the "PAUSED GAME" that appears when game's paused
    settextjustify( CENTER_TEXT, CENTER_TEXT );
    settextstyle( SMALL_FONT, HORIZ_DIR, 9 );
}
Пример #6
0
static void
handle_enrol_message (SnraClient * client, GstStructure * s)
{
  int clock_port;
  gint64 tmp;
  GstClockTime cur_time;
  gchar *server_ip_str = NULL;
  gdouble new_vol;

  if (!snra_json_structure_get_int (s, "clock-port", &clock_port))
    return;                     /* Invalid message */

  if (!snra_json_structure_get_int64 (s, "current-time", &tmp))
    return;                     /* Invalid message */
  cur_time = (GstClockTime) (tmp);

  if (snra_json_structure_get_double (s, "volume-level", &new_vol)) {
    if (client->player == NULL)
      construct_player (client);

    if (client->player) {
      //g_print ("New volume %g\n", new_vol);
      g_object_set (G_OBJECT (client->player), "volume", new_vol,
          "mute", (gboolean) (new_vol == 0.0), NULL);
    }
  }

  snra_json_structure_get_boolean (s, "enabled", &client->enabled);
  snra_json_structure_get_boolean (s, "paused", &client->paused);

#if GLIB_CHECK_VERSION(2,22,0)
  {
    GResolver *resolver = g_resolver_get_default ();
    GList *names;

    if (resolver == NULL)
      return;

    names =
        g_resolver_lookup_by_name (resolver, client->connected_server, NULL,
        NULL);
    if (names) {
      server_ip_str = g_inet_address_to_string ((GInetAddress *) (names->data));
      g_resolver_free_addresses (names);
    }
    g_object_unref (resolver);
  }
#else
  {
    struct addrinfo *names = NULL;
    if (getaddrinfo (client->connected_server, NULL, NULL, &names))
      return;
    if (names) {
      char hbuf[NI_MAXHOST];
      if (getnameinfo (names->ai_addr, names->ai_addrlen,
              hbuf, sizeof (hbuf), NULL, 0, NI_NUMERICHOST) == 0) {
        server_ip_str = g_strdup (hbuf);
      }
      freeaddrinfo (names);
    }
  }
#endif
  if (server_ip_str) {
    g_print ("Creating net clock at %s:%d time %" GST_TIME_FORMAT "\n",
        server_ip_str, clock_port, GST_TIME_ARGS (cur_time));
    if (client->net_clock)
      gst_object_unref (client->net_clock);
    client->net_clock = gst_net_client_clock_new ("net_clock", server_ip_str,
        clock_port, cur_time);
    g_free (server_ip_str);
  }
}