/* ===================================================================== * * =====================================================================*/ static GooCanvasItem *submarine_create_item(GooCanvasItem *parent) { GdkPixbuf *pixmap = NULL; GooCanvasItem *item = NULL; char s12[12]; int i; GooCanvasItem *rootItem = goo_canvas_group_new (parent, NULL); pixmap = gc_pixmap_load("submarine/submarine.png"); submarine_width = gdk_pixbuf_get_width(pixmap); submarine_height = gdk_pixbuf_get_height(pixmap); submarine_item = goo_canvas_image_new (rootItem, pixmap, 0, 0, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif pixmap = gc_pixmap_load("submarine/vanne.svg"); ballast_ar_purge_item = goo_canvas_image_new (rootItem, pixmap, PURGE_AR + schema_x, schema_y -1.0, NULL); g_signal_connect(ballast_ar_purge_item, "button-press-event", (GCallback) ballast_ar_purge_event, NULL); ballast_av_purge_item = goo_canvas_image_new (rootItem, pixmap, PURGE_AV + schema_x, schema_y -1.0, NULL); g_signal_connect(ballast_av_purge_item, "button-press-event", (GCallback) ballast_av_purge_event, NULL); regleur_purge_item = goo_canvas_image_new (rootItem, pixmap, REGLEUR + schema_x, schema_y -2.0, NULL); g_signal_connect(regleur_purge_item, "button-press-event", (GCallback) regleur_purge_event, NULL); item = goo_canvas_image_new (rootItem, pixmap, schema_x + CHASSE_BALLAST_AV_X, schema_y + CHASSE_BALLAST_AV_Y, NULL); g_signal_connect(item, "button-press-event", (GCallback) ballast_av_chasse_event, NULL); item = goo_canvas_image_new (rootItem, pixmap, schema_x + CHASSE_BALLAST_AR_X, schema_y + CHASSE_BALLAST_AR_Y, NULL); g_signal_connect(item, "button-press-event", (GCallback) ballast_ar_chasse_event, NULL); regleur_chasse_item = goo_canvas_image_new (rootItem, pixmap, schema_x + CHASSE_REGLEUR_X, schema_y + CHASSE_REGLEUR_Y, NULL); g_signal_connect(regleur_chasse_item, "button-press-event", (GCallback) regleur_chasse_event, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // DEPTH RUDDERS pixmap = gc_pixmap_load("submarine/rudder.png"); barre_av_item = goo_canvas_image_new (rootItem, pixmap, schema_x + BARRE_AV_X, schema_y + BARRE_AV_Y, NULL); barre_ar_item = goo_canvas_image_new (rootItem, pixmap, schema_x + BARRE_AR_X, schema_y + BARRE_AR_Y, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // displays the speed on the engine sprintf(s12,"%d",(int)submarine_horizontal_speed); speed_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + ENGINE_UP_X - ENGINE_DOWN_X +1, (gdouble) schema_y + ENGINE_UP_Y + 10 + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_BACK, NULL); speed_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + ENGINE_UP_X - ENGINE_DOWN_X, (gdouble) schema_y + ENGINE_UP_Y + 10, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the ballast_av_air value ballast_av_air_item_rect = goo_canvas_rect_new (rootItem, schema_x + BALLAST_AV_AIR_X1, schema_y + BALLAST_AV_AIR_Y1 + BALLAST_AV_AIR_H, BALLAST_AV_AIR_W, BALLAST_AV_AIR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d",(int)ballast_av_air); ballast_av_air_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BALLAST_AV_AIR_TEXT_X + 1, (gdouble) schema_y + BALLAST_AV_AIR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); ballast_av_air_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BALLAST_AV_AIR_TEXT_X, (gdouble) schema_y + BALLAST_AV_AIR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setBallastAV(ballast_av_air); // displays the ballast_ar_air value ballast_ar_air_item_rect = goo_canvas_rect_new (rootItem, schema_x + BALLAST_AR_AIR_X1, schema_y + BALLAST_AR_AIR_Y1 + BALLAST_AR_AIR_H, BALLAST_AR_AIR_W, BALLAST_AR_AIR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d",(int)ballast_ar_air); ballast_ar_air_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BALLAST_AR_AIR_TEXT_X + 1, (gdouble) schema_y + BALLAST_AR_AIR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); ballast_ar_air_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BALLAST_AR_AIR_TEXT_X, (gdouble) schema_y + BALLAST_AR_AIR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setBallastAR(ballast_ar_air); // displays the remaining air value sprintf(s12,"%d", (int)air); air_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + AIR_X +1, (gdouble) schema_y + AIR_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); air_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + AIR_X, (gdouble) schema_y + AIR_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the remaining battery value sprintf(s12,"%d", (int)battery); battery_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BATTERY_X +1, (gdouble) schema_y + BATTERY_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_BACK, NULL); battery_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BATTERY_X, (gdouble) schema_y + BATTERY_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the remaining regleur value regleur_item_rect = goo_canvas_rect_new (rootItem, schema_x + REGLEUR_X1, schema_y + REGLEUR_Y1 + REGLEUR_H, REGLEUR_W, REGLEUR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d", (int)regleur); regleur_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + REGLEUR_TEXT_X +1, (gdouble) schema_y + REGLEUR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); regleur_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + REGLEUR_TEXT_X, (gdouble) schema_y + REGLEUR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setRegleur(regleur); // displays an alert when some parameters are bad pixmap = gc_pixmap_load("submarine/alert_submarine.png"); alert_submarine = goo_canvas_image_new (rootItem, pixmap, ALERT_SUBMARINE_X, ALERT_SUBMARINE_Y, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif g_object_set (alert_submarine, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); // when the submarine makes some bubbles ... pixmap = gc_pixmap_load("submarine/bubbling.png"); for (i=0; i<3; i++) { bubbling[i] = goo_canvas_image_new (rootItem, pixmap, 0, 0, NULL); g_object_set (bubbling[i], "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); } #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // whale item switch(gcomprisBoard->level) { case 1: whale_x = 50; whale_y = MAX_DEPTH - 100; break; case 2: whale_x = 150; whale_y = MAX_DEPTH - 100; break; case 3: whale_x = 250; whale_y = MAX_DEPTH - 100; break; default: whale_x = 380; whale_y = MAX_DEPTH - 100; break; } pixmap = gc_pixmap_load("submarine/whale.png"); whale = goo_canvas_image_new (rootItem, pixmap, whale_x, whale_y, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // whale being hit pixmap = gc_pixmap_load("submarine/whale_hit.png"); big_explosion = goo_canvas_image_new (rootItem, pixmap, whale_x, whale_y, NULL); g_object_set (big_explosion, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // treasure item pixmap = gc_pixmap_load("submarine/crown.png"); treasure_x = (BOARDWIDTH*3)/4; treasure_y = MAX_DEPTH; treasure = goo_canvas_image_new (rootItem, pixmap, 0, 0, NULL); goo_canvas_item_translate(treasure, treasure_x, 0); goo_canvas_item_animate(treasure, treasure_x, treasure_y, 0.6, 0, TRUE, 6*1000, 40, GOO_CANVAS_ANIMATE_FREEZE); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // the triggers for air compressor and battery charger pixmap = gc_pixmap_load("submarine/manette.png"); air_compressor_item = goo_canvas_image_new (rootItem, pixmap, schema_x + AIR_TRIGGER_X, schema_y + AIR_TRIGGER_Y, NULL); battery_charger_item = goo_canvas_image_new (rootItem, pixmap, schema_x + BATTERY_TRIGGER_X, schema_y + BATTERY_TRIGGER_Y, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif g_signal_connect(air_compressor_item, "button-press-event", (GCallback) air_compressor_event, NULL); g_signal_connect(battery_charger_item, "button-press-event", (GCallback) battery_charger_event, NULL); /* * Set the right wall * ------------------ */ switch(gcomprisBoard->level) { case 1: gate_top_y = 80; gate_bottom_y = schema_y - 100; break; case 2: gate_top_y = 100; gate_bottom_y = schema_y - 120; break; default: gate_top_y = 120; gate_bottom_y = schema_y - 120; break; } /* At startup, the gate is closed */ gate_top_current_y = gate_bottom_y; top_gate_item = goo_canvas_rect_new (rootItem, BOARDWIDTH - 25, 40, 27, gate_top_current_y - 40, "fill_color_rgba", 0x989677FF, "stroke-color", "black", "line-width", 2.0, NULL); goo_canvas_rect_new (rootItem, BOARDWIDTH - 25, gate_bottom_y, 27, schema_y - gate_bottom_y, "fill_color_rgba", 0x989677FF, "stroke-color", "black", "line-width", 2.0, NULL); timer_id = g_timeout_add(UPDATE_DELAY, update_timeout, NULL); timer_slow_id = g_timeout_add(UPDATE_DELAY_SLOW, update_timeout_slow, NULL); timer_very_slow_id = g_timeout_add(UPDATE_DELAY_VERY_SLOW, update_timeout_very_slow, NULL); return rootItem; }
/* ===================================================================== * Periodically recalculate the submarine parameters * =====================================================================*/ static gboolean update_timeout() { gdouble delta_air; gboolean regleur_dirty = FALSE; gboolean air_dirty = FALSE; if(!boardRootItem) return FALSE; if(board_paused) return TRUE; /* air in ballasts */ if (ballast_av_purge_open) { ballast_av_air -= UPDATE_DELAY/1000.0 *500.0; // 500 liters go out per second if (ballast_av_air < 0.0) ballast_av_air = 0.0; setBallastAV(ballast_av_air); } if (ballast_ar_purge_open) { ballast_ar_air -= UPDATE_DELAY/1000.0 *500.0; if (ballast_ar_air < 0.0) ballast_ar_air = 0.0; setBallastAR(ballast_ar_air); } if (ballast_av_chasse_open && air>0.0) { delta_air = UPDATE_DELAY/1000.0 *500.0; // 200 liters are injected each second ballast_av_air += delta_air; air -= delta_air; if (air<0.0) air = 0.0; if (ballast_av_air > MAX_BALLAST) ballast_av_air = MAX_BALLAST; air_dirty = TRUE; setBallastAV(ballast_av_air); } if (ballast_ar_chasse_open && air>0.0) { delta_air = UPDATE_DELAY/1000.0 *500.0; ballast_ar_air += delta_air; air -= delta_air; if (air<0.0) air = 0.0; if (ballast_ar_air > MAX_BALLAST) ballast_ar_air = MAX_BALLAST; air_dirty = TRUE; setBallastAR(ballast_ar_air); } if (air_dirty) setAir(air); /* air in "regleur" (small ballast to finely balance the submarine) */ if (regleur_purge_open) { regleur += UPDATE_DELAY/1000.0 *50.0; // 100 liters enter per second if (regleur > MAX_REGLEUR) regleur = MAX_REGLEUR; regleur_dirty = TRUE; } if (regleur_chasse_open && air>0.0 && regleur > 0.0) { delta_air = UPDATE_DELAY/1000.0 *50.0; // 50 liters are injected each second regleur -= delta_air; air -= delta_air; if (air<0.0) air = 0.0; if (regleur < 0.0) regleur = 0.0; regleur_dirty = TRUE; setAir(air); } if (regleur_dirty) setRegleur(regleur); return TRUE; }
/* ===================================================================== * * =====================================================================*/ static GooCanvasItem *submarine_create_item(GooCanvasItem *parent) { GdkPixbuf *pixmap = NULL; char s12[12]; int i, w, h; boardRootItem = \ goo_canvas_group_new (goo_canvas_get_root_item(gcomprisBoard->canvas), NULL); pixmap = gc_pixmap_load("submarine/submarine.png"); submarine_width = gdk_pixbuf_get_width(pixmap); submarine_height = gdk_pixbuf_get_height(pixmap); submarine_item = goo_canvas_image_new (boardRootItem, pixmap, 0,//SUBMARINE_INITIAL_X, 0,//SUBMARINE_INITIAL_DEPTH + SURFACE_IN_BACKGROUND - submarine_height, NULL); gdk_pixbuf_unref(pixmap); pixmap = gc_pixmap_load("submarine/sub_schema.png"); w = gdk_pixbuf_get_width(pixmap); h = gdk_pixbuf_get_height(pixmap); schema_x = (BOARDWIDTH - w)/2 ; schema_y = BOARDHEIGHT - h; goo_canvas_image_new (boardRootItem, pixmap, schema_x, schema_y, NULL); gdk_pixbuf_unref(pixmap); pixmap = gc_pixmap_load("submarine/vanne.png"); ballast_ar_purge_item = goo_canvas_image_new (boardRootItem, pixmap, PURGE_AR + schema_x, schema_y -1.0, NULL); g_signal_connect(ballast_ar_purge_item, "button-press-event", (GtkSignalFunc) ballast_ar_purge_event, NULL); ballast_av_purge_item = goo_canvas_image_new (boardRootItem, pixmap, PURGE_AV + schema_x, schema_y -1.0, NULL); g_signal_connect(ballast_av_purge_item, "button-press-event", (GtkSignalFunc) ballast_av_purge_event, NULL); regleur_purge_item = goo_canvas_image_new (boardRootItem, pixmap, REGLEUR + schema_x, schema_y -2.0, NULL); g_signal_connect(regleur_purge_item, "button-press-event", (GtkSignalFunc) regleur_purge_event, NULL); ballast_av_chasse_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + CHASSE_BALLAST_AV_X, schema_y + CHASSE_BALLAST_AV_Y, NULL); g_signal_connect(ballast_av_chasse_item, "button-press-event", (GtkSignalFunc) ballast_av_chasse_event, NULL); ballast_ar_chasse_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + CHASSE_BALLAST_AR_X, schema_y + CHASSE_BALLAST_AR_Y, NULL); g_signal_connect(ballast_ar_chasse_item, "button-press-event", (GtkSignalFunc) ballast_ar_chasse_event, NULL); regleur_chasse_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + CHASSE_REGLEUR_X, schema_y + CHASSE_REGLEUR_Y, NULL); g_signal_connect(regleur_chasse_item, "button-press-event", (GtkSignalFunc) regleur_chasse_event, NULL); gdk_pixbuf_unref(pixmap); // DEPTH RUDDERS pixmap = gc_pixmap_load("submarine/rudder.png"); w = gdk_pixbuf_get_width(pixmap); h = gdk_pixbuf_get_height(pixmap); barre_av_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AV_X, schema_y + BARRE_AV_Y, NULL); barre_ar_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AR_X, schema_y + BARRE_AR_Y, NULL); gdk_pixbuf_unref(pixmap); #define COMMAND_OFFSET 20.0 pixmap = gc_pixmap_load("submarine/up.png"); int w2 = gdk_pixbuf_get_width(pixmap); barre_av_up_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AV_X + w - w2, schema_y + BARRE_AV_Y - COMMAND_OFFSET, NULL); barre_ar_up_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AR_X + w - w2, schema_y + BARRE_AR_Y - COMMAND_OFFSET, NULL); engine_up_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + ENGINE_UP_X, schema_y + ENGINE_UP_Y, NULL); gdk_pixbuf_unref(pixmap); pixmap = gc_pixmap_load("submarine/down.png"); barre_av_down_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AV_X + w - w2, schema_y + BARRE_AV_Y + COMMAND_OFFSET, NULL); barre_ar_down_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AR_X + w - w2, schema_y + BARRE_AR_Y + COMMAND_OFFSET, NULL); engine_down_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + ENGINE_DOWN_X, schema_y + ENGINE_DOWN_Y, NULL); gdk_pixbuf_unref(pixmap); g_signal_connect(barre_av_up_item, "button-press-event", (GtkSignalFunc) barre_av_event, GINT_TO_POINTER(UP)); g_signal_connect(barre_ar_up_item, "button-press-event", (GtkSignalFunc) barre_ar_event, GINT_TO_POINTER(UP)); g_signal_connect(barre_av_down_item, "button-press-event", (GtkSignalFunc) barre_av_event, GINT_TO_POINTER(DOWN)); g_signal_connect(barre_ar_down_item, "button-press-event", (GtkSignalFunc) barre_ar_event, GINT_TO_POINTER(DOWN)); g_signal_connect(engine_up_item, "button-press-event", (GtkSignalFunc) engine_event, GINT_TO_POINTER(UP)); g_signal_connect(engine_down_item, "button-press-event", (GtkSignalFunc) engine_event, GINT_TO_POINTER(DOWN)); // displays the speed on the engine sprintf(s12,"%d",(int)submarine_horizontal_speed); speed_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + ENGINE_UP_X - ENGINE_DOWN_X +1, (gdouble) schema_y + ENGINE_UP_Y + 10 + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_BACK, NULL); speed_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + ENGINE_UP_X - ENGINE_DOWN_X, (gdouble) schema_y + ENGINE_UP_Y + 10, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the ballast_av_air value ballast_av_air_item_rect = goo_canvas_rect_new (boardRootItem, schema_x + BALLAST_AV_AIR_X1, schema_y + BALLAST_AV_AIR_Y1 + BALLAST_AV_AIR_H, BALLAST_AV_AIR_W, BALLAST_AV_AIR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d",(int)ballast_av_air); ballast_av_air_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BALLAST_AV_AIR_TEXT_X + 1, (gdouble) schema_y + BALLAST_AV_AIR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); ballast_av_air_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BALLAST_AV_AIR_TEXT_X, (gdouble) schema_y + BALLAST_AV_AIR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setBallastAV(ballast_av_air); // displays the ballast_ar_air value ballast_ar_air_item_rect = goo_canvas_rect_new (boardRootItem, schema_x + BALLAST_AR_AIR_X1, schema_y + BALLAST_AR_AIR_Y1 + BALLAST_AR_AIR_H, BALLAST_AR_AIR_W, BALLAST_AR_AIR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d",(int)ballast_ar_air); ballast_ar_air_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BALLAST_AR_AIR_TEXT_X + 1, (gdouble) schema_y + BALLAST_AR_AIR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); ballast_ar_air_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BALLAST_AR_AIR_TEXT_X, (gdouble) schema_y + BALLAST_AR_AIR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setBallastAR(ballast_ar_air); // displays the remaining air value sprintf(s12,"%d", (int)air); air_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + AIR_X +1, (gdouble) schema_y + AIR_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); air_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + AIR_X, (gdouble) schema_y + AIR_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the remaining battery value sprintf(s12,"%d", (int)battery); battery_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BATTERY_X +1, (gdouble) schema_y + BATTERY_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_BACK, NULL); battery_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BATTERY_X, (gdouble) schema_y + BATTERY_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the remaining regleur value regleur_item_rect = goo_canvas_rect_new (boardRootItem, schema_x + REGLEUR_X1, schema_y + REGLEUR_Y1 + REGLEUR_H, REGLEUR_W, REGLEUR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d", (int)regleur); regleur_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + REGLEUR_TEXT_X +1, (gdouble) schema_y + REGLEUR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); regleur_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + REGLEUR_TEXT_X, (gdouble) schema_y + REGLEUR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setRegleur(regleur); // displays an alert when some parameters are bad pixmap = gc_pixmap_load("submarine/alert_submarine.png"); w = gdk_pixbuf_get_width(pixmap); h = gdk_pixbuf_get_height(pixmap); alert_submarine = goo_canvas_image_new (boardRootItem, pixmap, ALERT_SUBMARINE_X, ALERT_SUBMARINE_Y, NULL); gdk_pixbuf_unref(pixmap); g_object_set (alert_submarine, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); // when the submarine makes some bubbles ... pixmap = gc_pixmap_load("submarine/bubbling.png"); for (i=0; i<3; i++) { bubbling[i] = goo_canvas_image_new (boardRootItem, pixmap, 0, 0, NULL); g_object_set (bubbling[i], "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); } gdk_pixbuf_unref(pixmap); // whale item pixmap = gc_pixmap_load("submarine/whale.png"); whale_x = g_random_int_range((int)(BOARDWIDTH/4), (int)(BOARDWIDTH/2)); whale_y = g_random_int_range((int)(SURFACE_IN_BACKGROUND + gdk_pixbuf_get_height(pixmap)*2), (int)MAX_DEPTH); whale = goo_canvas_image_new (boardRootItem, pixmap, whale_x, whale_y, NULL); gdk_pixbuf_unref(pixmap); // whale being hit pixmap = gc_pixmap_load("submarine/whale_hit.png"); big_explosion = goo_canvas_image_new (boardRootItem, pixmap, whale_x, whale_y, NULL); g_object_set (big_explosion, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); gdk_pixbuf_unref(pixmap); // treasure item pixmap = gc_pixmap_load("submarine/crown.png"); treasure_x = (BOARDWIDTH*3)/4; treasure_y = MAX_DEPTH; treasure = goo_canvas_image_new (boardRootItem, pixmap, 0, 0, NULL); goo_canvas_item_translate(treasure, treasure_x, 0); goo_canvas_item_animate(treasure, treasure_x, treasure_y, 0.6, 0, TRUE, 6*1000, 40, GOO_CANVAS_ANIMATE_FREEZE); gdk_pixbuf_unref(pixmap); // the triggers for air compressor and battery charger pixmap = gc_pixmap_load("submarine/manette.png"); air_compressor_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + AIR_TRIGGER_X, schema_y + AIR_TRIGGER_Y, NULL); battery_charger_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BATTERY_TRIGGER_X, schema_y + BATTERY_TRIGGER_Y, NULL); gdk_pixbuf_unref(pixmap); g_signal_connect(air_compressor_item, "button-press-event", (GtkSignalFunc) air_compressor_event, NULL); g_signal_connect(battery_charger_item, "button-press-event", (GtkSignalFunc) battery_charger_event, NULL); // the antisubmarine warfare frigate pixmap = gc_pixmap_load("submarine/asw_frigate.png"); w = gdk_pixbuf_get_width(pixmap); frigate_item = goo_canvas_image_new (boardRootItem, pixmap, 0, 0, NULL); goo_canvas_item_translate(frigate_item, BOARDWIDTH, 2); goo_canvas_item_animate(frigate_item, -w, 2.0, 1, 0, TRUE, 30*1000, 40, GOO_CANVAS_ANIMATE_RESTART); gdk_pixbuf_unref(pixmap); /* * Set the right wall * ------------------ */ switch(gcomprisBoard->level) { case 1: gate_top_y = 80; gate_bottom_y = schema_y - 100; break; case 2: gate_top_y = 100; gate_bottom_y = schema_y - 120; break; default: gate_top_y = 120; gate_bottom_y = schema_y - 120; break; } /* At startup, the gate is closed */ gate_top_current_y = gate_bottom_y; top_gate_item = goo_canvas_rect_new (boardRootItem, BOARDWIDTH - 25, 40, 27, gate_top_current_y - 40, "fill_color_rgba", 0x989677FF, "stroke-color", "black", "line-width", 2.0, NULL); goo_canvas_rect_new (boardRootItem, BOARDWIDTH - 25, gate_bottom_y, 27, schema_y - gate_bottom_y, "fill_color_rgba", 0x989677FF, "stroke-color", "black", "line-width", 2.0, NULL); timer_id = g_timeout_add(UPDATE_DELAY, update_timeout, NULL); timer_slow_id = g_timeout_add(UPDATE_DELAY_SLOW, update_timeout_slow, NULL); timer_very_slow_id = g_timeout_add(UPDATE_DELAY_VERY_SLOW, update_timeout_very_slow, NULL); return NULL; }