Back to index

gcompris  8.2.2
Defines | Functions | Variables
bonus.c File Reference
#include "gcompris.h"
#include "gc_core.h"
#include <ctype.h>
#include <math.h>

Go to the source code of this file.

Defines

#define SOUNDLISTFILE   PACKAGE
#define BONUS_DURATION   2000
#define TUX_TIME_STEP   300
#define NUMBER_OF_GREETINGS   G_N_ELEMENTS(greetingsList)
#define NUMBER_OF_LOOSING   1
#define OFFSET   100

Functions

static void bonus_image (char *, BonusStatusList)
static void end_bonus (void)
static void end_gc_bonus_end_display ()
void gc_bonus_end_display (BoardFinishedList type)
void gc_bonus_display (BonusStatusList gamewon, BonusList bonus_id)

Variables

static GnomeCanvasGroup * bonus_group = NULL
static GnomeCanvasItem * door1_item = NULL
static GnomeCanvasItem * door2_item = NULL
static GnomeCanvasItem * tuxplane_item = NULL
static gboolean gc_bonus_end_display_running = FALSE
static gboolean bonus_display_running = FALSE
static gint end_bonus_id = 0
static gint gc_bonus_end_display_id = 0
static int left_door_limit = 0
static gchar * greetingsList []
static gchar * loosingList []

Define Documentation

#define BONUS_DURATION   2000

Definition at line 29 of file bonus.c.

#define NUMBER_OF_GREETINGS   G_N_ELEMENTS(greetingsList)

Definition at line 57 of file bonus.c.

#define NUMBER_OF_LOOSING   1

Definition at line 64 of file bonus.c.

#define OFFSET   100

Definition at line 112 of file bonus.c.

#define SOUNDLISTFILE   PACKAGE

Definition at line 28 of file bonus.c.

#define TUX_TIME_STEP   300

Definition at line 30 of file bonus.c.


Function Documentation

static void bonus_image ( char *  image,
BonusStatusList  gamewon 
) [static]

Definition at line 276 of file bonus.c.

