Exemple #1
0
void
gnibbles_worm_rescale (GnibblesWorm *worm, gint tilesize)
{
  int i;
  gfloat x_pos, y_pos;
  gint count;
  ClutterActor *tmp;
  GError *err = NULL;

  if (!worm)
    return;
  if (!worm->actors)
    return;

  count = clutter_group_get_n_children (CLUTTER_GROUP (worm->actors));

  for (i = 0; i < count; i++) {
    tmp = clutter_group_get_nth_child (CLUTTER_GROUP (worm->actors), i);
    clutter_actor_get_position (tmp, &x_pos, &y_pos);

    clutter_actor_set_position (tmp,
                                (x_pos / properties->tilesize) * tilesize,
                                (y_pos / properties->tilesize) * tilesize);

    gtk_clutter_texture_set_from_pixbuf (
       CLUTTER_TEXTURE (tmp),
       worm_pixmaps[properties->wormprops[worm->number]->color - 12],
       &err);
    if (err)
      gnibbles_error (err->message);
  }

}
Exemple #2
0
void
gnibbles_warpmanager_rescale (GnibblesWarpManager *warpmanager, gint tilesize)
{
  int i;
  gfloat x_pos, y_pos;
  GError *err = NULL;

  for (i = 0; i < warpmanager->numwarps; i++) {
    clutter_actor_get_position (warpmanager->warps[i]->actor, &x_pos, &y_pos);
    clutter_actor_set_position (warpmanager->warps[i]->actor,
                                (x_pos / properties->tilesize) * tilesize,
                                (y_pos / properties->tilesize) * tilesize);
    gtk_clutter_texture_set_from_pixbuf
      (CLUTTER_TEXTURE (warpmanager->warps[i]->actor), boni_pixmaps[WARP], &err);
    if (err)
      gnibbles_error (err->message);
  }
}
Exemple #3
0
static GdkPixbuf *
gnibbles_load_pixmap_file (const gchar * pixmap, gint xsize, gint ysize)
{
  GdkPixbuf *image;
  gchar *filename;

  filename = g_build_filename (DATA_DIRECTORY, "pixmaps", pixmap, NULL);

  if (!filename) {
    char *message =
      g_strdup_printf (_("Nibbles couldn't find pixmap file:\n%s\n\n"
                       "Please check your Nibbles installation"), pixmap);
    gnibbles_error (message);
    g_free(message);
  }

  image = gdk_pixbuf_new_from_file_at_scale (filename, xsize, ysize, TRUE, NULL);
  g_free (filename);

  return image;
}
Exemple #4
0
static GdkPixbuf *
gnibbles_load_pixmap_file (const gchar * pixmap, gint xsize, gint ysize)
{
  GdkPixbuf *image;
  gchar *filename;
  const char *dirname;

  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
  filename = g_build_filename (dirname, pixmap, NULL);

  if (!filename) {
    char *message =
      g_strdup_printf (_("Nibbles couldn't find pixmap file:\n%s\n\n"
                       "Please check your Nibbles installation"), pixmap);
    gnibbles_error (message);
    g_free(message);
  }

  image = gdk_pixbuf_new_from_file_at_scale (filename, xsize, ysize, TRUE, NULL);
  g_free (filename);

  return image;
}
Exemple #5
0
void
gnibbles_board_level_new (GnibblesBoard *board, gint level)
{

  gchar *tmp = NULL;
  const char *dirname;
  gchar *filename;
  FILE *in;
  gchar tmpboard [BOARDWIDTH +2];
  gint i,j;
  gint count = 0;

  board->current_level = level;

  tmp = g_strdup_printf("level%03d.gnl", level);

  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_GAMES_DIRECTORY);
  filename = g_build_filename (dirname, tmp, NULL);

  g_free (tmp);

  if ((in = fopen (filename, "r")) == NULL) {
    char *message =
      g_strdup_printf (_("Nibbles couldn't load level file:\n%s\n\n"
                        "Please check your Nibbles installation"), filename);
    gnibbles_error (message);
    g_free (message);
  }

  if (warpmanager)
    gnibbles_warpmanager_destroy (warpmanager);

  warpmanager = gnibbles_warpmanager_new ();

  if (boni)
    gnibbles_boni_destroy (boni);

  boni = gnibbles_boni_new ();

  for (i = 0; i < BOARDHEIGHT; i++) {
    if (!fgets (tmpboard, sizeof (tmpboard), in)) {
      char *message =
        g_strdup_printf (_("Level file appears to be damaged:\n%s\n\n"
                         "Please check your Nibbles installation"), filename);
      gnibbles_error (message);
      g_free (message);
      break;
    }

    for (j = 0; j < BOARDWIDTH; j++) {
      board->walls[j][i] = tmpboard[j];
      switch (board->walls[j][i]) {
        case 'm':
          board->walls[j][i] = EMPTYCHAR;
          if (count < properties->numworms)
            gnibbles_worm_set_start (worms[count++], j, i, WORMUP);
          break;
        case 'n':
          board->walls[j][i] = EMPTYCHAR;
          if (count < properties->numworms)
            gnibbles_worm_set_start(worms[count++], j, i, WORMLEFT);
          break;
        case 'o':
          board->walls[j][i] = EMPTYCHAR;
          if (count < properties->numworms)
            gnibbles_worm_set_start (worms[count++], j, i, WORMDOWN);
          break;
        case 'p':
          board->walls[j][i] = EMPTYCHAR;
          if (count < properties->numworms)
            gnibbles_worm_set_start (worms[count++], j, i, WORMRIGHT);
          break;
        case 'Q':
          gnibbles_warpmanager_add_warp (warpmanager, j - 1, i - 1, -1, -1);
          break;
        case 'R':
        case 'S':
        case 'T':
        case 'U':
        case 'V':
        case 'W':
        case 'X':
        case 'Y':
        case 'Z':
          gnibbles_warpmanager_add_warp
            (warpmanager, j - 1, i - 1, -(board->walls[j][i]), 0);
          break;
        case 'r':
        case 's':
        case 't':
        case 'u':
        case 'v':
        case 'w':
        case 'x':
        case 'y':
        case 'z':
          gnibbles_warpmanager_add_warp
            (warpmanager, -(board->walls[j][i] - 'a' + 'A'), 0, j, i);
          board->walls[j][i] = EMPTYCHAR;
          break;
       }
    }
  }

  g_free (filename);
  fclose (in);

  for (i = 0; i < count; i++) {
    if (worms[i]->direction == WORMRIGHT) {
      for (j = 0; j < worms[i]->length; j++)
        gnibbles_worm_move_head_pointer (worms[i]);
      worms[i]->xtail++;
    } else if ( worms[i]->direction == WORMLEFT) {
      for (j = 0; j < worms[i]->length; j++)
        gnibbles_worm_move_head_pointer (worms[i]);
      worms[i]->xtail--;
    } else if (worms[i]->direction == WORMDOWN) {
      for (j = 0; j < worms[i]->length; j++)
        gnibbles_worm_move_head_pointer (worms[i]);
      worms[i]->ytail++;
    } else if (worms[i]->direction == WORMUP) {
      for (j = 0; j < worms[i]->length; j++)
        gnibbles_worm_move_head_pointer (worms[i]);
      worms[i]->ytail--;
    }
    board->walls[worms[i]->xtail][worms[i]->ytail] = EMPTYCHAR;
  }
  gnibbles_board_load_level (board);
}