{
  char *str= NULL;
  int x,y;
  GdkPixbuf *pixmap = NULL;
  GcomprisBoard *gcomprisBoard = gc_board_get_current();

  /* check that bonus_group is a singleton */
  if (bonus_group != NULL) {
    bonus_display_running = FALSE;
    return;
  }


  switch (gamewon) {
  case BOARD_WIN :
    str = g_strdup_printf("%s%s%s", "gcompris/bonus/",image,"_good.png");
    /* Record the end of board */
    gc_log_end (gcomprisBoard, GCOMPRIS_LOG_STATUS_PASSED);
    break;
  case BOARD_LOOSE :
    str = g_strdup_printf("%s%s%s", "gcompris/bonus/",image,"_bad.png");
    /* Record the end of board */
    gc_log_end (gcomprisBoard, GCOMPRIS_LOG_STATUS_FAILED);
    break;
  case BOARD_DRAW :
    /* We do not have draw image so a text message is displayed bellow under the
     * win image
     */
    str = g_strdup_printf("%s%s%s", "gcompris/bonus/",image,"_good.png");
    /* Record the end of board */
    gc_log_end (gcomprisBoard, GCOMPRIS_LOG_STATUS_DRAW);
    break;
  }

  /* Log the board start again*/
  gc_log_start(gcomprisBoard);

  g_assert(gcomprisBoard != NULL);

  pixmap = gc_pixmap_load(str);

  bonus_group = (GnomeCanvasGroup *) \
    gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
                        gnome_canvas_group_get_type (),
                        "x", (double)0,
                        "y", (double)0,
                        NULL);

  x = (gcomprisBoard->width - gdk_pixbuf_get_width(pixmap))/2;
  y = (gcomprisBoard->height - gdk_pixbuf_get_height(pixmap))/2;
  gnome_canvas_item_new (bonus_group,
                      gnome_canvas_pixbuf_get_type (),
                      "pixbuf", pixmap,
                      "x", (double) x,
                      "y", (double) y,
                      "width", (double) gdk_pixbuf_get_width(pixmap),
                      "height", (double) gdk_pixbuf_get_height(pixmap),
                      "width_set", TRUE,
                      "height_set", TRUE,
                      NULL);


  if(gamewon==BOARD_DRAW) {
    gnome_canvas_item_new (bonus_group,
                        gnome_canvas_text_get_type (),
                        "text", _("Drawn game"),
                        "font", gc_skin_font_title,
                        "x", (double) BOARDWIDTH/2 + 1.0,
                        "y", (double) gdk_pixbuf_get_height(pixmap) + 1.0,
                        "anchor", GTK_ANCHOR_CENTER,
                        "fill_color", "black",
                        NULL);
    gnome_canvas_item_new (bonus_group,
                        gnome_canvas_text_get_type (),
                        "text", _("Drawn game"),
                        "font", gc_skin_font_title,
                        "x", (double) BOARDWIDTH/2,
                        "y", (double) gdk_pixbuf_get_height(pixmap),
                        "anchor", GTK_ANCHOR_CENTER,
                        "fill_color_rgba", gc_skin_color_title,
                        NULL);
  }

  gdk_pixbuf_unref(pixmap);

  g_free(str);
  end_bonus_id = gtk_timeout_add (BONUS_DURATION, (GtkFunction) end_bonus, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void end_bonus ( void  ) [static]

Definition at line 368 of file bonus.c.

{
  if (end_bonus_id) {
    gtk_timeout_remove (end_bonus_id);
    end_bonus_id = 0;
  }

  if(bonus_group)
    gtk_object_destroy (GTK_OBJECT(bonus_group));

  bonus_group = NULL;
  bonus_display_running = FALSE;

  gc_bar_hide(FALSE);

  /* Re-Start the board */
  gc_board_pause(FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void end_gc_bonus_end_display ( ) [static]

Definition at line 76 of file bonus.c.

                           {
  double dx1, dy1, dx2, dy2;
  //end_board_count++;
  gnome_canvas_item_get_bounds(tuxplane_item,  &dx1, &dy1, &dx2, &dy2);
  // animates tuxplane
  if (/*end_board_count*/ dx2 +50.0 < (double) (left_door_limit)) {
    gnome_canvas_item_move(tuxplane_item, 50, 0);
    return;
  }

  if (gc_bonus_end_display_id) {
    gtk_timeout_remove(gc_bonus_end_display_id);
    gc_bonus_end_display_id = 0;
  }

  if(door1_item)
    gtk_object_destroy (GTK_OBJECT(door1_item));
  if(door2_item)
    gtk_object_destroy (GTK_OBJECT(door2_item));
  if(tuxplane_item)
    gtk_object_destroy (GTK_OBJECT(tuxplane_item));

  door1_item = NULL;
  door2_item = NULL;
  tuxplane_item = NULL;

  gc_bonus_end_display_running = FALSE;
  
  gc_bar_hide(FALSE);

  // go back to previous board layout
  if (gc_board_get_current_board_plugin()->end_board)
    gc_board_get_current_board_plugin()->end_board();
  gc_board_end();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_bonus_display ( BonusStatusList  gamewon,
BonusList  bonus_id 
)

Definition at line 213 of file bonus.c.

{
  gchar *absolute_file;

  g_assert(bonus_id < BONUS_LAST);

  gc_bar_hide(TRUE);

  if (bonus_display_running)
    return;
  else
    bonus_display_running = TRUE;
  
  if(gamewon == BOARD_WIN || gamewon == BOARD_DRAW) {
    absolute_file = gc_file_find_absolute(greetingsList[RAND(0, NUMBER_OF_GREETINGS-1)]);

    if (absolute_file)
      {
       gc_sound_play_ogg(absolute_file, NULL);
       g_free(absolute_file);
      }
    else
      gc_sound_play_ogg("sounds/wahoo.ogg", NULL);

  } else {
    absolute_file = gc_file_find_absolute(loosingList[RAND(0, NUMBER_OF_LOOSING-1)]);

    if (absolute_file)
      {
       gc_sound_play_ogg(absolute_file, NULL);
       g_free(absolute_file);
      }
    else
      gc_sound_play_ogg("sounds/crash.ogg", NULL);
  }

  /* First pause the board */
  gc_board_pause(TRUE);

  if(bonus_id==BONUS_RANDOM)
    bonus_id = RAND(1, BONUS_LAST-2);

  switch(bonus_id) {
  case BONUS_SMILEY :
    bonus_image("smiley",gamewon);
    break;
  case BONUS_FLOWER :
    bonus_image("flower",gamewon);
    break;
  case BONUS_TUX :
    bonus_image("tux",gamewon);
    break;
  case BONUS_GNU :
    bonus_image("gnu",gamewon);
    break;
  default :
    bonus_image("smiley",gamewon);
    break;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 114 of file bonus.c.

                                             {
  GcomprisBoard *gcomprisBoard = gc_board_get_current();

  int x,y;
  GdkPixbuf *pixmap_door1 = NULL,*pixmap_door2 = NULL,*pixmap_tuxplane = NULL;
  char * str = NULL;

  g_assert(type < BOARD_FINISHED_LAST);

  gc_bar_hide(TRUE);

  if (gc_bonus_end_display_running)
    return;
  else
    gc_bonus_end_display_running = TRUE;

  /* First pause the board */
  gc_board_pause(TRUE);

  /* WARNING: I remove 1 to the BOARD_FINISHED_LAST because RANDOM is for GOOD end only */
  if(type==BOARD_FINISHED_RANDOM)
    type = RAND(1,BOARD_FINISHED_LAST-2);

  /* Record the end of board */
  gc_log_end (gcomprisBoard, GCOMPRIS_LOG_STATUS_COMPLETED);

  switch (type) {
       case BOARD_FINISHED_TUXPLANE :
              str = g_strdup_printf("gcompris/misc/tuxplane.png");
              break;
       case BOARD_FINISHED_TUXLOCO :
              str = g_strdup_printf("gcompris/misc/tuxloco.png");
              break;
       case BOARD_FINISHED_TOOMANYERRORS :
              str = g_strdup_printf("gcompris/misc/toomanyerrors.png");
              break;
       default :
              str = g_strdup_printf("gcompris/misc/tuxplane.png");
              break;
  }

  pixmap_door1 = gc_pixmap_load("gcompris/misc/door1.png");
  pixmap_door2 = gc_pixmap_load("gcompris/misc/door2.png");
  pixmap_tuxplane = gc_pixmap_load(str);
  g_free(str);

  g_assert(gcomprisBoard != NULL);

  x = gcomprisBoard->width - OFFSET - gdk_pixbuf_get_width(pixmap_door1);
  y = OFFSET;
  left_door_limit = x + gdk_pixbuf_get_width(pixmap_door1);

  door1_item = gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
                                  gnome_canvas_pixbuf_get_type (),
                                  "pixbuf", pixmap_door1,
                                  "x", (double) x,
                                  "y", (double) y,
                                  "width", (double) gdk_pixbuf_get_width(pixmap_door1),
                                  "height", (double) gdk_pixbuf_get_height(pixmap_door1),
                                  "width_set", TRUE,
                                  "height_set", TRUE,
                                  NULL);

  x = OFFSET;
  y = (gcomprisBoard->height - gdk_pixbuf_get_height(pixmap_tuxplane)) /2;
  tuxplane_item = gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
                                  gnome_canvas_pixbuf_get_type (),
                                  "pixbuf", pixmap_tuxplane,
                                  "x", (double) x,
                                  "y", (double) y,
                                  "width", (double) gdk_pixbuf_get_width(pixmap_tuxplane),
                                  "height", (double) gdk_pixbuf_get_height(pixmap_tuxplane),
                                  "width_set", TRUE,
                                  "height_set", TRUE,
                                  NULL);

  x = gcomprisBoard->width - OFFSET - gdk_pixbuf_get_width(pixmap_door2);
  y = OFFSET;
  door2_item = gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
                                  gnome_canvas_pixbuf_get_type (),
                                  "pixbuf", pixmap_door2,
                                  "x", (double) x,
                                  "y", (double) y,
                                  "width", (double) gdk_pixbuf_get_width(pixmap_door2),
                                  "height", (double) gdk_pixbuf_get_height(pixmap_door2),
                                  "width_set", TRUE,
                                  "height_set", TRUE,
                                  NULL);

  gdk_pixbuf_unref(pixmap_door1);
  gdk_pixbuf_unref(pixmap_door2);
  gdk_pixbuf_unref(pixmap_tuxplane);

  gc_bonus_end_display_id = gtk_timeout_add (TUX_TIME_STEP, (GtkFunction) end_gc_bonus_end_display, NULL);

}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

gboolean bonus_display_running = FALSE [static]

Definition at line 38 of file bonus.c.

GnomeCanvasGroup* bonus_group = NULL [static]

Definition at line 32 of file bonus.c.

GnomeCanvasItem* door1_item = NULL [static]

Definition at line 33 of file bonus.c.

GnomeCanvasItem* door2_item = NULL [static]

Definition at line 34 of file bonus.c.

gint end_bonus_id = 0 [static]

Definition at line 40 of file bonus.c.

gint gc_bonus_end_display_id = 0 [static]

Definition at line 40 of file bonus.c.

gboolean gc_bonus_end_display_running = FALSE [static]

Definition at line 37 of file bonus.c.

gchar* greetingsList[] [static]
Initial value:
{
  "sounds/$LOCALE/misc/congratulation.ogg",
  "sounds/$LOCALE/misc/great.ogg",
  "sounds/$LOCALE/misc/good.ogg",
  "sounds/$LOCALE/misc/awesome.ogg",
  "sounds/$LOCALE/misc/fantastic.ogg",
  "sounds/$LOCALE/misc/waytogo.ogg",
  "sounds/$LOCALE/misc/super.ogg",
  "sounds/$LOCALE/misc/perfect.ogg"
}

Definition at line 46 of file bonus.c.

int left_door_limit = 0 [static]

Definition at line 43 of file bonus.c.

gchar* loosingList[] [static]
Initial value:
{
  "sounds/$LOCALE/misc/check_answer.ogg",
}

Definition at line 60 of file bonus.c.

GnomeCanvasItem* tuxplane_item = NULL [static]

Definition at line 35 of file bonus.c.